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