Bluetooth: Remove superfluous call to hci_conn_check_pending()
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH v4 1/4 Bluetooth: Remove superfluous call to hci_conn_check_pending()
From: Jonas Dreßler <[email protected]>
The "pending connections" feature was originally introduced with commit 4c67bc74f016 ("[Bluetooth] Support concurrent connect requests") and 6bd57416127e ("[Bluetooth] Handling pending connect attempts after inquiry") to handle controllers supporting only a single connection request at a time. Later things were extended to also cancel ongoing inquiries on connect() with commit 89e65975fea5 ("Bluetooth: Cancel Inquiry before Create Connection").
With commit a9de9248064b ("[Bluetooth] Switch from OGF+OCF to using only opcodes"), hci_conn_check_pending() was introduced as a helper to consolidate a few places where we check for pending connections (indicated by the BT_CONNECT2 flag) and then try to connect.
This refactoring commit also snuck in two more calls to hci_conn_check_pending():
- One is in the failure callback of hci_cs_inquiry(), this one probably makes sense: If we send an "HCI Inquiry" command and then immediately after a "Create Connection" command, the "Create Connection" command might fail before the "HCI Inquiry" command, and then we want to retry the "Create Connection" on failure of the "HCI Inquiry".
- The other added call to hci_conn_check_pending() is in the event handler for the "Remote Name" event, this seems unrelated and is possibly a copy-paste error, so remove that one.
--- net/bluetooth/hci_event.c | 2 -- 1 file changed, 2 deletions(-)
net/bluetooth/hci_event.c +0 -2
@@ -3556,8 +3556,6 @@ static void hci_remote_name_evt(struct hci_dev *hdev, void *data,bt_dev_dbg (hdev,"status 0x%2.2x" , ev->status); -hci_conn_check_pending (hdev); -hci_dev_lock (hdev); conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &ev->bdaddr);
Signature · 1 line
2.43.0
Luiz Augusto von Dentz
maintainerPATCH v4 2/4 Bluetooth: hci_event: Use HCI error defines instead of magic values
From: Jonas Dreßler <[email protected]>
We have error defines already, so let's use them.
--- include/net/bluetooth/hci.h | 2 ++ net/bluetooth/hci_event.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-)
include/net/bluetooth/hci.h +2 -0
@@ -653,6 +653,7 @@ enum {#define HCI_ERROR_PIN_OR_KEY_MISSING 0x06#define HCI_ERROR_MEMORY_EXCEEDED 0x07#define HCI_ERROR_CONNECTION_TIMEOUT 0x08 +#define HCI_ERROR_COMMAND_DISALLOWED 0x0c#define HCI_ERROR_REJ_LIMITED_RESOURCES 0x0d#define HCI_ERROR_REJ_BAD_ADDR 0x0f#define HCI_ERROR_INVALID_PARAMETERS 0x12
@@ -661,6 +662,7 @@ enum {#define HCI_ERROR_REMOTE_POWER_OFF 0x15#define HCI_ERROR_LOCAL_HOST_TERM 0x16#define HCI_ERROR_PAIRING_NOT_ALLOWED 0x18 +#define HCI_ERROR_UNSUPPORTED_REMOTE_FEATURE 0x1e#define HCI_ERROR_INVALID_LL_PARAMS 0x1e#define HCI_ERROR_UNSPECIFIED 0x1f#define HCI_ERROR_ADVERTISING_TIMEOUT 0x3c
net/bluetooth/hci_event.c +4 -4
@@ -95,11 +95,11 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev *hdev, void *data,/* It is possible that we receive Inquiry Complete event right * before we receive Inquiry Cancel Command Complete event, in * which case the latter event should have status of Command -* Disallowed (0x0c). This should not be treated as error, since +* Disallowed. This should not be treated as error, since * we actually achieve what Inquiry Cancel wants to achieve, * which is to end the last Inquiry session. */ -if (rp->status ==0x0c && !test_bit (HCI_INQUIRY , &hdev->flags)) { +if (rp->status ==HCI_ERROR_COMMAND_DISALLOWED && !test_bit (HCI_INQUIRY , &hdev->flags)) {bt_dev_warn (hdev,"Ignoring error of Inquiry Cancel command" ); rp->status =0x00 ; }
@@ -2342,7 +2342,7 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)if (status) {if (conn && conn->state ==BT_CONNECT ) { -if (status !=0x0c || conn->attempt >2 ) { +if (status !=HCI_ERROR_COMMAND_DISALLOWED || conn->attempt >2 ) { conn->state =BT_CLOSED ;hci_connect_cfm (conn, status);hci_conn_del (conn);
@@ -6679,7 +6679,7 @@ static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, void *data,* transition into connected state and mark it as * successful. */ -if (!conn->out && ev->status ==0x1a && +if (!conn->out && ev->status ==HCI_ERROR_UNSUPPORTED_REMOTE_FEATURE && (hdev->le_features[0 ] &HCI_LE_PERIPHERAL_FEATURES )) status =0x00 ;else
Signature · 1 line
2.43.0
Luiz Augusto von Dentz
maintainerPATCH v4 3/4 Bluetooth: hci_conn: Only do ACL connections sequentially
In reply to Luiz Augusto von DentzFrom: Jonas Dreßler <[email protected]>
Pretty much all bluetooth chipsets only support paging a single device at a time, and if they don't reject a secondary "Create Connection" request while another is still ongoing, they'll most likely serialize those requests in the firware.
With commit 4c67bc74f016 ("[Bluetooth] Support concurrent connect requests") we started adding some serialization of our own in case the adapter returns "Command Disallowed" HCI error.
This commit was using the BT_CONNECT2 state for the serialization, this state is also used for a few more things (most notably to indicate we're waiting for an inquiry to cancel) and therefore a bit unreliable. Also not all BT firwares would respond with "Command Disallowed" on too many connection requests, some will also respond with "Hardware Failure" (BCM4378), and others will error out later and send a "Connect Complete" event with error "Rejected Limited Resources" (Marvell 88W8897).
We can clean things up a bit and also make the serialization more reliable by using our hci_sync machinery to always do "Create Connection" requests in a sequential manner.
This is very similar to what we're already doing for establishing LE connections, and it works well there.
--- include/net/bluetooth/hci.h | 1 + include/net/bluetooth/hci_sync.h | 4 ++ net/bluetooth/hci_conn.c | 69 ++++------------------------- net/bluetooth/hci_sync.c | 74 ++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 60 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -439,6 +439,7 @@ enum {#define HCI_ACL_TX_TIMEOUT msecs_to_jiffies(45000)/* 45 seconds */ #define HCI_AUTO_OFF_TIMEOUT msecs_to_jiffies(2000)/* 2 seconds */ #define HCI_LE_CONN_TIMEOUT msecs_to_jiffies(20000)/* 20 seconds */ +#define HCI_ACL_CONN_TIMEOUT msecs_to_jiffies(20000)/* 20 seconds */ #define HCI_LE_AUTOCONN_TIMEOUT msecs_to_jiffies(4000)/* 4 seconds */ /* HCI data types */
include/net/bluetooth/hci_sync.h +4 -0
@@ -138,3 +138,7 @@ int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason);int hci_le_big_terminate_sync (struct hci_dev *hdev,u8 handle);int hci_le_pa_terminate_sync (struct hci_dev *hdev,u16 handle); + +int hci_acl_create_conn_sync (struct hci_dev *hdev,struct hci_conn *conn); + +int hci_acl_create_conn (struct hci_dev *hdev,struct hci_conn *conn);
net/bluetooth/hci_conn.c +9 -60
90 lines not on this page · raw message
net/bluetooth/hci_sync.c +74 -0
77 lines not on this page · raw message
Signature · 1 line
2.43.0
Luiz Augusto von Dentz
maintainerPATCH v4 4/4 Bluetooth: Remove pending ACL connection attempts
In reply to Luiz Augusto von DentzFrom: Jonas Dreßler <[email protected]>
With the last commit we moved to using the hci_sync queue for "Create Connection" requests, removing the need for retrying the paging after finished/failed "Create Connection" requests and after the end of inquiries.
hci_conn_check_pending() was used to trigger this retry, we can remove it now.
Note that we can also remove the special handling for COMMAND_DISALLOWED errors in the completion handler of "Create Connection", because "Create Connection" requests are now always serialized.
This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support concurrent connect requests").
With this, the BT_CONNECT2 state of ACL hci_conn objects should now be back to meaning only one thing: That we received a "Connection Request" from another device (see hci_conn_request_evt), but the response to that is going to be deferred.
--- include/net/bluetooth/hci_core.h | 1 - net/bluetooth/hci_conn.c | 16 ---------------- net/bluetooth/hci_event.c | 21 ++++----------------- 3 files changed, 4 insertions(+), 34 deletions(-)
include/net/bluetooth/hci_core.h +0 -1
@@ -1480,7 +1480,6 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type, bdaddr_t *dst, u8 role);void hci_conn_del (struct hci_conn *conn);void hci_conn_hash_flush (struct hci_dev *hdev); -void hci_conn_check_pending (struct hci_dev *hdev);struct hci_chan *hci_chan_create (struct hci_conn *conn);void hci_chan_del (struct hci_chan *chan);
net/bluetooth/hci_conn.c +0 -16
@@ -2596,22 +2596,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) } } -/* Check pending connect attempts */ -void hci_conn_check_pending (struct hci_dev *hdev) -{ -struct hci_conn *conn; - -BT_DBG ("hdev %s" , hdev->name); - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_state (hdev,ACL_LINK ,BT_CONNECT2 ); -if (conn) -hci_acl_create_conn (hdev, conn); - -hci_dev_unlock (hdev); -} -static u32 get_link_mode (struct hci_conn *conn) {u32 link_mode =0 ;
net/bluetooth/hci_event.c +4 -17
@@ -120,8 +120,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev *hdev, void *data,hci_discovery_set_state (hdev,DISCOVERY_STOPPED );hci_dev_unlock (hdev); -hci_conn_check_pending (hdev); -return rp->status; }
@@ -152,8 +150,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev *hdev, void *data,hci_dev_clear_flag (hdev,HCI_PERIODIC_INQ ); -hci_conn_check_pending (hdev); -return rp->status; }
@@ -2314,10 +2310,8 @@ static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) {bt_dev_dbg (hdev,"status 0x%2.2x" , status); -if (status) { -hci_conn_check_pending (hdev); +if (status)return ; - }if (hci_sent_cmd_data (hdev,HCI_OP_INQUIRY ))set_bit (HCI_INQUIRY , &hdev->flags);
@@ -2342,12 +2336,9 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)if (status) {if (conn && conn->state ==BT_CONNECT ) { -if (status !=HCI_ERROR_COMMAND_DISALLOWED || conn->attempt >2 ) { - conn->state =BT_CLOSED ; -hci_connect_cfm (conn, status); -hci_conn_del (conn); - }else - conn->state =BT_CONNECT2 ; + conn->state =BT_CLOSED ; +hci_connect_cfm (conn, status); +hci_conn_del (conn); } }else {if (!conn) {
@@ -3039,8 +3030,6 @@ static void hci_inquiry_complete_evt(struct hci_dev *hdev, void *data,bt_dev_dbg (hdev,"status 0x%2.2x" , ev->status); -hci_conn_check_pending (hdev); -if (!test_and_clear_bit (HCI_INQUIRY , &hdev->flags))return ;
@@ -3262,8 +3251,6 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, unlock:hci_dev_unlock (hdev); - -hci_conn_check_pending (hdev); }static void hci_reject_conn (struct hci_dev *hdev,bdaddr_t *bdaddr)
Signature · 1 line
2.43.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=815485
---Test result---
Test Summary:
CheckPatch FAIL 3.12 seconds GitLint PASS 0.87 seconds SubjectPrefix PASS 0.28 seconds BuildKernel PASS 28.61 seconds CheckAllWarning PASS 31.31 seconds CheckSparse WARNING 37.01 seconds CheckSmatch WARNING 100.36 seconds BuildKernel32 PASS 27.23 seconds TestRunnerSetup PASS 446.17 seconds TestRunner_l2cap-tester PASS 23.56 seconds TestRunner_iso-tester PASS 47.72 seconds TestRunner_bnep-tester PASS 7.47 seconds TestRunner_mgmt-tester FAIL 230.72 seconds TestRunner_rfcomm-tester PASS 10.97 seconds TestRunner_sco-tester PASS 18.05 seconds TestRunner_ioctl-tester PASS 11.99 seconds TestRunner_mesh-tester PASS 8.73 seconds TestRunner_smp-tester PASS 9.70 seconds TestRunner_userchan-tester PASS 7.22 seconds IncrementalBuild PASS 96.93 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v4,3/4] Bluetooth: hci_conn: Only do ACL connections sequentially
WARNING: 'firware' may be misspelled - perhaps 'firmware'? #84:
requests in the firware.
^^^^^^^
total: 0 errors, 1 warnings, 0 checks, 181 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/src/13515173.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 497, Passed: 494 (99.4%), Failed: 1, Not Run: 2
Failed Test Cases
LL Privacy - Add Device 5 (2 Devices to RL) Failed 0.195 seconds
---
Regards,
Linux Bluetooth
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 11 lines · On Tue, 9 Jan 2024 12:49:25 -0500 you wrote:
From: Jonas Dreßler <[email protected]>
The "pending connections" feature was originally introduced with commit
4c67bc74f016("[Bluetooth] Support concurrent connect requests") and6bd57416127e("[Bluetooth] Handling pending connect attempts after inquiry") to handle controllers supporting only a single connection request at a time. Later things were extended to also cancel ongoing inquiries onconnect()with commit89e65975fea5("Bluetooth: Cancel Inquiry before Create Connection").[...]
Here is the summary with links:
- [v4,1/4] Bluetooth: Remove superfluous call to hci_conn_check_pending()
https://git.kernel.org/bluetooth/bluetooth-next/c/a7ee39bea315 - [v4,2/4] Bluetooth: hci_event: Use HCI error defines instead of magic values https://git.kernel.org/bluetooth/bluetooth-next/c/f8c47ee39e6d
- [v4,3/4] Bluetooth: hci_conn: Only do ACL connections sequentially (no matching commit)
- [v4,4/4] Bluetooth: Remove pending ACL connection attempts (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html