Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson AB 2010 |
| 3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com |
| 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 | f3621440 | 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 | f3621440 | 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 | f3621440 | 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 | |
| 48 | /* Use Start of frame extension */ |
| 49 | bool use_stx; |
| 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 | f3621440 | 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, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +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, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 68 | struct cflayer *adapt_layer); |
| 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 | f3621440 | 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); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 81 | if (!this) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 82 | pr_warn("Out of memory\n"); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 83 | return NULL; |
| 84 | } |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 85 | this->mux = cfmuxl_create(); |
| 86 | if (!this->mux) |
| 87 | goto out_of_mem; |
| 88 | this->ctrl = cfctrl_create(); |
| 89 | if (!this->ctrl) |
| 90 | goto out_of_mem; |
| 91 | /* Initiate response functions */ |
| 92 | resp = cfctrl_get_respfuncs(this->ctrl); |
| 93 | resp->enum_rsp = cfctrl_enum_resp; |
| 94 | resp->linkerror_ind = cfctrl_resp_func; |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 95 | resp->linkdestroy_rsp = cfcnfg_linkdestroy_rsp; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 96 | resp->sleep_rsp = cfctrl_resp_func; |
| 97 | resp->wake_rsp = cfctrl_resp_func; |
| 98 | resp->restart_rsp = cfctrl_resp_func; |
| 99 | resp->radioset_rsp = cfctrl_resp_func; |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 100 | resp->linksetup_rsp = cfcnfg_linkup_rsp; |
| 101 | resp->reject_rsp = cfcnfg_reject_rsp; |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 102 | INIT_LIST_HEAD(&this->phys); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 103 | |
| 104 | cfmuxl_set_uplayer(this->mux, this->ctrl, 0); |
| 105 | layer_set_dn(this->ctrl, this->mux); |
| 106 | layer_set_up(this->ctrl, this); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 107 | mutex_init(&this->lock); |
| 108 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 109 | return this; |
| 110 | out_of_mem: |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 111 | pr_warn("Out of memory\n"); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 112 | |
| 113 | synchronize_rcu(); |
| 114 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 115 | kfree(this->mux); |
| 116 | kfree(this->ctrl); |
| 117 | kfree(this); |
| 118 | return NULL; |
| 119 | } |
| 120 | EXPORT_SYMBOL(cfcnfg_create); |
| 121 | |
| 122 | void cfcnfg_remove(struct cfcnfg *cfg) |
| 123 | { |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 124 | might_sleep(); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 125 | if (cfg) { |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 126 | synchronize_rcu(); |
| 127 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 128 | kfree(cfg->mux); |
| 129 | kfree(cfg->ctrl); |
| 130 | kfree(cfg); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | static void cfctrl_resp_func(void) |
| 135 | { |
| 136 | } |
| 137 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 138 | static struct cfcnfg_phyinfo *cfcnfg_get_phyinfo_rcu(struct cfcnfg *cnfg, |
| 139 | u8 phyid) |
| 140 | { |
| 141 | struct cfcnfg_phyinfo *phy; |
| 142 | |
| 143 | list_for_each_entry_rcu(phy, &cnfg->phys, node) |
| 144 | if (phy->id == phyid) |
| 145 | return phy; |
| 146 | return NULL; |
| 147 | } |
| 148 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 149 | static void cfctrl_enum_resp(void) |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | struct dev_info *cfcnfg_get_phyid(struct cfcnfg *cnfg, |
| 154 | enum cfcnfg_phy_preference phy_pref) |
| 155 | { |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 156 | /* Try to match with specified preference */ |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 157 | struct cfcnfg_phyinfo *phy; |
| 158 | |
| 159 | list_for_each_entry_rcu(phy, &cnfg->phys, node) { |
| 160 | if (phy->up && phy->pref == phy_pref && |
| 161 | phy->frm_layer != NULL) |
| 162 | |
| 163 | return &phy->dev_info; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 164 | } |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 165 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 166 | /* Otherwise just return something */ |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 167 | list_for_each_entry_rcu(phy, &cnfg->phys, node) |
| 168 | if (phy->up) |
| 169 | return &phy->dev_info; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 170 | |
| 171 | return NULL; |
| 172 | } |
| 173 | |
André Carvalho de Matos | f2527ec | 2010-11-01 11:52:47 +0000 | [diff] [blame] | 174 | int cfcnfg_get_id_from_ifi(struct cfcnfg *cnfg, int ifi) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 175 | { |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 176 | struct cfcnfg_phyinfo *phy; |
| 177 | |
| 178 | list_for_each_entry_rcu(phy, &cnfg->phys, node) |
| 179 | if (phy->ifindex == ifi && phy->up) |
| 180 | return phy->id; |
André Carvalho de Matos | f2527ec | 2010-11-01 11:52:47 +0000 | [diff] [blame] | 181 | return -ENODEV; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 182 | } |
| 183 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 184 | int cfcnfg_disconn_adapt_layer(struct cfcnfg *cfg, struct cflayer *adap_layer) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 185 | { |
| 186 | u8 channel_id = 0; |
| 187 | int ret = 0; |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 188 | struct cflayer *servl = NULL; |
Dan Carpenter | 01a8590 | 2011-01-15 03:06:39 +0000 | [diff] [blame] | 189 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 190 | caif_assert(adap_layer != NULL); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 191 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 192 | channel_id = adap_layer->id; |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 193 | if (adap_layer->dn == NULL || channel_id == 0) { |
Sjur Braendeland | b04367d | 2010-09-21 11:44:44 +0000 | [diff] [blame] | 194 | pr_err("adap_layer->dn == NULL or adap_layer->id is 0\n"); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 195 | ret = -ENOTCONN; |
| 196 | goto end; |
| 197 | } |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 198 | |
| 199 | servl = cfmuxl_remove_uplayer(cfg->mux, channel_id); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 200 | if (servl == NULL) { |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 201 | pr_err("PROTOCOL ERROR - " |
| 202 | "Error removing service_layer Channel_Id(%d)", |
| 203 | channel_id); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 204 | ret = -EINVAL; |
| 205 | goto end; |
| 206 | } |
| 207 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 208 | ret = cfctrl_linkdown_req(cfg->ctrl, channel_id, adap_layer); |
| 209 | |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 210 | end: |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 211 | cfctrl_cancel_req(cfg->ctrl, adap_layer); |
| 212 | |
| 213 | /* Do RCU sync before initiating cleanup */ |
| 214 | synchronize_rcu(); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 215 | if (adap_layer->ctrlcmd != NULL) |
| 216 | adap_layer->ctrlcmd(adap_layer, CAIF_CTRLCMD_DEINIT_RSP, 0); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 217 | return ret; |
| 218 | |
| 219 | } |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 220 | EXPORT_SYMBOL(cfcnfg_disconn_adapt_layer); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 221 | |
Sjur Braendeland | 5b20865 | 2010-04-28 08:54:36 +0000 | [diff] [blame] | 222 | void cfcnfg_release_adap_layer(struct cflayer *adap_layer) |
| 223 | { |
| 224 | if (adap_layer->dn) |
| 225 | cfsrvl_put(adap_layer->dn); |
| 226 | } |
| 227 | EXPORT_SYMBOL(cfcnfg_release_adap_layer); |
| 228 | |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 229 | static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 230 | { |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Stephen Hemminger | 73d6ac6 | 2011-04-11 10:43:50 +0000 | [diff] [blame] | 233 | static const int protohead[CFCTRL_SRV_MASK] = { |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 234 | [CFCTRL_SRV_VEI] = 4, |
| 235 | [CFCTRL_SRV_DATAGRAM] = 7, |
| 236 | [CFCTRL_SRV_UTIL] = 4, |
| 237 | [CFCTRL_SRV_RFM] = 3, |
| 238 | [CFCTRL_SRV_DBG] = 3, |
| 239 | }; |
| 240 | |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 241 | int cfcnfg_add_adaptation_layer(struct cfcnfg *cnfg, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 242 | struct cfctrl_link_param *param, |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 243 | struct cflayer *adap_layer, |
| 244 | int *ifindex, |
| 245 | int *proto_head, |
| 246 | int *proto_tail) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 247 | { |
| 248 | struct cflayer *frml; |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 249 | struct cfcnfg_phyinfo *phy; |
| 250 | int err; |
| 251 | |
| 252 | rcu_read_lock(); |
| 253 | phy = cfcnfg_get_phyinfo_rcu(cnfg, param->phyid); |
| 254 | if (!phy) { |
| 255 | err = -ENODEV; |
| 256 | goto unlock; |
| 257 | } |
| 258 | err = -EINVAL; |
| 259 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 260 | if (adap_layer == NULL) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 261 | pr_err("adap_layer is zero\n"); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 262 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 263 | } |
| 264 | if (adap_layer->receive == NULL) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 265 | pr_err("adap_layer->receive is NULL\n"); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 266 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 267 | } |
| 268 | if (adap_layer->ctrlcmd == NULL) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 269 | pr_err("adap_layer->ctrlcmd == NULL\n"); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 270 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 271 | } |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 272 | |
| 273 | err = -ENODEV; |
| 274 | frml = phy->frm_layer; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 275 | if (frml == NULL) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 276 | pr_err("Specified PHY type does not exist!\n"); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 277 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 278 | } |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 279 | caif_assert(param->phyid == phy->id); |
| 280 | caif_assert(phy->frm_layer->id == |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 281 | param->phyid); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 282 | caif_assert(phy->phy_layer->id == |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 283 | param->phyid); |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 284 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 285 | *ifindex = phy->ifindex; |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 286 | *proto_tail = 2; |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 287 | *proto_head = |
| 288 | protohead[param->linktype] + (phy->use_stx ? 1 : 0); |
| 289 | |
| 290 | rcu_read_unlock(); |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 291 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 292 | /* FIXME: ENUMERATE INITIALLY WHEN ACTIVATING PHYSICAL INTERFACE */ |
| 293 | cfctrl_enum_req(cnfg->ctrl, param->phyid); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 294 | return cfctrl_linkup_request(cnfg->ctrl, param, adap_layer); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 295 | |
| 296 | unlock: |
| 297 | rcu_read_unlock(); |
| 298 | return err; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 299 | } |
| 300 | EXPORT_SYMBOL(cfcnfg_add_adaptation_layer); |
| 301 | |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 302 | static void cfcnfg_reject_rsp(struct cflayer *layer, u8 channel_id, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 303 | struct cflayer *adapt_layer) |
| 304 | { |
| 305 | if (adapt_layer != NULL && adapt_layer->ctrlcmd != NULL) |
| 306 | adapt_layer->ctrlcmd(adapt_layer, |
| 307 | CAIF_CTRLCMD_INIT_FAIL_RSP, 0); |
| 308 | } |
| 309 | |
| 310 | static void |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 311 | cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, enum cfctrl_srv serv, |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 312 | u8 phyid, struct cflayer *adapt_layer) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 313 | { |
| 314 | struct cfcnfg *cnfg = container_obj(layer); |
| 315 | struct cflayer *servicel = NULL; |
| 316 | struct cfcnfg_phyinfo *phyinfo; |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 317 | struct net_device *netdev; |
| 318 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 319 | rcu_read_lock(); |
| 320 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 321 | if (adapt_layer == NULL) { |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 322 | pr_debug("link setup response but no client exist," |
| 323 | "send linkdown back\n"); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 324 | cfctrl_linkdown_req(cnfg->ctrl, channel_id, NULL); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 325 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | caif_assert(cnfg != NULL); |
| 329 | caif_assert(phyid != 0); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 330 | |
| 331 | phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phyid); |
| 332 | if (phyinfo == NULL) { |
| 333 | pr_err("ERROR: Link Layer Device dissapeared" |
| 334 | "while connecting\n"); |
| 335 | goto unlock; |
| 336 | } |
| 337 | |
| 338 | caif_assert(phyinfo != NULL); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 339 | caif_assert(phyinfo->id == phyid); |
| 340 | caif_assert(phyinfo->phy_layer != NULL); |
| 341 | caif_assert(phyinfo->phy_layer->id == phyid); |
| 342 | |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 343 | adapt_layer->id = channel_id; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 344 | |
| 345 | switch (serv) { |
| 346 | case CFCTRL_SRV_VEI: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 347 | servicel = cfvei_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 348 | break; |
| 349 | case CFCTRL_SRV_DATAGRAM: |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 350 | servicel = cfdgml_create(channel_id, |
| 351 | &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 352 | break; |
| 353 | case CFCTRL_SRV_RFM: |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 354 | netdev = phyinfo->dev_info.dev; |
Sjur Braendeland | a7da1f5 | 2010-06-17 06:55:39 +0000 | [diff] [blame] | 355 | servicel = cfrfml_create(channel_id, &phyinfo->dev_info, |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 356 | netdev->mtu); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 357 | break; |
| 358 | case CFCTRL_SRV_UTIL: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 359 | servicel = cfutill_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 360 | break; |
| 361 | case CFCTRL_SRV_VIDEO: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 362 | servicel = cfvidl_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 363 | break; |
| 364 | case CFCTRL_SRV_DBG: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 365 | servicel = cfdbgl_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 366 | break; |
| 367 | default: |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 368 | pr_err("Protocol error. Link setup response " |
| 369 | "- unknown channel type\n"); |
| 370 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 371 | } |
| 372 | if (!servicel) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 373 | pr_warn("Out of memory\n"); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 374 | goto unlock; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 375 | } |
| 376 | layer_set_dn(servicel, cnfg->mux); |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 377 | cfmuxl_set_uplayer(cnfg->mux, servicel, channel_id); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 378 | layer_set_up(servicel, adapt_layer); |
| 379 | layer_set_dn(adapt_layer, servicel); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 380 | |
| 381 | rcu_read_unlock(); |
| 382 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 383 | servicel->ctrlcmd(servicel, CAIF_CTRLCMD_INIT_RSP, 0); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 384 | return; |
| 385 | unlock: |
| 386 | rcu_read_unlock(); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | void |
| 390 | cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type, |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 391 | struct net_device *dev, struct cflayer *phy_layer, |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 392 | u16 *phy_id, enum cfcnfg_phy_preference pref, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 393 | bool fcs, bool stx) |
| 394 | { |
| 395 | struct cflayer *frml; |
| 396 | struct cflayer *phy_driver = NULL; |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 397 | struct cfcnfg_phyinfo *phyinfo; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 398 | int i; |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 399 | u8 phyid; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 400 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 401 | mutex_lock(&cnfg->lock); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 402 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 403 | /* CAIF protocol allow maximum 6 link-layers */ |
| 404 | for (i = 0; i < 7; i++) { |
| 405 | phyid = (dev->ifindex + i) & 0x7; |
| 406 | if (phyid == 0) |
| 407 | continue; |
| 408 | if (cfcnfg_get_phyinfo_rcu(cnfg, phyid) == NULL) |
| 409 | goto got_phyid; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 410 | } |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 411 | pr_warn("Too many CAIF Link Layers (max 6)\n"); |
| 412 | goto out; |
| 413 | |
| 414 | got_phyid: |
| 415 | phyinfo = kzalloc(sizeof(struct cfcnfg_phyinfo), GFP_ATOMIC); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 416 | |
| 417 | switch (phy_type) { |
| 418 | case CFPHYTYPE_FRAG: |
| 419 | phy_driver = |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 420 | cfserl_create(CFPHYTYPE_FRAG, phyid, stx); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 421 | if (!phy_driver) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 422 | pr_warn("Out of memory\n"); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 423 | goto out; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 424 | } |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 425 | break; |
| 426 | case CFPHYTYPE_CAIF: |
| 427 | phy_driver = NULL; |
| 428 | break; |
| 429 | default: |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 430 | goto out; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 431 | } |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 432 | phy_layer->id = phyid; |
| 433 | phyinfo->pref = pref; |
| 434 | phyinfo->id = phyid; |
| 435 | phyinfo->dev_info.id = phyid; |
| 436 | phyinfo->dev_info.dev = dev; |
| 437 | phyinfo->phy_layer = phy_layer; |
| 438 | phyinfo->ifindex = dev->ifindex; |
| 439 | phyinfo->use_stx = stx; |
| 440 | phyinfo->use_fcs = fcs; |
Sjur Braendeland | 2aa40ae | 2010-06-17 06:55:40 +0000 | [diff] [blame] | 441 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 442 | phy_layer->type = phy_type; |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 443 | frml = cffrml_create(phyid, fcs); |
| 444 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 445 | if (!frml) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 446 | pr_warn("Out of memory\n"); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 447 | kfree(phyinfo); |
| 448 | goto out; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 449 | } |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 450 | phyinfo->frm_layer = frml; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 451 | layer_set_up(frml, cnfg->mux); |
| 452 | |
| 453 | if (phy_driver != NULL) { |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 454 | phy_driver->id = phyid; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 455 | layer_set_dn(frml, phy_driver); |
| 456 | layer_set_up(phy_driver, frml); |
| 457 | layer_set_dn(phy_driver, phy_layer); |
| 458 | layer_set_up(phy_layer, phy_driver); |
| 459 | } else { |
| 460 | layer_set_dn(frml, phy_layer); |
| 461 | layer_set_up(phy_layer, frml); |
| 462 | } |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 463 | |
| 464 | list_add_rcu(&phyinfo->node, &cnfg->phys); |
| 465 | out: |
| 466 | mutex_unlock(&cnfg->lock); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 467 | } |
| 468 | EXPORT_SYMBOL(cfcnfg_add_phy_layer); |
| 469 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 470 | int cfcnfg_set_phy_state(struct cfcnfg *cnfg, struct cflayer *phy_layer, |
| 471 | bool up) |
| 472 | { |
| 473 | struct cfcnfg_phyinfo *phyinfo; |
| 474 | |
| 475 | rcu_read_lock(); |
| 476 | phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phy_layer->id); |
| 477 | if (phyinfo == NULL) { |
| 478 | rcu_read_unlock(); |
| 479 | return -ENODEV; |
| 480 | } |
| 481 | |
| 482 | if (phyinfo->up == up) { |
| 483 | rcu_read_unlock(); |
| 484 | return 0; |
| 485 | } |
| 486 | phyinfo->up = up; |
| 487 | |
| 488 | if (up) { |
| 489 | cffrml_hold(phyinfo->frm_layer); |
| 490 | cfmuxl_set_dnlayer(cnfg->mux, phyinfo->frm_layer, |
| 491 | phy_layer->id); |
| 492 | } else { |
| 493 | cfmuxl_remove_dnlayer(cnfg->mux, phy_layer->id); |
| 494 | cffrml_put(phyinfo->frm_layer); |
| 495 | } |
| 496 | |
| 497 | rcu_read_unlock(); |
| 498 | return 0; |
| 499 | } |
| 500 | EXPORT_SYMBOL(cfcnfg_set_phy_state); |
| 501 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 502 | int cfcnfg_del_phy_layer(struct cfcnfg *cnfg, struct cflayer *phy_layer) |
| 503 | { |
| 504 | struct cflayer *frml, *frml_dn; |
| 505 | u16 phyid; |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 506 | struct cfcnfg_phyinfo *phyinfo; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 507 | |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 508 | might_sleep(); |
| 509 | |
| 510 | mutex_lock(&cnfg->lock); |
| 511 | |
| 512 | phyid = phy_layer->id; |
| 513 | phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phyid); |
| 514 | |
| 515 | if (phyinfo == NULL) |
| 516 | return 0; |
| 517 | caif_assert(phyid == phyinfo->id); |
| 518 | caif_assert(phy_layer == phyinfo->phy_layer); |
| 519 | caif_assert(phy_layer->id == phyid); |
| 520 | caif_assert(phyinfo->frm_layer->id == phyid); |
| 521 | |
| 522 | list_del_rcu(&phyinfo->node); |
| 523 | synchronize_rcu(); |
| 524 | |
| 525 | frml = phyinfo->frm_layer; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 526 | frml_dn = frml->dn; |
| 527 | cffrml_set_uplayer(frml, NULL); |
| 528 | cffrml_set_dnlayer(frml, NULL); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 529 | if (phy_layer != frml_dn) { |
| 530 | layer_set_up(frml_dn, NULL); |
| 531 | layer_set_dn(frml_dn, NULL); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 532 | } |
| 533 | layer_set_up(phy_layer, NULL); |
sjur.brandeland@stericsson.com | f3621440 | 2011-05-13 02:44:01 +0000 | [diff] [blame^] | 534 | |
| 535 | |
| 536 | |
| 537 | if (phyinfo->phy_layer != frml_dn) |
| 538 | kfree(frml_dn); |
| 539 | |
| 540 | kfree(frml); |
| 541 | kfree(phyinfo); |
| 542 | mutex_unlock(&cnfg->lock); |
| 543 | |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 544 | return 0; |
| 545 | } |
| 546 | EXPORT_SYMBOL(cfcnfg_del_phy_layer); |