Skip to content
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: Convert HCI drivers to use a proper Zephyr driver API #72323

Merged
merged 30 commits into from
Jun 11, 2024

Conversation

jhedberg
Copy link
Member

@jhedberg jhedberg commented May 5, 2024

Current status:

  • Create a base binding and API definition
  • Update the host to support new HCI driver instances
  • Update h4.c
  • Update native controller HCI driver
  • Fix samples/bluetooth/hci_uart_async/ to work with the new driver model
  • Fix bsim to work both with native and UART-based controllers (right now CI is failing)
  • Figure out what to do with bt_read_static_addr(). Taken care of by Bluetooth: Simplify Kconfig options and interface between the host and controller #72580
  • Figure out what to do with BT_HAS_HCI_VS, BT_HCI_VS and BT_HCI_VS_EXT (perhaps DTS properties?). Some preparation in Bluetooth: Simplify Kconfig options and interface between the host and controller #72580.
  • Fix controller unit tests: no devicetree available for unit_testing "board" right now: Bluetooth: controller: Add BT_CTLR_HCI Kconfig option #72871
  • Update ipc.c
  • Update userchan.c
  • Update h5.c
  • Update hci_ambiq.c (and associated DT binding)
  • Remove hci_b91.c: Bluetooth: drivers: Remove unmaintained B91 HCI driver #73289
  • Update hci_esp32.c
  • Update hci_psoc6_bless.c (and associated DT binding)
  • Update hci_spi_st.c (and associated DT binding)
  • Update hci_stm32wba.c
  • Update ipm_stm32wb.c (and associated DT binding)
  • Update spi.c
  • Update hci_da1469x.c
  • Update hci_nxp.c
  • Update slz_hci.c
  • Update documentation, especially stuff regarding /chosen properties
  • Make it possible for nrf52_bsim to use also UART for HCI
  • Update various apps under samples/ and tests/ that use the legacy HCI driver API
  • Get rid of the Kconfig choice section for HCI drivers
  • Get rid of BT_NO_DRIVER
  • Deprecate the old API
  • Lots of testing
    • bsim with virtual driver (hci_driver.c)
    • ipc.c tested in CI
    • Test on hardware with virtual bus (i.e. combined build)
    • Test on hardware with IPC (i.e. split build)
    • Test on hardware with UART (i.e. split build)
    • userchan.c
    • Test with an OoT driver (e.g. NCS)

Right now the host hci_core.c uses #if DT_HAS_CHOSEN(zephyr_bt_hci) to separate the new-style HCI drivers from the legacy HCI driver support. The old API has been deprecated, but will only be removed after a deprecation period.

The following drivers depend on "west blobs", so they're not covered by CI, but were manually compile tested:

What this PR doesn't try to tackle:

  • Find a solution for and fix driver dependencies on host HCI command sending APIs, which are e.g. not available with HCI_RAW.
    #if defined(CONFIG_BT_HCI_RAW)
    struct bt_hci_cmd_hdr hdr;
    hdr.opcode = sys_cpu_to_le16(HCI_VSC_UPDATE_NVDS_CFG_CMD_OPCODE);
    hdr.param_len = HCI_VSC_UPDATE_NVDS_CFG_CMD_LENGTH;
    buf = bt_buf_get_tx(BT_BUF_CMD, K_NO_WAIT, &hdr, sizeof(hdr));
    if (!buf) {
    return -ENOBUFS;
    }
    net_buf_add_mem(buf, &am_devices_cooper_nvds[0], HCI_VSC_UPDATE_NVDS_CFG_CMD_LENGTH);
    ret = bt_send(buf);
    if (!ret) {
    /* Give some time to make NVDS take effect in BLE controller */
    k_sleep(K_MSEC(5));
    /* Need to send reset command to make the NVDS take effect */
    hdr.opcode = sys_cpu_to_le16(BT_HCI_OP_RESET);
    hdr.param_len = 0;
    buf = bt_buf_get_tx(BT_BUF_CMD, K_NO_WAIT, &hdr, sizeof(hdr));
    if (!buf) {
    return -ENOBUFS;
    }
    ret = bt_send(buf);
    }
    #else
    uint8_t *p;
    buf = bt_hci_cmd_create(HCI_VSC_UPDATE_NVDS_CFG_CMD_OPCODE,
    HCI_VSC_UPDATE_NVDS_CFG_CMD_LENGTH);
    if (!buf) {
    return -ENOBUFS;
    }
    p = net_buf_add(buf, HCI_VSC_UPDATE_NVDS_CFG_CMD_LENGTH);
    memcpy(p, &am_devices_cooper_nvds[0], HCI_VSC_UPDATE_NVDS_CFG_CMD_LENGTH);
    ret = bt_hci_cmd_send_sync(HCI_VSC_UPDATE_NVDS_CFG_CMD_OPCODE, buf, NULL);
    if (!ret) {
    /* Give some time to make NVDS take effect in BLE controller */
    k_sleep(K_MSEC(5));
    }
    #endif /* defined(CONFIG_BT_HCI_RAW) */
  • Decide what to do with BT_HCI_ACL_FLOW_CONTROL currently referencing specific HCI drivers
  • net_buf allocations by drivers. Drivers should own their own memory rather than calling into the host side to do these allocations.
  • Making the HCI driver API support system calls. This is related to the above first point. We also can't have the driver make direct calls using the recv callback to the host, rather there needs to be another mechanism for the host to fetch data from the driver.

Fixes #51503

@jhedberg jhedberg force-pushed the bt_hci_driver branch 2 times, most recently from 7bebbc5 to a841b2a Compare May 5, 2024 16:06
jhedberg and others added 7 commits June 11, 2024 10:50
Convert the ipm_stm32wb.c HCI driver to the new HCI driver API.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
Convert the Renesas DA1469X HCI driver to the new HCI driver API.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
Convert the hci_nxp.c HCI driver to use the new HCI driver API. Also move
the driver binding under dts/bindings/bluetooth, like all other HCI driver
bindings.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
Convert the slz_hci.c HCI driver to use the new HCI driver API. This also
fixes the HCI bus type to correctly indicate VIRTUAL instead of UART.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
Deprecate the bt_recv() and bt_hci_driver_register() APIs. There are no
more users in the tree itself, but we should let any out of tree users
migrate before removing these APIs completely.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Update references to devicetree chosen properties and how devicetree nodes
should be defined in order to enable the new HCI drivers.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Document the changes coming with the new HCI driver API, and provide
information for how to migrate existing drivers.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
@jhedberg
Copy link
Member Author

@jerome-pouiller @Thalley could you take another look? Due to the size of this PR it'd be better to get it in sooner rather than later, especially since the feature freeze is coming this week. Since there doesn't seem to be any fundamental objections to the architectural/API change introduced here, any follow-up fixes & cleanups could happen after the feature freeze as well. There are a couple of other open HCI driver PRs which conflict with this one, which also target the next release, so it'd be good to start merging these sooner rather than later so we get the conflicts resolved and everything merged on time.

@Thalley
Copy link
Collaborator

Thalley commented Jun 11, 2024

@jerome-pouiller @Thalley could you take another look? Due to the size of this PR it'd be better to get it in sooner rather than later, especially since the feature freeze is coming this week. Since there doesn't seem to be any fundamental objections to the architectural/API change introduced here, any follow-up fixes & cleanups could happen after the feature freeze as well. There are a couple of other open HCI driver PRs which conflict with this one, which also target the next release, so it'd be good to start merging these sooner rather than later so we get the conflicts resolved and everything merged on time.

Indeed, and the number of commits easily hide comments on Github (...).

I'd be OK with merging as is, but I would have to have at least #72323 (comment) resolved ASAP so that we can do things properly (which I believe was the main point of this change in the first place ;) )

@carlescufi
Copy link
Member

@rugeGerritsen @aescolar @yeaissa @erwango @npal-cy @alwa-nordic please take a look ASAP, we would like to include this in Zephyr 3.7.0, which means merging it before this Friday

@nashif nashif merged commit 4b8aa82 into zephyrproject-rtos:main Jun 11, 2024
25 checks passed
@jhedberg jhedberg deleted the bt_hci_driver branch June 12, 2024 07:06
Copy link

@jerome-pouiller jerome-pouiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside my comment about efr32xg13. This PR is fine for me.

rugeGerritsen added a commit to rugeGerritsen/sdk-nrf that referenced this pull request Jun 12, 2024
The new driver API was introduced in
zephyrproject-rtos/zephyr#72323.

The driver was updated similar to how to the zephyr link layer
was updated.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bluetooth: HCI drivers should be first-class Zephyr drivers (driver API, DTS, etc)