usb: eth: Add CDC ECM/NCM support
cover usb: eth: Add CDC ECM/NCM support
This series adds support for CDC ECM and CDC NCM devices.
U-Boot currently only has support for automatic binding of the first device configuration for devices, so this implementaion works by adding bindings for VID/PID pairs and letting the drivers try to change active configuration during probe.
The driver implementations was created based of the CDC ECM 1.2 and CDC NCM 1.1 specifications and was tested on a few different USB Ethernet adapters using ASIX or Realtek IC.
Patch 1-3 import headers and macros from Linux kernel. Patch 4 export a helper that drivers can use to select a different device configuration.
Patch 5-6 adds drivers for CDC ECM and CDC NCM.
Patch 7-8 allows ASIX and Realtek adapters to use CDC ECM and CDC NCM.
Jonas Karlman (8):
usb: Import USB_DEVICE_VER() macro from Linux
usb: Import USB_INTERFACE_INFO() macro from Linux
usb: Sync linux/usb/cdc.h from Linux
usb: Extract usb_select_configuration_no() helper
usb: eth: Add CDC ECM support
usb: eth: Add CDC NCM driver
usb: eth: Bind ASIX AX88179A/AX88772D/AX88279 to CDC ECM/NCM driver
usb: eth: Bind Realtek RTL815x to CDC ECM driver
common/usb.c | 59 +++-- doc/README.usb | 2 + drivers/usb/eth/Kconfig | 18 ++ drivers/usb/eth/Makefile | 2 + drivers/usb/eth/asix88179.c | 5 + drivers/usb/eth/cdc_common.c | 265 +++++++++++++++++++ drivers/usb/eth/cdc_common.h | 35 +++ drivers/usb/eth/cdc_ecm.c | 292 +++++++++++++++++++++ drivers/usb/eth/cdc_ncm.c | 483 +++++++++++++++++++++++++++++++++++ include/linux/usb/cdc.h | 233 ++++++++++++++++- include/usb.h | 48 ++++ 11 files changed, 1417 insertions(+), 25 deletions(-) create mode 100644 drivers/usb/eth/cdc_common.c create mode 100644 drivers/usb/eth/cdc_common.h create mode 100644 drivers/usb/eth/cdc_ecm.c create mode 100644 drivers/usb/eth/cdc_ncm.c
Signature · 1 line
2.54.0
PATCH 1/8 usb: Import USB_DEVICE_VER() macro from Linux
Import the USB_DEVICE_VER() macro from Linux to make it less verbose to describe a specific USB device with a version range.
---
This macro existed in the initial Linux v2.6.12-rc2 git build.
--- include/usb.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/usb.h +20 -0
@@ -509,6 +509,10 @@ struct usb_driver_entry {#define USB_DEVICE_ID_MATCH_DEVICE \ (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT) +#define USB_DEVICE_ID_MATCH_DEV_RANGE \ + (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI) +#define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION \ + (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)/** * USB_DEVICE - macro used to describe a specific usb device
@@ -522,6 +526,22 @@ struct usb_driver_entry { .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \ .idVendor = (vend), \ .idProduct = (prod) +/** +* USB_DEVICE_VER - describe a specific usb device with a version range +* @vend: the 16 bit USB Vendor ID +* @prod: the 16 bit USB Product ID +* @lo: the bcdDevice_lo value +* @hi: the bcdDevice_hi value +* +* This macro is used to create a struct usb_device_id that matches a +* specific device, with a version range. + */ +#define USB_DEVICE_VER (vend, prod, lo, hi) \ + .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, \ + .idVendor = (vend), \ + .idProduct = (prod), \ + .bcdDevice_lo = (lo), \ + .bcdDevice_hi = (hi)#define U_BOOT_USB_DEVICE (__name, __match) \ ll_entry_declare(struct usb_driver_entry, __name, usb_driver_entry) = {\
Signature · 1 line
2.54.0
Re: [PATCH 1/8] usb: Import USB_DEVICE_VER() macro from Linux
Quoted 9 lines · Jonas Karlman
usb: Import
USB_DEVICE_VER()macro from LinuxImport the
USB_DEVICE_VER()macro from Linux to make it less verbose to describe a specific USB device with a version range.Signed-off-by Jonas Karlman <[email protected]>
include/usb.h| 20 ++++++++++++++++++++1 file changed, 20 insertions(+)
PATCH 2/8 usb: Import USB_INTERFACE_INFO() macro from Linux
In reply to Jonas KarlmanImport the USB_INTERFACE_INFO() macro from Linux to make it less verbose to describe a class of USB interfaces.
---
This macro existed in the initial Linux v2.6.12-rc2 git build.
--- include/usb.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/usb.h +18 -0
@@ -513,6 +513,10 @@ struct usb_driver_entry { (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)#define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION \ (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE) +#define USB_DEVICE_ID_MATCH_INT_INFO \ + (USB_DEVICE_ID_MATCH_INT_CLASS | \ + USB_DEVICE_ID_MATCH_INT_SUBCLASS | \ + USB_DEVICE_ID_MATCH_INT_PROTOCOL)/** * USB_DEVICE - macro used to describe a specific usb device
@@ -542,6 +546,20 @@ struct usb_driver_entry { .idProduct = (prod), \ .bcdDevice_lo = (lo), \ .bcdDevice_hi = (hi) +/** +* USB_INTERFACE_INFO - macro used to describe a class of usb interfaces +* @cl: bInterfaceClass value +* @sc: bInterfaceSubClass value +* @pr: bInterfaceProtocol value +* +* This macro is used to create a struct usb_device_id that matches a +* specific class of interfaces. + */ +#define USB_INTERFACE_INFO (cl, sc, pr) \ + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, \ + .bInterfaceClass = (cl), \ + .bInterfaceSubClass = (sc), \ + .bInterfaceProtocol = (pr)#define U_BOOT_USB_DEVICE (__name, __match) \ ll_entry_declare(struct usb_driver_entry, __name, usb_driver_entry) = {\
Signature · 1 line
2.54.0
Re: [PATCH 2/8] usb: Import USB_INTERFACE_INFO() macro from Linux
Quoted 9 lines · Jonas Karlman
usb: Import
USB_INTERFACE_INFO()macro from LinuxImport the
USB_INTERFACE_INFO()macro from Linux to make it less verbose to describe a class of USB interfaces.Signed-off-by Jonas Karlman <[email protected]>
include/usb.h| 18 ++++++++++++++++++1 file changed, 18 insertions(+)
PATCH 3/8 usb: Sync linux/usb/cdc.h from Linux
In reply to Jonas KarlmanCDC NCM constants and structures added in Linux commit 01154aa71424 ("usb: cdc: ncm constants and structures added") are missing from U-Boot.
Sync with Linux commit a67df6d1b939 ("uapi: cdc.h: cleanly provide for more interfaces and countries") from v6.19-rc1 to add any missing CDC related constants and structures.
--- include/linux/usb/cdc.h | 233 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 232 insertions(+), 1 deletion(-)
include/linux/usb/cdc.h +232 -1
@@ -15,6 +15,9 @@#define USB_CDC_SUBCLASS_DMM 0x09#define USB_CDC_SUBCLASS_MDLM 0x0a#define USB_CDC_SUBCLASS_OBEX 0x0b +#define USB_CDC_SUBCLASS_EEM 0x0c +#define USB_CDC_SUBCLASS_NCM 0x0d +#define USB_CDC_SUBCLASS_MBIM 0x0e#define USB_CDC_PROTO_NONE 0
@@ -26,6 +29,11 @@#define USB_CDC_ACM_PROTO_AT_CDMA 6#define USB_CDC_ACM_PROTO_VENDOR 0xff +#define USB_CDC_PROTO_EEM 7 + +#define USB_CDC_NCM_PROTO_NTB 1 +#define USB_CDC_MBIM_PROTO_NTB 2 +/*-------------------------------------------------------------------------*/ /*
@@ -44,6 +52,9 @@#define USB_CDC_MDLM_DETAIL_TYPE 0x13/* mdlm_detail_desc */ #define USB_CDC_DMM_TYPE 0x14#define USB_CDC_OBEX_TYPE 0x15 +#define USB_CDC_NCM_TYPE 0x1a +#define USB_CDC_MBIM_TYPE 0x1b +#define USB_CDC_MBIM_EXTENDED_TYPE 0x1c/* "Header Functional Descriptor" from CDC spec 5.2.3.1 */ struct usb_cdc_header_desc {
@@ -80,7 +91,7 @@ struct usb_cdc_acm_descriptor {#define USB_CDC_COMM_FEATURE 0x01#define USB_CDC_CAP_LINE 0x02 -#define USB_CDC_CAP_BRK 0x04 +#define USB_CDC_CAP_BRK 0x04#define USB_CDC_CAP_NOTIFY 0x08/* "Union Functional Descriptor" from CDC spec 5.2.3.8 */
@@ -130,6 +141,15 @@ struct usb_cdc_ether_desc {__u8 bNumberPowerFilters; } __attribute__ ((packed)); +/* "Telephone Control Model Functional Descriptor" from CDC WMC spec 6.3..3 */ +struct usb_cdc_dmm_desc { +__u8 bFunctionLength; +__u8 bDescriptorType; +__u8 bDescriptorSubtype; +__u16 bcdVersion; +__le16 wMaxCommand; +} __attribute__ ((packed)); +/* "MDLM Functional Descriptor" from CDC WMC spec 6.7.2.3 */ struct usb_cdc_mdlm_desc {__u8 bLength;
@@ -151,6 +171,50 @@ struct usb_cdc_mdlm_detail_desc {__u8 bDetailData[0 ]; } __attribute__ ((packed)); +/* "OBEX Control Model Functional Descriptor" */ +struct usb_cdc_obex_desc { +__u8 bLength; +__u8 bDescriptorType; +__u8 bDescriptorSubType; + +__le16 bcdVersion; +} __attribute__ ((packed)); + +/* "NCM Control Model Functional Descriptor" */ +struct usb_cdc_ncm_desc { +__u8 bLength; +__u8 bDescriptorType; +__u8 bDescriptorSubType; + +__le16 bcdNcmVersion; +__u8 bmNetworkCapabilities; +} __attribute__ ((packed)); + +/* "MBIM Control Model Functional Descriptor" */ +struct usb_cdc_mbim_desc { +__u8 bLength; +__u8 bDescriptorType; +__u8 bDescriptorSubType; + +__le16 bcdMBIMVersion; +__le16 wMaxControlMessage; +__u8 bNumberFilters; +__u8 bMaxFilterSize; +__le16 wMaxSegmentSize; +__u8 bmNetworkCapabilities; +} __attribute__ ((packed)); + +/* "MBIM Extended Functional Descriptor" from CDC MBIM spec 1.0 errata-1 */ +struct usb_cdc_mbim_extended_desc { +__u8 bLength; +__u8 bDescriptorType; +__u8 bDescriptorSubType; + +__le16 bcdMBIMExtendedVersion; +__u8 bMaxOutstandingCommandMessages; +__le16 wMTU; +} __attribute__ ((packed)); +/*-------------------------------------------------------------------------*/ /*
@@ -174,6 +238,17 @@ struct usb_cdc_mdlm_detail_desc {#define USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42#define USB_CDC_SET_ETHERNET_PACKET_FILTER 0x43#define USB_CDC_GET_ETHERNET_STATISTIC 0x44 +#define USB_CDC_GET_NTB_PARAMETERS 0x80 +#define USB_CDC_GET_NET_ADDRESS 0x81 +#define USB_CDC_SET_NET_ADDRESS 0x82 +#define USB_CDC_GET_NTB_FORMAT 0x83 +#define USB_CDC_SET_NTB_FORMAT 0x84 +#define USB_CDC_GET_NTB_INPUT_SIZE 0x85 +#define USB_CDC_SET_NTB_INPUT_SIZE 0x86 +#define USB_CDC_GET_MAX_DATAGRAM_SIZE 0x87 +#define USB_CDC_SET_MAX_DATAGRAM_SIZE 0x88 +#define USB_CDC_GET_CRC_MODE 0x89 +#define USB_CDC_SET_CRC_MODE 0x8a/* Line Coding Structure from CDC spec 6.2.13 */ struct usb_cdc_line_coding {
@@ -193,6 +268,10 @@ struct usb_cdc_line_coding {__u8 bDataBits; } __attribute__ ((packed)); +/* Control Signal Bitmap Values from 6.2.14 SetControlLineState */ +#define USB_CDC_CTRL_DTR (1 << 0) +#define USB_CDC_CTRL_RTS (1 << 1) +/* table 62; bits in multicast filter */ #define USB_CDC_PACKET_TYPE_PROMISCUOUS (1 << 0)#define USB_CDC_PACKET_TYPE_ALL_MULTICAST (1 << 1)/* no filter */
@@ -222,3 +301,155 @@ struct usb_cdc_notification {__le16 wIndex;__le16 wLength; } __attribute__ ((packed)); + +/* UART State Bitmap Values from 6.3.5 SerialState */ +#define USB_CDC_SERIAL_STATE_DCD (1 << 0) +#define USB_CDC_SERIAL_STATE_DSR (1 << 1) +#define USB_CDC_SERIAL_STATE_BREAK (1 << 2) +#define USB_CDC_SERIAL_STATE_RING_SIGNAL (1 << 3) +#define USB_CDC_SERIAL_STATE_FRAMING (1 << 4) +#define USB_CDC_SERIAL_STATE_PARITY (1 << 5) +#define USB_CDC_SERIAL_STATE_OVERRUN (1 << 6) + +struct usb_cdc_speed_change { +__le32 DLBitRRate;/* contains the downlink bit rate (IN pipe) */ +__le32 ULBitRate;/* contains the uplink bit rate (OUT pipe) */ +} __attribute__ ((packed)); + +/*-------------------------------------------------------------------------*/ + +/* +* Class Specific structures and constants +* +* CDC NCM NTB parameters structure, CDC NCM subclass 6.2.1 +* +*/ + +struct usb_cdc_ncm_ntb_parameters { +__le16 wLength; +__le16 bmNtbFormatsSupported; +__le32 dwNtbInMaxSize; +__le16 wNdpInDivisor; +__le16 wNdpInPayloadRemainder; +__le16 wNdpInAlignment; +__le16 wPadding1; +__le32 dwNtbOutMaxSize; +__le16 wNdpOutDivisor; +__le16 wNdpOutPayloadRemainder; +__le16 wNdpOutAlignment; +__le16 wNtbOutMaxDatagrams; +} __attribute__ ((packed)); + +/* +* CDC NCM transfer headers, CDC NCM subclass 3.2 +*/ + +#define USB_CDC_NCM_NTH16_SIGN 0x484D434E/* NCMH */ +#define USB_CDC_NCM_NTH32_SIGN 0x686D636E/* ncmh */ + +struct usb_cdc_ncm_nth16 { +__le32 dwSignature; +__le16 wHeaderLength; +__le16 wSequence; +__le16 wBlockLength; +__le16 wNdpIndex; +} __attribute__ ((packed)); + +struct usb_cdc_ncm_nth32 { +__le32 dwSignature; +__le16 wHeaderLength; +__le16 wSequence; +__le32 dwBlockLength; +__le32 dwNdpIndex; +} __attribute__ ((packed)); + +/* +* CDC NCM datagram pointers, CDC NCM subclass 3.3 +*/ + +#define USB_CDC_NCM_NDP16_CRC_SIGN 0x314D434E/* NCM1 */ +#define USB_CDC_NCM_NDP16_NOCRC_SIGN 0x304D434E/* NCM0 */ +#define USB_CDC_NCM_NDP32_CRC_SIGN 0x316D636E/* ncm1 */ +#define USB_CDC_NCM_NDP32_NOCRC_SIGN 0x306D636E/* ncm0 */ + +#define USB_CDC_MBIM_NDP16_IPS_SIGN 0x00535049/* IPS<sessionID> : IPS0 for now */ +#define USB_CDC_MBIM_NDP32_IPS_SIGN 0x00737069/* ips<sessionID> : ips0 for now */ +#define USB_CDC_MBIM_NDP16_DSS_SIGN 0x00535344/* DSS<sessionID> */ +#define USB_CDC_MBIM_NDP32_DSS_SIGN 0x00737364/* dss<sessionID> */ + +/* 16-bit NCM Datagram Pointer Entry */ +struct usb_cdc_ncm_dpe16 { +__le16 wDatagramIndex; +__le16 wDatagramLength; +} __attribute__((__packed__ )); + +/* 16-bit NCM Datagram Pointer Table */ +struct usb_cdc_ncm_ndp16 { +__le32 dwSignature; +__le16 wLength; +__le16 wNextNdpIndex; +struct usb_cdc_ncm_dpe16 dpe16[0 ]; +} __attribute__ ((packed)); + +/* 32-bit NCM Datagram Pointer Entry */ +struct usb_cdc_ncm_dpe32 { +__le32 dwDatagramIndex; +__le32 dwDatagramLength; +} __attribute__((__packed__ )); + +/* 32-bit NCM Datagram Pointer Table */ +struct usb_cdc_ncm_ndp32 { +__le32 dwSignature; +__le16 wLength; +__le16 wReserved6; +__le32 dwNextNdpIndex; +__le32 dwReserved12; +struct usb_cdc_ncm_dpe32 dpe32[0 ]; +} __attribute__ ((packed)); + +/* CDC NCM subclass 3.2.1 and 3.2.2 */ +#define USB_CDC_NCM_NDP16_INDEX_MIN 0x000C +#define USB_CDC_NCM_NDP32_INDEX_MIN 0x0010 + +/* CDC NCM subclass 3.3.3 Datagram Formatting */ +#define USB_CDC_NCM_DATAGRAM_FORMAT_CRC 0x30 +#define USB_CDC_NCM_DATAGRAM_FORMAT_NOCRC 0X31 + +/* CDC NCM subclass 4.2 NCM Communications Interface Protocol Code */ +#define USB_CDC_NCM_PROTO_CODE_NO_ENCAP_COMMANDS 0x00 +#define USB_CDC_NCM_PROTO_CODE_EXTERN_PROTO 0xFE + +/* CDC NCM subclass 5.2.1 NCM Functional Descriptor, bmNetworkCapabilities */ +#define USB_CDC_NCM_NCAP_ETH_FILTER (1 << 0) +#define USB_CDC_NCM_NCAP_NET_ADDRESS (1 << 1) +#define USB_CDC_NCM_NCAP_ENCAP_COMMAND (1 << 2) +#define USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE (1 << 3) +#define USB_CDC_NCM_NCAP_CRC_MODE (1 << 4) +#define USB_CDC_NCM_NCAP_NTB_INPUT_SIZE (1 << 5) + +/* CDC NCM subclass Table 6-3: NTB Parameter Structure */ +#define USB_CDC_NCM_NTB16_SUPPORTED (1 << 0) +#define USB_CDC_NCM_NTB32_SUPPORTED (1 << 1) + +/* CDC NCM subclass Table 6-3: NTB Parameter Structure */ +#define USB_CDC_NCM_NDP_ALIGN_MIN_SIZE 0x04 +#define USB_CDC_NCM_NTB_MAX_LENGTH 0x1C + +/* CDC NCM subclass 6.2.5 SetNtbFormat */ +#define USB_CDC_NCM_NTB16_FORMAT 0x00 +#define USB_CDC_NCM_NTB32_FORMAT 0x01 + +/* CDC NCM subclass 6.2.7 SetNtbInputSize */ +#define USB_CDC_NCM_NTB_MIN_IN_SIZE 2048 +#define USB_CDC_NCM_NTB_MIN_OUT_SIZE 2048 + +/* NTB Input Size Structure */ +struct usb_cdc_ncm_ndp_input_size { +__le32 dwNtbInMaxSize; +__le16 wNtbInMaxDatagrams; +__le16 wReserved; +} __attribute__ ((packed)); + +/* CDC NCM subclass 6.2.11 SetCrcMode */ +#define USB_CDC_NCM_CRC_NOT_APPENDED 0x00 +#define USB_CDC_NCM_CRC_APPENDED 0x01
Signature · 1 line
2.54.0
Re: [PATCH 3/8] usb: Sync linux/usb/cdc.h from Linux
Hi Jonas,
Quoted 6 lines · Jonas Karlman
usb: Sync
linux/usb/cdc.hfrom LinuxCDC NCM constants and structures added in Linux commit
01154aa71424("usb: cdc: ncm constants and structures added") are missing from U-Boot.
Quoted 8 lines
Sync with Linux commit
a67df6d1b939("uapi:cdc.h: cleanly provide for more interfaces and countries") from v6.19-rc1 to add any missing CDC related constants and structures.Signed-off-by Jonas Karlman <[email protected]>
include/linux/usb/cdc.h| 233 +++++++++++++++++++++++++++++++++++++++++++++++-1 file changed, 232 insertions(+), 1 deletion(-)
The flex array stuff is dropped, fair enough.
Regards,
Simon
PATCH 4/8 usb: Extract usb_select_configuration_no() helper
In reply to Jonas KarlmanU-Boot only has support for one configuration for devices.
Extract handing of selecting active configuration to a helper function to make it easier for drivers to select a different configuration.
This include a small change in behavior, errors from parsing config descriptors are no longer ignored and is instead returned.
--- common/usb.c | 59 ++++++++++++++++++++++++++++++--------------------- include/usb.h | 10 +++++++++ 2 files changed, 45 insertions(+), 24 deletions(-)
common/usb.c +35 -24
@@ -1149,11 +1149,38 @@ static int usb_device_is_ignored(u16 id_vendor, u16 id_product)return 0 ; } -int usb_select_config (struct usb_device *dev) +int usb_select_configuration_no (struct usb_device *dev,int cfgno) {unsigned char *tmpbuf =NULL ;int err; + err =usb_get_configuration_len (dev, cfgno); +if (err >=0 ) { + tmpbuf = (unsigned char *)malloc_cache_aligned (err); +if (!tmpbuf) + err = -ENOMEM ; +else + err =usb_get_configuration_no (dev, cfgno, tmpbuf, err); + } +if (err <0 ) { +free (tmpbuf); +return err; + } + + err =usb_parse_config (dev, tmpbuf, cfgno); +free (tmpbuf); +if (err <0 ) +return err; + +usb_set_maxpacket (dev); + +return usb_set_configuration (dev, dev->config.desc.bConfigurationValue); +} + +int usb_select_config (struct usb_device *dev) +{ +int err; + err =get_descriptor_len (dev,USB_DT_DEVICE_SIZE ,USB_DT_DEVICE_SIZE );if (err)return err;
@@ -1193,34 +1220,18 @@ int usb_select_config(struct usb_device *dev)*/ mdelay (1 ); -/* only support for one config for now */ - err =usb_get_configuration_len (dev,0 ); -if (err >=0 ) { - tmpbuf = (unsigned char *)malloc_cache_aligned (err); -if (!tmpbuf) - err = -ENOMEM ; -else - err =usb_get_configuration_no (dev,0 , tmpbuf, err); - } -if (err <0 ) { -printf ("usb_new_device: Cannot read configuration, " \ -"skipping device %04x:%04x\n" , - dev->descriptor.idVendor, dev->descriptor.idProduct); -free (tmpbuf); -return err; - } -usb_parse_config (dev, tmpbuf,0 ); -free (tmpbuf); -usb_set_maxpacket (dev);/* -* we set the default configuration here +* we select the default configuration here * This seems premature. If the driver wants a different configuration * it will need to select itself. */ - err =usb_set_configuration (dev, dev->config.desc.bConfigurationValue); + err =usb_select_configuration_no (dev,0 );if (err <0 ) { -printf ("failed to set default configuration " \ -"len %d, status %lX\n" , dev->act_len, dev->status); +printf ("failed to select default configuration " \ +"len %d, status %lX, " \ +"skipping device %04x:%04x\n" , + dev->act_len, dev->status, + dev->descriptor.idVendor, dev->descriptor.idProduct);return err; }
include/usb.h +10 -0
@@ -900,6 +900,16 @@ int usb_scan_device(struct udevice *parent, int port,*/ struct udevice *usb_get_bus (struct udevice *dev); +/** +* usb_select_configuration_no() - Select configuration to use for a device +* +* This re-reads the configuration descriptor and sets the configuration. +* +* @dev: Device to select configuration +* @cfgno: Configuration number to set +*/ +int usb_select_configuration_no (struct usb_device *dev,int cfgno); +/** * usb_select_config() - Set up a device ready for use *
Signature · 1 line
2.54.0
Re: [PATCH 4/8] usb: Extract usb_select_configuration_no() helper
Hi Jonas,
Quoted 16 lines · Jonas Karlman
usb: Extract
usb_select_configuration_no()helperU-Boot only has support for one configuration for devices.
Extract handing of selecting active configuration to a helper function to make it easier for drivers to select a different configuration.
This include a small change in behavior, errors from parsing config descriptors are no longer ignored and is instead returned.
Signed-off-by Jonas Karlman <[email protected]>
common/usb.c| 59 +++++++++++++++++++++++++++++++++++------------------------include/usb.h | 10 ++++++++++ 2 files changed, 45 insertions(+), 24 deletions(-)
Quoted 6 lines
Extract handing of selecting active configuration to a helper function to make it easier for drivers to select a different configuration.
This include a small change in behavior, errors from parsing config descriptors are no longer ignored and is instead returned.
Typos: 'handing' should be 'handling', 'This include' should be 'This includes' and 'is instead returned' should be 'are instead returned'.
common/usb.c static int usb_device_is_ignored(u16 id_vendor, u16 id_product) · line 1152
Quoted 6 lines
common/usb.c +4
-0@@ -1149,11 +1149,38 @@ static int usb_device_is_ignored(u16 id_vendor, u16 id_product) +usb_set_maxpacket (dev); + +return usb_set_configuration (dev, dev->config.desc.bConfigurationValue); +}
The mdelay(10) after Set Configuration stays in usb_select_config(), with a comment saying some devices need time to process the request. When the CDC ECM/NCM drivers in patches 5-6 call this helper to switch configuration during probe, they do not get that delay. I suspect the mdelay(10) should move into this helper so that every Set Configuration request gets the same treatment. What do you think?
common/usb.c int usb_select_config(struct usb_device *dev) · line 1224
Quoted 9 lines
common/usb.c +4
-2@@ -1193,34 +1220,18 @@ int usb_select_config(struct usb_device *dev) + err =usb_select_configuration_no (dev,0 );if (err <0 ) { -printf ("failed to set default configuration " \ -"len %d, status %lX\n" , dev->act_len, dev->status); + printf("failed to select default configuration " \ + "len %d, status %lX, " \ + "skipping device %04x:%04x\n",
This message now covers several failure modes (descriptor-length read, -ENOMEM, config parse, set configuration), but 'len' and 'status' are only meaningful for the last of these - for the others they are stale values from an earlier transfer. Perhaps print err as well, or drop the len/status part, so the output is not misleading.
include/usb.h int usb_scan_device(struct udevice *parent, int port, · line 903
Quoted 6 lines
include/usb.h +4
-0@@ -900,6 +900,16 @@ int usb_scan_device(struct udevice *parent, int port, +* @dev: Device to select configuration +* @cfgno: Configuration number to set +*/ +int usb_select_configuration_no (struct usb_device *dev,int cfgno);
Please can you add a 'Return: 0 if OK, -ve on error' line, as with usb_scan_device() above? It would also help to state that @cfgno is the zero-based configuration index (as passed to usb_get_configuration_no()) rather than a bConfigurationValue, since the two are easily confused.
Regards,
Simon
PATCH 5/8 usb: eth: Add CDC ECM support
In reply to Jonas KarlmanAdd support for CDC ECM (Communications Device Class, Ethernet Control Model) devices.
References:
- [USBECM12] USB Subclass Specification for Ethernet Control Model 1.2.
- [USBCDC12] USB Class Definitions for Communications Devices 1.2.
- [USB20] USB Specification 2.0.
--- doc/README.usb | 1 + drivers/usb/eth/Kconfig | 9 ++ drivers/usb/eth/Makefile | 1 + drivers/usb/eth/cdc_common.c | 153 +++++++++++++++++++ drivers/usb/eth/cdc_common.h | 26 ++++ drivers/usb/eth/cdc_ecm.c | 284 +++++++++++++++++++++++++++++++++++ 6 files changed, 474 insertions(+) create mode 100644 drivers/usb/eth/cdc_common.c create mode 100644 drivers/usb/eth/cdc_common.h create mode 100644 drivers/usb/eth/cdc_ecm.c
doc/README.usb +1 -0
@@ -133,6 +133,7 @@ and one or more of the following for individual adapter hardware: CONFIG_USB_ETHER_ASIX=y CONFIG_USB_ETHER_ASIX88179=y +CONFIG_USB_ETHER_CDC_ECM=y CONFIG_USB_ETHER_LAN75XX=y CONFIG_USB_ETHER_LAN78XX=y CONFIG_USB_ETHER_MCS7830=y
drivers/usb/eth/Kconfig +9 -0
@@ -20,6 +20,15 @@ config USB_ETHER_ASIX88179 Say Y here if you would like to support ASIX AX88179 based USB 3.0 Ethernet Devices. +config USB_ETHER_CDC_ECM + bool "CDC ECM support" + depends on USB_HOST_ETHER + help + Say Y here if you would like to support CDC ECM (Communications Device + Class, Ethernet Control Model) devices. The USB Communications Class + Subclass Specifications for Ethernet Control Model Devices is + available from <http://www.usb.org/>. + config USB_ETHER_LAN75XX bool "Microchip LAN75XX support" depends on USB_HOST_ETHER
drivers/usb/eth/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_USB_HOST_ETHER) += usb_ether.o obj-$(CONFIG_USB_ETHER_ASIX) += asix.o obj-$(CONFIG_USB_ETHER_ASIX88179) += asix88179.o +obj-$(CONFIG_USB_ETHER_CDC_ECM) += cdc_common.o cdc_ecm.o obj-$(CONFIG_USB_ETHER_MCS7830) += mcs7830.o obj-$(CONFIG_USB_ETHER_SMSC95XX) += smsc95xx.o obj-$(CONFIG_USB_ETHER_LAN75XX) += lan7x.o lan75xx.o
drivers/usb/eth/cdc_common.c new file +153 -0
153 lines not on this page · raw message
drivers/usb/eth/cdc_common.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright Contributors to the U-Boot project. */ + +#ifndef _USB_ETH_CDC_COMMON_H +#define _USB_ETH_CDC_COMMON_H + +#define USB_BULK_RECV_TIMEOUT 500 +#define USB_BULK_SEND_TIMEOUT 5000 +#define USB_CTRL_GET_TIMEOUT 5000 +#define USB_CTRL_SET_TIMEOUT 5000 + +int cdc_bulk_xfer (struct usb_device *udev,u32 pipe,void *data,int length, +int *actual_length,int timeout); + +int cdc_get_mac_address (struct usb_device *udev,int index,u8 *data); + +int cdc_set_ethernet_packet_filter (struct usb_device *udev,u16 index,u16 value); + +int cdc_set_interface (struct usb_device *udev,u16 index,u16 value); + +int cdc_wait_on_connection (struct usb_device *udev,u32 pipe,int interval); + +struct usb_config_descriptor *cdc_get_config_descriptor (struct usb_device *udev, +int cfgno); + +#endif
drivers/usb/eth/cdc_ecm.c new file +284 -0
284 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH 5/8] usb: eth: Add CDC ECM support
Quoted 9 lines · Jonas Karlman
Add support for CDC ECM (Communications Device Class, Ethernet Control Model) devices.
References:
- [USBECM12] USB Subclass Specification for Ethernet Control Model 1.2.
- [USBCDC12] USB Class Definitions for Communications Devices 1.2.
- [USB20] USB Specification 2.0.Signed-off-by Jonas Karlman <[email protected]>
Is this pulled from Linux or is this written from scratch ?
Re: [PATCH 5/8] usb: eth: Add CDC ECM support
Hi Marek,
Quoted 11 lines · Marek Vasut
Quoted 9 lines · Jonas Karlman
Add support for CDC ECM (Communications Device Class, Ethernet Control Model) devices.
References:
- [USBECM12] USB Subclass Specification for Ethernet Control Model 1.2.
- [USBCDC12] USB Class Definitions for Communications Devices 1.2.
- [USB20] USB Specification 2.0.Signed-off-by Jonas Karlman <[email protected]>Is this pulled from Linux or is this written from scratch ?
As stated in the cover letter this driver was written from scratch.
The driver implementations was created based of the CDC ECM 1.2 and CDC NCM 1.1 specifications and was tested on a few different USB Ethernet adapters using ASIX or Realtek IC.
At some point I looked and compared to Linux to ensure ordering of e.g. control messages and size limitations where closely matched.
In more detail the NCM driver was first created and tested on AX88179. Later when tested on RTL815x there were some issues, so I also added the ECM variant and tested that on both AX88179 and RTL815x.
The ECM variant is likely enough for U-Boot purposes, however NCM still has some good features such as custom MAC-addresses. So, I included both in this series, with NCM being preferred over ECM due to driver list sorting.
Regards,
Jonas
Re: [PATCH 5/8] usb: eth: Add CDC ECM support
Quoted 23 lines · Jonas Karlman
Hi Marek,
Quoted 11 lines · Marek Vasut
Quoted 9 lines · Jonas Karlman
Add support for CDC ECM (Communications Device Class, Ethernet Control Model) devices.
References:
- [USBECM12] USB Subclass Specification for Ethernet Control Model 1.2.
- [USBCDC12] USB Class Definitions for Communications Devices 1.2.
- [USB20] USB Specification 2.0.Signed-off-by Jonas Karlman <[email protected]>Is this pulled from Linux or is this written from scratch ?
As stated in the cover letter this driver was written from scratch.
The driver implementations was created based of the CDC ECM 1.2 and CDC NCM 1.1 specifications and was tested on a few different USB Ethernet adapters using ASIX or Realtek IC.
At some point I looked and compared to Linux to ensure ordering of e.g. control messages and size limitations where closely matched.
Quoted 8 lines
In more detail the NCM driver was first created and tested on AX88179. Later when tested on RTL815x there were some issues, so I also added the ECM variant and tested that on both AX88179 and RTL815x.
The ECM variant is likely enough for U-Boot purposes, however NCM still has some good features such as custom MAC-addresses. So, I included both in this series, with NCM being preferred over ECM due to driver list sorting.
OK
Re: [PATCH 5/8] usb: eth: Add CDC ECM support
In reply to Jonas KarlmanHi Jonas,
Quoted 22 lines · Jonas Karlman
usb: eth: Add CDC ECM support
Add support for CDC ECM (Communications Device Class, Ethernet Control Model) devices.
References:
- [USBECM12] USB Subclass Specification for Ethernet Control Model 1.2.
- [USBCDC12] USB Class Definitions for Communications Devices 1.2.
- [USB20] USB Specification 2.0.Signed-off-by Jonas Karlman <[email protected]>doc/README.usb | 1 +
drivers/usb/eth/Kconfig | 9 ++ drivers/usb/eth/Makefile | 1 + drivers/usb/eth/cdc_common.c | 153 +++++++++++++++++++++++ drivers/usb/eth/cdc_common.h | 26 ++++ drivers/usb/eth/cdc_ecm.c | 284 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 474 insertions(+)
drivers/usb/eth/cdc_common.c line 3
Quoted 3 lines
drivers/usb/eth/cdc_common.c +3
-0@@ -0,0 +1,153 @@ + maxpacket =usb_maxpacket (udev, pipe); +if (maxpacket <sizeof (struct usb_cdc_notification ) || maxpacket >64 ) +return -EINVAL ;
Just to check, why reject devices with a notification endpoint larger than 64 bytes? A high-speed interrupt endpoint can be up to 1024 bytes, so this fails the connection wait (and thus start()) on such a device. Since ALLOC_CACHE_ALIGN_BUFFER() accepts a runtime size, you could size tmpbuf from maxpacket and drop the upper limit. What do you think?
drivers/usb/eth/cdc_common.h line 2
Quoted 4 lines
drivers/usb/eth/cdc_common.h +2
-0@@ -0,0 +1,26 @@ +int cdc_bulk_xfer (struct usb_device *udev,u32 pipe,void *data,int length, +int *actual_length,int timeout);
Please can you add function comments for the exported functions in this header, in the normal U-Boot style (see doc/develop/codingstyle.rst)? For example, it is not obvious that cdc_get_mac_address() zeroes the data on failure, or that cdc_wait_on_connection() treats a zero pipe as success.
drivers/usb/eth/cdc_ecm.c line 5
Quoted 7 lines
drivers/usb/eth/cdc_ecm.c +5
-0@@ -0,0 +1,284 @@ +if (length <ETH_HLEN || length > priv->ether_desc.wMaxSegmentSize) +return -EINVAL ; + +return cdc_bulk_xfer (udev, priv->bulkoutpipe, packet, length, + &actual_length,USB_BULK_SEND_TIMEOUT );
I suspect this needs to handle a frame length that is an exact multiple of the bulk-out max packet size. The ECM spec (3.3.1) requires the segment to be terminated by a short packet, zero-length in that case, otherwise the device cannot tell where the frame ends. Linux handles this in usbnet by sending a ZLP (or padding by one byte). A zero-length usb_bulk_msg() after the transfer when length % maxpacket == 0 should be enough.
drivers/usb/eth/cdc_ecm.c line 2
Quoted 4 lines
drivers/usb/eth/cdc_ecm.c +2
-0@@ -0,0 +1,284 @@ +case USB_CDC_ETHERNET_TYPE : +memcpy (&priv->ether_desc, head,sizeof (priv->ether_desc));
This copies sizeof(priv->ether_desc) bytes but the earlier check only ensures bLength >= 4, so a malformed descriptor can cause a read past the end of the config buffer (or pull in bytes from the following descriptor). Please can you check that bLength matches sizeof(struct usb_cdc_ether_desc) before copying?
drivers/usb/eth/cdc_ecm.c line 4
Quoted 6 lines
drivers/usb/eth/cdc_ecm.c +4
-0@@ -0,0 +1,284 @@ +if (priv->control ==U16_MAX || priv->data ==U16_MAX || + priv->data_default ==U16_MAX || priv->data_normal ==U16_MAX || + !priv->bulkinpipe || !priv->bulkoutpipe) +return -ENODEV ;
This does not check that the Ethernet Networking Functional Descriptor was found. If a non-compliant device omits it, probe succeeds but ether_desc stays zeroed, so cdc_ecm_send() rejects every packet (wMaxSegmentSize is 0) and read_rom_hwaddr() fails. Since the descriptor is mandatory per the ECM spec, please can you add it to this check, e.g. by testing wMaxSegmentSize?
drivers/usb/eth/cdc_ecm.c line 4
Quoted 6 lines
drivers/usb/eth/cdc_ecm.c +4
-0@@ -0,0 +1,284 @@ +/* 9.4.3 Get Descriptor [USB20] */ + config =cdc_get_config_descriptor (udev, cfgno); +if (!config) +return -ENODEV ;
If reading one configuration fails, this gives up, whereas a parse failure moves on to the next one. It seems more consistent to 'continue' here so that a device with a bad first config but a good ECM config can still work.
drivers/usb/eth/cdc_ecm.c line 2
Quoted 4 lines
drivers/usb/eth/cdc_ecm.c +2
-0@@ -0,0 +1,284 @@ +U_BOOT_DRIVER (usb_cdc_2_ecm) = { + .name ='cdc_ecm' ,
The numbering is so NCM gets preference to ECM, right? Could you please add a comment?
Regards,
Simon
PATCH 6/8 usb: eth: Add CDC NCM driver
In reply to Jonas KarlmanAdd support for CDC NCM (Communications Device Class, Network Control Model) devices.
References:
- [USBNCM11] USB Subclass Specification for Network Control Model 1.1.
- [USBECM12] USB Subclass Specification for Ethernet Control Model 1.2.
- [USBCDC12] USB Class Definitions for Communications Devices 1.2.
- [USB20] USB Specification 2.0.
---
Please note that this driver currently does not fully implement alignment using wNdpOutDivisor and wNdpOutPayloadRemainder parameters. Something that did not seem to be needed for the CDC NCM devices that I have access to, so not something I could verify being correctly implemented.
--- doc/README.usb | 1 + drivers/usb/eth/Kconfig | 9 + drivers/usb/eth/Makefile | 1 + drivers/usb/eth/cdc_common.c | 112 ++++++++ drivers/usb/eth/cdc_common.h | 9 + drivers/usb/eth/cdc_ncm.c | 480 +++++++++++++++++++++++++++++++++++ 6 files changed, 612 insertions(+) create mode 100644 drivers/usb/eth/cdc_ncm.c
doc/README.usb +1 -0
@@ -134,6 +134,7 @@ and one or more of the following for individual adapter hardware: CONFIG_USB_ETHER_ASIX=y CONFIG_USB_ETHER_ASIX88179=y CONFIG_USB_ETHER_CDC_ECM=y +CONFIG_USB_ETHER_CDC_NCM=y CONFIG_USB_ETHER_LAN75XX=y CONFIG_USB_ETHER_LAN78XX=y CONFIG_USB_ETHER_MCS7830=y
drivers/usb/eth/Kconfig +9 -0
@@ -29,6 +29,15 @@ config USB_ETHER_CDC_ECM Subclass Specifications for Ethernet Control Model Devices is available from <http://www.usb.org/>. +config USB_ETHER_CDC_NCM + bool "CDC NCM support" + depends on USB_HOST_ETHER + help + Say Y here if you would like to support CDC NCM (Communications Device + Class, Network Control Model) devices. The USB Communications Class + Subclass Specifications for Network Control Model Devices is available + from <http://www.usb.org/>. + config USB_ETHER_LAN75XX bool "Microchip LAN75XX support" depends on USB_HOST_ETHER
drivers/usb/eth/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_USB_HOST_ETHER) += usb_ether.o obj-$(CONFIG_USB_ETHER_ASIX) += asix.o obj-$(CONFIG_USB_ETHER_ASIX88179) += asix88179.o obj-$(CONFIG_USB_ETHER_CDC_ECM) += cdc_common.o cdc_ecm.o +obj-$(CONFIG_USB_ETHER_CDC_NCM) += cdc_common.o cdc_ncm.o obj-$(CONFIG_USB_ETHER_MCS7830) += mcs7830.o obj-$(CONFIG_USB_ETHER_SMSC95XX) += smsc95xx.o obj-$(CONFIG_USB_ETHER_LAN75XX) += lan7x.o lan75xx.o
drivers/usb/eth/cdc_common.c +112 -0
130 lines not on this page · raw message
drivers/usb/eth/cdc_common.h +9 -0
@@ -14,10 +14,19 @@ int cdc_bulk_xfer(struct usb_device *udev, u32 pipe, void *data, int length,int cdc_get_mac_address (struct usb_device *udev,int index,u8 *data); +int cdc_get_net_address (struct usb_device *udev,int index,u8 *data); + +int cdc_get_ntb_parameters (struct usb_device *udev,u16 index, +struct usb_cdc_ncm_ntb_parameters *params); +int cdc_set_ethernet_packet_filter (struct usb_device *udev,u16 index,u16 value);int cdc_set_interface (struct usb_device *udev,u16 index,u16 value); +int cdc_set_net_address (struct usb_device *udev,u16 index,const u8 *data); + +int cdc_set_ntb_input_size (struct usb_device *udev,u16 index,u32 value); +int cdc_wait_on_connection (struct usb_device *udev,u32 pipe,int interval); struct usb_config_descriptor *cdc_get_config_descriptor(struct usb_device *udev,
drivers/usb/eth/cdc_ncm.c new file +480 -0
480 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH 6/8] usb: eth: Add CDC NCM driver
Hi Jonas,
Quoted 23 lines · Jonas Karlman
usb: eth: Add CDC NCM driver
Add support for CDC NCM (Communications Device Class, Network Control Model) devices.
References:
- [USBNCM11] USB Subclass Specification for Network Control Model 1.1.
- [USBECM12] USB Subclass Specification for Ethernet Control Model 1.2.
- [USBCDC12] USB Class Definitions for Communications Devices 1.2.
- [USB20] USB Specification 2.0.Signed-off-by Jonas Karlman <[email protected]>doc/README.usb | 1 +
drivers/usb/eth/Kconfig | 9 + drivers/usb/eth/Makefile | 1 + drivers/usb/eth/cdc_common.c | 112 ++++++++++ drivers/usb/eth/cdc_common.h | 9 + drivers/usb/eth/cdc_ncm.c | 480 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 612 insertions(+)
drivers/usb/eth/cdc_common.c int cdc_set_interface(struct usb_device *udev, u16 index, u16 value) · line 157
Quoted 1 line
drivers/usb/eth/cdc_common.c +1
-0@@ -74,6 +157,35 @@ int cdc_set_interface(struct usb_device *udev, u16 index, u16 value) +return ret ==ETH_ALEN ?0 : ret;
If the transfer is short (ret >= 0 but not ETH_ALEN) this returns a positive value, which cdc_ncm_write_hwaddr() then propagates out of the write_hwaddr op. Please can you return -EIO (or similar) for a short transfer? Same for cdc_set_ntb_input_size() below.
drivers/usb/eth/cdc_ncm.c line 2
Quoted 4 lines
drivers/usb/eth/cdc_ncm.c +2
-0@@ -0,0 +1,480 @@ +/* 7.2.6 SetNtbInputSize [USBNCM11] */ +cdc_set_ntb_input_size (udev, priv->control, priv->rx_size);
The return value is ignored here. If this request fails and rx_size has been reduced below dwNtbInMaxSize (which can happen via the usb_get_max_xfer_size() path in probe), the device may send NTBs larger than rx_buffer expects. Please can you check the return value and bail out, as you do for cdc_set_interface() just below?
drivers/usb/eth/cdc_ncm.c line 3
Quoted 5 lines
drivers/usb/eth/cdc_ncm.c +3
-0@@ -0,0 +1,480 @@ + dpe = (struct usb_cdc_ncm_dpe16 *)ndp->dpe16; +// FIXME: align using wNdpOutDivisor and wNdpOutPayloadRemainder ? + offset +=ALIGN (le16_to_cpu (ndp->wLength),16 );
Please can you resolve this FIXME before the driver lands? The device declares its required payload alignment via wNdpOutDivisor and wNdpOutPayloadRemainder, and Linux honours these when building the frame (see cdc_ncm_fill_tx_frame() and the tx_modulus / tx_remainder handling), so a device is entitled to reject a datagram that is not placed as requested. Since probe already fetches and validates the NTB parameters, using them here should be easy enough. If there is a good reason to hard-code 16, a /* */ comment explaining would be OK.
drivers/usb/eth/cdc_ncm.c line 1
Quoted 3 lines
drivers/usb/eth/cdc_ncm.c +1
-0@@ -0,0 +1,480 @@ + }while (++dpe);
This condition is always true since the pointer can never become NULL, so the loop only exits via the break or the return above. It does terminate, because the last DPE has already been verified to be a Null entry, but it took me a while to convince myself of that. A plain for (;;) loop, with a comment noting that the Null-entry check above bounds the walk, would be clearer. What do you think?
drivers/usb/eth/cdc_ncm.c line 3
Quoted 5 lines
drivers/usb/eth/cdc_ncm.c +3
-0@@ -0,0 +1,480 @@ +if (priv->control ==U16_MAX || priv->data ==U16_MAX || + !priv->intpipe || !priv->bulkinpipe || !priv->bulkoutpipe) +return -ENODEV ;
As with the ECM driver, this does not check that the Ethernet Networking Functional Descriptor was found. If it is missing, cdc_ncm_read_rom_hwaddr() will still pass iMACAddress (i.e. string index 0) to cdc_get_mac_address() when NCAP_NET_ADDRESS is not set. Since [USBNCM11] requires this descriptor, please can you also check here that it was found, e.g. that iMACAddress is non-zero?
Regards,
Simon
PATCH 7/8 usb: eth: Bind ASIX AX88179A/AX88772D/AX88279 to CDC ECM/NCM driver
In reply to Jonas KarlmanThe ASIX AX88179A, AX88772D and AX88279 USB Ethernet controller revisions has both CDC ECM and CDC NCM support.
AX88179: 0b95:1790 1.00
AX88179A: 0b95:1790 2.00
AX88772D: 0b95:1790 3.00
AX88279: 0b95:1790 4.00
Prefer using the CDC NCM or CDC ECM driver for the 2.00-4.00 version range of the 0b95:1790 ASIX USB Ethernet controllers.
--- drivers/usb/eth/asix88179.c | 5 +++++ drivers/usb/eth/cdc_ecm.c | 3 +++ drivers/usb/eth/cdc_ncm.c | 3 +++ 3 files changed, 11 insertions(+)
drivers/usb/eth/asix88179.c +5 -0
@@ -691,7 +691,12 @@ U_BOOT_DRIVER(ax88179_eth) = { };static const struct usb_device_id ax88179_eth_id_table[] = { +#if IS_ENABLED(CONFIG_USB_ETHER_CDC_ECM) || IS_ENABLED(CONFIG_USB_ETHER_CDC_NCM) + {USB_DEVICE_VER (0x0b95 ,0x1790 ,0 ,0x0100 ), + .driver_info =FLAG_TYPE_AX88179 }, +#else {USB_DEVICE (0x0b95 ,0x1790 ), .driver_info =FLAG_TYPE_AX88179 }, +#endif {USB_DEVICE (0x0b95 ,0x178a ), .driver_info = FLAG_TYPE_AX88178a }, {USB_DEVICE (0x2001 ,0x4a00 ), .driver_info =FLAG_TYPE_DLINK_DUB1312 }, {USB_DEVICE (0x0df6 ,0x0072 ), .driver_info =FLAG_TYPE_SITECOM },
drivers/usb/eth/cdc_ecm.c +3 -0
@@ -276,6 +276,9 @@ U_BOOT_DRIVER(usb_cdc_2_ecm) = { };static const struct usb_device_id cdc_ecm_id_table[] = { +/* ASIX AX88179A, AX88772D, AX88279 */ + {USB_DEVICE_VER (0x0b95 ,0x1790 ,0x0200 ,0x0400 ), }, +/* CDC ECM */ {USB_INTERFACE_INFO (USB_CLASS_COMM ,USB_CDC_SUBCLASS_ETHERNET ,USB_CDC_PROTO_NONE ), }, {/* sentinel */ }
drivers/usb/eth/cdc_ncm.c +3 -0
@@ -472,6 +472,9 @@ U_BOOT_DRIVER(usb_cdc_1_ncm) = { };static const struct usb_device_id cdc_ncm_id_table[] = { +/* ASIX AX88179A, AX88772D, AX88279 */ + {USB_DEVICE_VER (0x0b95 ,0x1790 ,0x0200 ,0x0400 ), }, +/* CDC NCM */ {USB_INTERFACE_INFO (USB_CLASS_COMM ,USB_CDC_SUBCLASS_NCM ,USB_CDC_PROTO_NONE ), }, {/* sentinel */ }
Signature · 1 line
2.54.0
Re: [PATCH 7/8] usb: eth: Bind ASIX AX88179A/AX88772D/AX88279 to CDC ECM/NCM driver
Quoted 10 lines · Jonas Karlman
The ASIX AX88179A, AX88772D and AX88279 USB Ethernet controller revisions has both CDC ECM and CDC NCM support.
AX88179: 0b95:1790 1.00 AX88179A: 0b95:1790 2.00 AX88772D: 0b95:1790 3.00 AX88279: 0b95:1790 4.00Prefer using the CDC NCM or CDC ECM driver for the 2.00-4.00 version range of the 0b95:1790 ASIX USB Ethernet controllers.
Why this specific range ?
[...]
drivers/usb/eth/asix88179.c U_BOOT_DRIVER(ax88179_eth) = { · line 694
Quoted 6 lines
+++
b/drivers/usb/eth/asix88179.cdrivers/usb/eth/asix88179.c +1
-0@@ -691,7 +691,12 @@ U_BOOT_DRIVER(ax88179_eth) = { };static const struct usb_device_id ax88179_eth_id_table[] = { +#if IS_ENABLED(CONFIG_USB_ETHER_CDC_ECM) || IS_ENABLED(CONFIG_USB_ETHER_CDC_NCM)
This is USB, this should be auto-detected without any need for ifdeffery.
drivers/usb/eth/asix88179.c U_BOOT_DRIVER(ax88179_eth) = { · line 700
Quoted 6 lines
drivers/usb/eth/asix88179.c +4
-0+ { USB_DEVICE_VER(0x0b95, 0x1790, 0, 0x0100), + .driver_info = FLAG_TYPE_AX88179 }, +#else { USB_DEVICE(0x0b95, 0x1790), .driver_info = FLAG_TYPE_AX88179 }, +#endif { USB_DEVICE(0x0b95, 0x178a), .driver_info = FLAG_TYPE_AX88178a },
[...]
I recall there was some USB URB size limit on this ASIX USB MAC, was that ever sorted out ?
Re: [PATCH 7/8] usb: eth: Bind ASIX AX88179A/AX88772D/AX88279 to CDC ECM/NCM driver
Hi Marek,
Quoted 9 lines · Marek Vasut
Quoted 8 lines · Jonas Karlman
The ASIX AX88179A, AX88772D and AX88279 USB Ethernet controller revisions has both CDC ECM and CDC NCM support.
AX88179: 0b95:1790 1.00 AX88179A: 0b95:1790 2.00 AX88772D: 0b95:1790 3.00 AX88279: 0b95:1790 4.00
Quoted 4 lines
Quoted 2 lines
Prefer using the CDC NCM or CDC ECM driver for the 2.00-4.00 version range of the 0b95:1790 ASIX USB Ethernet controllers.
Why this specific range ?
Sorry, my commit message was not clear enough. Only the last three entries listed above have ECM/NCM support stated in their datasheet.
The version seems to correlate with the different "generation" of the AX88179/AX88772 controllers.
The initial AX88179/AX88772 revisions, tagged with version 1.00, does not state support for ECM/NCM in the datasheet. And all my dongles are tagged with version 2.00 or above, i.e. using AX88179A or a later revision or version in the family.
The version matching also seems to match revision handling in vendor driver [1], so that suggest that these assumptions are correct. Based on
[1] it looks like version 5.00 for AX88279A was added recently.
[1] https://github.com/mmoya/asix-usb-nic-linux-driver/blob/main/ax_main.c#L2913-L2939
Quoted 11 lines
[...]
drivers/usb/eth/asix88179.c U_BOOT_DRIVER(ax88179_eth) = { · line 694
Quoted 6 lines
+++
b/drivers/usb/eth/asix88179.cdrivers/usb/eth/asix88179.c +1
-0@@ -691,7 +691,12 @@ U_BOOT_DRIVER(ax88179_eth) = { };static const struct usb_device_id ax88179_eth_id_table[] = { +#if IS_ENABLED(CONFIG_USB_ETHER_CDC_ECM) || IS_ENABLED(CONFIG_USB_ETHER_CDC_NCM)This is USB, this should be auto-detected without any need for ifdeffery.
As stated in the cover letter, U-Boot only support driver detection of the first (cfgno=0) configuration.
U-Boot currently only has support for automatic binding of the first device configuration for devices, so this implementaion works by adding bindings for VID/PID pairs and letting the drivers try to change active configuration during probe.
To work around this limitation, the VID/PID pair is added here.
U-Boot USB core structs only have support for carrying information about a single configuration, so the cfgno=0 is set as active configuration and USB driver matches only on information of this first config.
Initially I tried to add limited support for at least parsing all configuration descriptors and make usb command list all possible configs.
However, there are other parts that only where saved during config desc parsing and where then overwritten by parsing of next config descriptor.
Next hack was to just force setting the cfgno that matched NCM, and that made USB driver matching the new NCM driver, but this was not scalable.
So to not having to re-work how USB core store config and handles driver matching, the cleanest way was to export the set config helper and use VID/PID matching in these drivers.
Hopefully someone can add proper support for driver matching based on all possible device configurations in the future. Not something I plan to address, I just wanted my USB Ethernet dongles to work :-)
Quoted 11 lines
drivers/usb/eth/asix88179.c U_BOOT_DRIVER(ax88179_eth) = { · line 700
Quoted 7 lines
drivers/usb/eth/asix88179.c +4
-0+ { USB_DEVICE_VER(0x0b95, 0x1790, 0, 0x0100), + .driver_info = FLAG_TYPE_AX88179 }, +#else { USB_DEVICE(0x0b95, 0x1790), .driver_info = FLAG_TYPE_AX88179 }, +#endif { USB_DEVICE(0x0b95, 0x178a), .driver_info = FLAG_TYPE_AX88178a },[...]
I recall there was some USB URB size limit on this ASIX USB MAC, was that ever sorted out ?
Correct, the ax88179_eth driver is currently requesting a bigger RX buffer than what the MAC seem to be able to handle when EHCI controller is used.
Trying to get a workaround that limited the size to 16 KiB, similar to what Linux uses, was partially rejected.
This ultimately made me to look closer at NCM/ECM and the implementation of these drivers. And for U-Boot purpose using NCM/ECM mode seems more logical than continue trying to use the undocumented vendor magic :-)
For ECM only a single packet is sent, so a 2 KiB buffer is used. And for NCM it defaults to 16 KiB and also uses the information provided from the descriptors to keep the the used buffer size within device limits.
To conclude, using ECM/NCM mode resolved all issues I had related to USB URB size and this ASIX USB MAC so I have now fully switched to just using ECM/NCM driver for the boards in my personal lab.
Regards,
Jonas
Re: [PATCH 7/8] usb: eth: Bind ASIX AX88179A/AX88772D/AX88279 to CDC ECM/NCM driver
On 7/12/26 12:14 PM, Jonas Karlman wrote:
Hello Jonas,
Quoted 25 lines
Quoted 9 lines · Jonas Karlman
Quoted 8 lines
The ASIX AX88179A, AX88772D and AX88279 USB Ethernet controller revisions has both CDC ECM and CDC NCM support.
AX88179: 0b95:1790 1.00 AX88179A: 0b95:1790 2.00 AX88772D: 0b95:1790 3.00 AX88279: 0b95:1790 4.00Quoted 4 lines
Quoted 2 lines
Prefer using the CDC NCM or CDC ECM driver for the 2.00-4.00 version range of the 0b95:1790 ASIX USB Ethernet controllers.
Why this specific range ?
Sorry, my commit message was not clear enough. Only the last three entries listed above have ECM/NCM support stated in their datasheet.
The version seems to correlate with the different "generation" of the AX88179/AX88772 controllers.
The initial AX88179/AX88772 revisions, tagged with version 1.00, does not state support for ECM/NCM in the datasheet. And all my dongles are tagged with version 2.00 or above, i.e. using AX88179A or a later revision or version in the family.
Quoted 5 lines
The version matching also seems to match revision handling in vendor driver [1], so that suggest that these assumptions are correct. Based on
[1] it looks like version 5.00 for AX88279A was added recently.[1] https://github.com/mmoya/asix-usb-nic-linux-driver/blob/main/ax_main.c#L2913-L2939
OK
Quoted 34 lines
Quoted 10 lines
[...]
drivers/usb/eth/asix88179.c U_BOOT_DRIVER(ax88179_eth) = { · line 694
Quoted 6 lines
+++
b/drivers/usb/eth/asix88179.cdrivers/usb/eth/asix88179.c +1
-0@@ -691,7 +691,12 @@ U_BOOT_DRIVER(ax88179_eth) = { };static const struct usb_device_id ax88179_eth_id_table[] = { +#if IS_ENABLED(CONFIG_USB_ETHER_CDC_ECM) || IS_ENABLED(CONFIG_USB_ETHER_CDC_NCM)This is USB, this should be auto-detected without any need for ifdeffery.
As stated in the cover letter, U-Boot only support driver detection of the first (cfgno=0) configuration.
U-Boot currently only has support for automatic binding of the first device configuration for devices, so this implementaion works by adding bindings for VID/PID pairs and letting the drivers try to change active configuration during probe.
To work around this limitation, the VID/PID pair is added here.
U-Boot USB core structs only have support for carrying information about a single configuration, so the cfgno=0 is set as active configuration and USB driver matches only on information of this first config.
Initially I tried to add limited support for at least parsing all configuration descriptors and make usb command list all possible configs.
However, there are other parts that only where saved during config desc parsing and where then overwritten by parsing of next config descriptor.
Next hack was to just force setting the cfgno that matched NCM, and that made USB driver matching the new NCM driver, but this was not scalable.
Quoted 7 lines
So to not having to re-work how USB core store config and handles driver matching, the cleanest way was to export the set config helper and use VID/PID matching in these drivers.
Hopefully someone can add proper support for driver matching based on all possible device configurations in the future. Not something I plan to address, I just wanted my USB Ethernet dongles to work :-)
Try and look at 575c68279c41 ("usb: kbd: support Apple Magic Keyboards (2021)") , maybe that can help with some handling of second interface descriptor ?
Quoted 22 lines
Quoted 10 lines
drivers/usb/eth/asix88179.c U_BOOT_DRIVER(ax88179_eth) = { · line 700
Quoted 6 lines
drivers/usb/eth/asix88179.c +4
-0+ { USB_DEVICE_VER(0x0b95, 0x1790, 0, 0x0100), + .driver_info = FLAG_TYPE_AX88179 }, +#else { USB_DEVICE(0x0b95, 0x1790), .driver_info = FLAG_TYPE_AX88179 }, +#endif { USB_DEVICE(0x0b95, 0x178a), .driver_info = FLAG_TYPE_AX88178a },[...]
I recall there was some USB URB size limit on this ASIX USB MAC, was that ever sorted out ?
Correct, the
ax88179_ethdriver is currently requesting a bigger RX buffer than what the MAC seem to be able to handle when EHCI controller is used.Trying to get a workaround that limited the size to 16 KiB, similar to what Linux uses, was partially rejected.
This ultimately made me to look closer at NCM/ECM and the implementation of these drivers. And for U-Boot purpose using NCM/ECM mode seems more logical than continue trying to use the undocumented vendor magic :-)
Quoted 7 lines
For ECM only a single packet is sent, so a 2 KiB buffer is used. And for NCM it defaults to 16 KiB and also uses the information provided from the descriptors to keep the the used buffer size within device limits.
To conclude, using ECM/NCM mode resolved all issues I had related to USB URB size and this ASIX USB MAC so I have now fully switched to just using ECM/NCM driver for the boards in my personal lab.
Can we fix the EHCI driver too ?
It feels like there is a bug, which is papered over by these patches.
Re: [PATCH 7/8] usb: eth: Bind ASIX AX88179A/AX88772D/AX88279 to CDC ECM/NCM driver
Hi Marek,
Quoted 75 lines · Marek Vasut
On 7/12/26 12:14 PM, Jonas Karlman wrote:
Hello Jonas,
Quoted 25 lines
Quoted 9 lines · Jonas Karlman
Quoted 8 lines
The ASIX AX88179A, AX88772D and AX88279 USB Ethernet controller revisions has both CDC ECM and CDC NCM support.
AX88179: 0b95:1790 1.00 AX88179A: 0b95:1790 2.00 AX88772D: 0b95:1790 3.00 AX88279: 0b95:1790 4.00Quoted 4 lines
Quoted 2 lines
Prefer using the CDC NCM or CDC ECM driver for the 2.00-4.00 version range of the 0b95:1790 ASIX USB Ethernet controllers.
Why this specific range ?
Sorry, my commit message was not clear enough. Only the last three entries listed above have ECM/NCM support stated in their datasheet.
The version seems to correlate with the different "generation" of the AX88179/AX88772 controllers.
The initial AX88179/AX88772 revisions, tagged with version 1.00, does not state support for ECM/NCM in the datasheet. And all my dongles are tagged with version 2.00 or above, i.e. using AX88179A or a later revision or version in the family.
Quoted 5 lines
The version matching also seems to match revision handling in vendor driver [1], so that suggest that these assumptions are correct. Based on
[1] it looks like version 5.00 for AX88279A was added recently.[1] https://github.com/mmoya/asix-usb-nic-linux-driver/blob/main/ax_main.c#L2913-L2939
OK
Quoted 38 lines
Quoted 10 lines
[...]
drivers/usb/eth/asix88179.c U_BOOT_DRIVER(ax88179_eth) = { · line 694
Quoted 6 lines
+++
b/drivers/usb/eth/asix88179.cdrivers/usb/eth/asix88179.c +1
-0@@ -691,7 +691,12 @@ U_BOOT_DRIVER(ax88179_eth) = { };static const struct usb_device_id ax88179_eth_id_table[] = { +#if IS_ENABLED(CONFIG_USB_ETHER_CDC_ECM) || IS_ENABLED(CONFIG_USB_ETHER_CDC_NCM)This is USB, this should be auto-detected without any need for ifdeffery.
As stated in the cover letter, U-Boot only support driver detection of the first (cfgno=0) configuration.
U-Boot currently only has support for automatic binding of the first device configuration for devices, so this implementaion works by adding bindings for VID/PID pairs and letting the drivers try to change active configuration during probe.
To work around this limitation, the VID/PID pair is added here.
U-Boot USB core structs only have support for carrying information about a single configuration, so the cfgno=0 is set as active configuration and USB driver matches only on information of this first config.
Initially I tried to add limited support for at least parsing all configuration descriptors and make usb command list all possible configs.
However, there are other parts that only where saved during config desc parsing and where then overwritten by parsing of next config descriptor.
Next hack was to just force setting the cfgno that matched NCM, and that made USB driver matching the new NCM driver, but this was not scalable.
So to not having to re-work how USB core store config and handles driver matching, the cleanest way was to export the set config helper and use VID/PID matching in these drivers.
Quoted 7 lines
Quoted 3 lines
Hopefully someone can add proper support for driver matching based on all possible device configurations in the future. Not something I plan to address, I just wanted my USB Ethernet dongles to work :-)
Try and look at
575c68279c41("usb: kbd: support Apple Magic Keyboards (2021)") , maybe that can help with some handling of second interface descriptor ?
That seem to be an issue of Interface Descriptor. CDC ECM/NCM modes are described using dedicated Configuration Descriptors, typically there is:
cfgno=0, class: Vendor Specific
cfgno=1, class: Communications, NCM
cfgno=2, class: Communications, ECM
or similar, see [2] for a full descriptor print of AX88179A and RTL8156.
And U-Boot only use information from the first Configuration Descriptor when matching drivers, it also never test/use any other configuration.
This is why we need the VID/PID matching in CDC NCM/ECM drivers, unless someone first re-work USB core to fully support multiple configuration descriptors.
Here I did minimal effort to help support multiple configurations.
Do you think this should be handled differently? Is it the use of #if #else that is the problem? Please be specific on what and how you think it should be handled differently.
[2] https://gist.github.com/Kwiboo/166f1ca8d9ea6cfd35f0ab17f719fa76
Quoted 27 lines
Quoted 27 lines
Quoted 11 lines
drivers/usb/eth/asix88179.c U_BOOT_DRIVER(ax88179_eth) = { · line 700
Quoted 7 lines
drivers/usb/eth/asix88179.c +4
-0+ { USB_DEVICE_VER(0x0b95, 0x1790, 0, 0x0100), + .driver_info = FLAG_TYPE_AX88179 }, +#else { USB_DEVICE(0x0b95, 0x1790), .driver_info = FLAG_TYPE_AX88179 }, +#endif { USB_DEVICE(0x0b95, 0x178a), .driver_info = FLAG_TYPE_AX88178a },[...]
I recall there was some USB URB size limit on this ASIX USB MAC, was that ever sorted out ?
Correct, the
ax88179_ethdriver is currently requesting a bigger RX buffer than what the MAC seem to be able to handle when EHCI controller is used.Trying to get a workaround that limited the size to 16 KiB, similar to what Linux uses, was partially rejected.
This ultimately made me to look closer at NCM/ECM and the implementation of these drivers. And for U-Boot purpose using NCM/ECM mode seems more logical than continue trying to use the undocumented vendor magic :-)
For ECM only a single packet is sent, so a 2 KiB buffer is used. And for NCM it defaults to 16 KiB and also uses the information provided from the descriptors to keep the the used buffer size within device limits.
Quoted 6 lines
Quoted 3 lines
To conclude, using ECM/NCM mode resolved all issues I had related to USB URB size and this ASIX USB MAC so I have now fully switched to just using ECM/NCM driver for the boards in my personal lab.
Can we fix the EHCI driver too ?
It feels like there is a bug, which is papered over by these patches.
Yes, there are plenty of bugs, e.g.:
- ax88179 vendor format store the "header" as a "footer" so it fully depends on the packets read back reporting correct size or bad data is treated as the "header"
- ax88179 driver is requesting too much data so the "header" gets misaligned and packets gets dropped
- ECHI core does not handle short qTD in same way as Linux and instead just appends data to return as much data as possible, causing "header" to be located in the middle of the returned data [3]
There was also similar issues when an DWC3 host was used, so due to the vendor format being so sensitive to size being correctly reported forcing use of NCM/ECM and only keep using this driver for models that must use it to function was least resisting way to "solve" all these issues.
[3] https://gist.github.com/Kwiboo/43c141390fe12dbf54f0652a32804e15
Regards,
Jonas
PATCH 8/8 usb: eth: Bind Realtek RTL815x to CDC ECM driver
In reply to Jonas KarlmanThe Realtek RTL815x Ethernet controllers have CDC ECM support. The RTL8156 and RTL8157 also have CDC NCM support, however RTL8157 fails to signal Network Connection status on demand.
Bind the Realtek RTL815x Ethernet controllers to the CDC ECM driver. The driver is sorted last so should work as a fallback after the r8152 driver.
--- drivers/usb/eth/cdc_ecm.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/eth/cdc_ecm.c +5 -0
@@ -278,6 +278,11 @@ U_BOOT_DRIVER(usb_cdc_2_ecm) = {static const struct usb_device_id cdc_ecm_id_table[] = {/* ASIX AX88179A, AX88772D, AX88279 */ {USB_DEVICE_VER (0x0b95 ,0x1790 ,0x0200 ,0x0400 ), }, +/* Realtek RTL8152, RTL8153, RTL8156, RTL8157 */ + {USB_DEVICE (0x0bda ,0x8152 ), }, + {USB_DEVICE (0x0bda ,0x8153 ), }, + {USB_DEVICE (0x0bda ,0x8156 ), }, + {USB_DEVICE (0x0bda ,0x8157 ), },/* CDC ECM */ {USB_INTERFACE_INFO (USB_CLASS_COMM ,USB_CDC_SUBCLASS_ETHERNET ,USB_CDC_PROTO_NONE ), },
Signature · 1 line
2.54.0
Re: [PATCH 8/8] usb: eth: Bind Realtek RTL815x to CDC ECM driver
Hi Jonas,
Quoted 10 lines · Jonas Karlman
usb: eth: Bind Realtek RTL815x to CDC ECM driver
The Realtek RTL815x Ethernet controllers have CDC ECM support. The RTL8156 and RTL8157 also have CDC NCM support, however RTL8157 fails to signal Network Connection status on demand.
Bind the Realtek RTL815x Ethernet controllers to the CDC ECM driver. The driver is sorted last so should work as a fallback after the r8152 driver.
Quoted 8 lines
Signed-off-by Jonas Karlman <[email protected]>
drivers/usb/eth/cdc_ecm.c| 5 +++++1 file changed, 5 insertions(+)The Realtek RTL815x Ethernet controllers have CDC ECM support. The RTL8156 and RTL8157 also have CDC NCM support, however RTL8157 fails to signal Network Connection status on demand.
So you have chosen to use NCM for all RTL parts, right? That seems OK to me.
drivers/usb/eth/cdc_ecm.c U_BOOT_DRIVER(usb_cdc_2_ecm) = { · line 282
Quoted 7 lines
drivers/usb/eth/cdc_ecm.c +5
-0@@ -278,6 +278,11 @@ U_BOOT_DRIVER(usb_cdc_2_ecm) = { +/* Realtek RTL8152, RTL8153, RTL8156, RTL8157 */ + { USB_DEVICE(0x0bda, 0x8152), }, + { USB_DEVICE(0x0bda, 0x8153), }, + { USB_DEVICE(0x0bda, 0x8156), }, + { USB_DEVICE(0x0bda, 0x8157), },
The r8152 table also matches a number of RTL8153-based OEM devices (Samsung 04e8:a101, Lenovo 17ef:*, TP-Link 2357:*, NVIDIA 0955:09ff). Without entries here, those dongles get no ECM fallback when the r8152 driver is disabled, since their first configuration is presumably vendor class and so the USB_INTERFACE_INFO() entry will not match. Should those IDs be added as well, or is that better left until someone can test them?
Regards,
Simon
Hi Jonas,
Quoted 4 lines · Jonas Karlman
U-Boot currently only has support for automatic binding of the first device configuration for devices, so this implementaion works by adding bindings for VID/PID pairs and letting the drivers try to change active configuration during probe.
Since the VID/PID approach works around the USB core only matching against the first configuration, please can you record that limitation somewhere more permanent than the cover letter, e.g. a comment near the new helper?
BTW there is a typo here: 'implementaion'
Quoted 1 line
Patch 5-6 adds drivers for CDC ECM and CDC NCM.
The config-descriptor walking code in the two drivers is nearly identical, with the same interface/endpoint/functional-descriptor loop in each. Since you already have a common file, please can you see whether that loop can be shared, with the drivers providing just the matching logic? Then any fixes to the parsing only need to be made once.
Quoted 3 lines
The driver implementations was created based of the CDC ECM 1.2 and CDC NCM 1.1 specifications and was tested on a few different USB Ethernet adapters using ASIX or Realtek IC.
This series has no tests. We already have sandbox USB emulators for flash, keyboard and hub devices in drivers/usb/emul, so it should be possible to add a CDC ECM emulator and a test which binds the driver and exercises the descriptor parsing. That parsing handles untrusted data from the device, so it is exactly the sort of code that benefits from tests. Even covering just the ECM driver would help. What do you think?
Regards,
Simon