]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/uhub.c
Use uhci_pci_match to return the device description and rework the
[FreeBSD/FreeBSD.git] / sys / dev / usb / uhub.c
1 /*      $NetBSD: uhub.c,v 1.57 2001/11/20 16:08:37 augustss Exp $       */
2 /*      $FreeBSD$       */
3
4 /*
5  * Copyright (c) 1998 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@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/data/usbspec.zip
43  */
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #if defined(__NetBSD__) || defined(__OpenBSD__)
50 #include <sys/device.h>
51 #include <sys/proc.h>
52 #elif defined(__FreeBSD__)
53 #include <sys/module.h>
54 #include <sys/bus.h>
55 #include "bus_if.h"
56 #endif
57 #include <sys/sysctl.h>
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 USB_DEBUG
69 #define DPRINTF(x)      if (uhubdebug) logprintf x
70 #define DPRINTFN(n,x)   if (uhubdebug>(n)) logprintf x
71 int     uhubdebug = 0;
72 SYSCTL_NODE(_hw_usb, OID_AUTO, uhub, CTLFLAG_RW, 0, "USB uhub");
73 SYSCTL_INT(_hw_usb_uhub, OID_AUTO, debug, CTLFLAG_RW,
74            &uhubdebug, 0, "uhub debug level");
75 #else
76 #define DPRINTF(x)
77 #define DPRINTFN(n,x)
78 #endif
79
80 struct uhub_softc {
81         USBBASEDEVICE           sc_dev;         /* base device */
82         usbd_device_handle      sc_hub;         /* USB device */
83         usbd_pipe_handle        sc_ipipe;       /* interrupt pipe */
84         u_int8_t                sc_status[1];   /* XXX more ports */
85         u_char                  sc_running;
86 };
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_driver_added_t uhub_driver_added;
93 Static bus_child_detached_t uhub_child_detached;
94 #endif
95
96
97 /* 
98  * We need two attachment points:
99  * hub to usb and hub to hub
100  * Every other driver only connects to hubs
101  */
102
103 #if defined(__NetBSD__) || defined(__OpenBSD__)
104 USB_DECLARE_DRIVER(uhub);
105
106 /* Create the driver instance for the hub connected to hub case */
107 struct cfattach uhub_uhub_ca = {
108         sizeof(struct uhub_softc), uhub_match, uhub_attach,
109         uhub_detach, uhub_activate
110 };
111 #elif defined(__FreeBSD__)
112 USB_DECLARE_DRIVER_INIT(uhub,
113                         DEVMETHOD(bus_driver_added, uhub_driver_added),
114                         DEVMETHOD(bus_child_detached, uhub_child_detached),
115                         DEVMETHOD(device_suspend, bus_generic_suspend),
116                         DEVMETHOD(device_resume, bus_generic_resume),
117                         DEVMETHOD(device_shutdown, bus_generic_shutdown)
118                         );
119                         
120 /* Create the driver instance for the hub connected to usb case. */
121 devclass_t uhubroot_devclass;
122
123 Static device_method_t uhubroot_methods[] = {
124         DEVMETHOD(device_probe, uhub_match),
125         DEVMETHOD(device_attach, uhub_attach),
126
127         /* detach is not allowed for a root hub */
128         DEVMETHOD(device_suspend, bus_generic_suspend),
129         DEVMETHOD(device_resume, bus_generic_resume),
130         DEVMETHOD(device_shutdown, bus_generic_shutdown),
131         {0,0}
132 };
133
134 Static  driver_t uhubroot_driver = {
135         "uhub",
136         uhubroot_methods,
137         sizeof(struct uhub_softc)
138 };
139 #endif
140
141 USB_MATCH(uhub)
142 {
143         USB_MATCH_START(uhub, uaa);
144         usb_device_descriptor_t *dd = usbd_get_device_descriptor(uaa->device);
145         
146         DPRINTFN(5,("uhub_match, dd=%p\n", dd));
147         /* 
148          * The subclass for hubs seems to be 0 for some and 1 for others,
149          * so we just ignore the subclass.
150          */
151         if (uaa->iface == NULL && dd->bDeviceClass == UDCLASS_HUB)
152                 return (UMATCH_DEVCLASS_DEVSUBCLASS);
153         return (UMATCH_NONE);
154 }
155
156 USB_ATTACH(uhub)
157 {
158         USB_ATTACH_START(uhub, sc, uaa);
159         usbd_device_handle dev = uaa->device;
160         char *devinfo;
161         usbd_status err;
162         struct usbd_hub *hub;
163         usb_device_request_t req;
164         usb_hub_descriptor_t hubdesc;
165         int p, port, nports, nremov, pwrdly;
166         usbd_interface_handle iface;
167         usb_endpoint_descriptor_t *ed;
168         
169         devinfo = malloc(1024, M_TEMP, M_NOWAIT);
170         if (devinfo == NULL) {
171                 USB_ATTACH_ERROR_RETURN;
172         }
173         DPRINTFN(1,("uhub_attach\n"));
174         sc->sc_hub = dev;
175         usbd_devinfo(dev, 1, devinfo);
176         USB_ATTACH_SETUP;
177         printf("%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
178
179         err = usbd_set_config_index(dev, 0, 1);
180         if (err) {
181                 DPRINTF(("%s: configuration failed, error=%s\n",
182                          USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
183                 free(devinfo, M_TEMP);
184                 USB_ATTACH_ERROR_RETURN;
185         }
186
187         if (dev->depth > USB_HUB_MAX_DEPTH) {
188                 printf("%s: hub depth (%d) exceeded, hub ignored\n",
189                        USBDEVNAME(sc->sc_dev), USB_HUB_MAX_DEPTH);
190                 free(devinfo, M_TEMP);
191                 USB_ATTACH_ERROR_RETURN;
192         }
193
194         /* Get hub descriptor. */
195         req.bmRequestType = UT_READ_CLASS_DEVICE;
196         req.bRequest = UR_GET_DESCRIPTOR;
197         USETW(req.wValue, 0);
198         USETW(req.wIndex, 0);
199         USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE);
200         DPRINTFN(1,("usb_init_hub: getting hub descriptor\n"));
201         err = usbd_do_request(dev, &req, &hubdesc);
202         nports = hubdesc.bNbrPorts;
203         if (!err && nports > 7) {
204                 USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE + (nports+1) / 8);
205                 err = usbd_do_request(dev, &req, &hubdesc);
206         }
207         if (err) {
208                 DPRINTF(("%s: getting hub descriptor failed, error=%s\n",
209                          USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
210                 free(devinfo, M_TEMP);
211                 USB_ATTACH_ERROR_RETURN;
212         }
213
214         for (nremov = 0, port = 1; port <= nports; port++)
215                 if (!UHD_NOT_REMOV(&hubdesc, port))
216                         nremov++;
217         printf("%s: %d port%s with %d removable, %s powered\n",
218                USBDEVNAME(sc->sc_dev), nports, nports != 1 ? "s" : "",
219                nremov, dev->self_powered ? "self" : "bus");
220
221         hub = malloc(sizeof(*hub) + (nports-1) * sizeof(struct usbd_port),
222                      M_USBDEV, M_NOWAIT);
223         if (hub == NULL) {
224                 free(devinfo, M_TEMP);
225                 USB_ATTACH_ERROR_RETURN;
226         }
227         dev->hub = hub;
228         dev->hub->hubsoftc = sc;
229         hub->explore = uhub_explore;
230         hub->hubdesc = hubdesc;
231         
232         DPRINTFN(1,("usbhub_init_hub: selfpowered=%d, parent=%p, "
233                     "parent->selfpowered=%d\n",
234                  dev->self_powered, dev->powersrc->parent,
235                  dev->powersrc->parent ? 
236                  dev->powersrc->parent->self_powered : 0));
237
238         if (!dev->self_powered && dev->powersrc->parent != NULL &&
239             !dev->powersrc->parent->self_powered) {
240                 printf("%s: bus powered hub connected to bus powered hub, "
241                        "ignored\n", USBDEVNAME(sc->sc_dev));
242                 goto bad;
243         }
244
245         /* Set up interrupt pipe. */
246         err = usbd_device2interface_handle(dev, 0, &iface);
247         if (err) {
248                 printf("%s: no interface handle\n", USBDEVNAME(sc->sc_dev));
249                 goto bad;
250         }
251         ed = usbd_interface2endpoint_descriptor(iface, 0);
252         if (ed == NULL) {
253                 printf("%s: no endpoint descriptor\n", USBDEVNAME(sc->sc_dev));
254                 goto bad;
255         }
256         if ((ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
257                 printf("%s: bad interrupt endpoint\n", USBDEVNAME(sc->sc_dev));
258                 goto bad;
259         }
260
261         err = usbd_open_pipe_intr(iface, ed->bEndpointAddress,
262                   USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_status, 
263                   sizeof(sc->sc_status), uhub_intr, UHUB_INTR_INTERVAL);
264         if (err) {
265                 printf("%s: cannot open interrupt pipe\n", 
266                        USBDEVNAME(sc->sc_dev));
267                 goto bad;
268         }
269
270         /* Wait with power off for a while. */
271         usbd_delay_ms(dev, USB_POWER_DOWN_TIME);
272
273         usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, USBDEV(sc->sc_dev));
274
275         /*
276          * To have the best chance of success we do things in the exact same
277          * order as Windoze98.  This should not be necessary, but some
278          * devices do not follow the USB specs to the letter.
279          *
280          * These are the events on the bus when a hub is attached:
281          *  Get device and config descriptors (see attach code)
282          *  Get hub descriptor (see above)
283          *  For all ports
284          *     turn on power
285          *     wait for power to become stable
286          * (all below happens in explore code)
287          *  For all ports
288          *     clear C_PORT_CONNECTION
289          *  For all ports
290          *     get port status
291          *     if device connected
292          *        wait 100 ms
293          *        turn on reset
294          *        wait
295          *        clear C_PORT_RESET
296          *        get port status
297          *        proceed with device attachment
298          */
299
300         /* Set up data structures */
301         for (p = 0; p < nports; p++) {
302                 struct usbd_port *up = &hub->ports[p];
303                 up->device = 0;
304                 up->parent = dev;
305                 up->portno = p+1;
306                 if (dev->self_powered)
307                         /* Self powered hub, give ports maximum current. */
308                         up->power = USB_MAX_POWER;
309                 else
310                         up->power = USB_MIN_POWER;
311         }
312
313         /* XXX should check for none, individual, or ganged power? */
314
315         pwrdly = dev->hub->hubdesc.bPwrOn2PwrGood * UHD_PWRON_FACTOR
316             + USB_EXTRA_POWER_UP_TIME;
317         for (port = 1; port <= nports; port++) {
318                 /* Turn the power on. */
319                 err = usbd_set_port_feature(dev, port, UHF_PORT_POWER);
320                 if (err)
321                         printf("%s: port %d power on failed, %s\n", 
322                                USBDEVNAME(sc->sc_dev), port,
323                                usbd_errstr(err));
324                 DPRINTF(("usb_init_port: turn on port %d power\n", port));
325                 /* Wait for stable power. */
326                 usbd_delay_ms(dev, pwrdly);
327         }
328
329         /* The usual exploration will finish the setup. */
330
331         sc->sc_running = 1;
332
333         USB_ATTACH_SUCCESS_RETURN;
334
335  bad:
336         free(hub, M_USBDEV);
337         free(devinfo, M_TEMP);
338         dev->hub = 0;
339         USB_ATTACH_ERROR_RETURN;
340 }
341
342 usbd_status
343 uhub_explore(usbd_device_handle dev)
344 {
345         usb_hub_descriptor_t *hd = &dev->hub->hubdesc;
346         struct uhub_softc *sc = dev->hub->hubsoftc;
347         struct usbd_port *up;
348         usbd_status err;
349         int speed;
350         int port;
351         int change, status;
352
353         DPRINTFN(10, ("uhub_explore dev=%p addr=%d\n", dev, dev->address));
354
355         if (!sc->sc_running)
356                 return (USBD_NOT_STARTED);
357
358         /* Ignore hubs that are too deep. */
359         if (dev->depth > USB_HUB_MAX_DEPTH)
360                 return (USBD_TOO_DEEP);
361
362         for(port = 1; port <= hd->bNbrPorts; port++) {
363                 up = &dev->hub->ports[port-1];
364                 err = usbd_get_port_status(dev, port, &up->status);
365                 if (err) {
366                         DPRINTF(("uhub_explore: get port status failed, "
367                                  "error=%s\n", usbd_errstr(err)));
368                         continue;
369                 }
370                 status = UGETW(up->status.wPortStatus);
371                 change = UGETW(up->status.wPortChange);
372                 DPRINTFN(3,("uhub_explore: %s port %d status 0x%04x 0x%04x\n",
373                             USBDEVNAME(sc->sc_dev), port, status, change));
374                 if (change & UPS_C_PORT_ENABLED) {
375                         DPRINTF(("uhub_explore: C_PORT_ENABLED\n"));
376                         usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE);
377                         if (status & UPS_PORT_ENABLED) {
378                                 printf("%s: illegal enable change, port %d\n",
379                                        USBDEVNAME(sc->sc_dev), port);
380                         } else {
381                                 /* Port error condition. */
382                                 if (up->restartcnt) /* no message first time */
383                                         printf("%s: port error, restarting "
384                                                "port %d\n",
385                                                USBDEVNAME(sc->sc_dev), port);
386
387                                 if (up->restartcnt++ < USBD_RESTART_MAX)
388                                         goto disco;
389                                 else
390                                         printf("%s: port error, giving up "
391                                                "port %d\n",
392                                                USBDEVNAME(sc->sc_dev), port);
393                         }
394                 }
395                 if (!(change & UPS_C_CONNECT_STATUS)) {
396                         DPRINTFN(3,("uhub_explore: port=%d !C_CONNECT_"
397                                     "STATUS\n", port));
398                         /* No status change, just do recursive explore. */
399                         if (up->device != NULL && up->device->hub != NULL)
400                                 up->device->hub->explore(up->device);
401 #if 0 && defined(DIAGNOSTIC)
402                         if (up->device == NULL && 
403                             (status & UPS_CURRENT_CONNECT_STATUS))
404                                 printf("%s: connected, no device\n",
405                                        USBDEVNAME(sc->sc_dev));
406 #endif
407                         continue;
408                 }
409
410                 /* We have a connect status change, handle it. */
411
412                 DPRINTF(("uhub_explore: status change hub=%d port=%d\n",
413                          dev->address, port));
414                 usbd_clear_port_feature(dev, port, UHF_C_PORT_CONNECTION);
415                 /*usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE);*/
416                 /*
417                  * If there is already a device on the port the change status
418                  * must mean that is has disconnected.  Looking at the
419                  * current connect status is not enough to figure this out
420                  * since a new unit may have been connected before we handle
421                  * the disconnect.
422                  */
423         disco:
424                 if (up->device != NULL) {
425                         /* Disconnected */
426                         DPRINTF(("uhub_explore: device addr=%d disappeared "
427                                  "on port %d\n", up->device->address, port));
428                         usb_disconnect_port(up, USBDEV(sc->sc_dev));
429                         usbd_clear_port_feature(dev, port, 
430                                                 UHF_C_PORT_CONNECTION);
431                 }
432                 if (!(status & UPS_CURRENT_CONNECT_STATUS)) {
433                         /* Nothing connected, just ignore it. */
434                         DPRINTFN(3,("uhub_explore: port=%d !CURRENT_CONNECT"
435                                     "_STATUS\n", port));
436                         continue;
437                 }
438
439                 /* Connected */
440
441                 if (!(status & UPS_PORT_POWER))
442                         printf("%s: strange, connected port %d has no power\n",
443                                USBDEVNAME(sc->sc_dev), port);
444
445                 /* Wait for maximum device power up time. */
446                 usbd_delay_ms(dev, USB_PORT_POWERUP_DELAY);
447
448                 /* Reset port, which implies enabling it. */
449                 if (usbd_reset_port(dev, port, &up->status)) {
450                         printf("%s: port %d reset failed\n",
451                                USBDEVNAME(sc->sc_dev), port);
452                         continue;
453                 }
454                 /* Get port status again, it might have changed during reset */
455                 err = usbd_get_port_status(dev, port, &up->status);
456                 if (err) {
457                         DPRINTF(("uhub_explore: get port status failed, "
458                                  "error=%s\n", usbd_errstr(err)));
459                         continue;
460                 }
461                 status = UGETW(up->status.wPortStatus);
462                 change = UGETW(up->status.wPortChange);
463                 if (!(status & UPS_CURRENT_CONNECT_STATUS)) {
464                         /* Nothing connected, just ignore it. */
465 #ifdef DIAGNOSTIC
466                         printf("%s: port %d, device disappeared after reset\n",
467                                USBDEVNAME(sc->sc_dev), port);
468 #endif
469                         continue;
470                 }
471
472                 /* Figure out device speed */
473                 if (status & UPS_HIGH_SPEED)
474                         speed = USB_SPEED_HIGH;
475                 else if (status & UPS_LOW_SPEED)
476                         speed = USB_SPEED_LOW;
477                 else
478                         speed = USB_SPEED_FULL;
479                 /* Get device info and set its address. */
480                 err = usbd_new_device(USBDEV(sc->sc_dev), dev->bus, 
481                     dev->depth + 1, speed, port, up);
482                 /* XXX retry a few times? */
483                 if (err) {
484                         DPRINTFN(-1,("uhub_explore: usb_new_device failed, "
485                                      "error=%s\n", usbd_errstr(err)));
486                         /* Avoid addressing problems by disabling. */
487                         /* usbd_reset_port(dev, port, &up->status); */
488
489                         /* 
490                          * The unit refused to accept a new address, or had
491                          * some other serious problem.  Since we cannot leave
492                          * at 0 we have to disable the port instead.
493                          */
494                         printf("%s: device problem, disabling port %d\n",
495                                USBDEVNAME(sc->sc_dev), port);
496                         usbd_clear_port_feature(dev, port, UHF_PORT_ENABLE);
497                 } else {
498                         /* The port set up succeeded, reset error count. */
499                         up->restartcnt = 0;
500
501                         if (up->device->hub)
502                                 up->device->hub->explore(up->device);
503                 }
504         }
505         return (USBD_NORMAL_COMPLETION);
506 }
507
508 #if defined(__NetBSD__) || defined(__OpenBSD__)
509 int
510 uhub_activate(device_ptr_t self, enum devact act)
511 {
512         struct uhub_softc *sc = (struct uhub_softc *)self;
513         struct usbd_hub *hub = sc->sc_hub->hub;
514         usbd_device_handle dev;
515         int nports, port, i;
516
517         switch (act) {
518         case DVACT_ACTIVATE:
519                 return (EOPNOTSUPP);
520                 break;
521
522         case DVACT_DEACTIVATE:
523                 if (hub == NULL) /* malfunctioning hub */
524                         break;
525                 nports = hub->hubdesc.bNbrPorts;
526                 for(port = 0; port < nports; port++) {
527                         dev = hub->ports[port].device;
528                         if (dev != NULL && dev->subdevs != NULL) {
529                                 for (i = 0; dev->subdevs[i] != NULL; i++)
530                                         config_deactivate(dev->subdevs[i]);
531                         }
532                 }
533                 break;
534         }
535         return (0);
536 }
537 #endif
538
539 /*
540  * Called from process context when the hub is gone.
541  * Detach all devices on active ports.
542  */
543 USB_DETACH(uhub)
544 {
545         USB_DETACH_START(uhub, sc);
546         struct usbd_hub *hub = sc->sc_hub->hub;
547         struct usbd_port *rup;
548         int port, nports;
549
550 #if defined(__NetBSD__) || defined(__OpenBSD__)
551         DPRINTF(("uhub_detach: sc=%p flags=%d\n", sc, flags));
552 #elif defined(__FreeBSD__)
553         DPRINTF(("uhub_detach: sc=%port\n", sc));
554 #endif
555
556         if (hub == NULL)                /* Must be partially working */
557                 return (0);
558
559         usbd_abort_pipe(sc->sc_ipipe);
560         usbd_close_pipe(sc->sc_ipipe);
561
562         nports = hub->hubdesc.bNbrPorts;
563         for(port = 0; port < nports; port++) {
564                 rup = &hub->ports[port];
565                 if (rup->device)
566                         usb_disconnect_port(rup, self);
567         }
568
569         usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_hub,
570                            USBDEV(sc->sc_dev));
571
572         free(hub, M_USBDEV);
573         sc->sc_hub->hub = NULL;
574
575         return (0);
576 }
577
578 #if defined(__FreeBSD__)
579 /* Called when a device has been detached from it */
580 Static void
581 uhub_child_detached(device_t self, device_t child)
582 {
583        struct uhub_softc *sc = device_get_softc(self);
584        usbd_device_handle devhub = sc->sc_hub;
585        usbd_device_handle dev;
586        int nports;
587        int port;
588        int i;
589
590        if (!devhub->hub)  
591                /* should never happen; children are only created after init */
592                panic("hub not fully initialised, but child deleted?");
593
594        nports = devhub->hub->hubdesc.bNbrPorts;
595        for (port = 0; port < nports; port++) {
596                dev = devhub->hub->ports[port].device;
597                if (dev && dev->subdevs) {
598                        for (i = 0; dev->subdevs[i]; i++) {
599                                if (dev->subdevs[i] == child) {
600                                        dev->subdevs[i] = NULL;
601                                        return;
602                                }
603                        }
604                }
605        }
606 }
607
608 Static void
609 uhub_driver_added(device_t _dev, driver_t *_driver)
610 {
611         /* Don't do anything, as reprobing does not work currently. We should
612          * really call through to usbd_new_device or a function along those
613          * lines that reinitialises the device if it is not owned by any
614          * driver. But this is complicated. Manual replugging by the user is
615          * easier.
616          */
617
618          ;
619 }
620 #endif
621
622
623 /*
624  * Hub interrupt.
625  * This an indication that some port has changed status.
626  * Notify the bus event handler thread that we need
627  * to be explored again.
628  */
629 void
630 uhub_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
631 {
632         struct uhub_softc *sc = addr;
633
634         DPRINTFN(5,("uhub_intr: sc=%p\n", sc));
635         if (status == USBD_STALLED)
636                 usbd_clear_endpoint_stall_async(sc->sc_ipipe);
637         else if (status == USBD_NORMAL_COMPLETION)
638                 usb_needs_explore(sc->sc_hub);
639 }
640
641 #if defined(__FreeBSD__)
642 DRIVER_MODULE(uhub, usb, uhubroot_driver, uhubroot_devclass, 0, 0);
643 DRIVER_MODULE(uhub, uhub, uhub_driver, uhub_devclass, usbd_driver_load, 0);
644 #endif