2010-02-03 02:18:49 +03:00
|
|
|
/* $NetBSD: uhub.c,v 1.109 2010/02/02 23:18:49 pooka Exp $ */
|
1999-11-19 02:32:25 +03:00
|
|
|
/* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
/*
|
2005-03-02 14:37:27 +03:00
|
|
|
* Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
|
1998-07-12 23:51:55 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-11-26 01:32:04 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-04-27 19:26:44 +04:00
|
|
|
* by Lennart Augustsson (lennart@augustsson.net) at
|
1998-11-26 01:32:04 +03:00
|
|
|
* Carlstedt Research & Technology.
|
1998-07-12 23:51:55 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1999-01-10 14:13:36 +03:00
|
|
|
/*
|
2003-02-08 06:32:50 +03:00
|
|
|
* USB spec: http://www.usb.org/developers/docs/usbspec.zip
|
1999-01-10 14:13:36 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 09:24:53 +03:00
|
|
|
#include <sys/cdefs.h>
|
2010-02-03 02:18:49 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.109 2010/02/02 23:18:49 pooka Exp $");
|
2001-11-13 09:24:53 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/device.h>
|
1999-11-19 02:32:25 +03:00
|
|
|
#include <sys/proc.h>
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
1999-09-13 23:18:17 +04:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
|
|
|
#include <dev/usb/usbdivar.h>
|
|
|
|
|
1999-10-13 12:10:55 +04:00
|
|
|
#ifdef UHUB_DEBUG
|
1999-11-25 02:13:19 +03:00
|
|
|
#define DPRINTF(x) if (uhubdebug) logprintf x
|
|
|
|
#define DPRINTFN(n,x) if (uhubdebug>(n)) logprintf x
|
2003-01-02 06:20:09 +03:00
|
|
|
int uhubdebug = 0;
|
1998-07-12 23:51:55 +04:00
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct uhub_softc {
|
1999-09-05 23:32:18 +04:00
|
|
|
USBBASEDEVICE sc_dev; /* base device */
|
1998-12-26 15:53:00 +03:00
|
|
|
usbd_device_handle sc_hub; /* USB device */
|
Introduce different autoconf interface attributes for USB drivers
matching (and handling) a whole device and those which match an
interface only. This will allow to enforce some rules, eg that
the former don't use interface information for matching or that the
latter don't modify global device state.
The previous way left too much freedom do the drivers which led to
inconsistencies and abuse.
For now, I've not changed locators and submatch rules, this will
happen later.
There should not be any change in behaviour, except in the case of
some drivers which did behave inconsistently:
if_atu, if_axe, uep: matched the configured device in the interface
stage, but did configuration again. I've converted them to match
in the device stage.
ustir, utoppy: matched in the interface stage, but only against
vendor/device information, and used any configuration/interface
without checking. Changed to match in device stage, and added
some simple code to configure and use the first interface.
If you have one of those devices, please test!
2007-03-13 16:51:53 +03:00
|
|
|
int sc_proto; /* device protocol */
|
1998-12-26 15:53:00 +03:00
|
|
|
usbd_pipe_handle sc_ipipe; /* interrupt pipe */
|
2007-03-15 18:29:09 +03:00
|
|
|
|
|
|
|
/* XXX second buffer needed because we can't suspend pipes yet */
|
|
|
|
u_int8_t *sc_statusbuf;
|
2007-01-07 19:50:02 +03:00
|
|
|
u_int8_t *sc_status;
|
2007-03-15 18:29:09 +03:00
|
|
|
size_t sc_statuslen;
|
|
|
|
int sc_explorepending;
|
2008-06-16 14:37:54 +04:00
|
|
|
int sc_isehciroothub; /* see comment in uhub_intr() */
|
2007-03-15 18:29:09 +03:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
u_char sc_running;
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
2007-03-15 18:29:09 +03:00
|
|
|
|
Introduce different autoconf interface attributes for USB drivers
matching (and handling) a whole device and those which match an
interface only. This will allow to enforce some rules, eg that
the former don't use interface information for matching or that the
latter don't modify global device state.
The previous way left too much freedom do the drivers which led to
inconsistencies and abuse.
For now, I've not changed locators and submatch rules, this will
happen later.
There should not be any change in behaviour, except in the case of
some drivers which did behave inconsistently:
if_atu, if_axe, uep: matched the configured device in the interface
stage, but did configuration again. I've converted them to match
in the device stage.
ustir, utoppy: matched in the interface stage, but only against
vendor/device information, and used any configuration/interface
without checking. Changed to match in device stage, and added
some simple code to configure and use the first interface.
If you have one of those devices, please test!
2007-03-13 16:51:53 +03:00
|
|
|
#define UHUB_IS_HIGH_SPEED(sc) ((sc)->sc_proto != UDPROTO_FSHUB)
|
|
|
|
#define UHUB_IS_SINGLE_TT(sc) ((sc)->sc_proto == UDPROTO_HSHUBSTT)
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2007-03-15 18:29:09 +03:00
|
|
|
#define PORTSTAT_ISSET(sc, port) \
|
|
|
|
((sc)->sc_status[(port) / 8] & (1 << ((port) % 8)))
|
|
|
|
|
2000-06-01 18:28:57 +04:00
|
|
|
Static usbd_status uhub_explore(usbd_device_handle hub);
|
|
|
|
Static void uhub_intr(usbd_xfer_handle, usbd_private_handle,usbd_status);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-10-13 12:10:55 +04:00
|
|
|
|
2002-07-12 01:14:24 +04:00
|
|
|
/*
|
1999-10-13 12:10:55 +04:00
|
|
|
* We need two attachment points:
|
|
|
|
* hub to usb and hub to hub
|
|
|
|
* Every other driver only connects to hubs
|
|
|
|
*/
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2008-05-24 20:40:58 +04:00
|
|
|
int uhub_match(device_t, cfdata_t, void *);
|
2008-02-18 08:24:24 +03:00
|
|
|
void uhub_attach(device_t, device_t, void *);
|
2008-08-18 22:03:21 +04:00
|
|
|
int uhub_rescan(device_t, const char *, const int *);
|
2008-02-18 08:24:24 +03:00
|
|
|
void uhub_childdet(device_t, device_t);
|
|
|
|
int uhub_detach(device_t, int);
|
|
|
|
extern struct cfdriver uhub_cd;
|
2009-04-07 22:15:45 +04:00
|
|
|
CFATTACH_DECL3_NEW(uhub, sizeof(struct uhub_softc), uhub_match,
|
2009-11-12 23:11:35 +03:00
|
|
|
uhub_attach, uhub_detach, NULL, uhub_rescan, uhub_childdet,
|
2009-04-07 22:15:45 +04:00
|
|
|
DVF_DETACH_SHUTDOWN);
|
2008-05-26 01:41:35 +04:00
|
|
|
CFATTACH_DECL2_NEW(uroothub, sizeof(struct uhub_softc), uhub_match,
|
2009-11-12 23:11:35 +03:00
|
|
|
uhub_attach, uhub_detach, NULL, uhub_rescan, uhub_childdet);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2010-02-03 02:18:49 +03:00
|
|
|
/*
|
|
|
|
* Setting this to 1 makes sure than an uhub attaches even at higher
|
|
|
|
* priority than ugen when ugen_override is set to 1. This allows to
|
|
|
|
* probe the whole USB bus and attach functions with ugen.
|
|
|
|
*/
|
|
|
|
int uhub_ubermatch = 0;
|
|
|
|
|
2009-09-04 00:54:03 +04:00
|
|
|
int
|
|
|
|
uhub_match(device_t parent, cfdata_t match, void *aux)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2009-09-04 22:14:41 +04:00
|
|
|
struct usb_attach_arg *uaa = aux;
|
2010-02-03 02:18:49 +03:00
|
|
|
int matchvalue;
|
|
|
|
|
|
|
|
if (uhub_ubermatch)
|
|
|
|
matchvalue = UMATCH_HIGHEST+1;
|
|
|
|
else
|
|
|
|
matchvalue = UMATCH_DEVCLASS_DEVSUBCLASS;
|
2002-07-12 01:14:24 +04:00
|
|
|
|
2007-03-19 17:02:56 +03:00
|
|
|
DPRINTFN(5,("uhub_match, uaa=%p\n", uaa));
|
2002-07-12 01:14:24 +04:00
|
|
|
/*
|
1998-07-12 23:51:55 +04:00
|
|
|
* The subclass for hubs seems to be 0 for some and 1 for others,
|
|
|
|
* so we just ignore the subclass.
|
|
|
|
*/
|
Introduce different autoconf interface attributes for USB drivers
matching (and handling) a whole device and those which match an
interface only. This will allow to enforce some rules, eg that
the former don't use interface information for matching or that the
latter don't modify global device state.
The previous way left too much freedom do the drivers which led to
inconsistencies and abuse.
For now, I've not changed locators and submatch rules, this will
happen later.
There should not be any change in behaviour, except in the case of
some drivers which did behave inconsistently:
if_atu, if_axe, uep: matched the configured device in the interface
stage, but did configuration again. I've converted them to match
in the device stage.
ustir, utoppy: matched in the interface stage, but only against
vendor/device information, and used any configuration/interface
without checking. Changed to match in device stage, and added
some simple code to configure and use the first interface.
If you have one of those devices, please test!
2007-03-13 16:51:53 +03:00
|
|
|
if (uaa->class == UDCLASS_HUB)
|
2010-02-03 02:18:49 +03:00
|
|
|
return (matchvalue);
|
1998-07-12 23:51:55 +04:00
|
|
|
return (UMATCH_NONE);
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:54:03 +04:00
|
|
|
void
|
|
|
|
uhub_attach(device_t parent, device_t self, void *aux)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2009-09-04 22:14:41 +04:00
|
|
|
struct uhub_softc *sc = device_private(self);
|
|
|
|
struct usb_attach_arg *uaa = aux;
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_device_handle dev = uaa->device;
|
2005-05-11 14:02:28 +04:00
|
|
|
char *devinfop;
|
1999-11-12 03:34:57 +03:00
|
|
|
usbd_status err;
|
2004-10-23 20:17:56 +04:00
|
|
|
struct usbd_hub *hub = NULL;
|
1998-07-12 23:51:55 +04:00
|
|
|
usb_device_request_t req;
|
|
|
|
usb_hub_descriptor_t hubdesc;
|
2000-04-21 20:05:50 +04:00
|
|
|
int p, port, nports, nremov, pwrdly;
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_interface_handle iface;
|
|
|
|
usb_endpoint_descriptor_t *ed;
|
2006-12-01 23:48:50 +03:00
|
|
|
#if 0 /* notyet */
|
2004-10-23 20:17:56 +04:00
|
|
|
struct usbd_tt *tts = NULL;
|
2006-12-01 23:48:50 +03:00
|
|
|
#endif
|
2002-07-12 01:14:24 +04:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
DPRINTFN(1,("uhub_attach\n"));
|
2008-05-24 20:40:58 +04:00
|
|
|
sc->sc_dev = self;
|
1998-07-12 23:51:55 +04:00
|
|
|
sc->sc_hub = dev;
|
Introduce different autoconf interface attributes for USB drivers
matching (and handling) a whole device and those which match an
interface only. This will allow to enforce some rules, eg that
the former don't use interface information for matching or that the
latter don't modify global device state.
The previous way left too much freedom do the drivers which led to
inconsistencies and abuse.
For now, I've not changed locators and submatch rules, this will
happen later.
There should not be any change in behaviour, except in the case of
some drivers which did behave inconsistently:
if_atu, if_axe, uep: matched the configured device in the interface
stage, but did configuration again. I've converted them to match
in the device stage.
ustir, utoppy: matched in the interface stage, but only against
vendor/device information, and used any configuration/interface
without checking. Changed to match in device stage, and added
some simple code to configure and use the first interface.
If you have one of those devices, please test!
2007-03-13 16:51:53 +03:00
|
|
|
sc->sc_proto = uaa->proto;
|
2005-05-11 14:02:28 +04:00
|
|
|
|
|
|
|
devinfop = usbd_devinfo_alloc(dev, 1);
|
2008-04-22 03:31:18 +04:00
|
|
|
aprint_naive("\n");
|
|
|
|
aprint_normal(": %s\n", devinfop);
|
2005-05-11 14:02:28 +04:00
|
|
|
usbd_devinfo_free(devinfop);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2005-05-01 00:54:13 +04:00
|
|
|
if (dev->depth > 0 && UHUB_IS_HIGH_SPEED(sc)) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_normal_dev(self, "%s transaction translator%s\n",
|
2004-10-23 20:17:56 +04:00
|
|
|
UHUB_IS_SINGLE_TT(sc) ? "single" : "multiple",
|
|
|
|
UHUB_IS_SINGLE_TT(sc) ? "" : "s");
|
2004-10-22 16:03:21 +04:00
|
|
|
}
|
|
|
|
|
1999-11-12 03:34:57 +03:00
|
|
|
err = usbd_set_config_index(dev, 0, 1);
|
|
|
|
if (err) {
|
1999-08-19 23:51:36 +04:00
|
|
|
DPRINTF(("%s: configuration failed, error=%s\n",
|
2009-09-04 00:54:03 +04:00
|
|
|
device_xname(sc->sc_dev), usbd_errstr(err)));
|
2009-09-04 22:14:41 +04:00
|
|
|
return;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->depth > USB_HUB_MAX_DEPTH) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"hub depth (%d) exceeded, hub ignored\n",
|
|
|
|
USB_HUB_MAX_DEPTH);
|
2009-09-04 22:14:41 +04:00
|
|
|
return;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get hub descriptor. */
|
|
|
|
req.bmRequestType = UT_READ_CLASS_DEVICE;
|
|
|
|
req.bRequest = UR_GET_DESCRIPTOR;
|
2003-12-29 11:17:10 +03:00
|
|
|
USETW2(req.wValue, UDESC_HUB, 0);
|
1998-07-12 23:51:55 +04:00
|
|
|
USETW(req.wIndex, 0);
|
|
|
|
USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE);
|
|
|
|
DPRINTFN(1,("usb_init_hub: getting hub descriptor\n"));
|
1999-11-12 03:34:57 +03:00
|
|
|
err = usbd_do_request(dev, &req, &hubdesc);
|
1998-12-26 15:53:00 +03:00
|
|
|
nports = hubdesc.bNbrPorts;
|
1999-11-12 03:34:57 +03:00
|
|
|
if (!err && nports > 7) {
|
1998-12-26 15:53:00 +03:00
|
|
|
USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE + (nports+1) / 8);
|
1999-11-12 03:34:57 +03:00
|
|
|
err = usbd_do_request(dev, &req, &hubdesc);
|
1998-12-26 15:53:00 +03:00
|
|
|
}
|
1999-11-12 03:34:57 +03:00
|
|
|
if (err) {
|
1999-08-19 23:51:36 +04:00
|
|
|
DPRINTF(("%s: getting hub descriptor failed, error=%s\n",
|
2009-09-04 00:54:03 +04:00
|
|
|
device_xname(sc->sc_dev), usbd_errstr(err)));
|
2009-09-04 22:14:41 +04:00
|
|
|
return;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
for (nremov = 0, port = 1; port <= nports; port++)
|
|
|
|
if (!UHD_NOT_REMOV(&hubdesc, port))
|
|
|
|
nremov++;
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_verbose_dev(self, "%d port%s with %d removable, %s powered\n",
|
|
|
|
nports, nports != 1 ? "s" : "", nremov,
|
|
|
|
dev->self_powered ? "self" : "bus");
|
1998-12-26 15:53:00 +03:00
|
|
|
|
2004-10-23 20:17:56 +04:00
|
|
|
if (nports == 0) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_debug_dev(self, "no ports, hub ignored\n");
|
2004-10-23 20:17:56 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
hub = malloc(sizeof(*hub) + (nports-1) * sizeof(struct usbd_port),
|
1999-06-30 10:44:22 +04:00
|
|
|
M_USBDEV, M_NOWAIT);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (hub == NULL)
|
2009-09-04 22:14:41 +04:00
|
|
|
return;
|
1998-07-12 23:51:55 +04:00
|
|
|
dev->hub = hub;
|
1998-12-26 15:53:00 +03:00
|
|
|
dev->hub->hubsoftc = sc;
|
1998-07-12 23:51:55 +04:00
|
|
|
hub->explore = uhub_explore;
|
|
|
|
hub->hubdesc = hubdesc;
|
2002-07-12 01:14:24 +04:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Set up interrupt pipe. */
|
1999-11-12 03:34:57 +03:00
|
|
|
err = usbd_device2interface_handle(dev, 0, &iface);
|
|
|
|
if (err) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(self, "no interface handle\n");
|
1999-06-30 10:44:22 +04:00
|
|
|
goto bad;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
2006-12-01 23:48:50 +03:00
|
|
|
|
|
|
|
if (UHUB_IS_HIGH_SPEED(sc) && !UHUB_IS_SINGLE_TT(sc)) {
|
|
|
|
err = usbd_set_interface(iface, 1);
|
|
|
|
if (err)
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(self, "can't enable multiple TTs\n");
|
2006-12-01 23:48:50 +03:00
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
ed = usbd_interface2endpoint_descriptor(iface, 0);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (ed == NULL) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(self, "no endpoint descriptor\n");
|
1999-06-30 10:44:22 +04:00
|
|
|
goto bad;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
if ((ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(self, "bad interrupt endpoint\n");
|
1999-06-30 10:44:22 +04:00
|
|
|
goto bad;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
2007-03-15 18:29:09 +03:00
|
|
|
sc->sc_statuslen = (nports + 1 + 7) / 8;
|
|
|
|
sc->sc_statusbuf = malloc(sc->sc_statuslen, M_USBDEV, M_NOWAIT);
|
|
|
|
if (!sc->sc_statusbuf)
|
|
|
|
goto bad;
|
|
|
|
sc->sc_status = malloc(sc->sc_statuslen, M_USBDEV, M_NOWAIT);
|
2007-01-07 19:50:02 +03:00
|
|
|
if (!sc->sc_status)
|
|
|
|
goto bad;
|
2008-06-16 14:37:54 +04:00
|
|
|
if (device_is_a(device_parent(device_parent(sc->sc_dev)), "ehci"))
|
|
|
|
sc->sc_isehciroothub = 1;
|
2007-01-07 19:50:02 +03:00
|
|
|
|
2007-03-15 18:29:09 +03:00
|
|
|
/* force initial scan */
|
|
|
|
memset(sc->sc_status, 0xff, sc->sc_statuslen);
|
|
|
|
sc->sc_explorepending = 1;
|
|
|
|
|
1999-11-12 03:34:57 +03:00
|
|
|
err = usbd_open_pipe_intr(iface, ed->bEndpointAddress,
|
2007-03-15 18:29:09 +03:00
|
|
|
USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_statusbuf,
|
|
|
|
sc->sc_statuslen, uhub_intr, USBD_DEFAULT_INTERVAL);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (err) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(self, "cannot open interrupt pipe\n");
|
1999-06-30 10:44:22 +04:00
|
|
|
goto bad;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
/* Wait with power off for a while. */
|
1998-12-30 21:06:25 +03:00
|
|
|
usbd_delay_ms(dev, USB_POWER_DOWN_TIME);
|
1998-12-26 15:53:00 +03:00
|
|
|
|
2009-09-04 00:54:03 +04:00
|
|
|
usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, sc->sc_dev);
|
2000-02-02 10:33:59 +03:00
|
|
|
|
2000-04-21 20:05:50 +04:00
|
|
|
/*
|
|
|
|
* To have the best chance of success we do things in the exact same
|
|
|
|
* order as Windoze98. This should not be necessary, but some
|
|
|
|
* devices do not follow the USB specs to the letter.
|
|
|
|
*
|
|
|
|
* These are the events on the bus when a hub is attached:
|
|
|
|
* Get device and config descriptors (see attach code)
|
|
|
|
* Get hub descriptor (see above)
|
|
|
|
* For all ports
|
|
|
|
* turn on power
|
|
|
|
* wait for power to become stable
|
|
|
|
* (all below happens in explore code)
|
|
|
|
* For all ports
|
|
|
|
* clear C_PORT_CONNECTION
|
|
|
|
* For all ports
|
|
|
|
* get port status
|
|
|
|
* if device connected
|
2001-11-20 19:08:37 +03:00
|
|
|
* wait 100 ms
|
2000-04-21 20:05:50 +04:00
|
|
|
* turn on reset
|
|
|
|
* wait
|
|
|
|
* clear C_PORT_RESET
|
|
|
|
* get port status
|
|
|
|
* proceed with device attachment
|
|
|
|
*/
|
|
|
|
|
2006-12-01 23:48:50 +03:00
|
|
|
#if 0
|
2006-04-14 20:26:46 +04:00
|
|
|
if (UHUB_IS_HIGH_SPEED(sc) && nports > 0) {
|
2004-10-23 20:17:56 +04:00
|
|
|
tts = malloc((UHUB_IS_SINGLE_TT(sc) ? 1 : nports) *
|
|
|
|
sizeof (struct usbd_tt), M_USBDEV, M_NOWAIT);
|
|
|
|
if (!tts)
|
|
|
|
goto bad;
|
|
|
|
}
|
2006-12-01 23:48:50 +03:00
|
|
|
#endif
|
2000-04-21 20:05:50 +04:00
|
|
|
/* Set up data structures */
|
1998-12-26 15:53:00 +03:00
|
|
|
for (p = 0; p < nports; p++) {
|
|
|
|
struct usbd_port *up = &hub->ports[p];
|
2004-10-23 20:17:56 +04:00
|
|
|
up->device = NULL;
|
1998-12-26 15:53:00 +03:00
|
|
|
up->parent = dev;
|
|
|
|
up->portno = p+1;
|
2000-04-21 20:05:50 +04:00
|
|
|
if (dev->self_powered)
|
|
|
|
/* Self powered hub, give ports maximum current. */
|
|
|
|
up->power = USB_MAX_POWER;
|
|
|
|
else
|
|
|
|
up->power = USB_MIN_POWER;
|
2004-06-11 21:25:47 +04:00
|
|
|
up->restartcnt = 0;
|
2005-01-24 04:30:38 +03:00
|
|
|
up->reattach = 0;
|
2006-12-01 23:48:50 +03:00
|
|
|
#if 0
|
2004-10-23 20:17:56 +04:00
|
|
|
if (UHUB_IS_HIGH_SPEED(sc)) {
|
|
|
|
up->tt = &tts[UHUB_IS_SINGLE_TT(sc) ? 0 : p];
|
|
|
|
up->tt->hub = hub;
|
|
|
|
} else {
|
|
|
|
up->tt = NULL;
|
|
|
|
}
|
2006-12-01 23:48:50 +03:00
|
|
|
#endif
|
2000-04-21 20:05:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX should check for none, individual, or ganged power? */
|
|
|
|
|
|
|
|
pwrdly = dev->hub->hubdesc.bPwrOn2PwrGood * UHD_PWRON_FACTOR
|
|
|
|
+ USB_EXTRA_POWER_UP_TIME;
|
|
|
|
for (port = 1; port <= nports; port++) {
|
|
|
|
/* Turn the power on. */
|
|
|
|
err = usbd_set_port_feature(dev, port, UHF_PORT_POWER);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (err)
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(self, "port %d power on failed, %s\n",
|
|
|
|
port, usbd_errstr(err));
|
2000-04-21 20:05:50 +04:00
|
|
|
DPRINTF(("usb_init_port: turn on port %d power\n", port));
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
2000-04-21 20:05:50 +04:00
|
|
|
|
2008-01-25 03:29:12 +03:00
|
|
|
/* Wait for stable power if we are not a root hub */
|
|
|
|
if (dev->powersrc->parent != NULL)
|
|
|
|
usbd_delay_ms(dev, pwrdly);
|
|
|
|
|
2000-04-21 20:05:50 +04:00
|
|
|
/* The usual exploration will finish the setup. */
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
sc->sc_running = 1;
|
1998-12-26 15:53:00 +03:00
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
if (!pmf_device_register(self, NULL, NULL))
|
|
|
|
aprint_error_dev(self, "couldn't establish power handler\n");
|
|
|
|
|
2009-09-04 22:14:41 +04:00
|
|
|
return;
|
1998-12-26 15:53:00 +03:00
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
bad:
|
2007-01-07 19:50:02 +03:00
|
|
|
if (sc->sc_status)
|
|
|
|
free(sc->sc_status, M_USBDEV);
|
2008-06-16 14:37:54 +04:00
|
|
|
if (sc->sc_statusbuf)
|
|
|
|
free(sc->sc_statusbuf, M_USBDEV);
|
2004-10-23 20:17:56 +04:00
|
|
|
if (hub)
|
|
|
|
free(hub, M_USBDEV);
|
|
|
|
dev->hub = NULL;
|
2009-09-04 22:14:41 +04:00
|
|
|
return;
|
1998-12-26 15:53:00 +03:00
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_status
|
2000-06-01 18:28:57 +04:00
|
|
|
uhub_explore(usbd_device_handle dev)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
|
|
|
usb_hub_descriptor_t *hd = &dev->hub->hubdesc;
|
1998-12-26 15:53:00 +03:00
|
|
|
struct uhub_softc *sc = dev->hub->hubsoftc;
|
1998-07-12 23:51:55 +04:00
|
|
|
struct usbd_port *up;
|
1999-11-12 03:34:57 +03:00
|
|
|
usbd_status err;
|
2001-11-20 16:48:03 +03:00
|
|
|
int speed;
|
1998-07-12 23:51:55 +04:00
|
|
|
int port;
|
2005-01-24 04:30:38 +03:00
|
|
|
int change, status, reconnect;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
DPRINTFN(10, ("uhub_explore dev=%p addr=%d\n", dev, dev->address));
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
if (!sc->sc_running)
|
|
|
|
return (USBD_NOT_STARTED);
|
|
|
|
|
|
|
|
/* Ignore hubs that are too deep. */
|
|
|
|
if (dev->depth > USB_HUB_MAX_DEPTH)
|
|
|
|
return (USBD_TOO_DEEP);
|
|
|
|
|
2008-06-16 14:37:54 +04:00
|
|
|
if (PORTSTAT_ISSET(sc, 0)) { /* hub status change */
|
|
|
|
usb_hub_status_t hs;
|
|
|
|
|
|
|
|
err = usbd_get_hub_status(dev, &hs);
|
|
|
|
if (err) {
|
|
|
|
DPRINTF(("%s: get hub status failed, err=%d\n",
|
|
|
|
device_xname(sc->sc_dev), err));
|
|
|
|
} else {
|
|
|
|
/* just acknowledge */
|
|
|
|
status = UGETW(hs.wHubStatus);
|
|
|
|
change = UGETW(hs.wHubChange);
|
|
|
|
if (change & UHS_LOCAL_POWER)
|
|
|
|
usbd_clear_hub_feature(dev,
|
|
|
|
UHF_C_HUB_LOCAL_POWER);
|
|
|
|
if (change & UHS_OVER_CURRENT)
|
|
|
|
usbd_clear_hub_feature(dev,
|
|
|
|
UHF_C_HUB_OVER_CURRENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-07 19:50:02 +03:00
|
|
|
for (port = 1; port <= hd->bNbrPorts; port++) {
|
1998-07-12 23:51:55 +04:00
|
|
|
up = &dev->hub->ports[port-1];
|
2007-03-15 18:29:09 +03:00
|
|
|
|
|
|
|
/* reattach is needed after firmware upload */
|
2005-01-24 04:30:38 +03:00
|
|
|
reconnect = up->reattach;
|
|
|
|
up->reattach = 0;
|
2007-03-15 18:29:09 +03:00
|
|
|
|
|
|
|
status = change = 0;
|
|
|
|
|
|
|
|
/* don't check if no change summary notification */
|
|
|
|
if (PORTSTAT_ISSET(sc, port) || reconnect) {
|
|
|
|
err = usbd_get_port_status(dev, port, &up->status);
|
|
|
|
if (err) {
|
|
|
|
DPRINTF(("uhub_explore: get port stat failed, "
|
|
|
|
"error=%s\n", usbd_errstr(err)));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
status = UGETW(up->status.wPortStatus);
|
|
|
|
change = UGETW(up->status.wPortChange);
|
2008-06-16 14:37:54 +04:00
|
|
|
#if 0
|
|
|
|
printf("%s port %d: s/c=%x/%x\n",
|
|
|
|
device_xname(sc->sc_dev), port, status, change);
|
|
|
|
#endif
|
2007-03-15 18:29:09 +03:00
|
|
|
}
|
|
|
|
if (!change && !reconnect) {
|
|
|
|
/* No status change, just do recursive explore. */
|
|
|
|
if (up->device != NULL && up->device->hub != NULL)
|
|
|
|
up->device->hub->explore(up->device);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
if (change & UPS_C_PORT_ENABLED) {
|
1999-11-25 02:13:19 +03:00
|
|
|
DPRINTF(("uhub_explore: C_PORT_ENABLED\n"));
|
1998-12-26 15:53:00 +03:00
|
|
|
usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE);
|
2004-06-29 10:30:05 +04:00
|
|
|
if (change & UPS_C_CONNECT_STATUS) {
|
|
|
|
/* Ignore the port error if the device
|
|
|
|
vanished. */
|
|
|
|
} else if (status & UPS_PORT_ENABLED) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"illegal enable change, port %d\n", port);
|
1998-12-26 15:53:00 +03:00
|
|
|
} else {
|
|
|
|
/* Port error condition. */
|
2000-09-24 06:08:38 +04:00
|
|
|
if (up->restartcnt) /* no message first time */
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"port error, restarting port %d\n",
|
|
|
|
port);
|
2000-09-24 06:08:38 +04:00
|
|
|
|
|
|
|
if (up->restartcnt++ < USBD_RESTART_MAX)
|
1998-12-26 15:53:00 +03:00
|
|
|
goto disco;
|
2000-09-24 06:08:38 +04:00
|
|
|
else
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"port error, giving up port %d\n",
|
|
|
|
port);
|
1998-12-26 15:53:00 +03:00
|
|
|
}
|
|
|
|
}
|
2007-03-15 18:29:09 +03:00
|
|
|
|
|
|
|
/* XXX handle overcurrent and resume events! */
|
|
|
|
|
|
|
|
if (!(change & UPS_C_CONNECT_STATUS))
|
1998-07-12 23:51:55 +04:00
|
|
|
continue;
|
2000-04-21 20:05:50 +04:00
|
|
|
|
|
|
|
/* We have a connect status change, handle it. */
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
DPRINTF(("uhub_explore: status change hub=%d port=%d\n",
|
|
|
|
dev->address, port));
|
|
|
|
usbd_clear_port_feature(dev, port, UHF_C_PORT_CONNECTION);
|
|
|
|
/*
|
|
|
|
* If there is already a device on the port the change status
|
|
|
|
* must mean that is has disconnected. Looking at the
|
|
|
|
* current connect status is not enough to figure this out
|
|
|
|
* since a new unit may have been connected before we handle
|
|
|
|
* the disconnect.
|
|
|
|
*/
|
1998-12-26 15:53:00 +03:00
|
|
|
disco:
|
1999-11-12 03:34:57 +03:00
|
|
|
if (up->device != NULL) {
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Disconnected */
|
1999-11-25 02:13:19 +03:00
|
|
|
DPRINTF(("uhub_explore: device addr=%d disappeared "
|
1999-10-13 00:02:47 +04:00
|
|
|
"on port %d\n", up->device->address, port));
|
2009-11-12 23:11:35 +03:00
|
|
|
usb_disconnect_port(up, sc->sc_dev, DETACH_FORCE);
|
2002-07-12 01:14:24 +04:00
|
|
|
usbd_clear_port_feature(dev, port,
|
1998-07-12 23:51:55 +04:00
|
|
|
UHF_C_PORT_CONNECTION);
|
|
|
|
}
|
1999-11-25 02:13:19 +03:00
|
|
|
if (!(status & UPS_CURRENT_CONNECT_STATUS)) {
|
2000-04-21 20:05:50 +04:00
|
|
|
/* Nothing connected, just ignore it. */
|
1999-11-25 02:13:19 +03:00
|
|
|
DPRINTFN(3,("uhub_explore: port=%d !CURRENT_CONNECT"
|
|
|
|
"_STATUS\n", port));
|
1998-07-12 23:51:55 +04:00
|
|
|
continue;
|
1999-11-25 02:13:19 +03:00
|
|
|
}
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
/* Connected */
|
2000-04-21 20:05:50 +04:00
|
|
|
|
|
|
|
if (!(status & UPS_PORT_POWER))
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_normal_dev(sc->sc_dev,
|
|
|
|
"strange, connected port %d has no power\n", port);
|
2000-04-21 20:05:50 +04:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Wait for maximum device power up time. */
|
1998-12-30 21:06:25 +03:00
|
|
|
usbd_delay_ms(dev, USB_PORT_POWERUP_DELAY);
|
1998-12-26 15:53:00 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Reset port, which implies enabling it. */
|
1999-11-25 02:13:19 +03:00
|
|
|
if (usbd_reset_port(dev, port, &up->status)) {
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"port %d reset failed\n", port);
|
1998-07-12 23:51:55 +04:00
|
|
|
continue;
|
1999-11-25 02:13:19 +03:00
|
|
|
}
|
2001-11-16 04:57:47 +03:00
|
|
|
/* Get port status again, it might have changed during reset */
|
|
|
|
err = usbd_get_port_status(dev, port, &up->status);
|
|
|
|
if (err) {
|
|
|
|
DPRINTF(("uhub_explore: get port status failed, "
|
|
|
|
"error=%s\n", usbd_errstr(err)));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
status = UGETW(up->status.wPortStatus);
|
|
|
|
change = UGETW(up->status.wPortChange);
|
|
|
|
if (!(status & UPS_CURRENT_CONNECT_STATUS)) {
|
|
|
|
/* Nothing connected, just ignore it. */
|
|
|
|
#ifdef DIAGNOSTIC
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_debug_dev(sc->sc_dev,
|
|
|
|
"port %d, device disappeared after reset\n", port);
|
2001-11-16 04:57:47 +03:00
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2001-11-20 16:48:03 +03:00
|
|
|
/* Figure out device speed */
|
|
|
|
if (status & UPS_HIGH_SPEED)
|
|
|
|
speed = USB_SPEED_HIGH;
|
|
|
|
else if (status & UPS_LOW_SPEED)
|
|
|
|
speed = USB_SPEED_LOW;
|
|
|
|
else
|
|
|
|
speed = USB_SPEED_FULL;
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Get device info and set its address. */
|
2009-09-04 00:54:03 +04:00
|
|
|
err = usbd_new_device(sc->sc_dev, dev->bus,
|
2001-11-20 16:48:03 +03:00
|
|
|
dev->depth + 1, speed, port, up);
|
1998-07-12 23:51:55 +04:00
|
|
|
/* XXX retry a few times? */
|
1999-11-12 03:34:57 +03:00
|
|
|
if (err) {
|
1998-12-09 22:24:28 +03:00
|
|
|
DPRINTFN(-1,("uhub_explore: usb_new_device failed, "
|
1999-11-12 03:34:57 +03:00
|
|
|
"error=%s\n", usbd_errstr(err)));
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Avoid addressing problems by disabling. */
|
|
|
|
/* usbd_reset_port(dev, port, &up->status); */
|
1999-10-11 13:15:34 +04:00
|
|
|
|
2002-07-12 01:14:24 +04:00
|
|
|
/*
|
1999-10-11 13:15:34 +04:00
|
|
|
* The unit refused to accept a new address, or had
|
|
|
|
* some other serious problem. Since we cannot leave
|
|
|
|
* at 0 we have to disable the port instead.
|
|
|
|
*/
|
2008-05-24 20:40:58 +04:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"device problem, disabling port %d\n", port);
|
1999-10-11 13:15:34 +04:00
|
|
|
usbd_clear_port_feature(dev, port, UHF_PORT_ENABLE);
|
1998-07-12 23:51:55 +04:00
|
|
|
} else {
|
2000-09-24 06:08:38 +04:00
|
|
|
/* The port set up succeeded, reset error count. */
|
|
|
|
up->restartcnt = 0;
|
|
|
|
|
1999-11-19 02:32:25 +03:00
|
|
|
if (up->device->hub)
|
1998-12-26 15:53:00 +03:00
|
|
|
up->device->hub->explore(up->device);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
2007-03-15 18:29:09 +03:00
|
|
|
/* enable status change notifications again */
|
2008-06-16 14:37:54 +04:00
|
|
|
if (!sc->sc_isehciroothub)
|
|
|
|
memset(sc->sc_status, 0, sc->sc_statuslen);
|
2007-03-15 18:29:09 +03:00
|
|
|
sc->sc_explorepending = 0;
|
1998-07-12 23:51:55 +04:00
|
|
|
return (USBD_NORMAL_COMPLETION);
|
|
|
|
}
|
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
/*
|
|
|
|
* Called from process context when the hub is gone.
|
|
|
|
* Detach all devices on active ports.
|
|
|
|
*/
|
2009-09-04 00:54:03 +04:00
|
|
|
int
|
|
|
|
uhub_detach(device_t self, int flags)
|
1999-06-30 10:44:22 +04:00
|
|
|
{
|
2009-09-04 22:14:41 +04:00
|
|
|
struct uhub_softc *sc = device_private(self);
|
2000-02-13 02:44:16 +03:00
|
|
|
struct usbd_hub *hub = sc->sc_hub->hub;
|
1999-06-30 10:44:22 +04:00
|
|
|
struct usbd_port *rup;
|
2009-11-12 23:11:35 +03:00
|
|
|
int nports, port, rc;
|
1999-06-30 10:44:22 +04:00
|
|
|
|
|
|
|
DPRINTF(("uhub_detach: sc=%p flags=%d\n", sc, flags));
|
|
|
|
|
2000-02-13 02:44:16 +03:00
|
|
|
if (hub == NULL) /* Must be partially working */
|
1999-06-30 10:44:22 +04:00
|
|
|
return (0);
|
|
|
|
|
2000-02-13 02:44:16 +03:00
|
|
|
nports = hub->hubdesc.bNbrPorts;
|
1999-10-13 12:10:55 +04:00
|
|
|
for(port = 0; port < nports; port++) {
|
2000-02-13 02:44:16 +03:00
|
|
|
rup = &hub->ports[port];
|
2009-11-12 23:11:35 +03:00
|
|
|
if (rup->device == NULL)
|
|
|
|
continue;
|
|
|
|
if ((rc = usb_disconnect_port(rup, self, flags)) != 0)
|
|
|
|
return rc;
|
1999-06-30 10:44:22 +04:00
|
|
|
}
|
2002-07-12 01:14:24 +04:00
|
|
|
|
2009-11-12 23:11:35 +03:00
|
|
|
pmf_device_deregister(self);
|
|
|
|
usbd_abort_pipe(sc->sc_ipipe);
|
|
|
|
usbd_close_pipe(sc->sc_ipipe);
|
|
|
|
|
2009-09-04 00:54:03 +04:00
|
|
|
usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_hub, sc->sc_dev);
|
2000-02-02 10:33:59 +03:00
|
|
|
|
2006-12-01 23:48:50 +03:00
|
|
|
#if 0
|
2004-10-23 20:17:56 +04:00
|
|
|
if (hub->ports[0].tt)
|
|
|
|
free(hub->ports[0].tt, M_USBDEV);
|
2006-12-01 23:48:50 +03:00
|
|
|
#endif
|
2004-10-26 09:00:59 +04:00
|
|
|
free(hub, M_USBDEV);
|
2000-02-13 02:44:16 +03:00
|
|
|
sc->sc_hub->hub = NULL;
|
2007-01-07 19:50:02 +03:00
|
|
|
if (sc->sc_status)
|
|
|
|
free(sc->sc_status, M_USBDEV);
|
2008-06-16 14:37:54 +04:00
|
|
|
if (sc->sc_statusbuf)
|
|
|
|
free(sc->sc_statusbuf, M_USBDEV);
|
1999-06-30 10:44:22 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-08-18 22:03:21 +04:00
|
|
|
int
|
|
|
|
uhub_rescan(device_t self, const char *ifattr, const int *locators)
|
|
|
|
{
|
|
|
|
struct uhub_softc *sc = device_private(self);
|
|
|
|
struct usbd_hub *hub = sc->sc_hub->hub;
|
|
|
|
usbd_device_handle dev;
|
|
|
|
int port, err;
|
|
|
|
|
|
|
|
for (port = 0; port < hub->hubdesc.bNbrPorts; port++) {
|
|
|
|
dev = hub->ports[port].device;
|
|
|
|
if (dev == NULL)
|
|
|
|
continue;
|
2009-09-04 00:54:03 +04:00
|
|
|
err = usbd_reattach_device(sc->sc_dev, dev, port, locators);
|
2008-08-18 22:03:21 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-19 02:32:25 +03:00
|
|
|
/* Called when a device has been detached from it */
|
2008-02-18 08:24:24 +03:00
|
|
|
void
|
|
|
|
uhub_childdet(device_t self, device_t child)
|
1999-11-19 02:32:25 +03:00
|
|
|
{
|
2008-02-18 08:24:24 +03:00
|
|
|
struct uhub_softc *sc = device_private(self);
|
|
|
|
usbd_device_handle devhub = sc->sc_hub;
|
|
|
|
usbd_device_handle dev;
|
|
|
|
int nports;
|
|
|
|
int port;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!devhub->hub)
|
|
|
|
/* should never happen; children are only created after init */
|
|
|
|
panic("hub not fully initialised, but child deleted?");
|
|
|
|
|
|
|
|
nports = devhub->hub->hubdesc.bNbrPorts;
|
|
|
|
for (port = 0; port < nports; port++) {
|
|
|
|
dev = devhub->hub->ports[port].device;
|
2008-05-26 01:41:35 +04:00
|
|
|
if (!dev)
|
2008-02-18 08:24:24 +03:00
|
|
|
continue;
|
2008-05-26 01:41:35 +04:00
|
|
|
for (i = 0; i < dev->subdevlen; i++) {
|
2008-02-18 08:24:24 +03:00
|
|
|
if (dev->subdevs[i] == child) {
|
|
|
|
dev->subdevs[i] = NULL;
|
2008-07-28 19:22:01 +04:00
|
|
|
dev->nifaces_claimed--;
|
2008-02-18 08:24:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-11-19 02:32:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
/*
|
|
|
|
* Hub interrupt.
|
|
|
|
* This an indication that some port has changed status.
|
|
|
|
* Notify the bus event handler thread that we need
|
|
|
|
* to be explored again.
|
|
|
|
*/
|
1998-07-12 23:51:55 +04:00
|
|
|
void
|
2009-09-04 00:54:03 +04:00
|
|
|
uhub_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
|
|
|
struct uhub_softc *sc = addr;
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
DPRINTFN(5,("uhub_intr: sc=%p\n", sc));
|
2007-03-15 18:29:09 +03:00
|
|
|
|
2001-09-29 03:42:16 +04:00
|
|
|
if (status == USBD_STALLED)
|
1998-12-09 04:01:24 +03:00
|
|
|
usbd_clear_endpoint_stall_async(sc->sc_ipipe);
|
2007-03-15 18:29:09 +03:00
|
|
|
else if (status == USBD_NORMAL_COMPLETION &&
|
|
|
|
!sc->sc_explorepending) {
|
|
|
|
/*
|
|
|
|
* Make sure the status is not overwritten in between.
|
|
|
|
* XXX we should suspend the pipe instead
|
|
|
|
*/
|
|
|
|
memcpy(sc->sc_status, sc->sc_statusbuf, sc->sc_statuslen);
|
|
|
|
sc->sc_explorepending = 1;
|
2001-09-29 03:42:16 +04:00
|
|
|
usb_needs_explore(sc->sc_hub);
|
2007-03-15 18:29:09 +03:00
|
|
|
}
|
2007-03-24 00:51:34 +03:00
|
|
|
/*
|
|
|
|
* XXX workaround for broken implementation of the interrupt
|
|
|
|
* pipe in EHCI root hub emulation which doesn't resend
|
|
|
|
* status change notifications until handled: force a rescan
|
|
|
|
* of the ports we touched in the last run
|
|
|
|
*/
|
|
|
|
if (status == USBD_NORMAL_COMPLETION && sc->sc_explorepending &&
|
2008-06-16 14:37:54 +04:00
|
|
|
sc->sc_isehciroothub)
|
2007-03-24 00:51:34 +03:00
|
|
|
usb_needs_explore(sc->sc_hub);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|