-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth: Controller: Fix HCI command buffer allocation failure #83774
base: main
Are you sure you want to change the base?
Bluetooth: Controller: Fix HCI command buffer allocation failure #83774
Conversation
e9f6c00
to
c0b5240
Compare
c0b5240
to
3881e41
Compare
Fix HCI command buffer allocation failure, that can cause loss of Host Number of Completed Packets command. Fail by rejecting the HCI Host Buffer Size command if the required number of HCI command buffers are not allocated in the Controller implementation. Relates to commit 8161430 ("Bluetooth: Add workaround for no command buffer available")'. Relates to commit 297f4f4 ("Bluetooth: Split HCI command & event buffers to two pools"). Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
3881e41
to
7c899ff
Compare
When Controller to Host data flow control is enabled in the Host only | ||
build, ensure that BT_BUF_CMD_TX_COUNT is at least 2, to be able to | ||
send one normal HCI command and one Host Number of Completed Packets | ||
command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be enforced via Kconfig? Something like range 2 64 if !BT_CTLR && BT_HCI_ACL_FLOW_CONTROL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, depends on !BT_HCI_RAW || !HAS_BT_CTLR
?
I want to keep BT_BUF_CMD_TX_COUNT only for Host only and Host+Controller build, but not for Controller-only build, as it does not make sense when the Controller only supports 1 Num HCI Command Packets + BT_BUF_ACL_RX_COUNT (for Host Num Completed Packets commands).... where do you think is the right place to define BT_BUF_CMD_TX_COUNT internally, so that it is reference today in hci_raw.c and in the Controller code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep it in the place here, but make it promptless and default to 1 for controller-only builds?
When Controller to Host data flow control is supported in the | ||
Controller only build, ensure that BT_BUF_CMD_TX_COUNT is greater than | ||
or equal to (BT_BUF_ACL_RX_COUNT + Ncmd), where Ncmd is supported | ||
maximum Num_HCI_Command_Packets in the Controller implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can be enforced via Kconfig, but we can have BUILD_ASSERTs for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, added runtime check on Host Buffer Size command and will derive for Controller-only (not allow it to be configured incorrectly).
* Note: Zephyr Controller does not support Num_HCI_Command_Packets > 1. | ||
*/ | ||
if (acl_pkts >= CONFIG_BT_BUF_CMD_TX_COUNT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should CONFIG_BT_BUF_CMD_TX_COUNT
be limited to range 1 1
for the ZLL then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 when not enabling Controller to Host data flow control, and (1 + BT_BUF_ACL_RX_COUNT) when enabled.
HCI Controllers may not support Num_HCI_Command_Packets > 1, hence | ||
default to 1 when not enabling Controller to Host data flow control, | ||
BT_HCI_ACL_FLOW_CONTROL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph isn't completely clear to me. Even if a controller supports ncmd > 1, the Zephyr host has a command queue and will always round down the value to 1, or rather, treat it as a boolean:
zephyr/subsys/bluetooth/host/hci_core.c
Lines 2499 to 2503 in ddd795a
/* Allow next command to be sent */ | |
if (ncmd) { | |
k_sem_give(&bt_dev.ncmd_sem); | |
bt_tx_irq_raise(); | |
} |
The other help text paragraphs sort of make sense, but I just wanted to make sure the above host implementation detail is clear, so that this PR isn't making any false assumptions (since I haven't quite wrapped my head around all the details of it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Zephyr Host only implements ncmd
= 1. See,
zephyr/subsys/bluetooth/host/hci_core.c
Lines 4340 to 4348 in ddd795a
/* Give cmd_sem allowing to send first HCI_Reset cmd, the only | |
* exception is if the controller requests to wait for an | |
* initial Command Complete for NOP. | |
*/ | |
if (!IS_ENABLED(CONFIG_BT_WAIT_NOP)) { | |
k_sem_init(&bt_dev.ncmd_sem, 1, 1); | |
} else { | |
k_sem_init(&bt_dev.ncmd_sem, 0, 1); | |
} |
I guess it is not difficult to use the same semaphore and we able to support ncmd
> 1, but we do not have support in native Controller today for that though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Zephyr host has a command queue and will always round down the value to 1, or rather, treat it as a boolean:
@jhedberg I believe the implementation "can" support ncmd
> 1, but today ncmd
in the evt
is only used as a bool to pause the queuing, but the ncmd_sem
if initialized correctly would support ncmd
> 1. But we are not going towards that in this PR.
Fix HCI command buffer allocation failure, that can cause loss of Host Number of Completed Packets command.
Fail by rejecting the HCI Host Buffer Size command if the required number of HCI command buffers are not allocated in the Controller implementation.
Relates to commit 8161430 ("Bluetooth: Add workaround
for no command buffer available")'.
Relates to commit 297f4f4 ("Bluetooth: Split HCI
command & event buffers to two pools").
Relates to #81866
One of many CI failure exposing incorrect allocation: