From 4be3a38b028503d4fe2fde825d85b86938d9cff0 Mon Sep 17 00:00:00 2001 From: krw Date: Mon, 2 Oct 2023 23:38:11 +0000 Subject: [PATCH] Add 'host root port' information to hw.ucomnames. usbN.X.Y becomes usbN.Z.X.Y Display the usb string in ucom attach messages so grepping dmesg can be used to find the path to a ucom. More USB cluebats from kettenis@. Deep hub depths testing from drahn@. ok deraadt@ drahn@ kettenis@ --- lib/libc/sys/sysctl.2 | 8 ++++---- sys/dev/usb/ucom.c | 28 ++++++++++++++++++++++------ sys/dev/usb/usb_subr.c | 9 +++++++-- usr.bin/cu/cu.1 | 4 ++-- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/libc/sys/sysctl.2 b/lib/libc/sys/sysctl.2 index fc3ce55dd7d..59935fa0021 100644 --- a/lib/libc/sys/sysctl.2 +++ b/lib/libc/sys/sysctl.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sysctl.2,v 1.54 2023/10/02 05:29:59 jmc Exp $ +.\" $OpenBSD: sysctl.2,v 1.55 2023/10/02 23:38:11 krw Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -403,13 +403,13 @@ A comma-separated list of currently attached devices in the following format: .Pp .Sm off -.D1 Sy ucom Ar N : Sy usb Ar bus.route.interface +.D1 Sy ucom Ar N : Sy usb Ar bus.rootport.route.interface .Sm on .Pp The .Ar route -consists of five hexadecimal digits and identifies the port -containing the +consists of five hexadecimal digits identifying the path from +the root port to the port containing the .Ar interface . .It Dv HW_USERMEM The amount of available non-kernel memory in bytes. diff --git a/sys/dev/usb/ucom.c b/sys/dev/usb/ucom.c index 5cfd5d9613b..7b1fcf43bcc 100644 --- a/sys/dev/usb/ucom.c +++ b/sys/dev/usb/ucom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ucom.c,v 1.76 2023/10/01 15:58:11 krw Exp $ */ +/* $OpenBSD: ucom.c,v 1.77 2023/10/02 23:38:11 krw Exp $ */ /* $NetBSD: ucom.c,v 1.49 2003/01/01 00:10:25 thorpej Exp $ */ /* @@ -75,6 +75,9 @@ int ucomdebug = 0; #define UCOMUNIT(x) (minor(x) & UCOMUNIT_MASK) #define UCOMCUA(x) (minor(x) & UCOMCUA_MASK) +#define ROUTEROOTPORT(_x) ((_x) & 0xff) +#define ROUTESTRING(_x) (((_x) >> 8) & 0xfffff) + struct ucom_softc { struct device sc_dev; /* base device */ @@ -178,13 +181,15 @@ ucom_match(struct device *parent, void *match, void *aux) void ucom_attach(struct device *parent, struct device *self, void *aux) { + char path[32]; /* "usb000.000.00000.000" */ struct ucom_softc *sc = (struct ucom_softc *)self; struct ucom_attach_args *uca = aux; struct tty *tp; + uint32_t route; + uint8_t bus, ifaceno; if (uca->info != NULL) printf(", %s", uca->info); - printf("\n"); sc->sc_uparent = uca->device; sc->sc_iface = uca->iface; @@ -199,6 +204,15 @@ ucom_attach(struct device *parent, struct device *self, void *aux) sc->sc_parent = uca->arg; sc->sc_portno = uca->portno; + if (usbd_get_location(sc->sc_uparent, sc->sc_iface, &bus, &route, + &ifaceno) == 0) { + if (snprintf(path, sizeof(path), "usb%u.%u.%05x.%u", bus, + ROUTEROOTPORT(route), ROUTESTRING(route), ifaceno) < + sizeof(path)) + printf(": %s", path); + } + printf("\n"); + tp = ttymalloc(1000000); tp->t_oproc = ucomstart; tp->t_param = ucomparam; @@ -1237,7 +1251,7 @@ sysctl_ucominit(void) { static char *ucoms = NULL; static size_t ucomslen = 0; - char name[34]; /* sizeof(dv_xname) + strlen(":usb000.00000.000,") */ + char name[64]; /* dv_xname + ":usb000.000.00000.000," */ struct ucom_softc *sc; int rslt; unsigned int unit; @@ -1260,9 +1274,11 @@ sysctl_ucominit(void) if (usbd_get_location(sc->sc_uparent, sc->sc_iface, &bus, &route, &ifaceidx) == -1) continue; - rslt = snprintf(name, sizeof(name), "%s:usb%u.%05x.%u,", - sc->sc_dev.dv_xname, bus, route, ifaceidx); - if (rslt < sizeof(name) && (strlen(ucoms) + rslt) < ucomslen) + rslt = snprintf(name, sizeof(name), + "%s:usb%u.%u.%05x.%u,", sc->sc_dev.dv_xname, bus, + ROUTEROOTPORT(route), ROUTESTRING(route), ifaceidx); + if (rslt < sizeof(name) && (strlen(ucoms) + rslt) < + ucomslen) strlcat(ucoms, name, ucomslen); } } diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index 134b7b077f9..ca8d79cf517 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_subr.c,v 1.160 2023/10/01 15:58:11 krw Exp $ */ +/* $OpenBSD: usb_subr.c,v 1.161 2023/10/02 23:38:11 krw Exp $ */ /* $NetBSD: usb_subr.c,v 1.103 2003/01/10 11:19:13 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -1343,7 +1343,7 @@ usbd_get_routestring(struct usbd_device *dev, uint32_t *route) * section 8.9 of USB 3.1 Specification for more details. */ r = dev->powersrc ? dev->powersrc->portno : 0; - for (hub = dev->myhub; hub && hub->depth; hub = hub->myhub) { + for (hub = dev->myhub; hub && hub->depth > 1; hub = hub->myhub) { port = hub->powersrc ? hub->powersrc->portno : 0; if (port > 15) return -1; @@ -1351,6 +1351,11 @@ usbd_get_routestring(struct usbd_device *dev, uint32_t *route) r |= port; } + /* Add in the host root port, of which there may be 255. */ + port = (hub && hub->powersrc) ? hub->powersrc->portno : 0; + r <<= 8; + r |= port; + *route = r; return 0; } diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1 index c4829cb7c8a..720be2d3ca6 100644 --- a/usr.bin/cu/cu.1 +++ b/usr.bin/cu/cu.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cu.1,v 1.23 2023/10/02 14:48:10 krw Exp $ +.\" $OpenBSD: cu.1,v 1.24 2023/10/02 23:38:11 krw Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -64,7 +64,7 @@ Any of the forms .Pa cua00 , .Pa /dev/cua00 , or -.Pa usb0.1.2 +.Pa usb0.1.00002.3 are permitted. .Pp The default is -- 2.20.1