tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
USB port numbering
Hello
While working with USB code, I noticed the port numbering was
inconsistent: A device would be detected on port 5 during boot, but if I
detached and reattached it with drvctl, the kernel would tell about port
4.
This happens because attaching and reattaching do not go through the
same functions. I can make the port display consistent by the patch
below, but I am not sure it is the right fix. Any advice?
--- sys/dev/usb/uhub.c 27 Sep 2018 14:52:26 -0000 1.136.2.2
+++ sys/dev/usb/uhub.c 18 Oct 2018 00:32:58 -0000
@@ -821,10 +821,10 @@
/* XXXSMP usb */
KERNEL_LOCK(1, curlwp);
nports = hub->uh_hubdesc.bNbrPorts;
- for (port = 0; port < nports; port++) {
- rup = &hub->uh_ports[port];
+ for (port = 1; port <= nports; port++) {
+ rup = &hub->uh_ports[port - 1];
if (rup->up_dev == NULL)
continue;
if ((rc = usb_disconnect_port(rup, self, flags)) != 0) {
/* XXXSMP usb */
@@ -869,12 +869,13 @@
struct usbd_hub *hub = sc->sc_hub->ud_hub;
struct usbd_device *dev;
int port;
- for (port = 0; port < hub->uh_hubdesc.bNbrPorts; port++) {
- dev = hub->uh_ports[port].up_dev;
+ for (port = 1; port <= hub->uh_hubdesc.bNbrPorts; port++) {
+ dev = hub->uh_ports[port - 1].up_dev;
if (dev == NULL)
continue;
+printf("uhub_rescan > usbd_reattach_device port %d\n", port);
usbd_reattach_device(sc->sc_dev, dev, port, locators);
}
return 0;
}
@@ -894,10 +895,10 @@
/* should never happen; children are only created after
init */
panic("hub not fully initialised, but child deleted?");
nports = devhub->ud_hub->uh_hubdesc.bNbrPorts;
- for (port = 0; port < nports; port++) {
- dev = devhub->ud_hub->uh_ports[port].up_dev;
+ for (port = 1; port <= nports; port++) {
+ dev = devhub->ud_hub->uh_ports[port - 1].up_dev;
if (!dev || dev->ud_subdevlen == 0)
continue;
for (i = 0; i < dev->ud_subdevlen; i++) {
if (dev->ud_subdevs[i] == child) {
--
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index