7 #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
9 #include <linux/kernel.h>
10 #include <linux/stddef.h>
11 #include <linux/slab.h>
12 #include <linux/netdevice.h>
13 #include <linux/module.h>
24 #define container_obj(layr) container_of(layr, struct cfcnfg, layer)
63 static void cfcnfg_linkup_rsp(
struct cflayer *layer,
u8 channel_id,
66 static void cfcnfg_linkdestroy_rsp(
struct cflayer *layer,
u8 channel_id);
67 static void cfcnfg_reject_rsp(
struct cflayer *layer,
u8 channel_id,
69 static void cfctrl_resp_func(
void);
70 static void cfctrl_enum_resp(
void);
100 INIT_LIST_HEAD(&this->
phys);
129 static void cfctrl_resp_func(
void)
138 list_for_each_entry_rcu(phy, &cnfg->
phys,
node)
139 if (phy->
id == phyid)
144 static
void cfctrl_enum_resp(
void)
154 list_for_each_entry_rcu(phy, &cnfg->
phys,
node) {
155 if (phy->
up && phy->
pref == phy_pref &&
162 list_for_each_entry_rcu(phy, &cnfg->
phys,
node)
169 static
int cfcnfg_get_id_from_ifi(
struct cfcnfg *cnfg,
int ifi)
173 list_for_each_entry_rcu(phy, &cnfg->phys,
node)
186 channel_id = adap_layer->id;
187 if (channel_id != 0) {
194 pr_debug(
"nothing to disconnect\n");
198 if (adap_layer->ctrlcmd != NULL)
205 static void cfcnfg_linkdestroy_rsp(
struct cflayer *layer,
u8 channel_id)
218 static int caif_connect_req_to_link_param(
struct cfcnfg *cnfg,
231 res = cfcnfg_get_id_from_ifi(cnfg, s->
ifindex);
246 dev_info = cfcnfg_get_phyid(cnfg, pref);
247 if (dev_info == NULL)
272 sizeof(l->
u.
rfm.volume)-1);
273 l->
u.
rfm.volume[
sizeof(l->
u.
rfm.volume)-1] = 0;
303 struct cflayer *adap_layer,
int *ifindex,
314 err = caif_connect_req_to_link_param(cfg, conn_req, ¶m);
318 phy = cfcnfg_get_phyinfo_rcu(cfg, param.
phyid);
325 if (adap_layer == NULL) {
326 pr_err(
"adap_layer is zero\n");
329 if (adap_layer->
receive == NULL) {
330 pr_err(
"adap_layer->receive is NULL\n");
333 if (adap_layer->
ctrlcmd == NULL) {
334 pr_err(
"adap_layer->ctrlcmd == NULL\n");
341 pr_err(
"Specified PHY type does not exist!\n");
366 static void cfcnfg_reject_rsp(
struct cflayer *
layer,
u8 channel_id,
369 if (adapt_layer != NULL && adapt_layer->
ctrlcmd != NULL)
370 adapt_layer->
ctrlcmd(adapt_layer,
383 if (channel_id == 0) {
384 pr_warn(
"received channel_id zero\n");
385 if (adapt_layer != NULL && adapt_layer->
ctrlcmd != NULL)
386 adapt_layer->
ctrlcmd(adapt_layer,
393 if (adapt_layer == NULL) {
394 pr_debug(
"link setup response but no client exist,"
395 "send linkdown back\n");
403 phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phyid);
404 if (phyinfo == NULL) {
405 pr_err(
"ERROR: Link Layer Device dissapeared"
406 "while connecting\n");
415 adapt_layer->
id = channel_id;
440 pr_err(
"Protocol error. Link setup response "
441 "- unknown channel type\n");
464 bool fcs,
int head_room)
474 for (i = 0; i < 7; i++) {
478 if (cfcnfg_get_phyinfo_rcu(cnfg, phyid) ==
NULL)
481 pr_warn(
"Too many CAIF Link Layers (max 6)\n");
489 phy_layer->
id = phyid;
506 if (link_support != NULL) {
507 link_support->
id = phyid;
517 list_add_rcu(&phyinfo->
node, &cnfg->
phys);
534 phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phy_layer->
id);
535 if (phyinfo == NULL) {
540 if (phyinfo->
up == up) {
562 struct cflayer *frml, *frml_dn;
570 phyid = phy_layer->
id;
571 phyinfo = cfcnfg_get_phyinfo_rcu(cnfg, phyid);
573 if (phyinfo == NULL) {
582 list_del_rcu(&phyinfo->
node);
587 pr_info(
"Wait for device inuse\n");
588 list_add_rcu(&phyinfo->
node, &cnfg->
phys);
597 if (phy_layer != frml_dn) {