Tue Apr 16 18:45:39 2024 UTC (23d)
Pull up following revision(s) (requested by thorpej in ticket #649):

	sys/dev/usb/uftdi.c: revision 1.77
	share/man/man4/ugen.4: revision 1.39
	sys/dev/usb/ugen.c: revision 1.176
	sys/dev/usb/usbdevices.config: revision 1.43

Define a "flags 1" config directive for ugenif, which is similar to ugen's,
but rather forces the ugenif to match at the *lowest* match priority rather
than the highest.  This allows ugenif to claim only otherwise unclaimed
interfaces.

Add a "match quirk" mechanism to the uftdi driver that allows it to
selectively reject individual interfaces based on the combination of
- Vendor ID
- Product ID
- Interface number
- Vendor string
- Product string

This is necessary[*] to allow some devices that would otherwise match
uftdi (and thus instantiate a ucom) to be matched by ugenif instead,
which is required to make the device available to libusb1.

[*] ...due to a deficiency in the USB stack that does not provide a
mechanism for a user-space driver to claim a device from a kernel driver
and then return it back at a later time.

Use this new match quirk mechanism to reject "interface 1" of the
FTDI 2232C-based Tigard debug board; On this board, "interface 0"
is brought out to regular TTL-level UART pins, but "interface 1" is
brought out to SWD and JTAG headers, and is really only useful when
used with something like openocd.  Because the FTDI 2232C on this board
just uses the standard FTDI vendor and product IDs, it can only be
distinguished by the strings, which cannot be specified usbdevices.config,
thus necessitating the match quirk entry (that works in combination
with the ugenif entry added in usbdevices.config).


(martin)
diff -r1.38 -r1.38.6.1 src/share/man/man4/ugen.4
diff -r1.76 -r1.76.6.1 src/sys/dev/usb/uftdi.c
diff -r1.171 -r1.171.2.1 src/sys/dev/usb/ugen.c
diff -r1.42 -r1.42.10.1 src/sys/dev/usb/usbdevices.config

cvs diff -r1.38 -r1.38.6.1 src/share/man/man4/ugen.4 (expand / switch to unified diff)

--- src/share/man/man4/ugen.4 2020/08/28 16:07:49 1.38
+++ src/share/man/man4/ugen.4 2024/04/16 18:45:39 1.38.6.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: ugen.4,v 1.38 2020/08/28 16:07:49 fcambus Exp $ 1.\" $NetBSD: ugen.4,v 1.38.6.1 2024/04/16 18:45:39 martin Exp $
2.\" 2.\"
3.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 3.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation 6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Lennart Augustsson. 7.\" by Lennart Augustsson.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -17,73 +17,82 @@ @@ -17,73 +17,82 @@
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE. 28.\" POSSIBILITY OF SUCH DAMAGE.
29.\" 29.\"
30.Dd September 14, 2019 30.Dd March 25, 2024
31.Dt UGEN 4 31.Dt UGEN 4
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm ugen 34.Nm ugen
35.Nd USB generic device support 35.Nd USB generic device support
36.Sh SYNOPSIS 36.Sh SYNOPSIS
37.Cd "ugen* at uhub? flags N" 37.Cd "ugen* at uhub? flags N"
38.Cd "ugen* at uhub? vendor V product P flags 1" 38.Cd "ugen* at uhub? vendor V product P flags 1"
39.Cd "ugenif* at uhub? vendor V product P configuration C interface I" 39.Cd "ugenif* at uhub? vendor V product P configuration C interface I"
 40.Cd "ugenif* at uhub? vendor V product P configuration C interface I flags 1"
40.Sh DESCRIPTION 41.Sh DESCRIPTION
41The 42The
42.Nm 43.Nm
43driver provides support for all USB devices that do not have 44driver provides support for all USB devices that do not have
44a special driver. 45a special driver.
45It supports access to all parts of the device, 46It supports access to all parts of the device,
46but not in a way that is as convenient as a special purpose driver. 47but not in a way that is as convenient as a special purpose driver.
47.Pp 48.Pp
48Normally the 49Normally the
49.Nm 50.Nm
50driver is used when no other driver attaches to a device. 51driver is used when no other driver attaches to a device.
51If 52If
52.Dq flags 1 53.Dq flags 1
53is specified, the 54is specified, the
54.Nm 55.Nm
55will instead attach with a very high priority and always be used. 56will instead attach with a very high priority and always be used.
56Together with the 57Together with the
57.Cd vendor 58.Cd vendor
58and 59and
59.Cd product 60.Cd product
60locators this can be used to force the 61locators this can be used to force the
61.Nm 62.Nm
62driver to be used for a certain 63driver to be used for a certain
63device. 64device.
64.Pp 65.Pp
65The second form of attachment can be used to 66The
 67.Sq ugenif
 68form of attachment can be used to
66.Dq steal 69.Dq steal
67only one interface from some device for use by the 70only one interface from some device for use by the
68.Nm 71.Nm
69driver. 72driver.
70Most likely you want to explicitly specify at least vendor, 73Most likely you want to explicitly specify at least vendor,
71product and interface with this form, 74product and interface with this form,
72as otherwise the 75as otherwise the
73.Nm 76.Nm
74driver would capture all of your 77driver would capture all of your
75.Nm usb 78.Nm usb
76devices. 79devices.
 80If
 81.Dq flags 1
 82is specified, the
 83.Sq ugenif
 84form will match at the lowest priority, thus allowing it to match only
 85otherwise unclaimed interfaces.
77.Em NOTE : 86.Em NOTE :
78You have to be extremely careful, 87You have to be extremely careful,
79when using this form, 88when using this form,
80as the attached 89as the attached
81.Nm 90.Nm
82driver has access to all of the device 91driver has access to all of the device
83and can easily interfere with the driver(s) used for 92and can easily interfere with the driver(s) used for
84the other interface(s). 93the other interface(s).
85.Pp 94.Pp
86As an example of this second form of attachment there are 95As an example of this second form of attachment there are
87various debugging boards available based on some FTDI chip, 96various debugging boards available based on some FTDI chip,
88where one interface is used for JTAG debugging 97where one interface is used for JTAG debugging
89and the other is used as a serial interface. 98and the other is used as a serial interface.

cvs diff -r1.76 -r1.76.6.1 src/sys/dev/usb/uftdi.c (expand / switch to unified diff)

--- src/sys/dev/usb/uftdi.c 2021/08/07 16:19:17 1.76
+++ src/sys/dev/usb/uftdi.c 2024/04/16 18:45:39 1.76.6.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uftdi.c,v 1.76 2021/08/07 16:19:17 thorpej Exp $ */ 1/* $NetBSD: uftdi.c,v 1.76.6.1 2024/04/16 18:45:39 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net). 8 * by Lennart Augustsson (lennart@augustsson.net).
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,43 +20,44 @@ @@ -20,43 +20,44 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: uftdi.c,v 1.76 2021/08/07 16:19:17 thorpej Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: uftdi.c,v 1.76.6.1 2024/04/16 18:45:39 martin Exp $");
34 34
35#ifdef _KERNEL_OPT 35#ifdef _KERNEL_OPT
36#include "opt_usb.h" 36#include "opt_usb.h"
37#endif 37#endif
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/kernel.h> 41#include <sys/kernel.h>
42#include <sys/device.h> 42#include <sys/device.h>
43#include <sys/conf.h> 43#include <sys/conf.h>
44#include <sys/tty.h> 44#include <sys/tty.h>
45 45
46#include <dev/usb/usb.h> 46#include <dev/usb/usb.h>
47 47
48#include <dev/usb/usbdi.h> 48#include <dev/usb/usbdi.h>
49#include <dev/usb/usbdi_util.h> 49#include <dev/usb/usbdi_util.h>
 50#include <dev/usb/usbdivar.h>
50#include <dev/usb/usbdevs.h> 51#include <dev/usb/usbdevs.h>
51 52
52#include <dev/usb/ucomvar.h> 53#include <dev/usb/ucomvar.h>
53 54
54#include <dev/usb/uftdireg.h> 55#include <dev/usb/uftdireg.h>
55 56
56#ifdef UFTDI_DEBUG 57#ifdef UFTDI_DEBUG
57#define DPRINTF(x) if (uftdidebug) printf x 58#define DPRINTF(x) if (uftdidebug) printf x
58#define DPRINTFN(n,x) if (uftdidebug>(n)) printf x 59#define DPRINTFN(n,x) if (uftdidebug>(n)) printf x
59int uftdidebug = 0; 60int uftdidebug = 0;
60#else 61#else
61#define DPRINTF(x) 62#define DPRINTF(x)
62#define DPRINTFN(n,x) 63#define DPRINTFN(n,x)
@@ -174,39 +175,105 @@ static const struct usb_devno uftdi_devs @@ -174,39 +175,105 @@ static const struct usb_devno uftdi_devs
174 { USB_VENDOR_MISC, USB_PRODUCT_MISC_TELLSTICK }, 175 { USB_VENDOR_MISC, USB_PRODUCT_MISC_TELLSTICK },
175 { USB_VENDOR_MISC, USB_PRODUCT_MISC_TELLSTICK_DUO }, 176 { USB_VENDOR_MISC, USB_PRODUCT_MISC_TELLSTICK_DUO },
176}; 177};
177#define uftdi_lookup(v, p) usb_lookup(uftdi_devs, v, p) 178#define uftdi_lookup(v, p) usb_lookup(uftdi_devs, v, p)
178 179
179static int uftdi_match(device_t, cfdata_t, void *); 180static int uftdi_match(device_t, cfdata_t, void *);
180static void uftdi_attach(device_t, device_t, void *); 181static void uftdi_attach(device_t, device_t, void *);
181static void uftdi_childdet(device_t, device_t); 182static void uftdi_childdet(device_t, device_t);
182static int uftdi_detach(device_t, int); 183static int uftdi_detach(device_t, int);
183 184
184CFATTACH_DECL2_NEW(uftdi, sizeof(struct uftdi_softc), uftdi_match, 185CFATTACH_DECL2_NEW(uftdi, sizeof(struct uftdi_softc), uftdi_match,
185 uftdi_attach, uftdi_detach, NULL, NULL, uftdi_childdet); 186 uftdi_attach, uftdi_detach, NULL, NULL, uftdi_childdet);
186 187
 188struct uftdi_match_quirk_entry {
 189 uint16_t vendor_id;
 190 uint16_t product_id;
 191 int iface_no;
 192 const char * vendor_str;
 193 const char * product_str;
 194 int match_ret;
 195};
 196
 197static const struct uftdi_match_quirk_entry uftdi_match_quirks[] = {
 198 /*
 199 * The Tigard board (https://github.com/tigard-tools/tigard)
 200 * has two interfaces, one of which is meant to act as a
 201 * regular USB serial port (interface 0), the other of which
 202 * is meant for other protocols (SWD, JTAG, etc.). We must
 203 * reject interface 1 so that ugenif matches, thus allowing
 204 * full user-space control of that port.
 205 */
 206 {
 207 .vendor_id = USB_VENDOR_FTDI,
 208 .product_id = USB_PRODUCT_FTDI_SERIAL_2232C,
 209 .iface_no = 1,
 210 .vendor_str = "SecuringHardware.com",
 211 .product_str = "Tigard V1.1",
 212 .match_ret = UMATCH_NONE,
 213 }
 214};
 215
 216static int
 217uftdi_quirk_match(struct usbif_attach_arg *uiaa, int rv)
 218{
 219 struct usbd_device *dev = uiaa->uiaa_device;
 220 const struct uftdi_match_quirk_entry *q;
 221 int i;
 222
 223 for (i = 0; i < __arraycount(uftdi_match_quirks); i++) {
 224 q = &uftdi_match_quirks[i];
 225 if (uiaa->uiaa_vendor != q->vendor_id ||
 226 uiaa->uiaa_product != q->product_id ||
 227 uiaa->uiaa_ifaceno != q->iface_no) {
 228 continue;
 229 }
 230 if (q->vendor_str != NULL &&
 231 (dev->ud_vendor == NULL ||
 232 strcmp(dev->ud_vendor, q->vendor_str) != 0)) {
 233 continue;
 234 }
 235 if (q->product_str != NULL &&
 236 (dev->ud_product == NULL ||
 237 strcmp(dev->ud_product, q->product_str) != 0)) {
 238 continue;
 239 }
 240 /*
 241 * Got a match!
 242 */
 243 rv = q->match_ret;
 244 break;
 245 }
 246 return rv;
 247}
 248
187static int 249static int
188uftdi_match(device_t parent, cfdata_t match, void *aux) 250uftdi_match(device_t parent, cfdata_t match, void *aux)
189{ 251{
190 struct usbif_attach_arg *uiaa = aux; 252 struct usbif_attach_arg *uiaa = aux;
 253 int rv;
191 254
192 DPRINTFN(20,("uftdi: vendor=%#x, product=%#x\n", 255 DPRINTFN(20,("uftdi: vendor=%#x, product=%#x\n",
193 uiaa->uiaa_vendor, uiaa->uiaa_product)); 256 uiaa->uiaa_vendor, uiaa->uiaa_product));
194 257
195 if (uiaa->uiaa_configno != UFTDI_CONFIG_NO) 258 if (uiaa->uiaa_configno != UFTDI_CONFIG_NO)
196 return UMATCH_NONE; 259 return UMATCH_NONE;
197 260
198 return uftdi_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product) != NULL ? 261 rv = uftdi_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product) != NULL ?
199 UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE; 262 UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE;
 263 if (rv != UMATCH_NONE) {
 264 rv = uftdi_quirk_match(uiaa, rv);
 265 }
 266 return rv;
200} 267}
201 268
202static void 269static void
203uftdi_attach(device_t parent, device_t self, void *aux) 270uftdi_attach(device_t parent, device_t self, void *aux)
204{ 271{
205 struct uftdi_softc *sc = device_private(self); 272 struct uftdi_softc *sc = device_private(self);
206 struct usbif_attach_arg *uiaa = aux; 273 struct usbif_attach_arg *uiaa = aux;
207 struct usbd_device *dev = uiaa->uiaa_device; 274 struct usbd_device *dev = uiaa->uiaa_device;
208 struct usbd_interface *iface = uiaa->uiaa_iface; 275 struct usbd_interface *iface = uiaa->uiaa_iface;
209 usb_device_descriptor_t *ddesc; 276 usb_device_descriptor_t *ddesc;
210 usb_interface_descriptor_t *id; 277 usb_interface_descriptor_t *id;
211 usb_endpoint_descriptor_t *ed; 278 usb_endpoint_descriptor_t *ed;
212 char *devinfop; 279 char *devinfop;

cvs diff -r1.171 -r1.171.2.1 src/sys/dev/usb/ugen.c (expand / switch to unified diff)

--- src/sys/dev/usb/ugen.c 2022/10/23 11:06:37 1.171
+++ src/sys/dev/usb/ugen.c 2024/04/16 18:45:39 1.171.2.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ugen.c,v 1.171 2022/10/23 11:06:37 riastradh Exp $ */ 1/* $NetBSD: ugen.c,v 1.171.2.1 2024/04/16 18:45:39 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at 8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology. 9 * Carlstedt Research & Technology.
10 * 10 *
11 * Copyright (c) 2006 BBN Technologies Corp. All rights reserved. 11 * Copyright (c) 2006 BBN Technologies Corp. All rights reserved.
12 * Effort sponsored in part by the Defense Advanced Research Projects 12 * Effort sponsored in part by the Defense Advanced Research Projects
13 * Agency (DARPA) and the Department of the Interior National Business 13 * Agency (DARPA) and the Department of the Interior National Business
14 * Center under agreement number NBCHC050166. 14 * Center under agreement number NBCHC050166.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.171 2022/10/23 11:06:37 riastradh Exp $"); 40__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.171.2.1 2024/04/16 18:45:39 martin Exp $");
41 41
42#ifdef _KERNEL_OPT 42#ifdef _KERNEL_OPT
43#include "opt_compat_netbsd.h" 43#include "opt_compat_netbsd.h"
44#include "opt_usb.h" 44#include "opt_usb.h"
45#endif 45#endif
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/systm.h> 48#include <sys/systm.h>
49#include <sys/kernel.h> 49#include <sys/kernel.h>
50#include <sys/kmem.h> 50#include <sys/kmem.h>
51#include <sys/device.h> 51#include <sys/device.h>
52#include <sys/ioctl.h> 52#include <sys/ioctl.h>
53#include <sys/conf.h> 53#include <sys/conf.h>
@@ -348,28 +348,32 @@ ugen_match(device_t parent, cfdata_t mat @@ -348,28 +348,32 @@ ugen_match(device_t parent, cfdata_t mat
348 override = match->cf_flags & 1; 348 override = match->cf_flags & 1;
349 349
350 if (override) 350 if (override)
351 return UMATCH_HIGHEST; 351 return UMATCH_HIGHEST;
352 else if (uaa->uaa_usegeneric) 352 else if (uaa->uaa_usegeneric)
353 return UMATCH_GENERIC; 353 return UMATCH_GENERIC;
354 else 354 else
355 return UMATCH_NONE; 355 return UMATCH_NONE;
356} 356}
357 357
358static int 358static int
359ugenif_match(device_t parent, cfdata_t match, void *aux) 359ugenif_match(device_t parent, cfdata_t match, void *aux)
360{ 360{
361 /* Assume that they knew what they configured! (see ugenif(4)) */ 361 /*
362 return UMATCH_HIGHEST; 362 * Like ugen(4), ugenif(4) also has an override flag. It has the
 363 * opposite effect, however, causing us to match with GENERIC
 364 * priority rather than HIGHEST.
 365 */
 366 return (match->cf_flags & 1) ? UMATCH_GENERIC : UMATCH_HIGHEST;
363} 367}
364 368
365static void 369static void
366ugen_attach(device_t parent, device_t self, void *aux) 370ugen_attach(device_t parent, device_t self, void *aux)
367{ 371{
368 struct usb_attach_arg *uaa = aux; 372 struct usb_attach_arg *uaa = aux;
369 struct usbif_attach_arg uiaa; 373 struct usbif_attach_arg uiaa;
370 374
371 memset(&uiaa, 0, sizeof(uiaa)); 375 memset(&uiaa, 0, sizeof(uiaa));
372 uiaa.uiaa_port = uaa->uaa_port; 376 uiaa.uiaa_port = uaa->uaa_port;
373 uiaa.uiaa_vendor = uaa->uaa_vendor; 377 uiaa.uiaa_vendor = uaa->uaa_vendor;
374 uiaa.uiaa_product = uaa->uaa_product; 378 uiaa.uiaa_product = uaa->uaa_product;
375 uiaa.uiaa_release = uaa->uaa_release; 379 uiaa.uiaa_release = uaa->uaa_release;

cvs diff -r1.42 -r1.42.10.1 src/sys/dev/usb/usbdevices.config (expand / switch to unified diff)

--- src/sys/dev/usb/usbdevices.config 2021/06/29 10:22:37 1.42
+++ src/sys/dev/usb/usbdevices.config 2024/04/16 18:45:39 1.42.10.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: usbdevices.config,v 1.42 2021/06/29 10:22:37 nia Exp $ 1# $NetBSD: usbdevices.config,v 1.42.10.1 2024/04/16 18:45:39 martin Exp $
2# 2#
3# This file contains all USB related configuration. 3# This file contains all USB related configuration.
4# It is suitable for inclusion in a kernel config(5) file. 4# It is suitable for inclusion in a kernel config(5) file.
5# 5#
6 6
7# USB Controller and Devices 7# USB Controller and Devices
8 8
9# PCI USB controllers 9# PCI USB controllers
10#ehci* at pci? dev ? function ? # Enhanced Host Controller 10#ehci* at pci? dev ? function ? # Enhanced Host Controller
11#ohci* at pci? dev ? function ? # Open Host Controller 11#ohci* at pci? dev ? function ? # Open Host Controller
12#uhci* at pci? dev ? function ? # Universal Host Controller (Intel) 12#uhci* at pci? dev ? function ? # Universal Host Controller (Intel)
13 13
14# CardBus USB controllers 14# CardBus USB controllers
@@ -249,13 +249,20 @@ aubtfwl* at uhub? port ? # load Atheros  @@ -249,13 +249,20 @@ aubtfwl* at uhub? port ? # load Atheros
249bthub* at ubt? 249bthub* at ubt?
250 250
251# Araneus Alea I/II TRNG 251# Araneus Alea I/II TRNG
252ualea* at uhub? port ? configuration ? interface ? 252ualea* at uhub? port ? configuration ? interface ?
253 253
254# Yubikey -- CCID interface (OTP and FIDO are handled by uhidev(4)) 254# Yubikey -- CCID interface (OTP and FIDO are handled by uhidev(4))
255# https://support.yubico.com/support/solutions/articles/15000028104-yubikey-usb-id-values 255# https://support.yubico.com/support/solutions/articles/15000028104-yubikey-usb-id-values
256ugenif* at uhub? vendor 0x1050 product 0x0114 configuration 1 interface 1 256ugenif* at uhub? vendor 0x1050 product 0x0114 configuration 1 interface 1
257ugenif* at uhub? vendor 0x1050 product 0x0115 configuration 1 interface 1 257ugenif* at uhub? vendor 0x1050 product 0x0115 configuration 1 interface 1
258ugenif* at uhub? vendor 0x1050 product 0x0116 configuration 1 interface 2 258ugenif* at uhub? vendor 0x1050 product 0x0116 configuration 1 interface 2
259ugenif* at uhub? vendor 0x1050 product 0x0405 configuration 1 interface 1 259ugenif* at uhub? vendor 0x1050 product 0x0405 configuration 1 interface 1
260ugenif* at uhub? vendor 0x1050 product 0x0406 configuration 1 interface 1 260ugenif* at uhub? vendor 0x1050 product 0x0406 configuration 1 interface 1
261ugenif* at uhub? vendor 0x1050 product 0x0407 configuration 1 interface 2 261ugenif* at uhub? vendor 0x1050 product 0x0407 configuration 1 interface 2
 262
 263# Tigard debug board (FT2232C-based). This line is used in conjunction
 264# with a match quirk in uftdi.c. The "flags 1" is important; normally
 265# ugenif matches with higest priority, but we don't want that for all
 266# FT2232C interfaces, only interfaces that go unclaimed by uftdi (which
 267# is what the match quirk ensures).
 268ugenif* at uhub? vendor 0x0403 product 0x6010 configuration 1 interface 1 flags 1