Commit e9123b30 authored by Kai Germaschewski's avatar Kai Germaschewski

ISDN: CAPI: use <linux/list.h> lists

parent 64cf5d05
...@@ -112,11 +112,13 @@ static char capi_manufakturer[64] = "AVM Berlin"; ...@@ -112,11 +112,13 @@ static char capi_manufakturer[64] = "AVM Berlin";
static struct capi_appl applications[CAPI_MAXAPPL]; static struct capi_appl applications[CAPI_MAXAPPL];
static struct capi_ctr cards[CAPI_MAXCONTR]; static struct capi_ctr cards[CAPI_MAXCONTR];
static int ncards = 0; static int ncards;
static struct sk_buff_head recv_queue; static struct sk_buff_head recv_queue;
static struct capi_interface_user *capi_users = 0;
static spinlock_t capi_users_lock = SPIN_LOCK_UNLOCKED; static LIST_HEAD(users);
static struct capi_driver *drivers; static spinlock_t users_lock = SPIN_LOCK_UNLOCKED;
static LIST_HEAD(drivers);
static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED; static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED;
static struct tq_struct tq_state_notify; static struct tq_struct tq_state_notify;
...@@ -276,11 +278,14 @@ static int proc_ncci_read_proc(char *page, char **start, off_t off, ...@@ -276,11 +278,14 @@ static int proc_ncci_read_proc(char *page, char **start, off_t off,
static int proc_driver_read_proc(char *page, char **start, off_t off, static int proc_driver_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data) int count, int *eof, void *data)
{ {
struct list_head *l;
struct capi_driver *driver; struct capi_driver *driver;
int len = 0; int len = 0;
spin_lock(&drivers_lock); spin_lock(&drivers_lock);
for (driver = drivers; driver; driver = driver->next) { list_for_each(l, &drivers) {
driver = list_entry(l, struct capi_driver, driver_list);
len += sprintf(page+len, "%-32s %d %s\n", len += sprintf(page+len, "%-32s %d %s\n",
driver->name, driver->name,
driver->ncontroller, driver->ncontroller,
...@@ -310,11 +315,13 @@ static int proc_driver_read_proc(char *page, char **start, off_t off, ...@@ -310,11 +315,13 @@ static int proc_driver_read_proc(char *page, char **start, off_t off,
static int proc_users_read_proc(char *page, char **start, off_t off, static int proc_users_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data) int count, int *eof, void *data)
{ {
struct list_head *l;
struct capi_interface_user *cp; struct capi_interface_user *cp;
int len = 0; int len = 0;
spin_lock(&capi_users_lock); spin_lock(&users_lock);
for (cp = capi_users; cp ; cp = cp->next) { list_for_each(l, &users) {
cp = list_entry(l, struct capi_interface_user, user_list);
len += sprintf(page+len, "%s\n", cp->name); len += sprintf(page+len, "%s\n", cp->name);
if (len <= off) { if (len <= off) {
off -= len; off -= len;
...@@ -325,7 +332,7 @@ static int proc_users_read_proc(char *page, char **start, off_t off, ...@@ -325,7 +332,7 @@ static int proc_users_read_proc(char *page, char **start, off_t off,
} }
} }
endloop: endloop:
spin_unlock(&capi_users_lock); spin_unlock(&users_lock);
*start = page+off; *start = page+off;
if (len < count) if (len < count)
*eof = 1; *eof = 1;
...@@ -596,63 +603,74 @@ static int notify_push(unsigned int cmd, u32 controller, ...@@ -596,63 +603,74 @@ static int notify_push(unsigned int cmd, u32 controller,
static void notify_up(u32 contr) static void notify_up(u32 contr)
{ {
struct list_head *l;
struct capi_interface_user *p; struct capi_interface_user *p;
printk(KERN_NOTICE "kcapi: notify up contr %d\n", contr); printk(KERN_NOTICE "kcapi: notify up contr %d\n", contr);
spin_lock(&capi_users_lock); spin_lock(&users_lock);
for (p = capi_users; p; p = p->next) { list_for_each(l, &users) {
p = list_entry(l, struct capi_interface_user, user_list);
if (!p->callback) continue; if (!p->callback) continue;
(*p->callback) (KCI_CONTRUP, contr, &CARD(contr)->profile); (*p->callback) (KCI_CONTRUP, contr, &CARD(contr)->profile);
} }
spin_unlock(&capi_users_lock); spin_unlock(&users_lock);
} }
/* -------- KCI_CONTRDOWN ------------------------------------- */ /* -------- KCI_CONTRDOWN ------------------------------------- */
static void notify_down(u32 contr) static void notify_down(u32 contr)
{ {
struct list_head *l;
struct capi_interface_user *p; struct capi_interface_user *p;
printk(KERN_NOTICE "kcapi: notify down contr %d\n", contr); printk(KERN_NOTICE "kcapi: notify down contr %d\n", contr);
spin_lock(&capi_users_lock); spin_lock(&users_lock);
for (p = capi_users; p; p = p->next) { list_for_each(l, &users) {
p = list_entry(l, struct capi_interface_user, user_list);
if (!p->callback) continue; if (!p->callback) continue;
(*p->callback) (KCI_CONTRDOWN, contr, 0); (*p->callback) (KCI_CONTRDOWN, contr, 0);
} }
spin_unlock(&capi_users_lock); spin_unlock(&users_lock);
} }
/* -------- KCI_NCCIUP ---------------------------------------- */ /* -------- KCI_NCCIUP ---------------------------------------- */
static void notify_ncciup(u32 contr, u16 applid, u32 ncci) static void notify_ncciup(u32 contr, u16 applid, u32 ncci)
{ {
struct list_head *l;
struct capi_interface_user *p; struct capi_interface_user *p;
struct capi_ncciinfo n; struct capi_ncciinfo n;
n.applid = applid; n.applid = applid;
n.ncci = ncci; n.ncci = ncci;
/*printk(KERN_NOTICE "kcapi: notify up contr %d\n", contr);*/ /*printk(KERN_NOTICE "kcapi: notify up contr %d\n", contr);*/
spin_lock(&capi_users_lock); spin_lock(&users_lock);
for (p = capi_users; p; p = p->next) { list_for_each(l, &users) {
p = list_entry(l, struct capi_interface_user, user_list);
if (!p->callback) continue; if (!p->callback) continue;
(*p->callback) (KCI_NCCIUP, contr, &n); (*p->callback) (KCI_NCCIUP, contr, &n);
} }
spin_unlock(&capi_users_lock); spin_unlock(&users_lock);
}; };
/* -------- KCI_NCCIDOWN -------------------------------------- */ /* -------- KCI_NCCIDOWN -------------------------------------- */
static void notify_nccidown(u32 contr, u16 applid, u32 ncci) static void notify_nccidown(u32 contr, u16 applid, u32 ncci)
{ {
struct list_head *l;
struct capi_interface_user *p; struct capi_interface_user *p;
struct capi_ncciinfo n; struct capi_ncciinfo n;
n.applid = applid; n.applid = applid;
n.ncci = ncci; n.ncci = ncci;
/*printk(KERN_NOTICE "kcapi: notify down contr %d\n", contr);*/ /*printk(KERN_NOTICE "kcapi: notify down contr %d\n", contr);*/
spin_lock(&capi_users_lock); spin_lock(&users_lock);
for (p = capi_users; p; p = p->next) { list_for_each(l, &users) {
p = list_entry(l, struct capi_interface_user, user_list);
if (!p->callback) continue; if (!p->callback) continue;
(*p->callback) (KCI_NCCIDOWN, contr, &n); (*p->callback) (KCI_NCCIDOWN, contr, &n);
} }
spin_unlock(&capi_users_lock); spin_unlock(&users_lock);
}; };
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
...@@ -964,7 +982,7 @@ static void controllercb_resume_output(struct capi_ctr *card) ...@@ -964,7 +982,7 @@ static void controllercb_resume_output(struct capi_ctr *card)
struct capi_ctr * struct capi_ctr *
drivercb_attach_ctr(struct capi_driver *driver, char *name, void *driverdata) drivercb_attach_ctr(struct capi_driver *driver, char *name, void *driverdata)
{ {
struct capi_ctr *card, **pp; struct capi_ctr *card;
int i; int i;
for (i=0; i < CAPI_MAXCONTR && cards[i].cardstate != CARD_FREE; i++) ; for (i=0; i < CAPI_MAXCONTR && cards[i].cardstate != CARD_FREE; i++) ;
...@@ -991,9 +1009,7 @@ drivercb_attach_ctr(struct capi_driver *driver, char *name, void *driverdata) ...@@ -991,9 +1009,7 @@ drivercb_attach_ctr(struct capi_driver *driver, char *name, void *driverdata)
card->new_ncci = controllercb_new_ncci; card->new_ncci = controllercb_new_ncci;
card->free_ncci = controllercb_free_ncci; card->free_ncci = controllercb_free_ncci;
for (pp = &driver->controller; *pp; pp = &(*pp)->next) ; list_add_tail(&card->driver_list, &driver->contr_head);
card->next = 0;
*pp = card;
driver->ncontroller++; driver->ncontroller++;
sprintf(card->procfn, "capi/controllers/%d", card->cnr); sprintf(card->procfn, "capi/controllers/%d", card->cnr);
card->procent = create_proc_entry(card->procfn, 0, 0); card->procent = create_proc_entry(card->procfn, 0, 0);
...@@ -1013,20 +1029,16 @@ drivercb_attach_ctr(struct capi_driver *driver, char *name, void *driverdata) ...@@ -1013,20 +1029,16 @@ drivercb_attach_ctr(struct capi_driver *driver, char *name, void *driverdata)
static int drivercb_detach_ctr(struct capi_ctr *card) static int drivercb_detach_ctr(struct capi_ctr *card)
{ {
struct capi_driver *driver = card->driver; struct capi_driver *driver = card->driver;
struct capi_ctr **pp;
if (card->cardstate == CARD_FREE) if (card->cardstate == CARD_FREE)
return 0; return 0;
if (card->cardstate != CARD_DETECTED) if (card->cardstate != CARD_DETECTED)
controllercb_reseted(card); controllercb_reseted(card);
for (pp = &driver->controller; *pp ; pp = &(*pp)->next) {
if (*pp == card) { list_del(&card->driver_list);
*pp = card->next; driver->ncontroller--;
driver->ncontroller--; ncards--;
ncards--;
break;
}
}
if (card->procent) { if (card->procent) {
remove_proc_entry(card->procfn, 0); remove_proc_entry(card->procfn, 0);
card->procent = 0; card->procent = 0;
...@@ -1066,13 +1078,9 @@ static struct capi_driver_interface di = { ...@@ -1066,13 +1078,9 @@ static struct capi_driver_interface di = {
struct capi_driver_interface *attach_capi_driver(struct capi_driver *driver) struct capi_driver_interface *attach_capi_driver(struct capi_driver *driver)
{ {
struct capi_driver **pp; INIT_LIST_HEAD(&driver->contr_head);
MOD_INC_USE_COUNT;
spin_lock(&drivers_lock); spin_lock(&drivers_lock);
for (pp = &drivers; *pp; pp = &(*pp)->next) ; list_add_tail(&driver->driver_list, &drivers);
driver->next = 0;
*pp = driver;
spin_unlock(&drivers_lock); spin_unlock(&drivers_lock);
printk(KERN_NOTICE "kcapi: driver %s attached\n", driver->name); printk(KERN_NOTICE "kcapi: driver %s attached\n", driver->name);
sprintf(driver->procfn, "capi/drivers/%s", driver->name); sprintf(driver->procfn, "capi/drivers/%s", driver->name);
...@@ -1092,21 +1100,15 @@ struct capi_driver_interface *attach_capi_driver(struct capi_driver *driver) ...@@ -1092,21 +1100,15 @@ struct capi_driver_interface *attach_capi_driver(struct capi_driver *driver)
void detach_capi_driver(struct capi_driver *driver) void detach_capi_driver(struct capi_driver *driver)
{ {
struct capi_driver **pp;
spin_lock(&drivers_lock); spin_lock(&drivers_lock);
for (pp = &drivers; *pp && *pp != driver; pp = &(*pp)->next) ; list_del(&driver->driver_list);
if (*pp) {
*pp = (*pp)->next;
printk(KERN_NOTICE "kcapi: driver %s detached\n", driver->name);
} else {
printk(KERN_ERR "kcapi: driver %s double detach ?\n", driver->name);
}
spin_unlock(&drivers_lock); spin_unlock(&drivers_lock);
printk(KERN_NOTICE "kcapi: driver %s detached\n", driver->name);
if (driver->procent) { if (driver->procent) {
remove_proc_entry(driver->procfn, 0); remove_proc_entry(driver->procfn, 0);
driver->procent = 0; driver->procent = 0;
} }
MOD_DEC_USE_COUNT;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
...@@ -1310,11 +1312,16 @@ static u16 capi_get_profile(u32 contr, struct capi_profile *profp) ...@@ -1310,11 +1312,16 @@ static u16 capi_get_profile(u32 contr, struct capi_profile *profp)
static struct capi_driver *find_driver(char *name) static struct capi_driver *find_driver(char *name)
{ {
struct list_head *l;
struct capi_driver *dp; struct capi_driver *dp;
spin_lock(&drivers_lock); spin_lock(&drivers_lock);
for (dp = drivers; dp; dp = dp->next) list_for_each(l, &drivers) {
dp = list_entry(l, struct capi_driver, driver_list);
if (strcmp(dp->name, name) == 0) if (strcmp(dp->name, name) == 0)
break; goto found;
}
dp = NULL;
found:
spin_unlock(&drivers_lock); spin_unlock(&drivers_lock);
return dp; return dp;
} }
...@@ -1611,22 +1618,10 @@ struct capi_interface avmb1_interface = ...@@ -1611,22 +1618,10 @@ struct capi_interface avmb1_interface =
struct capi_interface *attach_capi_interface(struct capi_interface_user *userp) struct capi_interface *attach_capi_interface(struct capi_interface_user *userp)
{ {
struct capi_interface_user *p;
MOD_INC_USE_COUNT; spin_lock(&users_lock);
spin_lock(&capi_users_lock); list_add_tail(&userp->user_list, &users);
for (p = capi_users; p; p = p->next) { spin_unlock(&users_lock);
if (p == userp) {
spin_unlock(&capi_users_lock);
printk(KERN_ERR "kcapi: double attach from %s\n",
userp->name);
MOD_DEC_USE_COUNT;
return 0;
}
}
userp->next = capi_users;
capi_users = userp;
spin_unlock(&capi_users_lock);
printk(KERN_NOTICE "kcapi: %s attached\n", userp->name); printk(KERN_NOTICE "kcapi: %s attached\n", userp->name);
return &avmb1_interface; return &avmb1_interface;
...@@ -1634,22 +1629,10 @@ struct capi_interface *attach_capi_interface(struct capi_interface_user *userp) ...@@ -1634,22 +1629,10 @@ struct capi_interface *attach_capi_interface(struct capi_interface_user *userp)
int detach_capi_interface(struct capi_interface_user *userp) int detach_capi_interface(struct capi_interface_user *userp)
{ {
struct capi_interface_user **pp; spin_lock(&users_lock);
list_del(&userp->user_list);
spin_lock(&capi_users_lock); printk(KERN_NOTICE "kcapi: %s detached\n", userp->name);
for (pp = &capi_users; *pp; pp = &(*pp)->next) { return 0;
if (*pp == userp) {
*pp = userp->next;
spin_unlock(&capi_users_lock);
userp->next = 0;
printk(KERN_NOTICE "kcapi: %s detached\n", userp->name);
MOD_DEC_USE_COUNT;
return 0;
}
}
spin_unlock(&capi_users_lock);
printk(KERN_ERR "kcapi: double detach from %s\n", userp->name);
return -1;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
......
...@@ -188,10 +188,12 @@ int b1pcmcia_addcard_m2(unsigned int port, unsigned irq) ...@@ -188,10 +188,12 @@ int b1pcmcia_addcard_m2(unsigned int port, unsigned irq)
int b1pcmcia_delcard(unsigned int port, unsigned irq) int b1pcmcia_delcard(unsigned int port, unsigned irq)
{ {
struct list_head *l;
struct capi_ctr *ctrl; struct capi_ctr *ctrl;
avmcard *card; avmcard *card;
for (ctrl = b1pcmcia_driver.controller; ctrl; ctrl = ctrl->next) { list_for_each(l, &b1pcmcia_driver.contr_head) {
ctrl = list_entry(l, struct capi_ctr, driver_list);
card = ((avmctrl_info *)(ctrl->driverdata))->card; card = ((avmctrl_info *)(ctrl->driverdata))->card;
if (card->port == port && card->irq == irq) { if (card->port == port && card->irq == irq) {
b1pcmcia_remove_ctr(ctrl); b1pcmcia_remove_ctr(ctrl);
......
...@@ -344,6 +344,7 @@ static void t1isa_remove_ctr(struct capi_ctr *ctrl) ...@@ -344,6 +344,7 @@ static void t1isa_remove_ctr(struct capi_ctr *ctrl)
static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p) static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
{ {
struct capi_ctr *ctrl; struct capi_ctr *ctrl;
struct list_head *l;
avmctrl_info *cinfo; avmctrl_info *cinfo;
avmcard *card; avmcard *card;
int retval; int retval;
...@@ -376,8 +377,11 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p) ...@@ -376,8 +377,11 @@ static int t1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
retval = -EINVAL; retval = -EINVAL;
goto err_free; goto err_free;
} }
for (ctrl = driver->controller; ctrl; ctrl = ctrl->next) { list_for_each(l, &driver->contr_head) {
avmcard *cardp = ((avmctrl_info *)(ctrl->driverdata))->card; avmcard *cardp;
ctrl = list_entry(l, struct capi_ctr, driver_list);
cardp = ((avmctrl_info *)(ctrl->driverdata))->card;
if (cardp->cardnr == card->cardnr) { if (cardp->cardnr == card->cardnr) {
printk(KERN_WARNING "%s: card with number %d already installed at 0x%x.\n", printk(KERN_WARNING "%s: card with number %d already installed at 0x%x.\n",
driver->name, card->cardnr, cardp->port); driver->name, card->cardnr, cardp->port);
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#ifndef __CAPILLI_H__ #ifndef __CAPILLI_H__
#define __CAPILLI_H__ #define __CAPILLI_H__
#include <linux/list.h>
typedef struct capiloaddatapart { typedef struct capiloaddatapart {
int user; /* data in userspace ? */ int user; /* data in userspace ? */
int len; int len;
...@@ -34,7 +36,7 @@ typedef struct capicardparams { ...@@ -34,7 +36,7 @@ typedef struct capicardparams {
struct capi_driver; struct capi_driver;
struct capi_ctr { struct capi_ctr {
struct capi_ctr *next; /* next ctr of same driver */ struct list_head driver_list; /* contrs by driver */
struct capi_driver *driver; struct capi_driver *driver;
int cnr; /* controller number */ int cnr; /* controller number */
char name[32]; /* name of controller */ char name[32]; /* name of controller */
...@@ -99,8 +101,8 @@ struct capi_driver { ...@@ -99,8 +101,8 @@ struct capi_driver {
int (*add_card)(struct capi_driver *driver, capicardparams *data); int (*add_card)(struct capi_driver *driver, capicardparams *data);
/* intitialized by kcapi */ /* intitialized by kcapi */
struct capi_ctr *controller; /* list of controllers */ struct list_head contr_head; /* list of controllers */
struct capi_driver *next; struct list_head driver_list;
int ncontroller; int ncontroller;
struct proc_dir_entry *procent; struct proc_dir_entry *procent;
char procfn[128]; char procfn[128];
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#ifndef __KERNELCAPI_H__ #ifndef __KERNELCAPI_H__
#define __KERNELCAPI_H__ #define __KERNELCAPI_H__
#include <linux/list.h>
#define CAPI_MAXAPPL 128 /* maximum number of applications */ #define CAPI_MAXAPPL 128 /* maximum number of applications */
#define CAPI_MAXCONTR 16 /* maximum number of controller */ #define CAPI_MAXCONTR 16 /* maximum number of controller */
#define CAPI_MAXDATAWINDOW 8 #define CAPI_MAXDATAWINDOW 8
...@@ -81,7 +83,7 @@ struct capi_interface_user { ...@@ -81,7 +83,7 @@ struct capi_interface_user {
char name[20]; char name[20];
void (*callback) (unsigned int cmd, __u32 contr, void *data); void (*callback) (unsigned int cmd, __u32 contr, void *data);
/* internal */ /* internal */
struct capi_interface_user *next; struct list_head user_list;
}; };
struct capi_interface *attach_capi_interface(struct capi_interface_user *); struct capi_interface *attach_capi_interface(struct capi_interface_user *);
......
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