xref: /openbsd-src/sys/dev/usb/uhub.c (revision 0eea0d082377cb9c3ec583313dc4d52b7b6a4d6d)
1 /*	$OpenBSD: uhub.c,v 1.26 2004/07/11 05:32:38 deraadt Exp $ */
2 /*	$NetBSD: uhub.c,v 1.64 2003/02/08 03:32:51 ichiro Exp $	*/
3 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
4 
5 /*
6  * Copyright (c) 1998 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Lennart Augustsson (lennart@augustsson.net) at
11  * Carlstedt Research & Technology.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  *    must display the following acknowledgement:
23  *        This product includes software developed by the NetBSD
24  *        Foundation, Inc. and its contributors.
25  * 4. Neither the name of The NetBSD Foundation nor the names of its
26  *    contributors may be used to endorse or promote products derived
27  *    from this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 /*
43  * USB spec: http://www.usb.org/developers/docs/usbspec.zip
44  */
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #if defined(__NetBSD__) || defined(__OpenBSD__)
51 #include <sys/device.h>
52 #include <sys/proc.h>
53 #elif defined(__FreeBSD__)
54 #include <sys/module.h>
55 #include <sys/bus.h>
56 #include "bus_if.h"
57 #endif
58 
59 #include <machine/bus.h>
60 
61 #include <dev/usb/usb.h>
62 #include <dev/usb/usbdi.h>
63 #include <dev/usb/usbdi_util.h>
64 #include <dev/usb/usbdivar.h>
65 
66 #define UHUB_INTR_INTERVAL 255	/* ms */
67 
68 #ifdef UHUB_DEBUG
69 #define DPRINTF(x)	do { if (uhubdebug) logprintf x; } while (0)
70 #define DPRINTFN(n,x)	do { if (uhubdebug>(n)) logprintf x; } while (0)
71 int	uhubdebug = 0;
72 #else
73 #define DPRINTF(x)
74 #define DPRINTFN(n,x)
75 #endif
76 
77 struct uhub_softc {
78 	USBBASEDEVICE		sc_dev;		/* base device */
79 	usbd_device_handle	sc_hub;		/* USB device */
80 	usbd_pipe_handle	sc_ipipe;	/* interrupt pipe */
81 	u_int8_t		sc_status[1];	/* XXX more ports */
82 	u_char			sc_running;
83 };
84 
85 Static usbd_status uhub_explore(usbd_device_handle hub);
86 Static void uhub_intr(usbd_xfer_handle, usbd_private_handle,usbd_status);
87 
88 #if defined(__FreeBSD__)
89 Static bus_child_detached_t uhub_child_detached;
90 #endif
91 
92 
93 /*
94  * We need two attachment points:
95  * hub to usb and hub to hub
96  * Every other driver only connects to hubs
97  */
98 
99 #if defined(__NetBSD__) || defined(__OpenBSD__)
100 USB_DECLARE_DRIVER(uhub);
101 
102 #if defined(__NetBSD__)
103 /* Create the driver instance for the hub connected to hub case */
104 CFATTACH_DECL(uhub_uhub, sizeof(struct uhub_softc),
105     uhub_match, uhub_attach, uhub_detach, uhub_activate);
106 #else
107 struct cfattach uhub_uhub_ca = {
108 	sizeof(struct uhub_softc), uhub_match, uhub_attach,
109 	uhub_detach, uhub_activate
110 };
111 #endif
112 #elif defined(__FreeBSD__)
113 USB_DECLARE_DRIVER_INIT(uhub,
114 			DEVMETHOD(bus_child_detached, uhub_child_detached));
115 
116 /* Create the driver instance for the hub connected to usb case. */
117 devclass_t uhubroot_devclass;
118 
119 Static device_method_t uhubroot_methods[] = {
120 	DEVMETHOD(device_probe, uhub_match),
121 	DEVMETHOD(device_attach, uhub_attach),
122 
123 	/* detach is not allowed for a root hub */
124 	{0,0}
125 };
126 
127 Static	driver_t uhubroot_driver = {
128 	"uhub",
129 	uhubroot_methods,
130 	sizeof(struct uhub_softc)
131 };
132 #endif
133 
134 USB_MATCH(uhub)
135 {
136 	USB_MATCH_START(uhub, uaa);
137 	usb_device_descriptor_t *dd = usbd_get_device_descriptor(uaa->device);
138 
139 	DPRINTFN(5,("uhub_match, dd=%p\n", dd));
140 	/*
141 	 * The subclass for hubs seems to be 0 for some and 1 for others,
142 	 * so we just ignore the subclass.
143 	 */
144 	if (uaa->iface == NULL && dd->bDeviceClass == UDCLASS_HUB)
145 		return (UMATCH_DEVCLASS_DEVSUBCLASS);
146 	return (UMATCH_NONE);
147 }
148 
149 USB_ATTACH(uhub)
150 {
151 	USB_ATTACH_START(uhub, sc, uaa);
152 	usbd_device_handle dev = uaa->device;
153 	char devinfo[1024];
154 	usbd_status err;
155 	struct usbd_hub *hub;
156 	usb_device_request_t req;
157 	usb_hub_descriptor_t hubdesc;
158 	int p, port, nports, nremov, pwrdly;
159 	usbd_interface_handle iface;
160 	usb_endpoint_descriptor_t *ed;
161 
162 	DPRINTFN(1,("uhub_attach\n"));
163 	sc->sc_hub = dev;
164 	usbd_devinfo(dev, 1, devinfo, sizeof devinfo);
165 	USB_ATTACH_SETUP;
166 	printf("%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
167 
168 	err = usbd_set_config_index(dev, 0, 1);
169 	if (err) {
170 		DPRINTF(("%s: configuration failed, error=%s\n",
171 			 USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
172 		USB_ATTACH_ERROR_RETURN;
173 	}
174 
175 	if (dev->depth > USB_HUB_MAX_DEPTH) {
176 		printf("%s: hub depth (%d) exceeded, hub ignored\n",
177 		       USBDEVNAME(sc->sc_dev), USB_HUB_MAX_DEPTH);
178 		USB_ATTACH_ERROR_RETURN;
179 	}
180 
181 	/* Get hub descriptor. */
182 	req.bmRequestType = UT_READ_CLASS_DEVICE;
183 	req.bRequest = UR_GET_DESCRIPTOR;
184 	USETW2(req.wValue, UDESC_HUB, 0);
185 	USETW(req.wIndex, 0);
186 	USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE);
187 	DPRINTFN(1,("usb_init_hub: getting hub descriptor\n"));
188 	err = usbd_do_request(dev, &req, &hubdesc);
189 	nports = hubdesc.bNbrPorts;
190 	if (!err && nports > 7) {
191 		USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE + (nports+1) / 8);
192 		err = usbd_do_request(dev, &req, &hubdesc);
193 	}
194 	if (err) {
195 		DPRINTF(("%s: getting hub descriptor failed, error=%s\n",
196 			 USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
197 		USB_ATTACH_ERROR_RETURN;
198 	}
199 
200 	for (nremov = 0, port = 1; port <= nports; port++)
201 		if (!UHD_NOT_REMOV(&hubdesc, port))
202 			nremov++;
203 	printf("%s: %d port%s with %d removable, %s powered\n",
204 	       USBDEVNAME(sc->sc_dev), nports, nports != 1 ? "s" : "",
205 	       nremov, dev->self_powered ? "self" : "bus");
206 
207 	hub = malloc(sizeof(*hub) + (nports-1) * sizeof(struct usbd_port),
208 		     M_USBDEV, M_NOWAIT);
209 	if (hub == NULL)
210 		USB_ATTACH_ERROR_RETURN;
211 	dev->hub = hub;
212 	dev->hub->hubsoftc = sc;
213 	hub->explore = uhub_explore;
214 	hub->hubdesc = hubdesc;
215 
216 	DPRINTFN(1,("usbhub_init_hub: selfpowered=%d, parent=%p, "
217 		    "parent->selfpowered=%d\n",
218 		 dev->self_powered, dev->powersrc->parent,
219 		 dev->powersrc->parent ?
220 		 dev->powersrc->parent->self_powered : 0));
221 
222 	if (!dev->self_powered && dev->powersrc->parent != NULL &&
223 	    !dev->powersrc->parent->self_powered) {
224 		printf("%s: bus powered hub connected to bus powered hub, "
225 		       "ignored\n", USBDEVNAME(sc->sc_dev));
226 		goto bad;
227 	}
228 
229 	/* Set up interrupt pipe. */
230 	err = usbd_device2interface_handle(dev, 0, &iface);
231 	if (err) {
232 		printf("%s: no interface handle\n", USBDEVNAME(sc->sc_dev));
233 		goto bad;
234 	}
235 	ed = usbd_interface2endpoint_descriptor(iface, 0);
236 	if (ed == NULL) {
237 		printf("%s: no endpoint descriptor\n", USBDEVNAME(sc->sc_dev));
238 		goto bad;
239 	}
240 	if ((ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
241 		printf("%s: bad interrupt endpoint\n", USBDEVNAME(sc->sc_dev));
242 		goto bad;
243 	}
244 
245 	err = usbd_open_pipe_intr(iface, ed->bEndpointAddress,
246 		  USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_status,
247 		  sizeof(sc->sc_status), uhub_intr, UHUB_INTR_INTERVAL);
248 	if (err) {
249 		printf("%s: cannot open interrupt pipe\n",
250 		       USBDEVNAME(sc->sc_dev));
251 		goto bad;
252 	}
253 
254 	/* Wait with power off for a while. */
255 	usbd_delay_ms(dev, USB_POWER_DOWN_TIME);
256 
257 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, USBDEV(sc->sc_dev));
258 
259 	/*
260 	 * To have the best chance of success we do things in the exact same
261 	 * order as Windoze98.  This should not be necessary, but some
262 	 * devices do not follow the USB specs to the letter.
263 	 *
264 	 * These are the events on the bus when a hub is attached:
265 	 *  Get device and config descriptors (see attach code)
266 	 *  Get hub descriptor (see above)
267 	 *  For all ports
268 	 *     turn on power
269 	 *     wait for power to become stable
270 	 * (all below happens in explore code)
271 	 *  For all ports
272 	 *     clear C_PORT_CONNECTION
273 	 *  For all ports
274 	 *     get port status
275 	 *     if device connected
276 	 *        wait 100 ms
277 	 *        turn on reset
278 	 *        wait
279 	 *        clear C_PORT_RESET
280 	 *        get port status
281 	 *        proceed with device attachment
282 	 */
283 
284 	/* Set up data structures */
285 	for (p = 0; p < nports; p++) {
286 		struct usbd_port *up = &hub->ports[p];
287 		up->device = 0;
288 		up->parent = dev;
289 		up->portno = p+1;
290 		if (dev->self_powered)
291 			/* Self powered hub, give ports maximum current. */
292 			up->power = USB_MAX_POWER;
293 		else
294 			up->power = USB_MIN_POWER;
295 		up->restartcnt = 0;
296 	}
297 
298 	/* XXX should check for none, individual, or ganged power? */
299 
300 	pwrdly = dev->hub->hubdesc.bPwrOn2PwrGood * UHD_PWRON_FACTOR
301 	    + USB_EXTRA_POWER_UP_TIME;
302 	for (port = 1; port <= nports; port++) {
303 		/* Turn the power on. */
304 		err = usbd_set_port_feature(dev, port, UHF_PORT_POWER);
305 		if (err)
306 			printf("%s: port %d power on failed, %s\n",
307 			       USBDEVNAME(sc->sc_dev), port,
308 			       usbd_errstr(err));
309 		DPRINTF(("usb_init_port: turn on port %d power\n", port));
310 		/* Wait for stable power. */
311 		usbd_delay_ms(dev, pwrdly);
312 	}
313 
314 	/* The usual exploration will finish the setup. */
315 
316 	sc->sc_running = 1;
317 
318 	USB_ATTACH_SUCCESS_RETURN;
319 
320  bad:
321 	free(hub, M_USBDEV);
322 	dev->hub = 0;
323 	USB_ATTACH_ERROR_RETURN;
324 }
325 
326 usbd_status
327 uhub_explore(usbd_device_handle dev)
328 {
329 	usb_hub_descriptor_t *hd = &dev->hub->hubdesc;
330 	struct uhub_softc *sc = dev->hub->hubsoftc;
331 	struct usbd_port *up;
332 	usbd_status err;
333 	int speed;
334 	int port;
335 	int change, status;
336 
337 	DPRINTFN(10, ("uhub_explore dev=%p addr=%d\n", dev, dev->address));
338 
339 	if (!sc->sc_running)
340 		return (USBD_NOT_STARTED);
341 
342 	/* Ignore hubs that are too deep. */
343 	if (dev->depth > USB_HUB_MAX_DEPTH)
344 		return (USBD_TOO_DEEP);
345 
346 	for(port = 1; port <= hd->bNbrPorts; port++) {
347 		up = &dev->hub->ports[port-1];
348 		err = usbd_get_port_status(dev, port, &up->status);
349 		if (err) {
350 			DPRINTF(("uhub_explore: get port status failed, "
351 				 "error=%s\n", usbd_errstr(err)));
352 			continue;
353 		}
354 		status = UGETW(up->status.wPortStatus);
355 		change = UGETW(up->status.wPortChange);
356 		DPRINTFN(3,("uhub_explore: %s port %d status 0x%04x 0x%04x\n",
357 			    USBDEVNAME(sc->sc_dev), port, status, change));
358 		if (change & UPS_C_PORT_ENABLED) {
359 			DPRINTF(("uhub_explore: C_PORT_ENABLED\n"));
360 			usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE);
361 			if (change & UPS_C_CONNECT_STATUS) {
362 				/* Ignore the port error if the device
363 				   vanished. */
364 			} else if (status & UPS_PORT_ENABLED) {
365 				printf("%s: illegal enable change, port %d\n",
366 				       USBDEVNAME(sc->sc_dev), port);
367 			} else {
368 				/* Port error condition. */
369 				if (up->restartcnt) /* no message first time */
370 					printf("%s: port error, restarting "
371 					       "port %d\n",
372 					       USBDEVNAME(sc->sc_dev), port);
373 
374 				if (up->restartcnt++ < USBD_RESTART_MAX)
375 					goto disco;
376 				else
377 					printf("%s: port error, giving up "
378 					       "port %d\n",
379 					       USBDEVNAME(sc->sc_dev), port);
380 			}
381 		}
382 		if (!(change & UPS_C_CONNECT_STATUS)) {
383 			DPRINTFN(3,("uhub_explore: port=%d !C_CONNECT_"
384 				    "STATUS\n", port));
385 			/* No status change, just do recursive explore. */
386 			if (up->device != NULL && up->device->hub != NULL)
387 				up->device->hub->explore(up->device);
388 #if 0 && defined(DIAGNOSTIC)
389 			if (up->device == NULL &&
390 			    (status & UPS_CURRENT_CONNECT_STATUS))
391 				printf("%s: connected, no device\n",
392 				       USBDEVNAME(sc->sc_dev));
393 #endif
394 			continue;
395 		}
396 
397 		/* We have a connect status change, handle it. */
398 
399 		DPRINTF(("uhub_explore: status change hub=%d port=%d\n",
400 			 dev->address, port));
401 		usbd_clear_port_feature(dev, port, UHF_C_PORT_CONNECTION);
402 		/*usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE);*/
403 		/*
404 		 * If there is already a device on the port the change status
405 		 * must mean that is has disconnected.  Looking at the
406 		 * current connect status is not enough to figure this out
407 		 * since a new unit may have been connected before we handle
408 		 * the disconnect.
409 		 */
410 	disco:
411 		if (up->device != NULL) {
412 			/* Disconnected */
413 			DPRINTF(("uhub_explore: device addr=%d disappeared "
414 				 "on port %d\n", up->device->address, port));
415 			usb_disconnect_port(up, USBDEV(sc->sc_dev));
416 			usbd_clear_port_feature(dev, port,
417 						UHF_C_PORT_CONNECTION);
418 		}
419 		if (!(status & UPS_CURRENT_CONNECT_STATUS)) {
420 			/* Nothing connected, just ignore it. */
421 			DPRINTFN(3,("uhub_explore: port=%d !CURRENT_CONNECT"
422 				    "_STATUS\n", port));
423 			continue;
424 		}
425 
426 		/* Connected */
427 
428 		if (!(status & UPS_PORT_POWER))
429 			printf("%s: strange, connected port %d has no power\n",
430 			       USBDEVNAME(sc->sc_dev), port);
431 
432 		/* Wait for maximum device power up time. */
433 		usbd_delay_ms(dev, USB_PORT_POWERUP_DELAY);
434 
435 		/* Reset port, which implies enabling it. */
436 		if (usbd_reset_port(dev, port, &up->status)) {
437 			printf("%s: port %d reset failed\n",
438 			       USBDEVNAME(sc->sc_dev), port);
439 			continue;
440 		}
441 		/* Get port status again, it might have changed during reset */
442 		err = usbd_get_port_status(dev, port, &up->status);
443 		if (err) {
444 			DPRINTF(("uhub_explore: get port status failed, "
445 				 "error=%s\n", usbd_errstr(err)));
446 			continue;
447 		}
448 		status = UGETW(up->status.wPortStatus);
449 		change = UGETW(up->status.wPortChange);
450 		if (!(status & UPS_CURRENT_CONNECT_STATUS)) {
451 			/* Nothing connected, just ignore it. */
452 #ifdef UHUB_DEBUG
453 			printf("%s: port %d, device disappeared after reset\n",
454 			       USBDEVNAME(sc->sc_dev), port);
455 #endif
456 			continue;
457 		}
458 
459 		/* Figure out device speed */
460 		if (status & UPS_HIGH_SPEED)
461 			speed = USB_SPEED_HIGH;
462 		else if (status & UPS_LOW_SPEED)
463 			speed = USB_SPEED_LOW;
464 		else
465 			speed = USB_SPEED_FULL;
466 		/* Get device info and set its address. */
467 		err = usbd_new_device(USBDEV(sc->sc_dev), dev->bus,
468 			  dev->depth + 1, speed, port, up);
469 		/* XXX retry a few times? */
470 		if (err) {
471 			DPRINTFN(-1,("uhub_explore: usb_new_device failed, "
472 				     "error=%s\n", usbd_errstr(err)));
473 			/* Avoid addressing problems by disabling. */
474 			/* usbd_reset_port(dev, port, &up->status); */
475 
476 			/*
477 			 * The unit refused to accept a new address, or had
478 			 * some other serious problem.  Since we cannot leave
479 			 * at 0 we have to disable the port instead.
480 			 */
481 			printf("%s: device problem, disabling port %d\n",
482 			       USBDEVNAME(sc->sc_dev), port);
483 			usbd_clear_port_feature(dev, port, UHF_PORT_ENABLE);
484 		} else {
485 			/* The port set up succeeded, reset error count. */
486 			up->restartcnt = 0;
487 
488 			if (up->device->hub)
489 				up->device->hub->explore(up->device);
490 		}
491 	}
492 	return (USBD_NORMAL_COMPLETION);
493 }
494 
495 #if defined(__NetBSD__) || defined(__OpenBSD__)
496 int
497 uhub_activate(device_ptr_t self, enum devact act)
498 {
499 	struct uhub_softc *sc = (struct uhub_softc *)self;
500 	struct usbd_hub *hub = sc->sc_hub->hub;
501 	usbd_device_handle dev;
502 	int nports, port, i;
503 
504 	switch (act) {
505 	case DVACT_ACTIVATE:
506 		return (EOPNOTSUPP);
507 
508 	case DVACT_DEACTIVATE:
509 		if (hub == NULL) /* malfunctioning hub */
510 			break;
511 		nports = hub->hubdesc.bNbrPorts;
512 		for(port = 0; port < nports; port++) {
513 			dev = hub->ports[port].device;
514 			if (dev != NULL && dev->subdevs != NULL) {
515 				for (i = 0; dev->subdevs[i] != NULL; i++)
516 					config_deactivate(dev->subdevs[i]);
517 			}
518 		}
519 		break;
520 	}
521 	return (0);
522 }
523 #endif
524 
525 /*
526  * Called from process context when the hub is gone.
527  * Detach all devices on active ports.
528  */
529 USB_DETACH(uhub)
530 {
531 	USB_DETACH_START(uhub, sc);
532 	struct usbd_hub *hub = sc->sc_hub->hub;
533 	struct usbd_port *rup;
534 	int port, nports;
535 
536 #if defined(__NetBSD__) || defined(__OpenBSD__)
537 	DPRINTF(("uhub_detach: sc=%p flags=%d\n", sc, flags));
538 #elif defined(__FreeBSD__)
539 	DPRINTF(("uhub_detach: sc=%port\n", sc));
540 #endif
541 
542 	if (hub == NULL)		/* Must be partially working */
543 		return (0);
544 
545 	usbd_abort_pipe(sc->sc_ipipe);
546 	usbd_close_pipe(sc->sc_ipipe);
547 
548 	nports = hub->hubdesc.bNbrPorts;
549 	for(port = 0; port < nports; port++) {
550 		rup = &hub->ports[port];
551 		if (rup->device)
552 			usb_disconnect_port(rup, self);
553 	}
554 
555 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_hub,
556 			   USBDEV(sc->sc_dev));
557 
558 	free(hub, M_USBDEV);
559 	sc->sc_hub->hub = NULL;
560 
561 	return (0);
562 }
563 
564 #if defined(__FreeBSD__)
565 /* Called when a device has been detached from it */
566 Static void
567 uhub_child_detached(device_t self, device_t child)
568 {
569        struct uhub_softc *sc = device_get_softc(self);
570        usbd_device_handle devhub = sc->sc_hub;
571        usbd_device_handle dev;
572        int nports;
573        int port;
574        int i;
575 
576        if (!devhub->hub)
577                /* should never happen; children are only created after init */
578                panic("hub not fully initialised, but child deleted?");
579 
580        nports = devhub->hub->hubdesc.bNbrPorts;
581        for (port = 0; port < nports; port++) {
582                dev = devhub->hub->ports[port].device;
583                if (dev && dev->subdevs) {
584                        for (i = 0; dev->subdevs[i]; i++) {
585                                if (dev->subdevs[i] == child) {
586                                        dev->subdevs[i] = NULL;
587                                        return;
588                                }
589                        }
590                }
591        }
592 }
593 #endif
594 
595 
596 /*
597  * Hub interrupt.
598  * This an indication that some port has changed status.
599  * Notify the bus event handler thread that we need
600  * to be explored again.
601  */
602 void
603 uhub_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
604 {
605 	struct uhub_softc *sc = addr;
606 
607 	DPRINTFN(5,("uhub_intr: sc=%p\n", sc));
608 	if (status == USBD_STALLED)
609 		usbd_clear_endpoint_stall_async(sc->sc_ipipe);
610 	else if (status == USBD_NORMAL_COMPLETION)
611 		usb_needs_explore(sc->sc_hub);
612 }
613 
614 #if defined(__FreeBSD__)
615 DRIVER_MODULE(uhub, usb, uhubroot_driver, uhubroot_devclass, 0, 0);
616 DRIVER_MODULE(uhub, uhub, uhub_driver, uhub_devclass, usbd_driver_load, 0);
617 #endif
618