diff options
author | Jan Kiszka <jan.kiszka@web.de> | 2010-02-08 05:12:16 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-02-16 19:01:23 -0500 |
commit | 501c87a91909efaad91425635b29b01f1473c659 (patch) | |
tree | 18c8e7e1ece24e62818038ec9c336a8a8c101dcb /drivers/isdn/capi | |
parent | 88c896ef87fd0dd4dbf36e8e86e019c74b1f6649 (diff) |
CAPI: Reduce #ifdef mess around CONFIG_ISDN_CAPI_MIDDLEWARE
Make the code a bit more readable be providing stub functions for the
!CONFIG_ISDN_CAPI_MIDDLEWARE case. Though a few lines are moved around,
this comes with no functional changes.
Signed-off-by: Jan Kiszka <jan.kiszka@web.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/isdn/capi')
-rw-r--r-- | drivers/isdn/capi/capi.c | 150 |
1 files changed, 83 insertions, 67 deletions
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 3b077978c496..7d2ca6b2564c 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c | |||
@@ -23,14 +23,10 @@ | |||
23 | #include <linux/smp_lock.h> | 23 | #include <linux/smp_lock.h> |
24 | #include <linux/timer.h> | 24 | #include <linux/timer.h> |
25 | #include <linux/wait.h> | 25 | #include <linux/wait.h> |
26 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
27 | #include <linux/tty.h> | 26 | #include <linux/tty.h> |
28 | #ifdef CONFIG_PPP | ||
29 | #include <linux/netdevice.h> | 27 | #include <linux/netdevice.h> |
30 | #include <linux/ppp_defs.h> | 28 | #include <linux/ppp_defs.h> |
31 | #include <linux/if_ppp.h> | 29 | #include <linux/if_ppp.h> |
32 | #endif /* CONFIG_PPP */ | ||
33 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
34 | #include <linux/skbuff.h> | 30 | #include <linux/skbuff.h> |
35 | #include <linux/proc_fs.h> | 31 | #include <linux/proc_fs.h> |
36 | #include <linux/seq_file.h> | 32 | #include <linux/seq_file.h> |
@@ -56,17 +52,17 @@ MODULE_LICENSE("GPL"); | |||
56 | /* -------- driver information -------------------------------------- */ | 52 | /* -------- driver information -------------------------------------- */ |
57 | 53 | ||
58 | static struct class *capi_class; | 54 | static struct class *capi_class; |
59 | |||
60 | static int capi_major = 68; /* allocated */ | 55 | static int capi_major = 68; /* allocated */ |
56 | |||
57 | module_param_named(major, capi_major, uint, 0); | ||
58 | |||
61 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | 59 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
62 | #define CAPINC_NR_PORTS 32 | 60 | #define CAPINC_NR_PORTS 32 |
63 | #define CAPINC_MAX_PORTS 256 | 61 | #define CAPINC_MAX_PORTS 256 |
62 | |||
64 | static int capi_ttymajor = 191; | 63 | static int capi_ttymajor = 191; |
65 | static int capi_ttyminors = CAPINC_NR_PORTS; | 64 | static int capi_ttyminors = CAPINC_NR_PORTS; |
66 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
67 | 65 | ||
68 | module_param_named(major, capi_major, uint, 0); | ||
69 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
70 | module_param_named(ttymajor, capi_ttymajor, uint, 0); | 66 | module_param_named(ttymajor, capi_ttymajor, uint, 0); |
71 | module_param_named(ttyminors, capi_ttyminors, uint, 0); | 67 | module_param_named(ttyminors, capi_ttyminors, uint, 0); |
72 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | 68 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
@@ -81,7 +77,6 @@ module_param_named(ttyminors, capi_ttyminors, uint, 0); | |||
81 | 77 | ||
82 | struct capidev; | 78 | struct capidev; |
83 | struct capincci; | 79 | struct capincci; |
84 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
85 | struct capiminor; | 80 | struct capiminor; |
86 | 81 | ||
87 | struct datahandle_queue { | 82 | struct datahandle_queue { |
@@ -116,7 +111,6 @@ struct capiminor { | |||
116 | int nack; | 111 | int nack; |
117 | spinlock_t ackqlock; | 112 | spinlock_t ackqlock; |
118 | }; | 113 | }; |
119 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
120 | 114 | ||
121 | /* FIXME: The following lock is a sledgehammer-workaround to a | 115 | /* FIXME: The following lock is a sledgehammer-workaround to a |
122 | * locking issue with the capiminor (and maybe other) data structure(s). | 116 | * locking issue with the capiminor (and maybe other) data structure(s). |
@@ -156,14 +150,13 @@ static DEFINE_RWLOCK(capidev_list_lock); | |||
156 | static LIST_HEAD(capidev_list); | 150 | static LIST_HEAD(capidev_list); |
157 | 151 | ||
158 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | 152 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
153 | |||
159 | static DEFINE_RWLOCK(capiminor_list_lock); | 154 | static DEFINE_RWLOCK(capiminor_list_lock); |
160 | static LIST_HEAD(capiminor_list); | 155 | static LIST_HEAD(capiminor_list); |
161 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
162 | 156 | ||
163 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
164 | /* -------- datahandles --------------------------------------------- */ | 157 | /* -------- datahandles --------------------------------------------- */ |
165 | 158 | ||
166 | static int capincci_add_ack(struct capiminor *mp, u16 datahandle) | 159 | static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) |
167 | { | 160 | { |
168 | struct datahandle_queue *n; | 161 | struct datahandle_queue *n; |
169 | unsigned long flags; | 162 | unsigned long flags; |
@@ -301,26 +294,17 @@ static struct capiminor *capiminor_find(unsigned int minor) | |||
301 | 294 | ||
302 | return p; | 295 | return p; |
303 | } | 296 | } |
304 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
305 | 297 | ||
306 | /* -------- struct capincci ----------------------------------------- */ | 298 | /* -------- struct capincci ----------------------------------------- */ |
307 | 299 | ||
308 | static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) | 300 | static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) |
309 | { | 301 | { |
310 | struct capincci *np, **pp; | 302 | struct capiminor *mp; |
311 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
312 | struct capiminor *mp = NULL; | ||
313 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
314 | 303 | ||
315 | np = kzalloc(sizeof(*np), GFP_ATOMIC); | 304 | if (!(cdev->userflags & CAPIFLAG_HIGHJACKING)) |
316 | if (!np) | 305 | return; |
317 | return NULL; | 306 | |
318 | np->ncci = ncci; | 307 | mp = np->minorp = capiminor_alloc(&cdev->ap, np->ncci); |
319 | np->cdev = cdev; | ||
320 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
321 | mp = NULL; | ||
322 | if (cdev->userflags & CAPIFLAG_HIGHJACKING) | ||
323 | mp = np->minorp = capiminor_alloc(&cdev->ap, ncci); | ||
324 | if (mp) { | 308 | if (mp) { |
325 | mp->nccip = np; | 309 | mp->nccip = np; |
326 | #ifdef _DEBUG_REFCOUNT | 310 | #ifdef _DEBUG_REFCOUNT |
@@ -330,7 +314,58 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) | |||
330 | capifs_new_ncci(mp->minor, | 314 | capifs_new_ncci(mp->minor, |
331 | MKDEV(capi_ttymajor, mp->minor)); | 315 | MKDEV(capi_ttymajor, mp->minor)); |
332 | } | 316 | } |
333 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | 317 | } |
318 | |||
319 | static void capincci_free_minor(struct capincci *np) | ||
320 | { | ||
321 | struct capiminor *mp = np->minorp; | ||
322 | |||
323 | if (mp) { | ||
324 | capifs_free_ncci(mp->capifs_dentry); | ||
325 | if (mp->tty) { | ||
326 | mp->nccip = NULL; | ||
327 | #ifdef _DEBUG_REFCOUNT | ||
328 | printk(KERN_DEBUG "reset mp->nccip\n"); | ||
329 | #endif | ||
330 | tty_hangup(mp->tty); | ||
331 | } else { | ||
332 | capiminor_free(mp); | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | |||
337 | static inline unsigned int capincci_minor_opencount(struct capincci *np) | ||
338 | { | ||
339 | struct capiminor *mp = np->minorp; | ||
340 | |||
341 | return mp ? atomic_read(&mp->ttyopencount) : 0; | ||
342 | } | ||
343 | |||
344 | #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
345 | |||
346 | static inline void | ||
347 | capincci_alloc_minor(struct capidev *cdev, struct capincci *np) { } | ||
348 | static inline void capincci_free_minor(struct capincci *np) { } | ||
349 | |||
350 | static inline unsigned int capincci_minor_opencount(struct capincci *np) | ||
351 | { | ||
352 | return 0; | ||
353 | } | ||
354 | |||
355 | #endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
356 | |||
357 | static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) | ||
358 | { | ||
359 | struct capincci *np, **pp; | ||
360 | |||
361 | np = kzalloc(sizeof(*np), GFP_ATOMIC); | ||
362 | if (!np) | ||
363 | return NULL; | ||
364 | np->ncci = ncci; | ||
365 | np->cdev = cdev; | ||
366 | |||
367 | capincci_alloc_minor(cdev, np); | ||
368 | |||
334 | for (pp=&cdev->nccis; *pp; pp = &(*pp)->next) | 369 | for (pp=&cdev->nccis; *pp; pp = &(*pp)->next) |
335 | ; | 370 | ; |
336 | *pp = np; | 371 | *pp = np; |
@@ -340,29 +375,13 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) | |||
340 | static void capincci_free(struct capidev *cdev, u32 ncci) | 375 | static void capincci_free(struct capidev *cdev, u32 ncci) |
341 | { | 376 | { |
342 | struct capincci *np, **pp; | 377 | struct capincci *np, **pp; |
343 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
344 | struct capiminor *mp; | ||
345 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
346 | 378 | ||
347 | pp=&cdev->nccis; | 379 | pp=&cdev->nccis; |
348 | while (*pp) { | 380 | while (*pp) { |
349 | np = *pp; | 381 | np = *pp; |
350 | if (ncci == 0xffffffff || np->ncci == ncci) { | 382 | if (ncci == 0xffffffff || np->ncci == ncci) { |
351 | *pp = (*pp)->next; | 383 | *pp = (*pp)->next; |
352 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | 384 | capincci_free_minor(np); |
353 | if ((mp = np->minorp) != NULL) { | ||
354 | capifs_free_ncci(mp->capifs_dentry); | ||
355 | if (mp->tty) { | ||
356 | mp->nccip = NULL; | ||
357 | #ifdef _DEBUG_REFCOUNT | ||
358 | printk(KERN_DEBUG "reset mp->nccip\n"); | ||
359 | #endif | ||
360 | tty_hangup(mp->tty); | ||
361 | } else { | ||
362 | capiminor_free(mp); | ||
363 | } | ||
364 | } | ||
365 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
366 | kfree(np); | 385 | kfree(np); |
367 | if (*pp == NULL) return; | 386 | if (*pp == NULL) return; |
368 | } else { | 387 | } else { |
@@ -552,7 +571,7 @@ static int handle_minor_send(struct capiminor *mp) | |||
552 | capimsg_setu16(skb->data, 18, datahandle); | 571 | capimsg_setu16(skb->data, 18, datahandle); |
553 | capimsg_setu16(skb->data, 20, 0); /* Flags */ | 572 | capimsg_setu16(skb->data, 20, 0); /* Flags */ |
554 | 573 | ||
555 | if (capincci_add_ack(mp, datahandle) < 0) { | 574 | if (capiminor_add_ack(mp, datahandle) < 0) { |
556 | skb_pull(skb, CAPI_DATA_B3_REQ_LEN); | 575 | skb_pull(skb, CAPI_DATA_B3_REQ_LEN); |
557 | skb_queue_head(&mp->outqueue, skb); | 576 | skb_queue_head(&mp->outqueue, skb); |
558 | return count; | 577 | return count; |
@@ -628,10 +647,13 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) | |||
628 | spin_unlock_irqrestore(&workaround_lock, flags); | 647 | spin_unlock_irqrestore(&workaround_lock, flags); |
629 | return; | 648 | return; |
630 | } | 649 | } |
650 | |||
631 | #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE | 651 | #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE |
632 | skb_queue_tail(&cdev->recvqueue, skb); | 652 | skb_queue_tail(&cdev->recvqueue, skb); |
633 | wake_up_interruptible(&cdev->recvwait); | 653 | wake_up_interruptible(&cdev->recvwait); |
654 | |||
634 | #else /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | 655 | #else /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
656 | |||
635 | mp = np->minorp; | 657 | mp = np->minorp; |
636 | if (!mp) { | 658 | if (!mp) { |
637 | skb_queue_tail(&cdev->recvqueue, skb); | 659 | skb_queue_tail(&cdev->recvqueue, skb); |
@@ -639,10 +661,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) | |||
639 | spin_unlock_irqrestore(&workaround_lock, flags); | 661 | spin_unlock_irqrestore(&workaround_lock, flags); |
640 | return; | 662 | return; |
641 | } | 663 | } |
642 | |||
643 | |||
644 | if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) { | 664 | if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) { |
645 | |||
646 | datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2); | 665 | datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2); |
647 | #ifdef _DEBUG_DATAFLOW | 666 | #ifdef _DEBUG_DATAFLOW |
648 | printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n", | 667 | printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n", |
@@ -672,6 +691,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) | |||
672 | wake_up_interruptible(&cdev->recvwait); | 691 | wake_up_interruptible(&cdev->recvwait); |
673 | } | 692 | } |
674 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | 693 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
694 | |||
675 | spin_unlock_irqrestore(&workaround_lock, flags); | 695 | spin_unlock_irqrestore(&workaround_lock, flags); |
676 | } | 696 | } |
677 | 697 | ||
@@ -929,9 +949,6 @@ capi_ioctl(struct inode *inode, struct file *file, | |||
929 | case CAPI_NCCI_OPENCOUNT: | 949 | case CAPI_NCCI_OPENCOUNT: |
930 | { | 950 | { |
931 | struct capincci *nccip; | 951 | struct capincci *nccip; |
932 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
933 | struct capiminor *mp; | ||
934 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
935 | unsigned ncci; | 952 | unsigned ncci; |
936 | int count = 0; | 953 | int count = 0; |
937 | if (copy_from_user(&ncci, argp, sizeof(ncci))) | 954 | if (copy_from_user(&ncci, argp, sizeof(ncci))) |
@@ -942,11 +959,7 @@ capi_ioctl(struct inode *inode, struct file *file, | |||
942 | mutex_unlock(&cdev->ncci_list_mtx); | 959 | mutex_unlock(&cdev->ncci_list_mtx); |
943 | return 0; | 960 | return 0; |
944 | } | 961 | } |
945 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | 962 | count += capincci_minor_opencount(nccip); |
946 | if ((mp = nccip->minorp) != NULL) { | ||
947 | count += atomic_read(&mp->ttyopencount); | ||
948 | } | ||
949 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
950 | mutex_unlock(&cdev->ncci_list_mtx); | 963 | mutex_unlock(&cdev->ncci_list_mtx); |
951 | return count; | 964 | return count; |
952 | } | 965 | } |
@@ -1396,7 +1409,16 @@ static void capinc_tty_exit(void) | |||
1396 | put_tty_driver(drv); | 1409 | put_tty_driver(drv); |
1397 | } | 1410 | } |
1398 | 1411 | ||
1399 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | 1412 | #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ |
1413 | |||
1414 | static inline int capinc_tty_init(void) | ||
1415 | { | ||
1416 | return 0; | ||
1417 | } | ||
1418 | |||
1419 | static inline void capinc_tty_exit(void) { } | ||
1420 | |||
1421 | #endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
1400 | 1422 | ||
1401 | /* -------- /proc functions ----------------------------------------- */ | 1423 | /* -------- /proc functions ----------------------------------------- */ |
1402 | 1424 | ||
@@ -1505,23 +1527,19 @@ static int __init capi_init(void) | |||
1505 | 1527 | ||
1506 | device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi"); | 1528 | device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi"); |
1507 | 1529 | ||
1508 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
1509 | if (capinc_tty_init() < 0) { | 1530 | if (capinc_tty_init() < 0) { |
1510 | device_destroy(capi_class, MKDEV(capi_major, 0)); | 1531 | device_destroy(capi_class, MKDEV(capi_major, 0)); |
1511 | class_destroy(capi_class); | 1532 | class_destroy(capi_class); |
1512 | unregister_chrdev(capi_major, "capi20"); | 1533 | unregister_chrdev(capi_major, "capi20"); |
1513 | return -ENOMEM; | 1534 | return -ENOMEM; |
1514 | } | 1535 | } |
1515 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | ||
1516 | 1536 | ||
1517 | proc_init(); | 1537 | proc_init(); |
1518 | 1538 | ||
1519 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
1520 | #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) | 1539 | #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) |
1521 | compileinfo = " (middleware+capifs)"; | 1540 | compileinfo = " (middleware+capifs)"; |
1522 | #else | 1541 | #elif defined(CONFIG_ISDN_CAPI_MIDDLEWARE) |
1523 | compileinfo = " (no capifs)"; | 1542 | compileinfo = " (no capifs)"; |
1524 | #endif | ||
1525 | #else | 1543 | #else |
1526 | compileinfo = " (no middleware)"; | 1544 | compileinfo = " (no middleware)"; |
1527 | #endif | 1545 | #endif |
@@ -1539,9 +1557,7 @@ static void __exit capi_exit(void) | |||
1539 | class_destroy(capi_class); | 1557 | class_destroy(capi_class); |
1540 | unregister_chrdev(capi_major, "capi20"); | 1558 | unregister_chrdev(capi_major, "capi20"); |
1541 | 1559 | ||
1542 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | ||
1543 | capinc_tty_exit(); | 1560 | capinc_tty_exit(); |
1544 | #endif | ||
1545 | } | 1561 | } |
1546 | 1562 | ||
1547 | module_init(capi_init); | 1563 | module_init(capi_init); |