@@ -44,12 +44,10 @@ module_param(showcapimsgs, uint, 0);
4444
4545/* ------------------------------------------------------------- */
4646
47- struct capi_notifier {
47+ struct capictr_event {
4848 struct work_struct work ;
49- unsigned int cmd ;
49+ unsigned int type ;
5050 u32 controller ;
51- u16 applid ;
52- u32 ncci ;
5351};
5452
5553/* ------------------------------------------------------------- */
@@ -71,6 +69,8 @@ struct capi_ctr *capi_controller[CAPI_MAXCONTR];
7169
7270static int ncontrollers ;
7371
72+ static BLOCKING_NOTIFIER_HEAD (ctr_notifier_list );
73+
7474/* -------- controller ref counting -------------------------------------- */
7575
7676static inline struct capi_ctr *
@@ -165,8 +165,6 @@ static void release_appl(struct capi_ctr *ctr, u16 applid)
165165 capi_ctr_put (ctr );
166166}
167167
168- /* -------- KCI_CONTRUP --------------------------------------- */
169-
170168static void notify_up (u32 contr )
171169{
172170 struct capi20_appl * ap ;
@@ -188,16 +186,11 @@ static void notify_up(u32 contr)
188186 if (!ap || ap -> release_in_progress )
189187 continue ;
190188 register_appl (ctr , applid , & ap -> rparam );
191- if (ap -> callback && !ap -> release_in_progress )
192- ap -> callback (KCI_CONTRUP , contr ,
193- & ctr -> profile );
194189 }
195190 } else
196191 printk (KERN_WARNING "%s: invalid contr %d\n" , __func__ , contr );
197192}
198193
199- /* -------- KCI_CONTRDOWN ------------------------------------- */
200-
201194static void ctr_down (struct capi_ctr * ctr )
202195{
203196 struct capi20_appl * ap ;
@@ -215,11 +208,8 @@ static void ctr_down(struct capi_ctr *ctr)
215208
216209 for (applid = 1 ; applid <= CAPI_MAXAPPL ; applid ++ ) {
217210 ap = get_capi_appl_by_nr (applid );
218- if (ap && !ap -> release_in_progress ) {
219- if (ap -> callback )
220- ap -> callback (KCI_CONTRDOWN , ctr -> cnr , NULL );
211+ if (ap && !ap -> release_in_progress )
221212 capi_ctr_put (ctr );
222- }
223213 }
224214}
225215
@@ -237,45 +227,63 @@ static void notify_down(u32 contr)
237227 printk (KERN_WARNING "%s: invalid contr %d\n" , __func__ , contr );
238228}
239229
240- static void notify_handler (struct work_struct * work )
230+ static int
231+ notify_handler (struct notifier_block * nb , unsigned long val , void * v )
241232{
242- struct capi_notifier * np =
243- container_of (work , struct capi_notifier , work );
233+ u32 contr = (long )v ;
244234
245- switch (np -> cmd ) {
246- case KCI_CONTRUP :
247- notify_up (np -> controller );
235+ switch (val ) {
236+ case CAPICTR_UP :
237+ notify_up (contr );
248238 break ;
249- case KCI_CONTRDOWN :
250- notify_down (np -> controller );
239+ case CAPICTR_DOWN :
240+ notify_down (contr );
251241 break ;
252242 }
243+ return NOTIFY_OK ;
244+ }
245+
246+ static void do_notify_work (struct work_struct * work )
247+ {
248+ struct capictr_event * event =
249+ container_of (work , struct capictr_event , work );
253250
254- kfree (np );
251+ blocking_notifier_call_chain (& ctr_notifier_list , event -> type ,
252+ (void * )(long )event -> controller );
253+ kfree (event );
255254}
256255
257256/*
258257 * The notifier will result in adding/deleteing of devices. Devices can
259258 * only removed in user process, not in bh.
260259 */
261- static int notify_push (unsigned int cmd , u32 controller , u16 applid , u32 ncci )
260+ static int notify_push (unsigned int event_type , u32 controller )
262261{
263- struct capi_notifier * np = kmalloc (sizeof (* np ), GFP_ATOMIC );
262+ struct capictr_event * event = kmalloc (sizeof (* event ), GFP_ATOMIC );
264263
265- if (!np )
264+ if (!event )
266265 return - ENOMEM ;
267266
268- INIT_WORK (& np -> work , notify_handler );
269- np -> cmd = cmd ;
270- np -> controller = controller ;
271- np -> applid = applid ;
272- np -> ncci = ncci ;
267+ INIT_WORK (& event -> work , do_notify_work );
268+ event -> type = event_type ;
269+ event -> controller = controller ;
273270
274- schedule_work (& np -> work );
271+ schedule_work (& event -> work );
275272 return 0 ;
276273}
277274
278-
275+ int register_capictr_notifier (struct notifier_block * nb )
276+ {
277+ return blocking_notifier_chain_register (& ctr_notifier_list , nb );
278+ }
279+ EXPORT_SYMBOL_GPL (register_capictr_notifier );
280+
281+ int unregister_capictr_notifier (struct notifier_block * nb )
282+ {
283+ return blocking_notifier_chain_unregister (& ctr_notifier_list , nb );
284+ }
285+ EXPORT_SYMBOL_GPL (unregister_capictr_notifier );
286+
279287/* -------- Receiver ------------------------------------------ */
280288
281289static void recv_handler (struct work_struct * work )
@@ -401,7 +409,7 @@ void capi_ctr_ready(struct capi_ctr *ctr)
401409 printk (KERN_NOTICE "kcapi: controller [%03d] \"%s\" ready.\n" ,
402410 ctr -> cnr , ctr -> name );
403411
404- notify_push (KCI_CONTRUP , ctr -> cnr , 0 , 0 );
412+ notify_push (CAPICTR_UP , ctr -> cnr );
405413}
406414
407415EXPORT_SYMBOL (capi_ctr_ready );
@@ -418,7 +426,7 @@ void capi_ctr_down(struct capi_ctr *ctr)
418426{
419427 printk (KERN_NOTICE "kcapi: controller [%03d] down.\n" , ctr -> cnr );
420428
421- notify_push (KCI_CONTRDOWN , ctr -> cnr , 0 , 0 );
429+ notify_push (CAPICTR_DOWN , ctr -> cnr );
422430}
423431
424432EXPORT_SYMBOL (capi_ctr_down );
@@ -633,7 +641,6 @@ u16 capi20_register(struct capi20_appl *ap)
633641 ap -> nrecvdatapkt = 0 ;
634642 ap -> nsentctlpkt = 0 ;
635643 ap -> nsentdatapkt = 0 ;
636- ap -> callback = NULL ;
637644 mutex_init (& ap -> recv_mtx );
638645 skb_queue_head_init (& ap -> recv_queue );
639646 INIT_WORK (& ap -> recv_work , recv_handler );
@@ -1137,30 +1144,6 @@ int capi20_manufacturer(unsigned int cmd, void __user *data)
11371144
11381145EXPORT_SYMBOL (capi20_manufacturer );
11391146
1140- /* temporary hack */
1141-
1142- /**
1143- * capi20_set_callback() - set CAPI application notification callback function
1144- * @ap: CAPI application descriptor structure.
1145- * @callback: callback function (NULL to remove).
1146- *
1147- * If not NULL, the callback function will be called to notify the
1148- * application of the addition or removal of a controller.
1149- * The first argument (cmd) will tell whether the controller was added
1150- * (KCI_CONTRUP) or removed (KCI_CONTRDOWN).
1151- * The second argument (contr) will be the controller number.
1152- * For cmd==KCI_CONTRUP the third argument (data) will be a pointer to the
1153- * new controller's capability profile structure.
1154- */
1155-
1156- void capi20_set_callback (struct capi20_appl * ap ,
1157- void (* callback ) (unsigned int cmd , __u32 contr , void * data ))
1158- {
1159- ap -> callback = callback ;
1160- }
1161-
1162- EXPORT_SYMBOL (capi20_set_callback );
1163-
11641147/* ------------------------------------------------------------- */
11651148/* -------- Init & Cleanup ------------------------------------- */
11661149/* ------------------------------------------------------------- */
@@ -1169,10 +1152,17 @@ EXPORT_SYMBOL(capi20_set_callback);
11691152 * init / exit functions
11701153 */
11711154
1155+ static struct notifier_block capictr_nb = {
1156+ .notifier_call = notify_handler ,
1157+ .priority = INT_MAX ,
1158+ };
1159+
11721160static int __init kcapi_init (void )
11731161{
11741162 int err ;
11751163
1164+ register_capictr_notifier (& capictr_nb );
1165+
11761166 err = cdebug_init ();
11771167 if (!err )
11781168 kcapi_proc_init ();
0 commit comments