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

usb: device_next: add BT HCI USB transport layer #53870

Merged
merged 3 commits into from
Jan 26, 2023

Conversation

jfischer-no
Copy link
Collaborator

Add Bluetooth HCI USB transport layer implementation for the new USB device support,
porting of subsys/usb/device/class/bluetooth.c without H4 bloat.

jhedberg
jhedberg previously approved these changes Jan 17, 2023
Copy link
Member

@jhedberg jhedberg left a comment

Choose a reason for hiding this comment

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

Looks pretty good

Comment on lines +457 to +589
/*
* Bluetooth subsystem does not support multiple HCI instances,
* but we are almost ready for it.
*/
BT_HCI_DESCRIPTOR_DEFINE(0)
BT_HCI_CLASS_DATA_DEFINE(0)
Copy link
Member

Choose a reason for hiding this comment

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

I think this relates to #51503 too. Along with making the HCI driver DTS-based, it becomes more natural to declare multiple instances. That said, the host stack treats the controller as singleton. There's a single bt_dev struct that's accessed as a global variable in several places of the host. To make the host truly multi-HCI aware there would need to be this bt_dev context per controller instance that's then passed around as a parameter in most existing Bluetooth APIs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jhedberg @jfischer-no does anything need to be done here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I understood @carlescufi, not in the near future.

Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

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

Mostly code style comments, and some questions

samples/bluetooth/hci_usb/src/main.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/bt_hci.c Show resolved Hide resolved
* RAM usage efficient.
*/
NET_BUF_POOL_FIXED_DEFINE(bt_hci_ep_pool,
3, 512,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why these specific numbers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Three endpoints, maximum three transfers used synchronously, 512 is the maximum packet size of a high speed bulk endpoint. I will add a comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If 512 is a maximum defined by the USB specification, then I'd suggest to #define that value and use that

subsys/usb/device_next/class/bt_hci.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/bt_hci.c Show resolved Hide resolved
subsys/usb/device_next/class/bt_hci.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/bt_hci.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/bt_hci.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/bt_hci.c Show resolved Hide resolved
subsys/usb/device_next/class/bt_hci.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/bt_hci.c Outdated Show resolved Hide resolved
#define USB_BT_HCI_PROTOCOL 0x01

#define BT_HCI_DEFAULT_BULK_EP_MPS 0 /* Get maximum supported */
#define BT_HCI_DEFAULT_INT_EP_MPS 64
Copy link

Choose a reason for hiding this comment

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

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part B page 1667 suggests 16 bytes Max Packet Size as the default.

}

bi = udc_get_buf_info(buf);
memset(bi, 0, sizeof(struct udc_buf_info));
Copy link
Collaborator

Choose a reason for hiding this comment

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

When the intention is to clear a struct like here, it may be more readable to use the pointer to the struct for the sizeof

Suggested change
memset(bi, 0, sizeof(struct udc_buf_info));
memset(bi, 0, sizeof(*bi));

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No it is not more readable.

subsys/usb/device_next/class/bt_hci.c Show resolved Hide resolved
Comment on lines +251 to +292
case BT_BUF_ISO_OUT: {
struct bt_hci_iso_hdr *iso_hdr;

hdr_len = sizeof(*iso_hdr);
iso_hdr = (struct bt_hci_iso_hdr *)data;
len = bt_iso_hdr_len(sys_le16_to_cpu(iso_hdr->len)) + hdr_len;
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that this driver otherwise doesn't support ISO, should this be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe, but then it must later be added for H4 support.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems odd to only partially add ISO/H4 support

subsys/usb/device_next/class/bt_hci.c Outdated Show resolved Hide resolved
Zero data payload size for isochronous endpoints is a
is a valid setting for default interface.
Also do not update MPS of control endpoint since it is
set by the driver.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
@jfischer-no
Copy link
Collaborator Author

Cherry-picked first commit from #53998 and added interface descriptor for ISO endpoints (still unused).

desowin
desowin previously approved these changes Jan 25, 2023
Add Bluetooth HCI USB transport layer implementation for the new
experimental USB device support based on the existing implementation
subsys/usb/device/class/bluetooth.c.

This implementation, unlike existing one, contains the interface
descriptors for isochronous endpoints. Since we do not support voice
channels, these are just there to avoid issues with Linux kernel btusb
driver when this implementation is part of a composite configuration.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Enable Bluetooth HCI USB tranport layer from new experimental
USB device support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

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

Some minor suggestions left, otherwise LGTM


static uint8_t bt_hci_get_int_in(struct usbd_class_node *const c_nd)
{
struct usbd_bt_hci_desc *desc = c_nd->data->desc;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor:

Suggested change
struct usbd_bt_hci_desc *desc = c_nd->data->desc;
const struct usbd_bt_hci_desc *desc = c_nd->data->desc;


static uint8_t bt_hci_get_bulk_in(struct usbd_class_node *const c_nd)
{
struct usbd_bt_hci_desc *desc = c_nd->data->desc;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor:

Suggested change
struct usbd_bt_hci_desc *desc = c_nd->data->desc;
const struct usbd_bt_hci_desc *desc = c_nd->data->desc;


static uint8_t bt_hci_get_bulk_out(struct usbd_class_node *const c_nd)
{
struct usbd_bt_hci_desc *desc = c_nd->data->desc;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor:

Suggested change
struct usbd_bt_hci_desc *desc = c_nd->data->desc;
const struct usbd_bt_hci_desc *desc = c_nd->data->desc;

subsys/usb/device_next/class/bt_hci.c Show resolved Hide resolved
Comment on lines +457 to +589
/*
* Bluetooth subsystem does not support multiple HCI instances,
* but we are almost ready for it.
*/
BT_HCI_DESCRIPTOR_DEFINE(0)
BT_HCI_CLASS_DATA_DEFINE(0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jhedberg @jfischer-no does anything need to be done here?

@jfischer-no jfischer-no added this to the v3.3.0 milestone Jan 25, 2023
@stephanosio stephanosio merged commit cad8ae7 into zephyrproject-rtos:main Jan 26, 2023
@jfischer-no jfischer-no deleted the pr-device-next-bt branch January 26, 2023 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth area: USB Universal Serial Bus Experimental Experimental features not enabled by default
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants