On 2021/03/25 00:30, Patrick Wildt wrote: > Without having looked at anything, it might be worth looking at the most > recent mail in this thread: > > 'Re: [PATCH] umb(4) fix for X20 (DW5821e) in Dell Latitude 7300' >
oh, usb runs through all drivers looking for a VID/PID match before then running through all looking for a class match? I didn't realise (thought it would try driver-by-driver with first VID/PID then class) but that does make sense. Updated diff below adding my pid/vid and tweaking some comments. My card attaches to umb with this. I've only added it commented-out to the manual for now until I see it actually pass traffic. So this fixes Bryan's, at least improves mine (will look for another sim / sim-adapter tomorrow), and seems targetted enough to not risk fallout with existing working devices. I think this makes sense to commit. OK with me if you'd like to commit it Gerhard (I think it was your diff originally). I added this product to usbdevs as a short string; the other Huawei devices all say "HUAWEI Mobile xyz" rather than just "xyz" in the device string which I think should be trimmed as well, probably worth doing that on top. Index: share/man/man4/umb.4 =================================================================== RCS file: /cvs/src/share/man/man4/umb.4,v retrieving revision 1.11 diff -u -p -r1.11 umb.4 --- share/man/man4/umb.4 12 May 2020 13:03:52 -0000 1.11 +++ share/man/man4/umb.4 25 Mar 2021 00:03:58 -0000 @@ -44,8 +44,10 @@ PIN again even if the system was reboote The following devices should work: .Pp .Bl -tag -width Ds -offset indent -compact +.It Dell DW5821e .It Ericsson H5321gw and N5321gw .It Fibocom L831-EAU +.\" .It Huawei ME906s -- attaches but may need more work .It Medion Mobile S4222 (MediaTek OEM) .It Sierra Wireless EM7345 .It Sierra Wireless EM7455 Index: sys/dev/usb/if_umb.c =================================================================== RCS file: /cvs/src/sys/dev/usb/if_umb.c,v retrieving revision 1.37 diff -u -p -r1.37 if_umb.c --- sys/dev/usb/if_umb.c 29 Jan 2021 17:06:19 -0000 1.37 +++ sys/dev/usb/if_umb.c 24 Mar 2021 23:52:13 -0000 @@ -225,6 +225,28 @@ const struct cfattach umb_ca = { int umb_delay = 4000; /* + * Normally, MBIM devices are detected by their interface class and subclass. + * But for some models that have multiple configurations, it is better to + * match by vendor and product id so that we can select the desired + * configuration ourselves, e.g. to override a class-based match to another + * driver. + * + * OTOH, some devices identify themselves as an MBIM device but fail to speak + * the MBIM protocol. + */ +struct umb_products { + struct usb_devno dev; + int confno; +}; +const struct umb_products umb_devs[] = { + { { USB_VENDOR_DELL, USB_PRODUCT_DELL_DW5821E }, 2 }, + { { USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_ME906S }, 3 }, +}; + +#define umb_lookup(vid, pid) \ + ((const struct umb_products *)usb_lookup(umb_devs, vid, pid)) + +/* * These devices require an "FCC Authentication" command. */ const struct usb_devno umb_fccauth_devs[] = { @@ -263,6 +285,8 @@ umb_match(struct device *parent, void *m struct usb_attach_arg *uaa = aux; usb_interface_descriptor_t *id; + if (umb_lookup(uaa->vendor, uaa->product) != NULL) + return UMATCH_VENDOR_PRODUCT; if (!uaa->iface) return UMATCH_NONE; if ((id = usbd_get_interface_descriptor(uaa->iface)) == NULL) @@ -315,6 +339,43 @@ umb_attach(struct device *parent, struct sc->sc_ctrl_ifaceno = uaa->ifaceno; ml_init(&sc->sc_tx_ml); + if (uaa->configno < 0) { + /* + * In case the device was matched by VID/PID instead of + * InterfaceClass/InterfaceSubClass, we have to pick the + * correct configuration ourself. + */ + uaa->configno = umb_lookup(uaa->vendor, uaa->product)->confno; + DPRINTF("%s: switching to config #%d\n", DEVNAM(sc), + uaa->configno); + status = usbd_set_config_no(sc->sc_udev, uaa->configno, 1); + if (status) { + printf("%s: failed to switch to config #%d: %s\n", + DEVNAM(sc), uaa->configno, usbd_errstr(status)); + goto fail; + } + usbd_delay_ms(sc->sc_udev, 200); + + /* + * Need to do some manual setups that usbd_probe_and_attach() + * would do for us otherwise. + */ + uaa->nifaces = uaa->device->cdesc->bNumInterfaces; + for (i = 0; i < uaa->nifaces; i++) { + if (usbd_iface_claimed(sc->sc_udev, i)) + continue; + id = usbd_get_interface_descriptor(&uaa->device->ifaces[i]); + if (id != NULL && id->bInterfaceClass == UICLASS_CDC && + id->bInterfaceSubClass == + UISUBCLASS_MOBILE_BROADBAND_INTERFACE_MODEL) { + uaa->iface = &uaa->device->ifaces[i]; + uaa->ifaceno = uaa->iface->idesc->bInterfaceNumber; + sc->sc_ctrl_ifaceno = uaa->ifaceno; + break; + } + } + } + /* * Some MBIM hardware does not provide the mandatory CDC Union * Descriptor, so we also look at matching Interface @@ -382,9 +443,9 @@ umb_attach(struct device *parent, struct for (i = 0; i < uaa->nifaces; i++) { if (usbd_iface_claimed(sc->sc_udev, i)) continue; - id = usbd_get_interface_descriptor(uaa->ifaces[i]); + id = usbd_get_interface_descriptor(&sc->sc_udev->ifaces[i]); if (id != NULL && id->bInterfaceNumber == data_ifaceno) { - sc->sc_data_iface = uaa->ifaces[i]; + sc->sc_data_iface = &sc->sc_udev->ifaces[i]; usbd_claim_iface(sc->sc_udev, i); } } Index: sys/dev/usb/usbdevs =================================================================== RCS file: /cvs/src/sys/dev/usb/usbdevs,v retrieving revision 1.734 diff -u -p -r1.734 usbdevs --- sys/dev/usb/usbdevs 24 Mar 2021 18:49:25 -0000 1.734 +++ sys/dev/usb/usbdevs 24 Mar 2021 23:52:13 -0000 @@ -1519,6 +1519,7 @@ product DELL PRISM_GT_2 0x8104 PrismGT product DELL W5500 0x8115 W5500 HSDPA product DELL U740 0x8135 U740 CDMA product DELL EU870D 0x8138 EU870D HSDPA +product DELL DW5821E 0x81d7 DW5821e LTE product DELL DW700 0x9500 DW700 GPS product DELL2 UPS 0xffff UPS @@ -2302,6 +2303,7 @@ product HUAWEI E392_INIT 0x1505 HUAWEI M product HUAWEI K3765_INIT 0x1520 HUAWEI Mobile K3765 Initial product HUAWEI K3772_INIT 0x1526 HUAWEI Mobile K3772 Initial product HUAWEI MU609 0x1573 HUAWEI Mobile ME906 +product HUAWEI ME906S 0x15c1 ME906s LTE product HUAWEI E173S 0x1c05 HUAWEI Mobile E173s product HUAWEI E173S_INIT 0x1c0b HUAWEI Mobile E173s Initial product HUAWEI E303 0x1f01 HUAWEI Mobile E303