Commit d25500eb authored by Kai Germaschewski's avatar Kai Germaschewski

ISDN: CAPI maintain driver MOD_USE_COUNT

Apart from the indentation changes, add an owner field to the hardware
driver struct and use that to automatically inc/dec the module use count
on register_appl()/release_appl()
parent 83bc4e5e
...@@ -122,6 +122,27 @@ static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED; ...@@ -122,6 +122,27 @@ static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED;
static struct tq_struct tq_state_notify; static struct tq_struct tq_state_notify;
static struct tq_struct tq_recv_notify; static struct tq_struct tq_recv_notify;
/* -------- ref counting -------------------------------------- */
static inline struct capi_ctr *
capi_ctr_get(struct capi_ctr *card)
{
if (card->driver->owner) {
if (try_inc_mod_count(card->driver->owner))
return card;
else
return NULL;
}
return card;
}
static inline void
capi_ctr_put(struct capi_ctr *card)
{
if (card->driver->owner)
__MOD_DEC_USE_COUNT(card->driver->owner);
}
/* -------- util functions ------------------------------------ */ /* -------- util functions ------------------------------------ */
static char *cardstate2str(unsigned short cardstate) static char *cardstate2str(unsigned short cardstate)
...@@ -473,6 +494,8 @@ static void proc_capi_exit(void) ...@@ -473,6 +494,8 @@ static void proc_capi_exit(void)
static void register_appl(struct capi_ctr *card, u16 applid, capi_register_params *rparam) static void register_appl(struct capi_ctr *card, u16 applid, capi_register_params *rparam)
{ {
card = capi_ctr_get(card);
card->driver->register_appl(card, applid, rparam); card->driver->register_appl(card, applid, rparam);
} }
...@@ -495,6 +518,8 @@ static void release_appl(struct capi_ctr *card, u16 applid) ...@@ -495,6 +518,8 @@ static void release_appl(struct capi_ctr *card, u16 applid)
} }
card->driver->release_appl(card, applid); card->driver->release_appl(card, applid);
capi_ctr_put(card);
} }
...@@ -909,6 +934,7 @@ static void controllercb_reseted(struct capi_ctr * card) ...@@ -909,6 +934,7 @@ static void controllercb_reseted(struct capi_ctr * card)
nextpp = &(*pp)->next; nextpp = &(*pp)->next;
} }
} }
capi_ctr_put(card);
} }
printk(KERN_NOTICE "kcapi: card %d down.\n", CARDNR(card)); printk(KERN_NOTICE "kcapi: card %d down.\n", CARDNR(card));
......
...@@ -154,20 +154,21 @@ static char *b1isa_procinfo(struct capi_ctr *ctrl) ...@@ -154,20 +154,21 @@ static char *b1isa_procinfo(struct capi_ctr *ctrl)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static struct capi_driver b1isa_driver = { static struct capi_driver b1isa_driver = {
name: "b1isa", owner: THIS_MODULE,
revision: "0.0", name: "b1isa",
load_firmware: b1_load_firmware, revision: "0.0",
reset_ctr: b1_reset_ctr, load_firmware: b1_load_firmware,
remove_ctr: b1isa_remove_ctr, reset_ctr: b1_reset_ctr,
register_appl: b1_register_appl, remove_ctr: b1isa_remove_ctr,
release_appl: b1_release_appl, register_appl: b1_register_appl,
send_message: b1_send_message, release_appl: b1_release_appl,
send_message: b1_send_message,
procinfo: b1isa_procinfo,
ctr_read_proc: b1ctl_read_proc, procinfo: b1isa_procinfo,
driver_read_proc: 0, /* use standard driver_read_proc */ ctr_read_proc: b1ctl_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: b1isa_add_card,
add_card: b1isa_add_card,
}; };
static int __init b1isa_init(void) static int __init b1isa_init(void)
......
...@@ -165,20 +165,21 @@ static void b1pci_remove_ctr(struct capi_ctr *ctrl) ...@@ -165,20 +165,21 @@ static void b1pci_remove_ctr(struct capi_ctr *ctrl)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static struct capi_driver b1pci_driver = { static struct capi_driver b1pci_driver = {
name: "b1pci", owner: THIS_MODULE,
revision: "0.0", name: "b1pci",
load_firmware: b1_load_firmware, revision: "0.0",
reset_ctr: b1_reset_ctr, load_firmware: b1_load_firmware,
remove_ctr: b1pci_remove_ctr, reset_ctr: b1_reset_ctr,
register_appl: b1_register_appl, remove_ctr: b1pci_remove_ctr,
release_appl: b1_release_appl, register_appl: b1_register_appl,
send_message: b1_send_message, release_appl: b1_release_appl,
send_message: b1_send_message,
procinfo: b1pci_procinfo,
ctr_read_proc: b1ctl_read_proc, procinfo: b1pci_procinfo,
driver_read_proc: 0, /* use standard driver_read_proc */ ctr_read_proc: b1ctl_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: 0, /* no add_card function */
add_card: 0, /* no add_card function */
}; };
#ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
...@@ -327,20 +328,21 @@ static void b1pciv4_remove_ctr(struct capi_ctr *ctrl) ...@@ -327,20 +328,21 @@ static void b1pciv4_remove_ctr(struct capi_ctr *ctrl)
static struct capi_driver b1pciv4_driver = { static struct capi_driver b1pciv4_driver = {
name: "b1pciv4", owner: THIS_MODULE,
revision: "0.0", name: "b1pciv4",
load_firmware: b1dma_load_firmware, revision: "0.0",
reset_ctr: b1dma_reset_ctr, load_firmware: b1dma_load_firmware,
remove_ctr: b1pciv4_remove_ctr, reset_ctr: b1dma_reset_ctr,
register_appl: b1dma_register_appl, remove_ctr: b1pciv4_remove_ctr,
release_appl: b1dma_release_appl, register_appl: b1dma_register_appl,
send_message: b1dma_send_message, release_appl: b1dma_release_appl,
send_message: b1dma_send_message,
procinfo: b1pciv4_procinfo,
ctr_read_proc: b1dmactl_read_proc, procinfo: b1pciv4_procinfo,
driver_read_proc: 0, /* use standard driver_read_proc */ ctr_read_proc: b1dmactl_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: 0, /* no add_card function */
add_card: 0, /* no add_card function */
}; };
#endif /* CONFIG_ISDN_DRV_AVMB1_B1PCIV4 */ #endif /* CONFIG_ISDN_DRV_AVMB1_B1PCIV4 */
......
...@@ -152,20 +152,21 @@ static char *b1pcmcia_procinfo(struct capi_ctr *ctrl) ...@@ -152,20 +152,21 @@ static char *b1pcmcia_procinfo(struct capi_ctr *ctrl)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static struct capi_driver b1pcmcia_driver = { static struct capi_driver b1pcmcia_driver = {
name: "b1pcmcia", owner: THIS_MODULE,
revision: "0.0", name: "b1pcmcia",
load_firmware: b1_load_firmware, revision: "0.0",
reset_ctr: b1_reset_ctr, load_firmware: b1_load_firmware,
remove_ctr: b1pcmcia_remove_ctr, reset_ctr: b1_reset_ctr,
register_appl: b1_register_appl, remove_ctr: b1pcmcia_remove_ctr,
release_appl: b1_release_appl, register_appl: b1_register_appl,
send_message: b1_send_message, release_appl: b1_release_appl,
send_message: b1_send_message,
procinfo: b1pcmcia_procinfo,
ctr_read_proc: b1ctl_read_proc, procinfo: b1pcmcia_procinfo,
driver_read_proc: 0, /* use standard driver_read_proc */ ctr_read_proc: b1ctl_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: 0,
add_card: 0,
}; };
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
......
...@@ -1200,37 +1200,39 @@ static int c4_add_card(struct capi_driver *driver, ...@@ -1200,37 +1200,39 @@ static int c4_add_card(struct capi_driver *driver,
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static struct capi_driver c2_driver = { static struct capi_driver c2_driver = {
name: "c2", owner: THIS_MODULE,
revision: "0.0", name: "c2",
load_firmware: c4_load_firmware, revision: "0.0",
reset_ctr: c4_reset_ctr, load_firmware: c4_load_firmware,
remove_ctr: c4_remove_ctr, reset_ctr: c4_reset_ctr,
register_appl: c4_register_appl, remove_ctr: c4_remove_ctr,
release_appl: c4_release_appl, register_appl: c4_register_appl,
send_message: c4_send_message, release_appl: c4_release_appl,
send_message: c4_send_message,
procinfo: c4_procinfo,
ctr_read_proc: c4_read_proc, procinfo: c4_procinfo,
driver_read_proc: 0, /* use standard driver_read_proc */ ctr_read_proc: c4_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: 0, /* no add_card function */
add_card: 0, /* no add_card function */
}; };
static struct capi_driver c4_driver = { static struct capi_driver c4_driver = {
name: "c4", owner: THIS_MODULE,
revision: "0.0", name: "c4",
load_firmware: c4_load_firmware, revision: "0.0",
reset_ctr: c4_reset_ctr, load_firmware: c4_load_firmware,
remove_ctr: c4_remove_ctr, reset_ctr: c4_reset_ctr,
register_appl: c4_register_appl, remove_ctr: c4_remove_ctr,
release_appl: c4_release_appl, register_appl: c4_register_appl,
send_message: c4_send_message, release_appl: c4_release_appl,
send_message: c4_send_message,
procinfo: c4_procinfo,
ctr_read_proc: c4_read_proc, procinfo: c4_procinfo,
driver_read_proc: 0, /* use standard driver_read_proc */ ctr_read_proc: c4_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: 0, /* no add_card function */
add_card: 0, /* no add_card function */
}; };
static int c4_attach_driver (struct capi_driver * driver) static int c4_attach_driver (struct capi_driver * driver)
......
...@@ -479,20 +479,21 @@ static char *t1isa_procinfo(struct capi_ctr *ctrl) ...@@ -479,20 +479,21 @@ static char *t1isa_procinfo(struct capi_ctr *ctrl)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static struct capi_driver t1isa_driver = { static struct capi_driver t1isa_driver = {
name: "t1isa", owner: THIS_MODULE,
revision: "0.0", name: "t1isa",
load_firmware: t1isa_load_firmware, revision: "0.0",
reset_ctr: t1isa_reset_ctr, load_firmware: t1isa_load_firmware,
remove_ctr: t1isa_remove_ctr, reset_ctr: t1isa_reset_ctr,
register_appl: b1_register_appl, remove_ctr: t1isa_remove_ctr,
release_appl: b1_release_appl, register_appl: b1_register_appl,
send_message: t1isa_send_message, release_appl: b1_release_appl,
send_message: t1isa_send_message,
procinfo: t1isa_procinfo,
ctr_read_proc: b1ctl_read_proc, procinfo: t1isa_procinfo,
driver_read_proc: 0, /* use standard driver_read_proc */ ctr_read_proc: b1ctl_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: t1isa_add_card,
add_card: t1isa_add_card,
}; };
static int __init t1isa_init(void) static int __init t1isa_init(void)
......
...@@ -189,20 +189,21 @@ static char *t1pci_procinfo(struct capi_ctr *ctrl) ...@@ -189,20 +189,21 @@ static char *t1pci_procinfo(struct capi_ctr *ctrl)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static struct capi_driver t1pci_driver = { static struct capi_driver t1pci_driver = {
name: "t1pci", owner: THIS_MODULE,
revision: "0.0", name: "t1pci",
load_firmware: b1dma_load_firmware, revision: "0.0",
reset_ctr: b1dma_reset_ctr, load_firmware: b1dma_load_firmware,
remove_ctr: t1pci_remove_ctr, reset_ctr: b1dma_reset_ctr,
register_appl: b1dma_register_appl, remove_ctr: t1pci_remove_ctr,
release_appl: b1dma_release_appl, register_appl: b1dma_register_appl,
send_message: b1dma_send_message, release_appl: b1dma_release_appl,
send_message: b1dma_send_message,
procinfo: t1pci_procinfo,
ctr_read_proc: b1dmactl_read_proc, procinfo: t1pci_procinfo,
driver_read_proc: 0, /* use standard driver_read_proc */ ctr_read_proc: b1dmactl_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: 0, /* no add_card function */
add_card: 0, /* no add_card function */
}; };
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
......
...@@ -252,7 +252,6 @@ hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl, ...@@ -252,7 +252,6 @@ hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl,
rp, sizeof(capi_register_params)); rp, sizeof(capi_register_params));
/* MOD_INC_USE_COUNT; */ /* MOD_INC_USE_COUNT; */
ctrl->appl_registered(ctrl, appl);
} }
/********************************************************************* /*********************************************************************
...@@ -313,7 +312,6 @@ hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl) ...@@ -313,7 +312,6 @@ hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl)
{ {
hycapi_release_internal(ctrl, appl); hycapi_release_internal(ctrl, appl);
} }
ctrl->appl_released(ctrl, appl);
/* MOD_DEC_USE_COUNT; */ /* MOD_DEC_USE_COUNT; */
} }
...@@ -666,18 +664,21 @@ hycapi_tx_capiget(hysdn_card *card) ...@@ -666,18 +664,21 @@ hycapi_tx_capiget(hysdn_card *card)
static struct capi_driver hycapi_driver = { static struct capi_driver hycapi_driver = {
"hysdn", owner: THIS_MODULE,
"0.0", name: "hysdn",
hycapi_load_firmware, revision: "0.0",
hycapi_reset_ctr, load_firmware: hycapi_load_firmware,
hycapi_remove_ctr, reset_ctr: hycapi_reset_ctr,
hycapi_register_appl, remove_ctr: hycapi_remove_ctr,
hycapi_release_appl, register_appl: hycapi_register_appl,
hycapi_send_message, release_appl: hycapi_release_appl,
hycapi_procinfo, send_message: hycapi_send_message,
hycapi_read_proc,
0, /* use standard driver_read_proc */ procinfo: hycapi_procinfo,
0, /* no add_card function */ ctr_read_proc: hycapi_read_proc,
driver_read_proc: 0, /* use standard driver_read_proc */
add_card: 0, /* no add_card function */
}; };
......
...@@ -79,30 +79,31 @@ struct capi_driver_interface { ...@@ -79,30 +79,31 @@ struct capi_driver_interface {
}; };
struct capi_driver { struct capi_driver {
char name[32]; /* driver name */ struct module *owner;
char revision[32]; char name[32]; /* driver name */
int (*load_firmware)(struct capi_ctr *, capiloaddata *); char revision[32];
void (*reset_ctr)(struct capi_ctr *); int (*load_firmware)(struct capi_ctr *, capiloaddata *);
void (*remove_ctr)(struct capi_ctr *); void (*reset_ctr)(struct capi_ctr *);
void (*register_appl)(struct capi_ctr *, __u16 appl, void (*remove_ctr)(struct capi_ctr *);
capi_register_params *); void (*register_appl)(struct capi_ctr *, __u16 appl,
void (*release_appl)(struct capi_ctr *, __u16 appl); capi_register_params *);
void (*send_message)(struct capi_ctr *, struct sk_buff *skb); void (*release_appl)(struct capi_ctr *, __u16 appl);
void (*send_message)(struct capi_ctr *, struct sk_buff *skb);
char *(*procinfo)(struct capi_ctr *);
int (*ctr_read_proc)(char *page, char **start, off_t off, char *(*procinfo)(struct capi_ctr *);
int count, int *eof, struct capi_ctr *card); int (*ctr_read_proc)(char *page, char **start, off_t off,
int (*driver_read_proc)(char *page, char **start, off_t off, int count, int *eof, struct capi_ctr *card);
int count, int *eof, struct capi_driver *driver); int (*driver_read_proc)(char *page, char **start, off_t off,
int count, int *eof, struct capi_driver *driver);
int (*add_card)(struct capi_driver *driver, capicardparams *data);
int (*add_card)(struct capi_driver *driver, capicardparams *data);
/* intitialized by kcapi */
struct capi_ctr *controller; /* list of controllers */ /* intitialized by kcapi */
struct capi_driver *next; struct capi_ctr *controller; /* list of controllers */
int ncontroller; struct capi_driver *next;
struct proc_dir_entry *procent; int ncontroller;
char procfn[128]; struct proc_dir_entry *procent;
char procfn[128];
}; };
struct capi_driver_interface *attach_capi_driver(struct capi_driver *driver); struct capi_driver_interface *attach_capi_driver(struct capi_driver *driver);
......
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