Skip to content

Commit c898f6d

Browse files
committed
Bluetooth: hci_sync: Introduce hci_cmd_sync_run/hci_cmd_sync_run_once
This introduces hci_cmd_sync_run/hci_cmd_sync_run_once which acts like hci_cmd_sync_queue/hci_cmd_sync_queue_once but runs immediately when already on hdev->cmd_sync_work context. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 8ae22de commit c898f6d

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

include/net/bluetooth/hci_sync.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
7373
void *data, hci_cmd_sync_work_destroy_t destroy);
7474
int hci_cmd_sync_queue_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
7575
void *data, hci_cmd_sync_work_destroy_t destroy);
76+
int hci_cmd_sync_run(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
77+
void *data, hci_cmd_sync_work_destroy_t destroy);
78+
int hci_cmd_sync_run_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
79+
void *data, hci_cmd_sync_work_destroy_t destroy);
7680
struct hci_cmd_sync_work_entry *
7781
hci_cmd_sync_lookup_entry(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
7882
void *data, hci_cmd_sync_work_destroy_t destroy);

net/bluetooth/hci_sync.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
783783
EXPORT_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

Comments
 (0)