aboutsummaryrefslogtreecommitdiffstats
path: root/net/caif
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2011-04-11 06:43:50 -0400
committerDavid S. Miller <davem@davemloft.net>2011-04-11 18:08:47 -0400
commit73d6ac633c6c0ca703f90db0b808d9593e46aef6 (patch)
tree738fb16f97e24288f9db9c6b43b4bcee4f794dc6 /net/caif
parent1c01a80cfec6f806246f31ff2680cd3639b30e67 (diff)
caif: code cleanup
Cleanup of new CAIF code. * make local functions static * remove code that is never used * expand get_caif_conf() since wrapper is no longer needed * make args to comparison functions const * rename connect_req_to_link_param to keep exported names consistent Compile tested only. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Acked-by: Sjur Brændeland <sjur.brandeland@stericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/caif')
-rw-r--r--net/caif/caif_config_util.c6
-rw-r--r--net/caif/caif_dev.c24
-rw-r--r--net/caif/cfcnfg.c2
-rw-r--r--net/caif/cfctrl.c75
-rw-r--r--net/caif/cfmuxl.c35
-rw-r--r--net/caif/cfpkt_skbuff.c178
-rw-r--r--net/caif/cfsrvl.c7
7 files changed, 23 insertions, 304 deletions
diff --git a/net/caif/caif_config_util.c b/net/caif/caif_config_util.c
index d522d8c1703e..9b63e4e3910e 100644
--- a/net/caif/caif_config_util.c
+++ b/net/caif/caif_config_util.c
@@ -10,9 +10,9 @@
10#include <net/caif/cfcnfg.h> 10#include <net/caif/cfcnfg.h>
11#include <net/caif/caif_dev.h> 11#include <net/caif/caif_dev.h>
12 12
13int connect_req_to_link_param(struct cfcnfg *cnfg, 13int caif_connect_req_to_link_param(struct cfcnfg *cnfg,
14 struct caif_connect_request *s, 14 struct caif_connect_request *s,
15 struct cfctrl_link_param *l) 15 struct cfctrl_link_param *l)
16{ 16{
17 struct dev_info *dev_info; 17 struct dev_info *dev_info;
18 enum cfcnfg_phy_preference pref; 18 enum cfcnfg_phy_preference pref;
diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
index a42a408306e4..b533bb09a002 100644
--- a/net/caif/caif_dev.c
+++ b/net/caif/caif_dev.c
@@ -257,7 +257,7 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what,
257 break; 257 break;
258 } 258 }
259 dev_hold(dev); 259 dev_hold(dev);
260 cfcnfg_add_phy_layer(get_caif_conf(), 260 cfcnfg_add_phy_layer(cfg,
261 phy_type, 261 phy_type,
262 dev, 262 dev,
263 &caifd->layer, 263 &caifd->layer,
@@ -300,7 +300,7 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what,
300 if (atomic_read(&caifd->in_use)) 300 if (atomic_read(&caifd->in_use))
301 netdev_warn(dev, 301 netdev_warn(dev,
302 "Unregistering an active CAIF device\n"); 302 "Unregistering an active CAIF device\n");
303 cfcnfg_del_phy_layer(get_caif_conf(), &caifd->layer); 303 cfcnfg_del_phy_layer(cfg, &caifd->layer);
304 dev_put(dev); 304 dev_put(dev);
305 atomic_set(&caifd->state, what); 305 atomic_set(&caifd->state, what);
306 break; 306 break;
@@ -322,24 +322,18 @@ static struct notifier_block caif_device_notifier = {
322 .priority = 0, 322 .priority = 0,
323}; 323};
324 324
325
326struct cfcnfg *get_caif_conf(void)
327{
328 return cfg;
329}
330EXPORT_SYMBOL(get_caif_conf);
331
332int caif_connect_client(struct caif_connect_request *conn_req, 325int caif_connect_client(struct caif_connect_request *conn_req,
333 struct cflayer *client_layer, int *ifindex, 326 struct cflayer *client_layer, int *ifindex,
334 int *headroom, int *tailroom) 327 int *headroom, int *tailroom)
335{ 328{
336 struct cfctrl_link_param param; 329 struct cfctrl_link_param param;
337 int ret; 330 int ret;
338 ret = connect_req_to_link_param(get_caif_conf(), conn_req, &param); 331
332 ret = caif_connect_req_to_link_param(cfg, conn_req, &param);
339 if (ret) 333 if (ret)
340 return ret; 334 return ret;
341 /* Hook up the adaptation layer. */ 335 /* Hook up the adaptation layer. */
342 return cfcnfg_add_adaptation_layer(get_caif_conf(), &param, 336 return cfcnfg_add_adaptation_layer(cfg, &param,
343 client_layer, ifindex, 337 client_layer, ifindex,
344 headroom, tailroom); 338 headroom, tailroom);
345} 339}
@@ -347,16 +341,10 @@ EXPORT_SYMBOL(caif_connect_client);
347 341
348int caif_disconnect_client(struct cflayer *adap_layer) 342int caif_disconnect_client(struct cflayer *adap_layer)
349{ 343{
350 return cfcnfg_disconn_adapt_layer(get_caif_conf(), adap_layer); 344 return cfcnfg_disconn_adapt_layer(cfg, adap_layer);
351} 345}
352EXPORT_SYMBOL(caif_disconnect_client); 346EXPORT_SYMBOL(caif_disconnect_client);
353 347
354void caif_release_client(struct cflayer *adap_layer)
355{
356 cfcnfg_release_adap_layer(adap_layer);
357}
358EXPORT_SYMBOL(caif_release_client);
359
360/* Per-namespace Caif devices handling */ 348/* Per-namespace Caif devices handling */
361static int caif_init_net(struct net *net) 349static int caif_init_net(struct net *net)
362{ 350{
diff --git a/net/caif/cfcnfg.c b/net/caif/cfcnfg.c
index f1f98d967d8a..25c0b198e285 100644
--- a/net/caif/cfcnfg.c
+++ b/net/caif/cfcnfg.c
@@ -253,7 +253,7 @@ static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id)
253{ 253{
254} 254}
255 255
256int protohead[CFCTRL_SRV_MASK] = { 256static const int protohead[CFCTRL_SRV_MASK] = {
257 [CFCTRL_SRV_VEI] = 4, 257 [CFCTRL_SRV_VEI] = 4,
258 [CFCTRL_SRV_DATAGRAM] = 7, 258 [CFCTRL_SRV_DATAGRAM] = 7,
259 [CFCTRL_SRV_UTIL] = 4, 259 [CFCTRL_SRV_UTIL] = 4,
diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
index 3cd8f978e309..397a2c099e2c 100644
--- a/net/caif/cfctrl.c
+++ b/net/caif/cfctrl.c
@@ -58,7 +58,8 @@ struct cflayer *cfctrl_create(void)
58 return &this->serv.layer; 58 return &this->serv.layer;
59} 59}
60 60
61static bool param_eq(struct cfctrl_link_param *p1, struct cfctrl_link_param *p2) 61static bool param_eq(const struct cfctrl_link_param *p1,
62 const struct cfctrl_link_param *p2)
62{ 63{
63 bool eq = 64 bool eq =
64 p1->linktype == p2->linktype && 65 p1->linktype == p2->linktype &&
@@ -100,8 +101,8 @@ static bool param_eq(struct cfctrl_link_param *p1, struct cfctrl_link_param *p2)
100 return false; 101 return false;
101} 102}
102 103
103bool cfctrl_req_eq(struct cfctrl_request_info *r1, 104static bool cfctrl_req_eq(const struct cfctrl_request_info *r1,
104 struct cfctrl_request_info *r2) 105 const struct cfctrl_request_info *r2)
105{ 106{
106 if (r1->cmd != r2->cmd) 107 if (r1->cmd != r2->cmd)
107 return false; 108 return false;
@@ -112,7 +113,7 @@ bool cfctrl_req_eq(struct cfctrl_request_info *r1,
112} 113}
113 114
114/* Insert request at the end */ 115/* Insert request at the end */
115void cfctrl_insert_req(struct cfctrl *ctrl, 116static void cfctrl_insert_req(struct cfctrl *ctrl,
116 struct cfctrl_request_info *req) 117 struct cfctrl_request_info *req)
117{ 118{
118 spin_lock(&ctrl->info_list_lock); 119 spin_lock(&ctrl->info_list_lock);
@@ -123,8 +124,8 @@ void cfctrl_insert_req(struct cfctrl *ctrl,
123} 124}
124 125
125/* Compare and remove request */ 126/* Compare and remove request */
126struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl, 127static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
127 struct cfctrl_request_info *req) 128 struct cfctrl_request_info *req)
128{ 129{
129 struct cfctrl_request_info *p, *tmp, *first; 130 struct cfctrl_request_info *p, *tmp, *first;
130 131
@@ -154,16 +155,6 @@ struct cfctrl_rsp *cfctrl_get_respfuncs(struct cflayer *layer)
154 return &this->res; 155 return &this->res;
155} 156}
156 157
157void cfctrl_set_dnlayer(struct cflayer *this, struct cflayer *dn)
158{
159 this->dn = dn;
160}
161
162void cfctrl_set_uplayer(struct cflayer *this, struct cflayer *up)
163{
164 this->up = up;
165}
166
167static void init_info(struct caif_payload_info *info, struct cfctrl *cfctrl) 158static void init_info(struct caif_payload_info *info, struct cfctrl *cfctrl)
168{ 159{
169 info->hdr_len = 0; 160 info->hdr_len = 0;
@@ -304,58 +295,6 @@ int cfctrl_linkdown_req(struct cflayer *layer, u8 channelid,
304 return ret; 295 return ret;
305} 296}
306 297
307void cfctrl_sleep_req(struct cflayer *layer)
308{
309 int ret;
310 struct cfctrl *cfctrl = container_obj(layer);
311 struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN);
312 if (!pkt) {
313 pr_warn("Out of memory\n");
314 return;
315 }
316 cfpkt_addbdy(pkt, CFCTRL_CMD_SLEEP);
317 init_info(cfpkt_info(pkt), cfctrl);
318 ret =
319 cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt);
320 if (ret < 0)
321 cfpkt_destroy(pkt);
322}
323
324void cfctrl_wake_req(struct cflayer *layer)
325{
326 int ret;
327 struct cfctrl *cfctrl = container_obj(layer);
328 struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN);
329 if (!pkt) {
330 pr_warn("Out of memory\n");
331 return;
332 }
333 cfpkt_addbdy(pkt, CFCTRL_CMD_WAKE);
334 init_info(cfpkt_info(pkt), cfctrl);
335 ret =
336 cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt);
337 if (ret < 0)
338 cfpkt_destroy(pkt);
339}
340
341void cfctrl_getstartreason_req(struct cflayer *layer)
342{
343 int ret;
344 struct cfctrl *cfctrl = container_obj(layer);
345 struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN);
346 if (!pkt) {
347 pr_warn("Out of memory\n");
348 return;
349 }
350 cfpkt_addbdy(pkt, CFCTRL_CMD_START_REASON);
351 init_info(cfpkt_info(pkt), cfctrl);
352 ret =
353 cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt);
354 if (ret < 0)
355 cfpkt_destroy(pkt);
356}
357
358
359void cfctrl_cancel_req(struct cflayer *layr, struct cflayer *adap_layer) 298void cfctrl_cancel_req(struct cflayer *layr, struct cflayer *adap_layer)
360{ 299{
361 struct cfctrl_request_info *p, *tmp; 300 struct cfctrl_request_info *p, *tmp;
diff --git a/net/caif/cfmuxl.c b/net/caif/cfmuxl.c
index 24f1ffa74b06..f8ce0f3d9210 100644
--- a/net/caif/cfmuxl.c
+++ b/net/caif/cfmuxl.c
@@ -71,41 +71,6 @@ int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid)
71 return 0; 71 return 0;
72} 72}
73 73
74bool cfmuxl_is_phy_inuse(struct cflayer *layr, u8 phyid)
75{
76 struct list_head *node;
77 struct cflayer *layer;
78 struct cfmuxl *muxl = container_obj(layr);
79 bool match = false;
80 spin_lock(&muxl->receive_lock);
81
82 list_for_each(node, &muxl->srvl_list) {
83 layer = list_entry(node, struct cflayer, node);
84 if (cfsrvl_phyid_match(layer, phyid)) {
85 match = true;
86 break;
87 }
88
89 }
90 spin_unlock(&muxl->receive_lock);
91 return match;
92}
93
94u8 cfmuxl_get_phyid(struct cflayer *layr, u8 channel_id)
95{
96 struct cflayer *up;
97 int phyid;
98 struct cfmuxl *muxl = container_obj(layr);
99 spin_lock(&muxl->receive_lock);
100 up = get_up(muxl, channel_id);
101 if (up != NULL)
102 phyid = cfsrvl_getphyid(up);
103 else
104 phyid = 0;
105 spin_unlock(&muxl->receive_lock);
106 return phyid;
107}
108
109int cfmuxl_set_dnlayer(struct cflayer *layr, struct cflayer *dn, u8 phyid) 74int cfmuxl_set_dnlayer(struct cflayer *layr, struct cflayer *dn, u8 phyid)
110{ 75{
111 struct cfmuxl *muxl = (struct cfmuxl *) layr; 76 struct cfmuxl *muxl = (struct cfmuxl *) layr;
diff --git a/net/caif/cfpkt_skbuff.c b/net/caif/cfpkt_skbuff.c
index d7e865e2ff65..20c6cb3522e0 100644
--- a/net/caif/cfpkt_skbuff.c
+++ b/net/caif/cfpkt_skbuff.c
@@ -42,22 +42,22 @@ struct cfpkt_priv_data {
42 bool erronous; 42 bool erronous;
43}; 43};
44 44
45inline struct cfpkt_priv_data *cfpkt_priv(struct cfpkt *pkt) 45static inline struct cfpkt_priv_data *cfpkt_priv(struct cfpkt *pkt)
46{ 46{
47 return (struct cfpkt_priv_data *) pkt->skb.cb; 47 return (struct cfpkt_priv_data *) pkt->skb.cb;
48} 48}
49 49
50inline bool is_erronous(struct cfpkt *pkt) 50static inline bool is_erronous(struct cfpkt *pkt)
51{ 51{
52 return cfpkt_priv(pkt)->erronous; 52 return cfpkt_priv(pkt)->erronous;
53} 53}
54 54
55inline struct sk_buff *pkt_to_skb(struct cfpkt *pkt) 55static inline struct sk_buff *pkt_to_skb(struct cfpkt *pkt)
56{ 56{
57 return &pkt->skb; 57 return &pkt->skb;
58} 58}
59 59
60inline struct cfpkt *skb_to_pkt(struct sk_buff *skb) 60static inline struct cfpkt *skb_to_pkt(struct sk_buff *skb)
61{ 61{
62 return (struct cfpkt *) skb; 62 return (struct cfpkt *) skb;
63} 63}
@@ -317,17 +317,6 @@ int cfpkt_setlen(struct cfpkt *pkt, u16 len)
317} 317}
318EXPORT_SYMBOL(cfpkt_setlen); 318EXPORT_SYMBOL(cfpkt_setlen);
319 319
320struct cfpkt *cfpkt_create_uplink(const unsigned char *data, unsigned int len)
321{
322 struct cfpkt *pkt = cfpkt_create_pfx(len + PKT_POSTFIX, PKT_PREFIX);
323 if (!pkt)
324 return NULL;
325 if (unlikely(data != NULL))
326 cfpkt_add_body(pkt, data, len);
327 return pkt;
328}
329EXPORT_SYMBOL(cfpkt_create_uplink);
330
331struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, 320struct cfpkt *cfpkt_append(struct cfpkt *dstpkt,
332 struct cfpkt *addpkt, 321 struct cfpkt *addpkt,
333 u16 expectlen) 322 u16 expectlen)
@@ -408,169 +397,12 @@ struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos)
408} 397}
409EXPORT_SYMBOL(cfpkt_split); 398EXPORT_SYMBOL(cfpkt_split);
410 399
411char *cfpkt_log_pkt(struct cfpkt *pkt, char *buf, int buflen) 400bool cfpkt_erroneous(struct cfpkt *pkt)
412{
413 struct sk_buff *skb = pkt_to_skb(pkt);
414 char *p = buf;
415 int i;
416
417 /*
418 * Sanity check buffer length, it needs to be at least as large as
419 * the header info: ~=50+ bytes
420 */
421 if (buflen < 50)
422 return NULL;
423
424 snprintf(buf, buflen, "%s: pkt:%p len:%ld(%ld+%ld) {%ld,%ld} data: [",
425 is_erronous(pkt) ? "ERRONOUS-SKB" :
426 (skb->data_len != 0 ? "COMPLEX-SKB" : "SKB"),
427 skb,
428 (long) skb->len,
429 (long) (skb_tail_pointer(skb) - skb->data),
430 (long) skb->data_len,
431 (long) (skb->data - skb->head),
432 (long) (skb_tail_pointer(skb) - skb->head));
433 p = buf + strlen(buf);
434
435 for (i = 0; i < skb_tail_pointer(skb) - skb->data && i < 300; i++) {
436 if (p > buf + buflen - 10) {
437 sprintf(p, "...");
438 p = buf + strlen(buf);
439 break;
440 }
441 sprintf(p, "%02x,", skb->data[i]);
442 p = buf + strlen(buf);
443 }
444 sprintf(p, "]\n");
445 return buf;
446}
447EXPORT_SYMBOL(cfpkt_log_pkt);
448
449int cfpkt_raw_append(struct cfpkt *pkt, void **buf, unsigned int buflen)
450{
451 struct sk_buff *skb = pkt_to_skb(pkt);
452 struct sk_buff *lastskb;
453
454 caif_assert(buf != NULL);
455 if (unlikely(is_erronous(pkt)))
456 return -EPROTO;
457 /* Make sure SKB is writable */
458 if (unlikely(skb_cow_data(skb, 0, &lastskb) < 0)) {
459 PKT_ERROR(pkt, "skb_cow_data failed\n");
460 return -EPROTO;
461 }
462
463 if (unlikely(skb_linearize(skb) != 0)) {
464 PKT_ERROR(pkt, "linearize failed\n");
465 return -EPROTO;
466 }
467
468 if (unlikely(skb_tailroom(skb) < buflen)) {
469 PKT_ERROR(pkt, "buffer too short - failed\n");
470 return -EPROTO;
471 }
472
473 *buf = skb_put(skb, buflen);
474 return 1;
475}
476EXPORT_SYMBOL(cfpkt_raw_append);
477
478int cfpkt_raw_extract(struct cfpkt *pkt, void **buf, unsigned int buflen)
479{
480 struct sk_buff *skb = pkt_to_skb(pkt);
481
482 caif_assert(buf != NULL);
483 if (unlikely(is_erronous(pkt)))
484 return -EPROTO;
485
486 if (unlikely(buflen > skb->len)) {
487 PKT_ERROR(pkt, "buflen too large - failed\n");
488 return -EPROTO;
489 }
490
491 if (unlikely(buflen > skb_headlen(skb))) {
492 if (unlikely(skb_linearize(skb) != 0)) {
493 PKT_ERROR(pkt, "linearize failed\n");
494 return -EPROTO;
495 }
496 }
497
498 *buf = skb->data;
499 skb_pull(skb, buflen);
500
501 return 1;
502}
503EXPORT_SYMBOL(cfpkt_raw_extract);
504
505inline bool cfpkt_erroneous(struct cfpkt *pkt)
506{ 401{
507 return cfpkt_priv(pkt)->erronous; 402 return cfpkt_priv(pkt)->erronous;
508} 403}
509EXPORT_SYMBOL(cfpkt_erroneous); 404EXPORT_SYMBOL(cfpkt_erroneous);
510 405
511struct cfpktq *cfpktq_create(void)
512{
513 struct cfpktq *q = kmalloc(sizeof(struct cfpktq), GFP_ATOMIC);
514 if (!q)
515 return NULL;
516 skb_queue_head_init(&q->head);
517 atomic_set(&q->count, 0);
518 spin_lock_init(&q->lock);
519 return q;
520}
521EXPORT_SYMBOL(cfpktq_create);
522
523void cfpkt_queue(struct cfpktq *pktq, struct cfpkt *pkt, unsigned short prio)
524{
525 atomic_inc(&pktq->count);
526 spin_lock(&pktq->lock);
527 skb_queue_tail(&pktq->head, pkt_to_skb(pkt));
528 spin_unlock(&pktq->lock);
529
530}
531EXPORT_SYMBOL(cfpkt_queue);
532
533struct cfpkt *cfpkt_qpeek(struct cfpktq *pktq)
534{
535 struct cfpkt *tmp;
536 spin_lock(&pktq->lock);
537 tmp = skb_to_pkt(skb_peek(&pktq->head));
538 spin_unlock(&pktq->lock);
539 return tmp;
540}
541EXPORT_SYMBOL(cfpkt_qpeek);
542
543struct cfpkt *cfpkt_dequeue(struct cfpktq *pktq)
544{
545 struct cfpkt *pkt;
546 spin_lock(&pktq->lock);
547 pkt = skb_to_pkt(skb_dequeue(&pktq->head));
548 if (pkt) {
549 atomic_dec(&pktq->count);
550 caif_assert(atomic_read(&pktq->count) >= 0);
551 }
552 spin_unlock(&pktq->lock);
553 return pkt;
554}
555EXPORT_SYMBOL(cfpkt_dequeue);
556
557int cfpkt_qcount(struct cfpktq *pktq)
558{
559 return atomic_read(&pktq->count);
560}
561EXPORT_SYMBOL(cfpkt_qcount);
562
563struct cfpkt *cfpkt_clone_release(struct cfpkt *pkt)
564{
565 struct cfpkt *clone;
566 clone = skb_to_pkt(skb_clone(pkt_to_skb(pkt), GFP_ATOMIC));
567 /* Free original packet. */
568 cfpkt_destroy(pkt);
569 if (!clone)
570 return NULL;
571 return clone;
572}
573EXPORT_SYMBOL(cfpkt_clone_release);
574 406
575struct caif_payload_info *cfpkt_info(struct cfpkt *pkt) 407struct caif_payload_info *cfpkt_info(struct cfpkt *pkt)
576{ 408{
diff --git a/net/caif/cfsrvl.c b/net/caif/cfsrvl.c
index ab5e542526bf..24ba392f203b 100644
--- a/net/caif/cfsrvl.c
+++ b/net/caif/cfsrvl.c
@@ -151,12 +151,7 @@ static int cfservl_modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl)
151 return -EINVAL; 151 return -EINVAL;
152} 152}
153 153
154void cfservl_destroy(struct cflayer *layer) 154static void cfsrvl_release(struct kref *kref)
155{
156 kfree(layer);
157}
158
159void cfsrvl_release(struct kref *kref)
160{ 155{
161 struct cfsrvl *service = container_of(kref, struct cfsrvl, ref); 156 struct cfsrvl *service = container_of(kref, struct cfsrvl, ref);
162 kfree(service); 157 kfree(service);