@@ -2374,61 +2374,6 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
23742374 }
23752375}
23762376
2377- static void hci_suspend_clear_tasks (struct hci_dev * hdev )
2378- {
2379- int i ;
2380-
2381- for (i = 0 ; i < __SUSPEND_NUM_TASKS ; i ++ )
2382- clear_bit (i , hdev -> suspend_tasks );
2383-
2384- wake_up (& hdev -> suspend_wait_q );
2385- }
2386-
2387- static int hci_suspend_wait_event (struct hci_dev * hdev )
2388- {
2389- #define WAKE_COND \
2390- (find_first_bit(hdev->suspend_tasks, __SUSPEND_NUM_TASKS) == \
2391- __SUSPEND_NUM_TASKS)
2392-
2393- int i ;
2394- int ret = wait_event_timeout (hdev -> suspend_wait_q ,
2395- WAKE_COND , SUSPEND_NOTIFIER_TIMEOUT );
2396-
2397- if (ret == 0 ) {
2398- bt_dev_err (hdev , "Timed out waiting for suspend events" );
2399- for (i = 0 ; i < __SUSPEND_NUM_TASKS ; ++ i ) {
2400- if (test_bit (i , hdev -> suspend_tasks ))
2401- bt_dev_err (hdev , "Suspend timeout bit: %d" , i );
2402- clear_bit (i , hdev -> suspend_tasks );
2403- }
2404-
2405- ret = - ETIMEDOUT ;
2406- } else {
2407- ret = 0 ;
2408- }
2409-
2410- return ret ;
2411- }
2412-
2413- static void hci_prepare_suspend (struct work_struct * work )
2414- {
2415- struct hci_dev * hdev =
2416- container_of (work , struct hci_dev , suspend_prepare );
2417-
2418- hci_dev_lock (hdev );
2419- hci_req_prepare_suspend (hdev , hdev -> suspend_state_next );
2420- hci_dev_unlock (hdev );
2421- }
2422-
2423- static int hci_change_suspend_state (struct hci_dev * hdev ,
2424- enum suspended_state next )
2425- {
2426- hdev -> suspend_state_next = next ;
2427- set_bit (SUSPEND_PREPARE_NOTIFIER , hdev -> suspend_tasks );
2428- queue_work (hdev -> req_workqueue , & hdev -> suspend_prepare );
2429- return hci_suspend_wait_event (hdev );
2430- }
2431-
24322377static void hci_clear_wake_reason (struct hci_dev * hdev )
24332378{
24342379 hci_dev_lock (hdev );
@@ -2565,7 +2510,6 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)
25652510 INIT_WORK (& hdev -> tx_work , hci_tx_work );
25662511 INIT_WORK (& hdev -> power_on , hci_power_on );
25672512 INIT_WORK (& hdev -> error_reset , hci_error_reset );
2568- INIT_WORK (& hdev -> suspend_prepare , hci_prepare_suspend );
25692513
25702514 hci_cmd_sync_init (hdev );
25712515
@@ -2576,7 +2520,6 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)
25762520 skb_queue_head_init (& hdev -> raw_q );
25772521
25782522 init_waitqueue_head (& hdev -> req_wait_q );
2579- init_waitqueue_head (& hdev -> suspend_wait_q );
25802523
25812524 INIT_DELAYED_WORK (& hdev -> cmd_timer , hci_cmd_timeout );
25822525 INIT_DELAYED_WORK (& hdev -> ncmd_timer , hci_ncmd_timeout );
@@ -2729,11 +2672,8 @@ void hci_unregister_dev(struct hci_dev *hdev)
27292672
27302673 hci_cmd_sync_clear (hdev );
27312674
2732- if (!test_bit (HCI_QUIRK_NO_SUSPEND_NOTIFIER , & hdev -> quirks )) {
2733- hci_suspend_clear_tasks (hdev );
2675+ if (!test_bit (HCI_QUIRK_NO_SUSPEND_NOTIFIER , & hdev -> quirks ))
27342676 unregister_pm_notifier (& hdev -> suspend_notifier );
2735- cancel_work_sync (& hdev -> suspend_prepare );
2736- }
27372677
27382678 msft_unregister (hdev );
27392679
@@ -2800,7 +2740,6 @@ EXPORT_SYMBOL(hci_release_dev);
28002740int hci_suspend_dev (struct hci_dev * hdev )
28012741{
28022742 int ret ;
2803- u8 state = BT_RUNNING ;
28042743
28052744 bt_dev_dbg (hdev , "" );
28062745
@@ -2809,40 +2748,17 @@ int hci_suspend_dev(struct hci_dev *hdev)
28092748 hci_dev_test_flag (hdev , HCI_UNREGISTER ))
28102749 return 0 ;
28112750
2812- /* If powering down, wait for completion. */
2813- if (mgmt_powering_down (hdev )) {
2814- set_bit (SUSPEND_POWERING_DOWN , hdev -> suspend_tasks );
2815- ret = hci_suspend_wait_event (hdev );
2816- if (ret )
2817- goto done ;
2818- }
2819-
2820- /* Suspend consists of two actions:
2821- * - First, disconnect everything and make the controller not
2822- * connectable (disabling scanning)
2823- * - Second, program event filter/accept list and enable scan
2824- */
2825- ret = hci_change_suspend_state (hdev , BT_SUSPEND_DISCONNECT );
2826- if (ret )
2827- goto clear ;
2828-
2829- state = BT_SUSPEND_DISCONNECT ;
2751+ /* If powering down don't attempt to suspend */
2752+ if (mgmt_powering_down (hdev ))
2753+ return 0 ;
28302754
2831- /* Only configure accept list if device may wakeup. */
2832- if (hdev -> wakeup && hdev -> wakeup (hdev )) {
2833- ret = hci_change_suspend_state (hdev , BT_SUSPEND_CONFIGURE_WAKE );
2834- if (!ret )
2835- state = BT_SUSPEND_CONFIGURE_WAKE ;
2836- }
2755+ hci_req_sync_lock (hdev );
2756+ ret = hci_suspend_sync (hdev );
2757+ hci_req_sync_unlock (hdev );
28372758
2838- clear :
28392759 hci_clear_wake_reason (hdev );
2840- mgmt_suspending (hdev , state );
2760+ mgmt_suspending (hdev , hdev -> suspend_state );
28412761
2842- done :
2843- /* We always allow suspend even if suspend preparation failed and
2844- * attempt to recover in resume.
2845- */
28462762 hci_sock_dev_event (hdev , HCI_DEV_SUSPEND );
28472763 return ret ;
28482764}
@@ -2864,10 +2780,12 @@ int hci_resume_dev(struct hci_dev *hdev)
28642780 if (mgmt_powering_down (hdev ))
28652781 return 0 ;
28662782
2867- ret = hci_change_suspend_state (hdev , BT_RUNNING );
2783+ hci_req_sync_lock (hdev );
2784+ ret = hci_resume_sync (hdev );
2785+ hci_req_sync_unlock (hdev );
28682786
28692787 mgmt_resuming (hdev , hdev -> wake_reason , & hdev -> wake_addr ,
2870- hdev -> wake_addr_type );
2788+ hdev -> wake_addr_type );
28712789
28722790 hci_sock_dev_event (hdev , HCI_DEV_RESUME );
28732791 return ret ;
0 commit comments