Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson AB 2010 |
sjur.brandeland@stericsson.com | 26ee65e | 2013-04-22 23:57:01 +0000 | [diff] [blame] | 3 | * Author: Sjur Brendeland |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 4 | * License terms: GNU General Public License (GPL) version 2 |
| 5 | */ |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 6 | |
| 7 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__ |
| 8 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | #include <linux/stddef.h> |
Stephen Rothwell | 6c57990 | 2010-04-01 00:28:49 -0700 | [diff] [blame] | 11 | #include <linux/slab.h> |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 12 | #include <linux/netdevice.h> |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 13 | #include <linux/module.h> |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 14 | #include <net/caif/caif_layer.h> |
| 15 | #include <net/caif/cfpkt.h> |
| 16 | #include <net/caif/cfcnfg.h> |
| 17 | #include <net/caif/cfctrl.h> |
| 18 | #include <net/caif/cfmuxl.h> |
| 19 | #include <net/caif/cffrml.h> |
| 20 | #include <net/caif/cfserl.h> |
| 21 | #include <net/caif/cfsrvl.h> |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 22 | #include <net/caif/caif_dev.h> |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 23 | |
| 24 | #define container_obj(layr) container_of(layr, struct cfcnfg, layer) |
| 25 | |
| 26 | /* Information about CAIF physical interfaces held by Config Module in order |
| 27 | * to manage physical interfaces |
| 28 | */ |
| 29 | struct cfcnfg_phyinfo { |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 30 | struct list_head node; |
| 31 | bool up; |
| 32 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 33 | /* Pointer to the layer below the MUX (framing layer) */ |
| 34 | struct cflayer *frm_layer; |
| 35 | /* Pointer to the lowest actual physical layer */ |
| 36 | struct cflayer *phy_layer; |
| 37 | /* Unique identifier of the physical interface */ |
| 38 | unsigned int id; |
| 39 | /* Preference of the physical in interface */ |
| 40 | enum cfcnfg_phy_preference pref; |
| 41 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 42 | /* Information about the physical device */ |
| 43 | struct dev_info dev_info; |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 44 | |
| 45 | /* Interface index */ |
| 46 | int ifindex; |
| 47 | |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 48 | /* Protocol head room added for CAIF link layer */ |
| 49 | int head_room; |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 50 | |
| 51 | /* Use Start of frame checksum */ |
| 52 | bool use_fcs; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct cfcnfg { |
| 56 | struct cflayer layer; |
| 57 | struct cflayer *ctrl; |
| 58 | struct cflayer *mux; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 59 | struct list_head phys; |
| 60 | struct mutex lock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 63 | static void cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, |
Silviu-Mihai Popescu | 3bffc47 | 2013-03-06 19:39:57 +0000 | [diff] [blame] | 64 | enum cfctrl_srv serv, u8 phyid, |
| 65 | struct cflayer *adapt_layer); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 66 | static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id); |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 67 | static void cfcnfg_reject_rsp(struct cflayer *layer, u8 channel_id, |
Silviu-Mihai Popescu | 3bffc47 | 2013-03-06 19:39:57 +0000 | [diff] [blame] | 68 | struct cflayer *adapt_layer); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 69 | static void cfctrl_resp_func(void); |
| 70 | static void cfctrl_enum_resp(void); |
| 71 | |
| 72 | struct cfcnfg *cfcnfg_create(void) |
| 73 | { |
| 74 | struct cfcnfg *this; |
| 75 | struct cfctrl_rsp *resp; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 76 | |
| 77 | might_sleep(); |
| 78 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 79 | /* Initiate this layer */ |
Julia Lawall | 49afa55 | 2010-05-13 10:03:32 +0000 | [diff] [blame] | 80 | this = kzalloc(sizeof(struct cfcnfg), GFP_ATOMIC); |
Joe Perches | 7ac2ed0 | 2011-08-25 13:22:24 +0000 | [diff] [blame] | 81 | if (!this) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 82 | return NULL; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 83 | this->mux = cfmuxl_create(); |
| 84 | if (!this->mux) |
| 85 | goto out_of_mem; |
| 86 | this->ctrl = cfctrl_create(); |
| 87 | if (!this->ctrl) |
| 88 | goto out_of_mem; |
| 89 | /* Initiate response functions */ |
| 90 | resp = cfctrl_get_respfuncs(this->ctrl); |
| 91 | resp->enum_rsp = cfctrl_enum_resp; |
| 92 | resp->linkerror_ind = cfctrl_resp_func; |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 93 | resp->linkdestroy_rsp = cfcnfg_linkdestroy_rsp; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 94 | resp->sleep_rsp = cfctrl_resp_func; |
| 95 | resp->wake_rsp = cfctrl_resp_func; |
| 96 | resp->restart_rsp = cfctrl_resp_func; |
| 97 | resp->radioset_rsp = cfctrl_resp_func; |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 98 | resp->linksetup_rsp = cfcnfg_linkup_rsp; |
| 99 | resp->reject_rsp = cfcnfg_reject_rsp; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 100 | INIT_LIST_HEAD(&this->phys); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 101 | |
| 102 | cfmuxl_set_uplayer(this->mux, this->ctrl, 0); |
| 103 | layer_set_dn(this->ctrl, this->mux); |
| 104 | layer_set_up(this->ctrl, this); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 105 | mutex_init(&this->lock); |
| 106 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 107 | return this; |
| 108 | out_of_mem: |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 109 | synchronize_rcu(); |
| 110 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 111 | kfree(this->mux); |
| 112 | kfree(this->ctrl); |
| 113 | kfree(this); |
| 114 | return NULL; |
| 115 | } |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 116 | |
| 117 | void cfcnfg_remove(struct cfcnfg *cfg) |
| 118 | { |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 119 | might_sleep(); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 120 | if (cfg) { |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 121 | synchronize_rcu(); |
| 122 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 123 | kfree(cfg->mux); |
sjur.brandeland@stericsson.com | c85c295 | 2011-05-13 02:44:06 +0000 | [diff] [blame] | 124 | cfctrl_remove(cfg->ctrl); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 125 | kfree(cfg); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | static void cfctrl_resp_func(void) |
| 130 | { |
| 131 | } |
| 132 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 133 | static struct cfcnfg_phyinfo *cfcnfg_get_phyinfo_rcu(struct cfcnfg *cnfg, |
Silviu-Mihai Popescu | 3bffc47 | 2013-03-06 19:39:57 +0000 | [diff] [blame] | 134 | u8 phyid) |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 135 | { |
| 136 | struct cfcnfg_phyinfo *phy; |
| 137 | |
| 138 | list_for_each_entry_rcu(phy, &cnfg->phys, node) |
| 139 | if (phy->id == phyid) |
| 140 | return phy; |
| 141 | return NULL; |
| 142 | } |
| 143 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 144 | static void cfctrl_enum_resp(void) |
| 145 | { |
| 146 | } |
| 147 | |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 148 | static struct dev_info *cfcnfg_get_phyid(struct cfcnfg *cnfg, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 149 | enum cfcnfg_phy_preference phy_pref) |
| 150 | { |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 151 | /* Try to match with specified preference */ |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 152 | struct cfcnfg_phyinfo *phy; |
| 153 | |
| 154 | list_for_each_entry_rcu(phy, &cnfg->phys, node) { |
| 155 | if (phy->up && phy->pref == phy_pref && |
| 156 | phy->frm_layer != NULL) |
| 157 | |
| 158 | return &phy->dev_info; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 159 | } |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 160 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 161 | /* Otherwise just return something */ |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 162 | list_for_each_entry_rcu(phy, &cnfg->phys, node) |
| 163 | if (phy->up) |
| 164 | return &phy->dev_info; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 165 | |
| 166 | return NULL; |
| 167 | } |
| 168 | |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 169 | static int cfcnfg_get_id_from_ifi(struct cfcnfg *cnfg, int ifi) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 170 | { |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 171 | struct cfcnfg_phyinfo *phy; |
| 172 | |
| 173 | list_for_each_entry_rcu(phy, &cnfg->phys, node) |
| 174 | if (phy->ifindex == ifi && phy->up) |
| 175 | return phy->id; |
André Carvalho de Matos | f2527ec | 2010-11-01 11:52:47 +0000 | [diff] [blame] | 176 | return -ENODEV; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 177 | } |
| 178 | |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 179 | int caif_disconnect_client(struct net *net, struct cflayer *adap_layer) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 180 | { |
sjur.brandeland@stericsson.com | 54e90fb | 2011-05-22 11:18:51 +0000 | [diff] [blame] | 181 | u8 channel_id; |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 182 | struct cfcnfg *cfg = get_cfcnfg(net); |
Dan Carpenter | 01a8590 | 2011-01-15 03:06:39 +0000 | [diff] [blame] | 183 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 184 | caif_assert(adap_layer != NULL); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 185 | cfctrl_cancel_req(cfg->ctrl, adap_layer); |
sjur.brandeland@stericsson.com | 54e90fb | 2011-05-22 11:18:51 +0000 | [diff] [blame] | 186 | channel_id = adap_layer->id; |
| 187 | if (channel_id != 0) { |
| 188 | struct cflayer *servl; |
| 189 | servl = cfmuxl_remove_uplayer(cfg->mux, channel_id); |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 190 | cfctrl_linkdown_req(cfg->ctrl, channel_id, adap_layer); |
sjur.brandeland@stericsson.com | 54e90fb | 2011-05-22 11:18:51 +0000 | [diff] [blame] | 191 | if (servl != NULL) |
| 192 | layer_set_up(servl, NULL); |
| 193 | } else |
| 194 | pr_debug("nothing to disconnect\n"); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 195 | |
| 196 | /* Do RCU sync before initiating cleanup */ |
| 197 | synchronize_rcu(); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 198 | if (adap_layer->ctrlcmd != NULL) |
| 199 | adap_layer->ctrlcmd(adap_layer, CAIF_CTRLCMD_DEINIT_RSP, 0); |
sjur.brandeland@stericsson.com | 54e90fb | 2011-05-22 11:18:51 +0000 | [diff] [blame] | 200 | return 0; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 201 | |
| 202 | } |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 203 | EXPORT_SYMBOL(caif_disconnect_client); |
Sjur Braendeland | 5b20865 | 2010-04-28 08:54:36 +0000 | [diff] [blame] | 204 | |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 205 | static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 206 | { |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Stephen Hemminger | 73d6ac6 | 2011-04-11 10:43:50 +0000 | [diff] [blame] | 209 | static const int protohead[CFCTRL_SRV_MASK] = { |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 210 | [CFCTRL_SRV_VEI] = 4, |
| 211 | [CFCTRL_SRV_DATAGRAM] = 7, |
| 212 | [CFCTRL_SRV_UTIL] = 4, |
| 213 | [CFCTRL_SRV_RFM] = 3, |
| 214 | [CFCTRL_SRV_DBG] = 3, |
| 215 | }; |
| 216 | |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 217 | |
| 218 | static int caif_connect_req_to_link_param(struct cfcnfg *cnfg, |
Silviu-Mihai Popescu | 3bffc47 | 2013-03-06 19:39:57 +0000 | [diff] [blame] | 219 | struct caif_connect_request *s, |
| 220 | struct cfctrl_link_param *l) |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 221 | { |
| 222 | struct dev_info *dev_info; |
| 223 | enum cfcnfg_phy_preference pref; |
| 224 | int res; |
| 225 | |
| 226 | memset(l, 0, sizeof(*l)); |
| 227 | /* In caif protocol low value is high priority */ |
| 228 | l->priority = CAIF_PRIO_MAX - s->priority + 1; |
| 229 | |
| 230 | if (s->ifindex != 0) { |
| 231 | res = cfcnfg_get_id_from_ifi(cnfg, s->ifindex); |
| 232 | if (res < 0) |
| 233 | return res; |
| 234 | l->phyid = res; |
| 235 | } else { |
| 236 | switch (s->link_selector) { |
| 237 | case CAIF_LINK_HIGH_BANDW: |
| 238 | pref = CFPHYPREF_HIGH_BW; |
| 239 | break; |
| 240 | case CAIF_LINK_LOW_LATENCY: |
| 241 | pref = CFPHYPREF_LOW_LAT; |
| 242 | break; |
| 243 | default: |
| 244 | return -EINVAL; |
| 245 | } |
| 246 | dev_info = cfcnfg_get_phyid(cnfg, pref); |
| 247 | if (dev_info == NULL) |
| 248 | return -ENODEV; |
| 249 | l->phyid = dev_info->id; |
| 250 | } |
| 251 | switch (s->protocol) { |
| 252 | case CAIFPROTO_AT: |
| 253 | l->linktype = CFCTRL_SRV_VEI; |
| 254 | l->endpoint = (s->sockaddr.u.at.type >> 2) & 0x3; |
| 255 | l->chtype = s->sockaddr.u.at.type & 0x3; |
| 256 | break; |
| 257 | case CAIFPROTO_DATAGRAM: |
| 258 | l->linktype = CFCTRL_SRV_DATAGRAM; |
| 259 | l->chtype = 0x00; |
| 260 | l->u.datagram.connid = s->sockaddr.u.dgm.connection_id; |
| 261 | break; |
| 262 | case CAIFPROTO_DATAGRAM_LOOP: |
| 263 | l->linktype = CFCTRL_SRV_DATAGRAM; |
| 264 | l->chtype = 0x03; |
| 265 | l->endpoint = 0x00; |
| 266 | l->u.datagram.connid = s->sockaddr.u.dgm.connection_id; |
| 267 | break; |
| 268 | case CAIFPROTO_RFM: |
| 269 | l->linktype = CFCTRL_SRV_RFM; |
| 270 | l->u.datagram.connid = s->sockaddr.u.rfm.connection_id; |
| 271 | strncpy(l->u.rfm.volume, s->sockaddr.u.rfm.volume, |
| 272 | sizeof(l->u.rfm.volume)-1); |
| 273 | l->u.rfm.volume[sizeof(l->u.rfm.volume)-1] = 0; |
| 274 | break; |
| 275 | case CAIFPROTO_UTIL: |
| 276 | l->linktype = CFCTRL_SRV_UTIL; |
| 277 | l->endpoint = 0x00; |
| 278 | l->chtype = 0x00; |
| 279 | strncpy(l->u.utility.name, s->sockaddr.u.util.service, |
| 280 | sizeof(l->u.utility.name)-1); |
| 281 | l->u.utility.name[sizeof(l->u.utility.name)-1] = 0; |
| 282 | caif_assert(sizeof(l->u.utility.name) > 10); |
| 283 | l->u.utility.paramlen = s->param.size; |
| 284 | if (l->u.utility.paramlen > sizeof(l->u.utility.params)) |
| 285 | l->u.utility.paramlen = sizeof(l->u.utility.params); |
| 286 | |
| 287 | memcpy(l->u.utility.params, s->param.data, |
| 288 | l->u.utility.paramlen); |
| 289 | |
| 290 | break; |
| 291 | case CAIFPROTO_DEBUG: |
| 292 | l->linktype = CFCTRL_SRV_DBG; |
| 293 | l->endpoint = s->sockaddr.u.dbg.service; |
| 294 | l->chtype = s->sockaddr.u.dbg.type; |
| 295 | break; |
| 296 | default: |
| 297 | return -EINVAL; |
| 298 | } |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | int caif_connect_client(struct net *net, struct caif_connect_request *conn_req, |
| 303 | struct cflayer *adap_layer, int *ifindex, |
Silviu-Mihai Popescu | 3bffc47 | 2013-03-06 19:39:57 +0000 | [diff] [blame] | 304 | int *proto_head, int *proto_tail) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 305 | { |
| 306 | struct cflayer *frml; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 307 | struct cfcnfg_phyinfo *phy; |
| 308 | int err; |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 309 | struct cfctrl_link_param param; |
| 310 | struct cfcnfg *cfg = get_cfcnfg(net); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 311 | |
| 312 | rcu_read_lock(); |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 313 | err = caif_connect_req_to_link_param(cfg, conn_req, ¶m); |
| 314 | if (err) |
| 315 | goto unlock; |
| 316 | |
| 317 | phy = cfcnfg_get_phyinfo_rcu(cfg, param.phyid); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 318 | if (!phy) { |
| 319 | err = -ENODEV; |
| 320 | goto unlock; |
| 321 | } |
| 322 | err = -EINVAL; |
| 323 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 324 | if (adap_layer == NULL) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 325 | pr_err("adap_layer is zero\n"); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 326 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 327 | } |
| 328 | if (adap_layer->receive == NULL) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 329 | pr_err("adap_layer->receive is NULL\n"); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 330 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 331 | } |
| 332 | if (adap_layer->ctrlcmd == NULL) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 333 | pr_err("adap_layer->ctrlcmd == NULL\n"); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 334 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 335 | } |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 336 | |
| 337 | err = -ENODEV; |
| 338 | frml = phy->frm_layer; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 339 | if (frml == NULL) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 340 | pr_err("Specified PHY type does not exist!\n"); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 341 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 342 | } |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 343 | caif_assert(param.phyid == phy->id); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 344 | caif_assert(phy->frm_layer->id == |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 345 | param.phyid); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 346 | caif_assert(phy->phy_layer->id == |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 347 | param.phyid); |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 348 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 349 | *ifindex = phy->ifindex; |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 350 | *proto_tail = 2; |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 351 | *proto_head = protohead[param.linktype] + phy->head_room; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 352 | |
| 353 | rcu_read_unlock(); |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 354 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 355 | /* FIXME: ENUMERATE INITIALLY WHEN ACTIVATING PHYSICAL INTERFACE */ |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 356 | cfctrl_enum_req(cfg->ctrl, param.phyid); |
| 357 | return cfctrl_linkup_request(cfg->ctrl, ¶m, adap_layer); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 358 | |
| 359 | unlock: |
| 360 | rcu_read_unlock(); |
| 361 | return err; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 362 | } |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 363 | EXPORT_SYMBOL(caif_connect_client); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 364 | |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 365 | static void cfcnfg_reject_rsp(struct cflayer *layer, u8 channel_id, |
Silviu-Mihai Popescu | 3bffc47 | 2013-03-06 19:39:57 +0000 | [diff] [blame] | 366 | struct cflayer *adapt_layer) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 367 | { |
| 368 | if (adapt_layer != NULL && adapt_layer->ctrlcmd != NULL) |
| 369 | adapt_layer->ctrlcmd(adapt_layer, |
| 370 | CAIF_CTRLCMD_INIT_FAIL_RSP, 0); |
| 371 | } |
| 372 | |
| 373 | static void |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 374 | cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, enum cfctrl_srv serv, |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 375 | u8 phyid, struct cflayer *adapt_layer) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 376 | { |
| 377 | struct cfcnfg *cnfg = container_obj(layer); |
| 378 | struct cflayer *servicel = NULL; |
| 379 | struct cfcnfg_phyinfo *phyinfo; |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 380 | struct net_device *netdev; |
| 381 | |
sjur.brandeland@stericsson.com | 54e90fb | 2011-05-22 11:18:51 +0000 | [diff] [blame] | 382 | if (channel_id == 0) { |
| 383 | pr_warn("received channel_id zero\n"); |
| 384 | if (adapt_layer != NULL && adapt_layer->ctrlcmd != NULL) |
| 385 | adapt_layer->ctrlcmd(adapt_layer, |
| 386 | CAIF_CTRLCMD_INIT_FAIL_RSP, 0); |
| 387 | return; |
| 388 | } |
| 389 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 390 | rcu_read_lock(); |
| 391 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 392 | if (adapt_layer == NULL) { |
Colin Ian King | b09edbd | 2016-10-25 12:18:42 +0100 | [diff] [blame] | 393 | pr_debug("link setup response but no client exist, send linkdown back\n"); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 394 | cfctrl_linkdown_req(cnfg->ctrl, channel_id, NULL); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 395 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | caif_assert(cnfg != NULL); |
| 399 | caif_assert(phyid != 0); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 400 | |
| 401 | phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phyid); |
| 402 | if (phyinfo == NULL) { |
Colin Ian King | b09edbd | 2016-10-25 12:18:42 +0100 | [diff] [blame] | 403 | pr_err("ERROR: Link Layer Device disappeared while connecting\n"); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 404 | goto unlock; |
| 405 | } |
| 406 | |
| 407 | caif_assert(phyinfo != NULL); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 408 | caif_assert(phyinfo->id == phyid); |
| 409 | caif_assert(phyinfo->phy_layer != NULL); |
| 410 | caif_assert(phyinfo->phy_layer->id == phyid); |
| 411 | |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 412 | adapt_layer->id = channel_id; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 413 | |
| 414 | switch (serv) { |
| 415 | case CFCTRL_SRV_VEI: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 416 | servicel = cfvei_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 417 | break; |
| 418 | case CFCTRL_SRV_DATAGRAM: |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 419 | servicel = cfdgml_create(channel_id, |
| 420 | &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 421 | break; |
| 422 | case CFCTRL_SRV_RFM: |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 423 | netdev = phyinfo->dev_info.dev; |
Sjur Braendeland | a7da1f5 | 2010-06-17 06:55:39 +0000 | [diff] [blame] | 424 | servicel = cfrfml_create(channel_id, &phyinfo->dev_info, |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 425 | netdev->mtu); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 426 | break; |
| 427 | case CFCTRL_SRV_UTIL: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 428 | servicel = cfutill_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 429 | break; |
| 430 | case CFCTRL_SRV_VIDEO: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 431 | servicel = cfvidl_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 432 | break; |
| 433 | case CFCTRL_SRV_DBG: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 434 | servicel = cfdbgl_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 435 | break; |
| 436 | default: |
Colin Ian King | b09edbd | 2016-10-25 12:18:42 +0100 | [diff] [blame] | 437 | pr_err("Protocol error. Link setup response - unknown channel type\n"); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 438 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 439 | } |
Joe Perches | 7ac2ed0 | 2011-08-25 13:22:24 +0000 | [diff] [blame] | 440 | if (!servicel) |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 441 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 442 | layer_set_dn(servicel, cnfg->mux); |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 443 | cfmuxl_set_uplayer(cnfg->mux, servicel, channel_id); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 444 | layer_set_up(servicel, adapt_layer); |
| 445 | layer_set_dn(adapt_layer, servicel); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 446 | |
| 447 | rcu_read_unlock(); |
| 448 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 449 | servicel->ctrlcmd(servicel, CAIF_CTRLCMD_INIT_RSP, 0); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 450 | return; |
| 451 | unlock: |
| 452 | rcu_read_unlock(); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | void |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 456 | cfcnfg_add_phy_layer(struct cfcnfg *cnfg, |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 457 | struct net_device *dev, struct cflayer *phy_layer, |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 458 | enum cfcnfg_phy_preference pref, |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 459 | struct cflayer *link_support, |
| 460 | bool fcs, int head_room) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 461 | { |
| 462 | struct cflayer *frml; |
Dan Carpenter | 5bb20ed | 2011-09-20 21:21:59 +0000 | [diff] [blame] | 463 | struct cfcnfg_phyinfo *phyinfo = NULL; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 464 | int i; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 465 | u8 phyid; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 466 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 467 | mutex_lock(&cnfg->lock); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 468 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 469 | /* CAIF protocol allow maximum 6 link-layers */ |
| 470 | for (i = 0; i < 7; i++) { |
| 471 | phyid = (dev->ifindex + i) & 0x7; |
| 472 | if (phyid == 0) |
| 473 | continue; |
| 474 | if (cfcnfg_get_phyinfo_rcu(cnfg, phyid) == NULL) |
| 475 | goto got_phyid; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 476 | } |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 477 | pr_warn("Too many CAIF Link Layers (max 6)\n"); |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 478 | goto out; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 479 | |
| 480 | got_phyid: |
| 481 | phyinfo = kzalloc(sizeof(struct cfcnfg_phyinfo), GFP_ATOMIC); |
Dan Carpenter | 5bb20ed | 2011-09-20 21:21:59 +0000 | [diff] [blame] | 482 | if (!phyinfo) |
| 483 | goto out_err; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 484 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 485 | phy_layer->id = phyid; |
| 486 | phyinfo->pref = pref; |
| 487 | phyinfo->id = phyid; |
| 488 | phyinfo->dev_info.id = phyid; |
| 489 | phyinfo->dev_info.dev = dev; |
| 490 | phyinfo->phy_layer = phy_layer; |
| 491 | phyinfo->ifindex = dev->ifindex; |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 492 | phyinfo->head_room = head_room; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 493 | phyinfo->use_fcs = fcs; |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 494 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 495 | frml = cffrml_create(phyid, fcs); |
| 496 | |
Dan Carpenter | 5bb20ed | 2011-09-20 21:21:59 +0000 | [diff] [blame] | 497 | if (!frml) |
| 498 | goto out_err; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 499 | phyinfo->frm_layer = frml; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 500 | layer_set_up(frml, cnfg->mux); |
| 501 | |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 502 | if (link_support != NULL) { |
| 503 | link_support->id = phyid; |
| 504 | layer_set_dn(frml, link_support); |
| 505 | layer_set_up(link_support, frml); |
| 506 | layer_set_dn(link_support, phy_layer); |
| 507 | layer_set_up(phy_layer, link_support); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 508 | } else { |
| 509 | layer_set_dn(frml, phy_layer); |
| 510 | layer_set_up(phy_layer, frml); |
| 511 | } |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 512 | |
| 513 | list_add_rcu(&phyinfo->node, &cnfg->phys); |
sjur.brandeland@stericsson.com | 7c18d22 | 2011-11-30 09:22:47 +0000 | [diff] [blame] | 514 | out: |
Dan Carpenter | 5bb20ed | 2011-09-20 21:21:59 +0000 | [diff] [blame] | 515 | mutex_unlock(&cnfg->lock); |
| 516 | return; |
| 517 | |
| 518 | out_err: |
Dan Carpenter | 5bb20ed | 2011-09-20 21:21:59 +0000 | [diff] [blame] | 519 | kfree(phyinfo); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 520 | mutex_unlock(&cnfg->lock); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 521 | } |
| 522 | EXPORT_SYMBOL(cfcnfg_add_phy_layer); |
| 523 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 524 | int cfcnfg_set_phy_state(struct cfcnfg *cnfg, struct cflayer *phy_layer, |
Silviu-Mihai Popescu | 3bffc47 | 2013-03-06 19:39:57 +0000 | [diff] [blame] | 525 | bool up) |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 526 | { |
| 527 | struct cfcnfg_phyinfo *phyinfo; |
| 528 | |
| 529 | rcu_read_lock(); |
| 530 | phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phy_layer->id); |
| 531 | if (phyinfo == NULL) { |
| 532 | rcu_read_unlock(); |
| 533 | return -ENODEV; |
| 534 | } |
| 535 | |
| 536 | if (phyinfo->up == up) { |
| 537 | rcu_read_unlock(); |
| 538 | return 0; |
| 539 | } |
| 540 | phyinfo->up = up; |
| 541 | |
| 542 | if (up) { |
| 543 | cffrml_hold(phyinfo->frm_layer); |
| 544 | cfmuxl_set_dnlayer(cnfg->mux, phyinfo->frm_layer, |
| 545 | phy_layer->id); |
| 546 | } else { |
| 547 | cfmuxl_remove_dnlayer(cnfg->mux, phy_layer->id); |
| 548 | cffrml_put(phyinfo->frm_layer); |
| 549 | } |
| 550 | |
| 551 | rcu_read_unlock(); |
| 552 | return 0; |
| 553 | } |
| 554 | EXPORT_SYMBOL(cfcnfg_set_phy_state); |
| 555 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 556 | int cfcnfg_del_phy_layer(struct cfcnfg *cnfg, struct cflayer *phy_layer) |
| 557 | { |
| 558 | struct cflayer *frml, *frml_dn; |
| 559 | u16 phyid; |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 560 | struct cfcnfg_phyinfo *phyinfo; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 561 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 562 | might_sleep(); |
| 563 | |
| 564 | mutex_lock(&cnfg->lock); |
| 565 | |
| 566 | phyid = phy_layer->id; |
| 567 | phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phyid); |
| 568 | |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 569 | if (phyinfo == NULL) { |
| 570 | mutex_unlock(&cnfg->lock); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 571 | return 0; |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 572 | } |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 573 | caif_assert(phyid == phyinfo->id); |
| 574 | caif_assert(phy_layer == phyinfo->phy_layer); |
| 575 | caif_assert(phy_layer->id == phyid); |
| 576 | caif_assert(phyinfo->frm_layer->id == phyid); |
| 577 | |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 578 | list_del_rcu(&phyinfo->node); |
| 579 | synchronize_rcu(); |
| 580 | |
sjur.brandeland@stericsson.com | cb3cb42 | 2011-05-13 02:44:02 +0000 | [diff] [blame] | 581 | /* Fail if reference count is not zero */ |
| 582 | if (cffrml_refcnt_read(phyinfo->frm_layer) != 0) { |
| 583 | pr_info("Wait for device inuse\n"); |
sjur.brandeland@stericsson.com | bee925d | 2011-05-13 02:44:05 +0000 | [diff] [blame] | 584 | list_add_rcu(&phyinfo->node, &cnfg->phys); |
sjur.brandeland@stericsson.com | cb3cb42 | 2011-05-13 02:44:02 +0000 | [diff] [blame] | 585 | mutex_unlock(&cnfg->lock); |
| 586 | return -EAGAIN; |
| 587 | } |
| 588 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 589 | frml = phyinfo->frm_layer; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 590 | frml_dn = frml->dn; |
| 591 | cffrml_set_uplayer(frml, NULL); |
| 592 | cffrml_set_dnlayer(frml, NULL); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 593 | if (phy_layer != frml_dn) { |
| 594 | layer_set_up(frml_dn, NULL); |
| 595 | layer_set_dn(frml_dn, NULL); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 596 | } |
| 597 | layer_set_up(phy_layer, NULL); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 598 | |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 599 | if (phyinfo->phy_layer != frml_dn) |
| 600 | kfree(frml_dn); |
| 601 | |
sjur.brandeland@stericsson.com | cb3cb42 | 2011-05-13 02:44:02 +0000 | [diff] [blame] | 602 | cffrml_free(frml); |
sjur.brandeland@stericsson.com | f362144 | 2011-05-13 02:44:01 +0000 | [diff] [blame] | 603 | kfree(phyinfo); |
| 604 | mutex_unlock(&cnfg->lock); |
| 605 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 606 | return 0; |
| 607 | } |
| 608 | EXPORT_SYMBOL(cfcnfg_del_phy_layer); |