@@ -112,7 +112,7 @@ static void hci_cmd_sync_add(struct hci_request *req, u16 opcode, u32 plen,
112112 skb_queue_tail (& req -> cmd_q , skb );
113113}
114114
115- static int hci_cmd_sync_run (struct hci_request * req )
115+ static int hci_req_sync_run (struct hci_request * req )
116116{
117117 struct hci_dev * hdev = req -> hdev ;
118118 struct sk_buff * skb ;
@@ -169,7 +169,7 @@ struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen,
169169
170170 hdev -> req_status = HCI_REQ_PEND ;
171171
172- err = hci_cmd_sync_run (& req );
172+ err = hci_req_sync_run (& req );
173173 if (err < 0 )
174174 return ERR_PTR (err );
175175
@@ -782,6 +782,44 @@ int hci_cmd_sync_queue_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
782782}
783783EXPORT_SYMBOL (hci_cmd_sync_queue_once );
784784
785+ /* Run HCI command:
786+ *
787+ * - hdev must be running
788+ * - if on cmd_sync_work then run immediately otherwise queue
789+ */
790+ int hci_cmd_sync_run (struct hci_dev * hdev , hci_cmd_sync_work_func_t func ,
791+ void * data , hci_cmd_sync_work_destroy_t destroy )
792+ {
793+ /* Only queue command if hdev is running which means it had been opened
794+ * and is either on init phase or is already up.
795+ */
796+ if (!test_bit (HCI_RUNNING , & hdev -> flags ))
797+ return - ENETDOWN ;
798+
799+ /* If on cmd_sync_work then run immediately otherwise queue */
800+ if (current_work () == & hdev -> cmd_sync_work )
801+ return func (hdev , data );
802+
803+ return hci_cmd_sync_submit (hdev , func , data , destroy );
804+ }
805+ EXPORT_SYMBOL (hci_cmd_sync_run );
806+
807+ /* Run HCI command entry once:
808+ *
809+ * - Lookup if an entry already exist and only if it doesn't creates a new entry
810+ * and run it.
811+ * - if on cmd_sync_work then run immediately otherwise queue
812+ */
813+ int hci_cmd_sync_run_once (struct hci_dev * hdev , hci_cmd_sync_work_func_t func ,
814+ void * data , hci_cmd_sync_work_destroy_t destroy )
815+ {
816+ if (hci_cmd_sync_lookup_entry (hdev , func , data , destroy ))
817+ return 0 ;
818+
819+ return hci_cmd_sync_run (hdev , func , data , destroy );
820+ }
821+ EXPORT_SYMBOL (hci_cmd_sync_run_once );
822+
785823/* Lookup HCI command entry:
786824 *
787825 * - Return first entry that matches by function callback or data or
0 commit comments