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 | */ |
| 6 | #include <linux/kernel.h> |
| 7 | #include <linux/stddef.h> |
Stephen Rothwell | 6c57990 | 2010-04-01 00:28:49 -0700 | [diff] [blame] | 8 | #include <linux/slab.h> |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 9 | #include <net/caif/caif_layer.h> |
| 10 | #include <net/caif/cfpkt.h> |
| 11 | #include <net/caif/cfcnfg.h> |
| 12 | #include <net/caif/cfctrl.h> |
| 13 | #include <net/caif/cfmuxl.h> |
| 14 | #include <net/caif/cffrml.h> |
| 15 | #include <net/caif/cfserl.h> |
| 16 | #include <net/caif/cfsrvl.h> |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <asm/atomic.h> |
| 20 | |
| 21 | #define MAX_PHY_LAYERS 7 |
| 22 | #define PHY_NAME_LEN 20 |
| 23 | |
| 24 | #define container_obj(layr) container_of(layr, struct cfcnfg, layer) |
Sjur Braendeland | a7da1f5 | 2010-06-17 06:55:39 +0000 | [diff] [blame^] | 25 | #define RFM_FRAGMENT_SIZE 4030 |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 26 | |
| 27 | /* Information about CAIF physical interfaces held by Config Module in order |
| 28 | * to manage physical interfaces |
| 29 | */ |
| 30 | struct cfcnfg_phyinfo { |
| 31 | /* Pointer to the layer below the MUX (framing layer) */ |
| 32 | struct cflayer *frm_layer; |
| 33 | /* Pointer to the lowest actual physical layer */ |
| 34 | struct cflayer *phy_layer; |
| 35 | /* Unique identifier of the physical interface */ |
| 36 | unsigned int id; |
| 37 | /* Preference of the physical in interface */ |
| 38 | enum cfcnfg_phy_preference pref; |
| 39 | |
| 40 | /* Reference count, number of channels using the device */ |
| 41 | int phy_ref_count; |
| 42 | |
| 43 | /* Information about the physical device */ |
| 44 | struct dev_info dev_info; |
| 45 | }; |
| 46 | |
| 47 | struct cfcnfg { |
| 48 | struct cflayer layer; |
| 49 | struct cflayer *ctrl; |
| 50 | struct cflayer *mux; |
| 51 | u8 last_phyid; |
| 52 | struct cfcnfg_phyinfo phy_layers[MAX_PHY_LAYERS]; |
| 53 | }; |
| 54 | |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 55 | static void cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 56 | enum cfctrl_srv serv, u8 phyid, |
| 57 | struct cflayer *adapt_layer); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 58 | static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id); |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 59 | static void cfcnfg_reject_rsp(struct cflayer *layer, u8 channel_id, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 60 | struct cflayer *adapt_layer); |
| 61 | static void cfctrl_resp_func(void); |
| 62 | static void cfctrl_enum_resp(void); |
| 63 | |
| 64 | struct cfcnfg *cfcnfg_create(void) |
| 65 | { |
| 66 | struct cfcnfg *this; |
| 67 | struct cfctrl_rsp *resp; |
| 68 | /* Initiate this layer */ |
Julia Lawall | 49afa55 | 2010-05-13 10:03:32 +0000 | [diff] [blame] | 69 | this = kzalloc(sizeof(struct cfcnfg), GFP_ATOMIC); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 70 | if (!this) { |
| 71 | pr_warning("CAIF: %s(): Out of memory\n", __func__); |
| 72 | return NULL; |
| 73 | } |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 74 | this->mux = cfmuxl_create(); |
| 75 | if (!this->mux) |
| 76 | goto out_of_mem; |
| 77 | this->ctrl = cfctrl_create(); |
| 78 | if (!this->ctrl) |
| 79 | goto out_of_mem; |
| 80 | /* Initiate response functions */ |
| 81 | resp = cfctrl_get_respfuncs(this->ctrl); |
| 82 | resp->enum_rsp = cfctrl_enum_resp; |
| 83 | resp->linkerror_ind = cfctrl_resp_func; |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 84 | resp->linkdestroy_rsp = cfcnfg_linkdestroy_rsp; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 85 | resp->sleep_rsp = cfctrl_resp_func; |
| 86 | resp->wake_rsp = cfctrl_resp_func; |
| 87 | resp->restart_rsp = cfctrl_resp_func; |
| 88 | resp->radioset_rsp = cfctrl_resp_func; |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 89 | resp->linksetup_rsp = cfcnfg_linkup_rsp; |
| 90 | resp->reject_rsp = cfcnfg_reject_rsp; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 91 | |
| 92 | this->last_phyid = 1; |
| 93 | |
| 94 | cfmuxl_set_uplayer(this->mux, this->ctrl, 0); |
| 95 | layer_set_dn(this->ctrl, this->mux); |
| 96 | layer_set_up(this->ctrl, this); |
| 97 | return this; |
| 98 | out_of_mem: |
| 99 | pr_warning("CAIF: %s(): Out of memory\n", __func__); |
| 100 | kfree(this->mux); |
| 101 | kfree(this->ctrl); |
| 102 | kfree(this); |
| 103 | return NULL; |
| 104 | } |
| 105 | EXPORT_SYMBOL(cfcnfg_create); |
| 106 | |
| 107 | void cfcnfg_remove(struct cfcnfg *cfg) |
| 108 | { |
| 109 | if (cfg) { |
| 110 | kfree(cfg->mux); |
| 111 | kfree(cfg->ctrl); |
| 112 | kfree(cfg); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | static void cfctrl_resp_func(void) |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | static void cfctrl_enum_resp(void) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | struct dev_info *cfcnfg_get_phyid(struct cfcnfg *cnfg, |
| 125 | enum cfcnfg_phy_preference phy_pref) |
| 126 | { |
| 127 | u16 i; |
| 128 | |
| 129 | /* Try to match with specified preference */ |
| 130 | for (i = 1; i < MAX_PHY_LAYERS; i++) { |
| 131 | if (cnfg->phy_layers[i].id == i && |
| 132 | cnfg->phy_layers[i].pref == phy_pref && |
| 133 | cnfg->phy_layers[i].frm_layer != NULL) { |
| 134 | caif_assert(cnfg->phy_layers != NULL); |
| 135 | caif_assert(cnfg->phy_layers[i].id == i); |
| 136 | return &cnfg->phy_layers[i].dev_info; |
| 137 | } |
| 138 | } |
| 139 | /* Otherwise just return something */ |
| 140 | for (i = 1; i < MAX_PHY_LAYERS; i++) { |
| 141 | if (cnfg->phy_layers[i].id == i) { |
| 142 | caif_assert(cnfg->phy_layers != NULL); |
| 143 | caif_assert(cnfg->phy_layers[i].id == i); |
| 144 | return &cnfg->phy_layers[i].dev_info; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return NULL; |
| 149 | } |
| 150 | |
| 151 | static struct cfcnfg_phyinfo *cfcnfg_get_phyinfo(struct cfcnfg *cnfg, |
| 152 | u8 phyid) |
| 153 | { |
| 154 | int i; |
| 155 | /* Try to match with specified preference */ |
| 156 | for (i = 0; i < MAX_PHY_LAYERS; i++) |
| 157 | if (cnfg->phy_layers[i].frm_layer != NULL && |
| 158 | cnfg->phy_layers[i].id == phyid) |
| 159 | return &cnfg->phy_layers[i]; |
| 160 | return NULL; |
| 161 | } |
| 162 | |
| 163 | int cfcnfg_get_named(struct cfcnfg *cnfg, char *name) |
| 164 | { |
| 165 | int i; |
| 166 | |
| 167 | /* Try to match with specified name */ |
| 168 | for (i = 0; i < MAX_PHY_LAYERS; i++) { |
| 169 | if (cnfg->phy_layers[i].frm_layer != NULL |
| 170 | && strcmp(cnfg->phy_layers[i].phy_layer->name, |
| 171 | name) == 0) |
| 172 | return cnfg->phy_layers[i].frm_layer->id; |
| 173 | } |
| 174 | return 0; |
| 175 | } |
| 176 | |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 177 | int cfcnfg_disconn_adapt_layer(struct cfcnfg *cnfg, struct cflayer *adap_layer) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 178 | { |
| 179 | u8 channel_id = 0; |
| 180 | int ret = 0; |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 181 | struct cflayer *servl = NULL; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 182 | struct cfcnfg_phyinfo *phyinfo = NULL; |
| 183 | u8 phyid = 0; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 184 | caif_assert(adap_layer != NULL); |
| 185 | channel_id = adap_layer->id; |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 186 | if (adap_layer->dn == NULL || channel_id == 0) { |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 187 | pr_err("CAIF: %s():adap_layer->id is 0\n", __func__); |
| 188 | ret = -ENOTCONN; |
| 189 | goto end; |
| 190 | } |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 191 | servl = cfmuxl_remove_uplayer(cnfg->mux, channel_id); |
| 192 | if (servl == NULL) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 193 | goto end; |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 194 | layer_set_up(servl, NULL); |
| 195 | ret = cfctrl_linkdown_req(cnfg->ctrl, channel_id, adap_layer); |
| 196 | if (servl == NULL) { |
| 197 | pr_err("CAIF: %s(): PROTOCOL ERROR " |
| 198 | "- Error removing service_layer Channel_Id(%d)", |
| 199 | __func__, channel_id); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 200 | ret = -EINVAL; |
| 201 | goto end; |
| 202 | } |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 203 | caif_assert(channel_id == servl->id); |
| 204 | if (adap_layer->dn != NULL) { |
| 205 | phyid = cfsrvl_getphyid(adap_layer->dn); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 206 | |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 207 | phyinfo = cfcnfg_get_phyinfo(cnfg, phyid); |
| 208 | if (phyinfo == NULL) { |
| 209 | pr_warning("CAIF: %s(): " |
| 210 | "No interface to send disconnect to\n", |
| 211 | __func__); |
| 212 | ret = -ENODEV; |
| 213 | goto end; |
| 214 | } |
| 215 | if (phyinfo->id != phyid || |
| 216 | phyinfo->phy_layer->id != phyid || |
| 217 | phyinfo->frm_layer->id != phyid) { |
| 218 | pr_err("CAIF: %s(): " |
| 219 | "Inconsistency in phy registration\n", |
| 220 | __func__); |
| 221 | ret = -EINVAL; |
| 222 | goto end; |
| 223 | } |
| 224 | } |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 225 | if (phyinfo != NULL && --phyinfo->phy_ref_count == 0 && |
| 226 | phyinfo->phy_layer != NULL && |
| 227 | phyinfo->phy_layer->modemcmd != NULL) { |
| 228 | phyinfo->phy_layer->modemcmd(phyinfo->phy_layer, |
| 229 | _CAIF_MODEMCMD_PHYIF_USELESS); |
| 230 | } |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 231 | end: |
| 232 | cfsrvl_put(servl); |
| 233 | cfctrl_cancel_req(cnfg->ctrl, adap_layer); |
| 234 | if (adap_layer->ctrlcmd != NULL) |
| 235 | adap_layer->ctrlcmd(adap_layer, CAIF_CTRLCMD_DEINIT_RSP, 0); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 236 | return ret; |
| 237 | |
| 238 | } |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 239 | EXPORT_SYMBOL(cfcnfg_disconn_adapt_layer); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 240 | |
Sjur Braendeland | 5b20865 | 2010-04-28 08:54:36 +0000 | [diff] [blame] | 241 | void cfcnfg_release_adap_layer(struct cflayer *adap_layer) |
| 242 | { |
| 243 | if (adap_layer->dn) |
| 244 | cfsrvl_put(adap_layer->dn); |
| 245 | } |
| 246 | EXPORT_SYMBOL(cfcnfg_release_adap_layer); |
| 247 | |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 248 | static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id) |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 249 | { |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 252 | int cfcnfg_add_adaptation_layer(struct cfcnfg *cnfg, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 253 | struct cfctrl_link_param *param, |
| 254 | struct cflayer *adap_layer) |
| 255 | { |
| 256 | struct cflayer *frml; |
| 257 | if (adap_layer == NULL) { |
| 258 | pr_err("CAIF: %s(): adap_layer is zero", __func__); |
| 259 | return -EINVAL; |
| 260 | } |
| 261 | if (adap_layer->receive == NULL) { |
| 262 | pr_err("CAIF: %s(): adap_layer->receive is NULL", __func__); |
| 263 | return -EINVAL; |
| 264 | } |
| 265 | if (adap_layer->ctrlcmd == NULL) { |
| 266 | pr_err("CAIF: %s(): adap_layer->ctrlcmd == NULL", __func__); |
| 267 | return -EINVAL; |
| 268 | } |
| 269 | frml = cnfg->phy_layers[param->phyid].frm_layer; |
| 270 | if (frml == NULL) { |
| 271 | pr_err("CAIF: %s(): Specified PHY type does not exist!", |
| 272 | __func__); |
| 273 | return -ENODEV; |
| 274 | } |
| 275 | caif_assert(param->phyid == cnfg->phy_layers[param->phyid].id); |
| 276 | caif_assert(cnfg->phy_layers[param->phyid].frm_layer->id == |
| 277 | param->phyid); |
| 278 | caif_assert(cnfg->phy_layers[param->phyid].phy_layer->id == |
| 279 | param->phyid); |
| 280 | /* FIXME: ENUMERATE INITIALLY WHEN ACTIVATING PHYSICAL INTERFACE */ |
| 281 | cfctrl_enum_req(cnfg->ctrl, param->phyid); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 282 | return cfctrl_linkup_request(cnfg->ctrl, param, adap_layer); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 283 | } |
| 284 | EXPORT_SYMBOL(cfcnfg_add_adaptation_layer); |
| 285 | |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 286 | static void cfcnfg_reject_rsp(struct cflayer *layer, u8 channel_id, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 287 | struct cflayer *adapt_layer) |
| 288 | { |
| 289 | if (adapt_layer != NULL && adapt_layer->ctrlcmd != NULL) |
| 290 | adapt_layer->ctrlcmd(adapt_layer, |
| 291 | CAIF_CTRLCMD_INIT_FAIL_RSP, 0); |
| 292 | } |
| 293 | |
| 294 | static void |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 295 | cfcnfg_linkup_rsp(struct cflayer *layer, u8 channel_id, enum cfctrl_srv serv, |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 296 | u8 phyid, struct cflayer *adapt_layer) |
| 297 | { |
| 298 | struct cfcnfg *cnfg = container_obj(layer); |
| 299 | struct cflayer *servicel = NULL; |
| 300 | struct cfcnfg_phyinfo *phyinfo; |
| 301 | if (adapt_layer == NULL) { |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 302 | pr_debug("CAIF: %s(): link setup response " |
| 303 | "but no client exist, send linkdown back\n", |
| 304 | __func__); |
| 305 | cfctrl_linkdown_req(cnfg->ctrl, channel_id, NULL); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 306 | return; |
| 307 | } |
| 308 | |
| 309 | caif_assert(cnfg != NULL); |
| 310 | caif_assert(phyid != 0); |
| 311 | phyinfo = &cnfg->phy_layers[phyid]; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 312 | caif_assert(phyinfo->id == phyid); |
| 313 | caif_assert(phyinfo->phy_layer != NULL); |
| 314 | caif_assert(phyinfo->phy_layer->id == phyid); |
| 315 | |
Dan Carpenter | 9bfca3c | 2010-05-24 06:29:34 +0000 | [diff] [blame] | 316 | phyinfo->phy_ref_count++; |
| 317 | if (phyinfo->phy_ref_count == 1 && |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 318 | phyinfo->phy_layer->modemcmd != NULL) { |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 319 | phyinfo->phy_layer->modemcmd(phyinfo->phy_layer, |
| 320 | _CAIF_MODEMCMD_PHYIF_USEFULL); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 321 | } |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 322 | adapt_layer->id = channel_id; |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 323 | |
| 324 | switch (serv) { |
| 325 | case CFCTRL_SRV_VEI: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 326 | servicel = cfvei_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 327 | break; |
| 328 | case CFCTRL_SRV_DATAGRAM: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 329 | servicel = cfdgml_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 330 | break; |
| 331 | case CFCTRL_SRV_RFM: |
Sjur Braendeland | a7da1f5 | 2010-06-17 06:55:39 +0000 | [diff] [blame^] | 332 | servicel = cfrfml_create(channel_id, &phyinfo->dev_info, |
| 333 | RFM_FRAGMENT_SIZE); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 334 | break; |
| 335 | case CFCTRL_SRV_UTIL: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 336 | servicel = cfutill_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 337 | break; |
| 338 | case CFCTRL_SRV_VIDEO: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 339 | servicel = cfvidl_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 340 | break; |
| 341 | case CFCTRL_SRV_DBG: |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 342 | servicel = cfdbgl_create(channel_id, &phyinfo->dev_info); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 343 | break; |
| 344 | default: |
| 345 | pr_err("CAIF: %s(): Protocol error. " |
| 346 | "Link setup response - unknown channel type\n", |
| 347 | __func__); |
| 348 | return; |
| 349 | } |
| 350 | if (!servicel) { |
| 351 | pr_warning("CAIF: %s(): Out of memory\n", __func__); |
| 352 | return; |
| 353 | } |
| 354 | layer_set_dn(servicel, cnfg->mux); |
Sjur Braendeland | e539d83 | 2010-04-28 08:54:35 +0000 | [diff] [blame] | 355 | cfmuxl_set_uplayer(cnfg->mux, servicel, channel_id); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 356 | layer_set_up(servicel, adapt_layer); |
| 357 | layer_set_dn(adapt_layer, servicel); |
Sjur Braendeland | 8d545c8 | 2010-04-28 08:54:37 +0000 | [diff] [blame] | 358 | cfsrvl_get(servicel); |
Sjur Braendeland | 15c9ac0 | 2010-03-30 13:56:24 +0000 | [diff] [blame] | 359 | servicel->ctrlcmd(servicel, CAIF_CTRLCMD_INIT_RSP, 0); |
| 360 | } |
| 361 | |
| 362 | void |
| 363 | cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type, |
| 364 | void *dev, struct cflayer *phy_layer, u16 *phyid, |
| 365 | enum cfcnfg_phy_preference pref, |
| 366 | bool fcs, bool stx) |
| 367 | { |
| 368 | struct cflayer *frml; |
| 369 | struct cflayer *phy_driver = NULL; |
| 370 | int i; |
| 371 | |
| 372 | |
| 373 | if (cnfg->phy_layers[cnfg->last_phyid].frm_layer == NULL) { |
| 374 | *phyid = cnfg->last_phyid; |
| 375 | |
| 376 | /* range: * 1..(MAX_PHY_LAYERS-1) */ |
| 377 | cnfg->last_phyid = |
| 378 | (cnfg->last_phyid % (MAX_PHY_LAYERS - 1)) + 1; |
| 379 | } else { |
| 380 | *phyid = 0; |
| 381 | for (i = 1; i < MAX_PHY_LAYERS; i++) { |
| 382 | if (cnfg->phy_layers[i].frm_layer == NULL) { |
| 383 | *phyid = i; |
| 384 | break; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | if (*phyid == 0) { |
| 389 | pr_err("CAIF: %s(): No Available PHY ID\n", __func__); |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | switch (phy_type) { |
| 394 | case CFPHYTYPE_FRAG: |
| 395 | phy_driver = |
| 396 | cfserl_create(CFPHYTYPE_FRAG, *phyid, stx); |
| 397 | if (!phy_driver) { |
| 398 | pr_warning("CAIF: %s(): Out of memory\n", __func__); |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | break; |
| 403 | case CFPHYTYPE_CAIF: |
| 404 | phy_driver = NULL; |
| 405 | break; |
| 406 | default: |
| 407 | pr_err("CAIF: %s(): %d", __func__, phy_type); |
| 408 | return; |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | phy_layer->id = *phyid; |
| 413 | cnfg->phy_layers[*phyid].pref = pref; |
| 414 | cnfg->phy_layers[*phyid].id = *phyid; |
| 415 | cnfg->phy_layers[*phyid].dev_info.id = *phyid; |
| 416 | cnfg->phy_layers[*phyid].dev_info.dev = dev; |
| 417 | cnfg->phy_layers[*phyid].phy_layer = phy_layer; |
| 418 | cnfg->phy_layers[*phyid].phy_ref_count = 0; |
| 419 | phy_layer->type = phy_type; |
| 420 | frml = cffrml_create(*phyid, fcs); |
| 421 | if (!frml) { |
| 422 | pr_warning("CAIF: %s(): Out of memory\n", __func__); |
| 423 | return; |
| 424 | } |
| 425 | cnfg->phy_layers[*phyid].frm_layer = frml; |
| 426 | cfmuxl_set_dnlayer(cnfg->mux, frml, *phyid); |
| 427 | layer_set_up(frml, cnfg->mux); |
| 428 | |
| 429 | if (phy_driver != NULL) { |
| 430 | phy_driver->id = *phyid; |
| 431 | layer_set_dn(frml, phy_driver); |
| 432 | layer_set_up(phy_driver, frml); |
| 433 | layer_set_dn(phy_driver, phy_layer); |
| 434 | layer_set_up(phy_layer, phy_driver); |
| 435 | } else { |
| 436 | layer_set_dn(frml, phy_layer); |
| 437 | layer_set_up(phy_layer, frml); |
| 438 | } |
| 439 | } |
| 440 | EXPORT_SYMBOL(cfcnfg_add_phy_layer); |
| 441 | |
| 442 | int cfcnfg_del_phy_layer(struct cfcnfg *cnfg, struct cflayer *phy_layer) |
| 443 | { |
| 444 | struct cflayer *frml, *frml_dn; |
| 445 | u16 phyid; |
| 446 | phyid = phy_layer->id; |
| 447 | caif_assert(phyid == cnfg->phy_layers[phyid].id); |
| 448 | caif_assert(phy_layer == cnfg->phy_layers[phyid].phy_layer); |
| 449 | caif_assert(phy_layer->id == phyid); |
| 450 | caif_assert(cnfg->phy_layers[phyid].frm_layer->id == phyid); |
| 451 | |
| 452 | memset(&cnfg->phy_layers[phy_layer->id], 0, |
| 453 | sizeof(struct cfcnfg_phyinfo)); |
| 454 | frml = cfmuxl_remove_dnlayer(cnfg->mux, phy_layer->id); |
| 455 | frml_dn = frml->dn; |
| 456 | cffrml_set_uplayer(frml, NULL); |
| 457 | cffrml_set_dnlayer(frml, NULL); |
| 458 | kfree(frml); |
| 459 | |
| 460 | if (phy_layer != frml_dn) { |
| 461 | layer_set_up(frml_dn, NULL); |
| 462 | layer_set_dn(frml_dn, NULL); |
| 463 | kfree(frml_dn); |
| 464 | } |
| 465 | layer_set_up(phy_layer, NULL); |
| 466 | return 0; |
| 467 | } |
| 468 | EXPORT_SYMBOL(cfcnfg_del_phy_layer); |