Commit 501c87a9 authored by Jan Kiszka's avatar Jan Kiszka Committed by David S. Miller

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: default avatarJan Kiszka <jan.kiszka@web.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 88c896ef
...@@ -23,14 +23,10 @@ ...@@ -23,14 +23,10 @@
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/wait.h> #include <linux/wait.h>
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
#include <linux/tty.h> #include <linux/tty.h>
#ifdef CONFIG_PPP
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/ppp_defs.h> #include <linux/ppp_defs.h>
#include <linux/if_ppp.h> #include <linux/if_ppp.h>
#endif /* CONFIG_PPP */
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
...@@ -56,17 +52,17 @@ MODULE_LICENSE("GPL"); ...@@ -56,17 +52,17 @@ MODULE_LICENSE("GPL");
/* -------- driver information -------------------------------------- */ /* -------- driver information -------------------------------------- */
static struct class *capi_class; static struct class *capi_class;
static int capi_major = 68; /* allocated */ static int capi_major = 68; /* allocated */
module_param_named(major, capi_major, uint, 0);
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
#define CAPINC_NR_PORTS 32 #define CAPINC_NR_PORTS 32
#define CAPINC_MAX_PORTS 256 #define CAPINC_MAX_PORTS 256
static int capi_ttymajor = 191; static int capi_ttymajor = 191;
static int capi_ttyminors = CAPINC_NR_PORTS; static int capi_ttyminors = CAPINC_NR_PORTS;
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
module_param_named(major, capi_major, uint, 0);
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
module_param_named(ttymajor, capi_ttymajor, uint, 0); module_param_named(ttymajor, capi_ttymajor, uint, 0);
module_param_named(ttyminors, capi_ttyminors, uint, 0); module_param_named(ttyminors, capi_ttyminors, uint, 0);
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
...@@ -81,7 +77,6 @@ module_param_named(ttyminors, capi_ttyminors, uint, 0); ...@@ -81,7 +77,6 @@ module_param_named(ttyminors, capi_ttyminors, uint, 0);
struct capidev; struct capidev;
struct capincci; struct capincci;
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
struct capiminor; struct capiminor;
struct datahandle_queue { struct datahandle_queue {
...@@ -116,7 +111,6 @@ struct capiminor { ...@@ -116,7 +111,6 @@ struct capiminor {
int nack; int nack;
spinlock_t ackqlock; spinlock_t ackqlock;
}; };
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
/* FIXME: The following lock is a sledgehammer-workaround to a /* FIXME: The following lock is a sledgehammer-workaround to a
* locking issue with the capiminor (and maybe other) data structure(s). * locking issue with the capiminor (and maybe other) data structure(s).
...@@ -156,14 +150,13 @@ static DEFINE_RWLOCK(capidev_list_lock); ...@@ -156,14 +150,13 @@ static DEFINE_RWLOCK(capidev_list_lock);
static LIST_HEAD(capidev_list); static LIST_HEAD(capidev_list);
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
static DEFINE_RWLOCK(capiminor_list_lock); static DEFINE_RWLOCK(capiminor_list_lock);
static LIST_HEAD(capiminor_list); static LIST_HEAD(capiminor_list);
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
/* -------- datahandles --------------------------------------------- */ /* -------- datahandles --------------------------------------------- */
static int capincci_add_ack(struct capiminor *mp, u16 datahandle) static int capiminor_add_ack(struct capiminor *mp, u16 datahandle)
{ {
struct datahandle_queue *n; struct datahandle_queue *n;
unsigned long flags; unsigned long flags;
...@@ -301,26 +294,17 @@ static struct capiminor *capiminor_find(unsigned int minor) ...@@ -301,26 +294,17 @@ static struct capiminor *capiminor_find(unsigned int minor)
return p; return p;
} }
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
/* -------- struct capincci ----------------------------------------- */ /* -------- struct capincci ----------------------------------------- */
static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np)
{ {
struct capincci *np, **pp; struct capiminor *mp;
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
struct capiminor *mp = NULL;
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
np = kzalloc(sizeof(*np), GFP_ATOMIC); if (!(cdev->userflags & CAPIFLAG_HIGHJACKING))
if (!np) return;
return NULL;
np->ncci = ncci; mp = np->minorp = capiminor_alloc(&cdev->ap, np->ncci);
np->cdev = cdev;
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
mp = NULL;
if (cdev->userflags & CAPIFLAG_HIGHJACKING)
mp = np->minorp = capiminor_alloc(&cdev->ap, ncci);
if (mp) { if (mp) {
mp->nccip = np; mp->nccip = np;
#ifdef _DEBUG_REFCOUNT #ifdef _DEBUG_REFCOUNT
...@@ -330,7 +314,58 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) ...@@ -330,7 +314,58 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
capifs_new_ncci(mp->minor, capifs_new_ncci(mp->minor,
MKDEV(capi_ttymajor, mp->minor)); MKDEV(capi_ttymajor, mp->minor));
} }
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ }
static void capincci_free_minor(struct capincci *np)
{
struct capiminor *mp = np->minorp;
if (mp) {
capifs_free_ncci(mp->capifs_dentry);
if (mp->tty) {
mp->nccip = NULL;
#ifdef _DEBUG_REFCOUNT
printk(KERN_DEBUG "reset mp->nccip\n");
#endif
tty_hangup(mp->tty);
} else {
capiminor_free(mp);
}
}
}
static inline unsigned int capincci_minor_opencount(struct capincci *np)
{
struct capiminor *mp = np->minorp;
return mp ? atomic_read(&mp->ttyopencount) : 0;
}
#else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */
static inline void
capincci_alloc_minor(struct capidev *cdev, struct capincci *np) { }
static inline void capincci_free_minor(struct capincci *np) { }
static inline unsigned int capincci_minor_opencount(struct capincci *np)
{
return 0;
}
#endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */
static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
{
struct capincci *np, **pp;
np = kzalloc(sizeof(*np), GFP_ATOMIC);
if (!np)
return NULL;
np->ncci = ncci;
np->cdev = cdev;
capincci_alloc_minor(cdev, np);
for (pp=&cdev->nccis; *pp; pp = &(*pp)->next) for (pp=&cdev->nccis; *pp; pp = &(*pp)->next)
; ;
*pp = np; *pp = np;
...@@ -340,29 +375,13 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) ...@@ -340,29 +375,13 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
static void capincci_free(struct capidev *cdev, u32 ncci) static void capincci_free(struct capidev *cdev, u32 ncci)
{ {
struct capincci *np, **pp; struct capincci *np, **pp;
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
struct capiminor *mp;
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
pp=&cdev->nccis; pp=&cdev->nccis;
while (*pp) { while (*pp) {
np = *pp; np = *pp;
if (ncci == 0xffffffff || np->ncci == ncci) { if (ncci == 0xffffffff || np->ncci == ncci) {
*pp = (*pp)->next; *pp = (*pp)->next;
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE capincci_free_minor(np);
if ((mp = np->minorp) != NULL) {
capifs_free_ncci(mp->capifs_dentry);
if (mp->tty) {
mp->nccip = NULL;
#ifdef _DEBUG_REFCOUNT
printk(KERN_DEBUG "reset mp->nccip\n");
#endif
tty_hangup(mp->tty);
} else {
capiminor_free(mp);
}
}
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
kfree(np); kfree(np);
if (*pp == NULL) return; if (*pp == NULL) return;
} else { } else {
...@@ -552,7 +571,7 @@ static int handle_minor_send(struct capiminor *mp) ...@@ -552,7 +571,7 @@ static int handle_minor_send(struct capiminor *mp)
capimsg_setu16(skb->data, 18, datahandle); capimsg_setu16(skb->data, 18, datahandle);
capimsg_setu16(skb->data, 20, 0); /* Flags */ capimsg_setu16(skb->data, 20, 0); /* Flags */
if (capincci_add_ack(mp, datahandle) < 0) { if (capiminor_add_ack(mp, datahandle) < 0) {
skb_pull(skb, CAPI_DATA_B3_REQ_LEN); skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
skb_queue_head(&mp->outqueue, skb); skb_queue_head(&mp->outqueue, skb);
return count; return count;
...@@ -628,10 +647,13 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) ...@@ -628,10 +647,13 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
spin_unlock_irqrestore(&workaround_lock, flags); spin_unlock_irqrestore(&workaround_lock, flags);
return; return;
} }
#ifndef CONFIG_ISDN_CAPI_MIDDLEWARE #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE
skb_queue_tail(&cdev->recvqueue, skb); skb_queue_tail(&cdev->recvqueue, skb);
wake_up_interruptible(&cdev->recvwait); wake_up_interruptible(&cdev->recvwait);
#else /* CONFIG_ISDN_CAPI_MIDDLEWARE */ #else /* CONFIG_ISDN_CAPI_MIDDLEWARE */
mp = np->minorp; mp = np->minorp;
if (!mp) { if (!mp) {
skb_queue_tail(&cdev->recvqueue, skb); skb_queue_tail(&cdev->recvqueue, skb);
...@@ -639,10 +661,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) ...@@ -639,10 +661,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
spin_unlock_irqrestore(&workaround_lock, flags); spin_unlock_irqrestore(&workaround_lock, flags);
return; return;
} }
if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) { if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) {
datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2); datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2);
#ifdef _DEBUG_DATAFLOW #ifdef _DEBUG_DATAFLOW
printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n", 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,6 +691,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
wake_up_interruptible(&cdev->recvwait); wake_up_interruptible(&cdev->recvwait);
} }
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
spin_unlock_irqrestore(&workaround_lock, flags); spin_unlock_irqrestore(&workaround_lock, flags);
} }
...@@ -929,9 +949,6 @@ capi_ioctl(struct inode *inode, struct file *file, ...@@ -929,9 +949,6 @@ capi_ioctl(struct inode *inode, struct file *file,
case CAPI_NCCI_OPENCOUNT: case CAPI_NCCI_OPENCOUNT:
{ {
struct capincci *nccip; struct capincci *nccip;
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
struct capiminor *mp;
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
unsigned ncci; unsigned ncci;
int count = 0; int count = 0;
if (copy_from_user(&ncci, argp, sizeof(ncci))) if (copy_from_user(&ncci, argp, sizeof(ncci)))
...@@ -942,11 +959,7 @@ capi_ioctl(struct inode *inode, struct file *file, ...@@ -942,11 +959,7 @@ capi_ioctl(struct inode *inode, struct file *file,
mutex_unlock(&cdev->ncci_list_mtx); mutex_unlock(&cdev->ncci_list_mtx);
return 0; return 0;
} }
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE count += capincci_minor_opencount(nccip);
if ((mp = nccip->minorp) != NULL) {
count += atomic_read(&mp->ttyopencount);
}
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
mutex_unlock(&cdev->ncci_list_mtx); mutex_unlock(&cdev->ncci_list_mtx);
return count; return count;
} }
...@@ -1396,7 +1409,16 @@ static void capinc_tty_exit(void) ...@@ -1396,7 +1409,16 @@ static void capinc_tty_exit(void)
put_tty_driver(drv); put_tty_driver(drv);
} }
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */
static inline int capinc_tty_init(void)
{
return 0;
}
static inline void capinc_tty_exit(void) { }
#endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */
/* -------- /proc functions ----------------------------------------- */ /* -------- /proc functions ----------------------------------------- */
...@@ -1505,23 +1527,19 @@ static int __init capi_init(void) ...@@ -1505,23 +1527,19 @@ static int __init capi_init(void)
device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi"); device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi");
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
if (capinc_tty_init() < 0) { if (capinc_tty_init() < 0) {
device_destroy(capi_class, MKDEV(capi_major, 0)); device_destroy(capi_class, MKDEV(capi_major, 0));
class_destroy(capi_class); class_destroy(capi_class);
unregister_chrdev(capi_major, "capi20"); unregister_chrdev(capi_major, "capi20");
return -ENOMEM; return -ENOMEM;
} }
#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
proc_init(); proc_init();
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
compileinfo = " (middleware+capifs)"; compileinfo = " (middleware+capifs)";
#else #elif defined(CONFIG_ISDN_CAPI_MIDDLEWARE)
compileinfo = " (no capifs)"; compileinfo = " (no capifs)";
#endif
#else #else
compileinfo = " (no middleware)"; compileinfo = " (no middleware)";
#endif #endif
...@@ -1539,9 +1557,7 @@ static void __exit capi_exit(void) ...@@ -1539,9 +1557,7 @@ static void __exit capi_exit(void)
class_destroy(capi_class); class_destroy(capi_class);
unregister_chrdev(capi_major, "capi20"); unregister_chrdev(capi_major, "capi20");
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
capinc_tty_exit(); capinc_tty_exit();
#endif
} }
module_init(capi_init); module_init(capi_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment