22
22
#include <linux/kernel.h>
23
23
#include <linux/init.h>
24
24
#include <linux/errno.h>
25
- #include <linux/semaphore.h>
26
25
#include <linux/string.h>
27
26
#include <linux/skbuff.h>
28
27
#include <linux/wakelock.h>
41
40
*/
42
41
43
42
#define RX_Q_MONITOR (500) /* 500 milli second */
44
- #define HCI_REGISTER_SET 0
45
43
46
44
47
45
static int hcismd_set ;
48
- static DEFINE_SEMAPHORE (hci_smd_enable );
49
-
50
- static int restart_in_progress ;
46
+ static DEFINE_MUTEX (hci_smd_enable );
51
47
52
48
static int hcismd_set_enable (const char * val , struct kernel_param * kp );
53
49
module_param_call (hcismd_set , hcismd_set_enable , NULL , & hcismd_set , 0644 );
54
50
55
- static void hci_dev_smd_open (struct work_struct * worker );
56
51
static void hci_dev_restart (struct work_struct * worker );
57
52
58
53
struct hci_smd_data {
59
54
struct hci_dev * hdev ;
60
- unsigned long flags ;
55
+
61
56
struct smd_channel * event_channel ;
62
57
struct smd_channel * data_channel ;
63
58
struct wake_lock wake_lock_tx ;
@@ -320,8 +315,6 @@ static void hci_smd_notify_event(void *data, unsigned int event)
320
315
struct hci_dev * hdev = hs .hdev ;
321
316
struct hci_smd_data * hsmd = & hs ;
322
317
struct work_struct * reset_worker ;
323
- struct work_struct * open_worker ;
324
-
325
318
int len = 0 ;
326
319
327
320
if (!hdev ) {
@@ -341,13 +334,6 @@ static void hci_smd_notify_event(void *data, unsigned int event)
341
334
case SMD_EVENT_OPEN :
342
335
BT_INFO ("opening HCI-SMD channel :%s" , EVENT_CHANNEL );
343
336
hci_smd_open (hdev );
344
- open_worker = kzalloc (sizeof (* open_worker ), GFP_ATOMIC );
345
- if (!open_worker ) {
346
- BT_ERR ("Out of memory" );
347
- break ;
348
- }
349
- INIT_WORK (open_worker , hci_dev_smd_open );
350
- schedule_work (open_worker );
351
337
break ;
352
338
case SMD_EVENT_CLOSE :
353
339
BT_INFO ("Closing HCI-SMD channel :%s" , EVENT_CHANNEL );
@@ -398,29 +384,9 @@ static void hci_smd_notify_data(void *data, unsigned int event)
398
384
399
385
}
400
386
401
- static int hci_smd_hci_register_dev (struct hci_smd_data * hsmd )
402
- {
403
- struct hci_dev * hdev ;
404
-
405
- hdev = hsmd -> hdev ;
406
- if (test_and_set_bit (HCI_REGISTER_SET , & hsmd -> flags )) {
407
- BT_ERR ("HCI device registered already" );
408
- return 0 ;
409
- } else
410
- BT_INFO ("HCI device registration is starting" );
411
- if (hci_register_dev (hdev ) < 0 ) {
412
- BT_ERR ("Can't register HCI device" );
413
- hci_free_dev (hdev );
414
- hsmd -> hdev = NULL ;
415
- clear_bit (HCI_REGISTER_SET , & hsmd -> flags );
416
- return - ENODEV ;
417
- }
418
- return 0 ;
419
- }
420
-
421
- static int hci_smd_register_smd (struct hci_smd_data * hsmd )
387
+ static int hci_smd_register_dev (struct hci_smd_data * hsmd )
422
388
{
423
- struct hci_dev * hdev ;
389
+ static struct hci_dev * hdev ;
424
390
int rc ;
425
391
426
392
/* Initialize and register HCI device */
@@ -455,7 +421,7 @@ static int hci_smd_register_smd(struct hci_smd_data *hsmd)
455
421
if (rc < 0 ) {
456
422
BT_ERR ("Cannot open the command channel" );
457
423
hci_free_dev (hdev );
458
- hsmd -> hdev = NULL ;
424
+ hdev = NULL ;
459
425
return - ENODEV ;
460
426
}
461
427
@@ -464,25 +430,25 @@ static int hci_smd_register_smd(struct hci_smd_data *hsmd)
464
430
if (rc < 0 ) {
465
431
BT_ERR ("Failed to open the Data channel" );
466
432
hci_free_dev (hdev );
467
- hsmd -> hdev = NULL ;
433
+ hdev = NULL ;
468
434
return - ENODEV ;
469
435
}
470
436
471
437
/* Disable the read interrupts on the channel */
472
438
smd_disable_read_intr (hsmd -> event_channel );
473
439
smd_disable_read_intr (hsmd -> data_channel );
440
+ if (hci_register_dev (hdev ) < 0 ) {
441
+ BT_ERR ("Can't register HCI device" );
442
+ hci_free_dev (hdev );
443
+ return - ENODEV ;
444
+ }
474
445
return 0 ;
475
446
}
476
447
477
448
static void hci_smd_deregister_dev (struct hci_smd_data * hsmd )
478
449
{
479
450
tasklet_kill (& hs .rx_task );
480
451
481
- if (!test_and_clear_bit (HCI_REGISTER_SET , & hsmd -> flags )) {
482
- BT_ERR ("HCI device un-registered already" );
483
- return ;
484
- } else
485
- BT_INFO ("HCI device un-registration going on" );
486
452
if (hsmd -> hdev ) {
487
453
if (hci_unregister_dev (hsmd -> hdev ) < 0 )
488
454
BT_ERR ("Can't unregister HCI device %s" ,
@@ -510,34 +476,18 @@ static void hci_smd_deregister_dev(struct hci_smd_data *hsmd)
510
476
511
477
static void hci_dev_restart (struct work_struct * worker )
512
478
{
513
- down (& hci_smd_enable );
514
- restart_in_progress = 1 ;
479
+ mutex_lock (& hci_smd_enable );
515
480
hci_smd_deregister_dev (& hs );
516
- hci_smd_register_smd (& hs );
517
- up (& hci_smd_enable );
518
- kfree (worker );
519
- }
520
-
521
- static void hci_dev_smd_open (struct work_struct * worker )
522
- {
523
- down (& hci_smd_enable );
524
- if (restart_in_progress == 1 ) {
525
- /* Allow wcnss to initialize */
526
- restart_in_progress = 0 ;
527
- msleep (10000 );
528
- }
529
- hci_smd_hci_register_dev (& hs );
530
- up (& hci_smd_enable );
481
+ hci_smd_register_dev (& hs );
482
+ mutex_unlock (& hci_smd_enable );
531
483
kfree (worker );
532
484
}
533
485
534
486
static int hcismd_set_enable (const char * val , struct kernel_param * kp )
535
487
{
536
488
int ret = 0 ;
537
489
538
- pr_err ("hcismd_set_enable %d" , hcismd_set );
539
-
540
- down (& hci_smd_enable );
490
+ mutex_lock (& hci_smd_enable );
541
491
542
492
ret = param_set_int (val , kp );
543
493
@@ -547,8 +497,7 @@ static int hcismd_set_enable(const char *val, struct kernel_param *kp)
547
497
switch (hcismd_set ) {
548
498
549
499
case 1 :
550
- if (hs .hdev == NULL )
551
- hci_smd_register_smd (& hs );
500
+ hci_smd_register_dev (& hs );
552
501
break ;
553
502
case 0 :
554
503
hci_smd_deregister_dev (& hs );
@@ -558,7 +507,7 @@ static int hcismd_set_enable(const char *val, struct kernel_param *kp)
558
507
}
559
508
560
509
done :
561
- up (& hci_smd_enable );
510
+ mutex_unlock (& hci_smd_enable );
562
511
return ret ;
563
512
}
564
513
static int __init hci_smd_init (void )
@@ -567,8 +516,6 @@ static int __init hci_smd_init(void)
567
516
"msm_smd_Rx" );
568
517
wake_lock_init (& hs .wake_lock_tx , WAKE_LOCK_SUSPEND ,
569
518
"msm_smd_Tx" );
570
- restart_in_progress = 0 ;
571
- hs .hdev = NULL ;
572
519
return 0 ;
573
520
}
574
521
module_init (hci_smd_init );
0 commit comments