2003-07-14 20:31:03 +00:00
|
|
|
/* $NetBSD: usb_subr.c,v 1.99 2002/07/11 21:14:34 augustss Exp $ */
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2003-07-14 20:31:03 +00:00
|
|
|
/* Also already have from NetBSD:
|
|
|
|
* $NetBSD: usb_subr.c,v 1.102 2003/01/01 16:21:50 augustss Exp $
|
|
|
|
* $NetBSD: usb_subr.c,v 1.103 2003/01/10 11:19:13 augustss Exp $
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1999-01-07 23:07:57 +00:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-05-14 16:43:10 +00:00
|
|
|
* by Lennart Augustsson (lennart@augustsson.net) at
|
1999-01-07 23:07:57 +00:00
|
|
|
* Carlstedt Research & Technology.
|
1998-11-26 23:13:13 +00: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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
1999-10-07 19:26:38 +00:00
|
|
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
1998-11-26 23:13:13 +00:00
|
|
|
#include <sys/device.h>
|
1999-11-08 23:47:34 +00:00
|
|
|
#include <sys/select.h>
|
1998-11-26 23:13:13 +00:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
|
|
|
#include <dev/usb/usbdivar.h>
|
|
|
|
#include <dev/usb/usbdevs.h>
|
|
|
|
#include <dev/usb/usb_quirks.h>
|
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
2000-10-16 18:50:00 +00:00
|
|
|
#include <machine/clock.h>
|
1999-01-07 23:07:57 +00:00
|
|
|
#define delay(d) DELAY(d)
|
1998-11-26 23:13:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USB_DEBUG
|
1999-04-11 20:50:33 +00:00
|
|
|
#define DPRINTF(x) if (usbdebug) logprintf x
|
|
|
|
#define DPRINTFN(n,x) if (usbdebug>(n)) logprintf x
|
1998-11-26 23:13:13 +00:00
|
|
|
extern int usbdebug;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
2001-07-05 10:12:59 +00:00
|
|
|
Static usbd_status usbd_set_config(usbd_device_handle, int);
|
|
|
|
Static void usbd_devinfo_vp(usbd_device_handle, char *, char *, int);
|
2000-07-17 18:41:20 +00:00
|
|
|
Static char *usbd_get_string(usbd_device_handle, int, char *);
|
|
|
|
Static int usbd_getnewaddr(usbd_bus_handle bus);
|
1999-10-07 19:26:38 +00:00
|
|
|
#if defined(__NetBSD__)
|
2000-07-17 18:41:20 +00:00
|
|
|
Static int usbd_print(void *aux, const char *pnp);
|
|
|
|
Static int usbd_submatch(device_ptr_t, struct cfdata *cf, void *);
|
1999-10-07 19:26:38 +00:00
|
|
|
#elif defined(__OpenBSD__)
|
2001-07-05 10:12:59 +00:00
|
|
|
Static int usbd_print(void *aux, const char *pnp);
|
2000-07-17 18:41:20 +00:00
|
|
|
Static int usbd_submatch(device_ptr_t, void *, void *);
|
1999-10-07 19:26:38 +00:00
|
|
|
#endif
|
2000-07-17 18:41:20 +00:00
|
|
|
Static void usbd_free_iface_data(usbd_device_handle dev, int ifcno);
|
|
|
|
Static void usbd_kill_pipe(usbd_pipe_handle);
|
2001-07-05 10:12:59 +00:00
|
|
|
Static usbd_status usbd_probe_and_attach(device_ptr_t parent,
|
|
|
|
usbd_device_handle dev, int port, int addr);
|
1999-10-07 19:26:38 +00:00
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static u_int32_t usb_cookie_no = 0;
|
1999-10-07 19:26:38 +00:00
|
|
|
|
|
|
|
#ifdef USBVERBOSE
|
1999-04-19 20:25:18 +00:00
|
|
|
typedef u_int16_t usb_vendor_id_t;
|
|
|
|
typedef u_int16_t usb_product_id_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Descriptions of of known vendors and devices ("products").
|
|
|
|
*/
|
|
|
|
struct usb_knowndev {
|
1999-10-07 19:26:38 +00:00
|
|
|
usb_vendor_id_t vendor;
|
|
|
|
usb_product_id_t product;
|
|
|
|
int flags;
|
|
|
|
char *vendorname, *productname;
|
1999-04-19 20:25:18 +00:00
|
|
|
};
|
1999-10-07 19:26:38 +00:00
|
|
|
#define USB_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
|
1999-04-19 20:25:18 +00:00
|
|
|
|
|
|
|
#include <dev/usb/usbdevs_data.h>
|
1999-11-17 22:33:51 +00:00
|
|
|
#endif /* USBVERBOSE */
|
1999-04-19 20:25:18 +00:00
|
|
|
|
2001-07-05 10:12:59 +00:00
|
|
|
Static const char * const usbd_error_strs[] = {
|
1999-10-07 19:26:38 +00:00
|
|
|
"NORMAL_COMPLETION",
|
|
|
|
"IN_PROGRESS",
|
|
|
|
"PENDING_REQUESTS",
|
|
|
|
"NOT_STARTED",
|
|
|
|
"INVAL",
|
|
|
|
"NOMEM",
|
|
|
|
"CANCELLED",
|
|
|
|
"BAD_ADDRESS",
|
|
|
|
"IN_USE",
|
|
|
|
"NO_ADDR",
|
|
|
|
"SET_ADDR_FAILED",
|
|
|
|
"NO_POWER",
|
|
|
|
"TOO_DEEP",
|
|
|
|
"IOERROR",
|
|
|
|
"NOT_CONFIGURED",
|
|
|
|
"TIMEOUT",
|
|
|
|
"SHORT_XFER",
|
|
|
|
"STALLED",
|
|
|
|
"INTERRUPTED",
|
|
|
|
"XXX",
|
|
|
|
};
|
1999-04-19 20:25:18 +00:00
|
|
|
|
1999-10-07 19:26:38 +00:00
|
|
|
const char *
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_errstr(usbd_status err)
|
1999-10-07 19:26:38 +00:00
|
|
|
{
|
|
|
|
static char buffer[5];
|
1999-01-07 23:07:57 +00:00
|
|
|
|
1999-10-07 19:26:38 +00:00
|
|
|
if (err < USBD_ERROR_MAX) {
|
|
|
|
return usbd_error_strs[err];
|
|
|
|
} else {
|
|
|
|
snprintf(buffer, sizeof buffer, "%d", err);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_get_string_desc(usbd_device_handle dev, int sindex, int langid,
|
|
|
|
usb_string_descriptor_t *sdesc)
|
1999-01-07 23:07:57 +00:00
|
|
|
{
|
|
|
|
usb_device_request_t req;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
2003-01-14 23:07:43 +00:00
|
|
|
int actlen;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
|
|
req.bmRequestType = UT_READ_DEVICE;
|
|
|
|
req.bRequest = UR_GET_DESCRIPTOR;
|
|
|
|
USETW2(req.wValue, UDESC_STRING, sindex);
|
|
|
|
USETW(req.wIndex, langid);
|
2003-01-14 23:07:43 +00:00
|
|
|
USETW(req.wLength, 2); /* only size byte first */
|
|
|
|
err = usbd_do_request_flags(dev, &req, sdesc, USBD_SHORT_XFER_OK,
|
|
|
|
&actlen, USBD_DEFAULT_TIMEOUT);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err)
|
|
|
|
return (err);
|
2003-01-14 23:07:43 +00:00
|
|
|
|
|
|
|
if (actlen < 1)
|
|
|
|
return (USBD_SHORT_XFER);
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
USETW(req.wLength, sdesc->bLength); /* the whole string */
|
|
|
|
return (usbd_do_request(dev, &req, sdesc));
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
char *
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_get_string(usbd_device_handle dev, int si, char *buf)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
int swap = dev->quirks->uq_flags & UQ_SWAP_UNICODE;
|
|
|
|
usb_string_descriptor_t us;
|
1999-10-07 19:26:38 +00:00
|
|
|
char *s;
|
1998-11-26 23:13:13 +00:00
|
|
|
int i, n;
|
|
|
|
u_int16_t c;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
if (si == 0)
|
1998-12-13 22:27:42 +00:00
|
|
|
return (0);
|
|
|
|
if (dev->quirks->uq_flags & UQ_NO_STRINGS)
|
|
|
|
return (0);
|
1999-01-07 23:07:57 +00:00
|
|
|
if (dev->langid == USBD_NOLANG) {
|
|
|
|
/* Set up default language */
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_get_string_desc(dev, USB_LANGUAGE_TABLE, 0, &us);
|
|
|
|
if (err || us.bLength < 4) {
|
2002-04-25 12:51:08 +00:00
|
|
|
dev->langid = 0; /* Well, just pick something then */
|
1999-01-07 23:07:57 +00:00
|
|
|
} else {
|
|
|
|
/* Pick the first language as the default. */
|
|
|
|
dev->langid = UGETW(us.bString[0]);
|
|
|
|
}
|
|
|
|
}
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_get_string_desc(dev, si, dev->langid, &us);
|
|
|
|
if (err)
|
1999-01-07 23:07:57 +00:00
|
|
|
return (0);
|
1999-10-07 19:26:38 +00:00
|
|
|
s = buf;
|
1998-11-26 23:13:13 +00:00
|
|
|
n = us.bLength / 2 - 1;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
c = UGETW(us.bString[i]);
|
|
|
|
/* Convert from Unicode, handle buggy strings. */
|
|
|
|
if ((c & 0xff00) == 0)
|
1999-10-07 19:26:38 +00:00
|
|
|
*s++ = c;
|
1998-11-26 23:13:13 +00:00
|
|
|
else if ((c & 0x00ff) == 0 && swap)
|
1999-10-07 19:26:38 +00:00
|
|
|
*s++ = c >> 8;
|
2003-07-04 01:50:39 +00:00
|
|
|
else
|
1999-10-07 19:26:38 +00:00
|
|
|
*s++ = '?';
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-10-07 19:26:38 +00:00
|
|
|
*s++ = 0;
|
1999-11-17 22:33:51 +00:00
|
|
|
return (buf);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
2001-07-05 10:12:59 +00:00
|
|
|
Static void
|
|
|
|
usbd_trim_spaces(char *p)
|
|
|
|
{
|
|
|
|
char *q, *e;
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
q = e = p;
|
|
|
|
while (*q == ' ') /* skip leading spaces */
|
|
|
|
q++;
|
|
|
|
while ((*p = *q++)) /* copy string */
|
|
|
|
if (*p++ != ' ') /* remember last non-space */
|
|
|
|
e = p;
|
|
|
|
*e = 0; /* kill trailing spaces */
|
|
|
|
}
|
|
|
|
|
|
|
|
Static void
|
|
|
|
usbd_devinfo_vp(usbd_device_handle dev, char *v, char *p, int usedev)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
usb_device_descriptor_t *udd = &dev->ddesc;
|
1999-10-07 19:26:38 +00:00
|
|
|
char *vendor = 0, *product = 0;
|
|
|
|
#ifdef USBVERBOSE
|
2001-07-05 10:12:59 +00:00
|
|
|
const struct usb_knowndev *kdp;
|
1999-10-07 19:26:38 +00:00
|
|
|
#endif
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dev == NULL) {
|
1999-10-07 19:26:38 +00:00
|
|
|
v[0] = p[0] = '\0';
|
|
|
|
return;
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2001-07-05 10:12:59 +00:00
|
|
|
if (usedev) {
|
|
|
|
vendor = usbd_get_string(dev, udd->iManufacturer, v);
|
|
|
|
usbd_trim_spaces(vendor);
|
|
|
|
product = usbd_get_string(dev, udd->iProduct, p);
|
|
|
|
usbd_trim_spaces(product);
|
2004-01-18 12:46:19 +00:00
|
|
|
if (vendor && !*vendor)
|
|
|
|
vendor = NULL;
|
|
|
|
if (product && !*product)
|
|
|
|
product = NULL;
|
2001-07-05 10:12:59 +00:00
|
|
|
} else {
|
|
|
|
vendor = NULL;
|
|
|
|
product = NULL;
|
|
|
|
}
|
1999-10-07 19:26:38 +00:00
|
|
|
#ifdef USBVERBOSE
|
2000-08-13 18:39:24 +00:00
|
|
|
if (vendor == NULL || product == NULL) {
|
1999-04-19 20:25:18 +00:00
|
|
|
for(kdp = usb_knowndevs;
|
|
|
|
kdp->vendorname != NULL;
|
|
|
|
kdp++) {
|
2003-07-04 01:50:39 +00:00
|
|
|
if (kdp->vendor == UGETW(udd->idVendor) &&
|
1999-04-19 20:25:18 +00:00
|
|
|
(kdp->product == UGETW(udd->idProduct) ||
|
1999-10-07 19:26:38 +00:00
|
|
|
(kdp->flags & USB_KNOWNDEV_NOPROD) != 0))
|
1999-04-19 20:25:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-08-13 18:39:24 +00:00
|
|
|
if (kdp->vendorname != NULL) {
|
2001-07-05 10:12:59 +00:00
|
|
|
if (vendor == NULL)
|
|
|
|
vendor = kdp->vendorname;
|
|
|
|
if (product == NULL)
|
|
|
|
product = (kdp->flags & USB_KNOWNDEV_NOPROD) == 0 ?
|
1999-10-07 19:26:38 +00:00
|
|
|
kdp->productname : NULL;
|
1999-04-19 20:25:18 +00:00
|
|
|
}
|
|
|
|
}
|
1999-10-07 19:26:38 +00:00
|
|
|
#endif
|
2001-07-05 10:12:59 +00:00
|
|
|
if (vendor != NULL && *vendor)
|
1998-11-26 23:13:13 +00:00
|
|
|
strcpy(v, vendor);
|
|
|
|
else
|
|
|
|
sprintf(v, "vendor 0x%04x", UGETW(udd->idVendor));
|
2001-07-05 10:12:59 +00:00
|
|
|
if (product != NULL && *product)
|
1998-11-26 23:13:13 +00:00
|
|
|
strcpy(p, product);
|
|
|
|
else
|
|
|
|
sprintf(p, "product 0x%04x", UGETW(udd->idProduct));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_printBCD(char *cp, int bcd)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
return (sprintf(cp, "%x.%02x", bcd >> 8, bcd & 0xff));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_devinfo(usbd_device_handle dev, int showclass, char *cp)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
usb_device_descriptor_t *udd = &dev->ddesc;
|
|
|
|
char vendor[USB_MAX_STRING_LEN];
|
|
|
|
char product[USB_MAX_STRING_LEN];
|
|
|
|
int bcdDevice, bcdUSB;
|
|
|
|
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_devinfo_vp(dev, vendor, product, 1);
|
1998-12-13 22:27:42 +00:00
|
|
|
cp += sprintf(cp, "%s %s", vendor, product);
|
1998-11-26 23:13:13 +00:00
|
|
|
if (showclass)
|
1999-01-07 23:07:57 +00:00
|
|
|
cp += sprintf(cp, ", class %d/%d",
|
1998-11-26 23:13:13 +00:00
|
|
|
udd->bDeviceClass, udd->bDeviceSubClass);
|
|
|
|
bcdUSB = UGETW(udd->bcdUSB);
|
|
|
|
bcdDevice = UGETW(udd->bcdDevice);
|
1999-01-07 23:07:57 +00:00
|
|
|
cp += sprintf(cp, ", rev ");
|
1998-11-26 23:13:13 +00:00
|
|
|
cp += usbd_printBCD(cp, bcdUSB);
|
|
|
|
*cp++ = '/';
|
|
|
|
cp += usbd_printBCD(cp, bcdDevice);
|
1999-01-07 23:07:57 +00:00
|
|
|
cp += sprintf(cp, ", addr %d", dev->address);
|
|
|
|
*cp = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delay for a certain number of ms */
|
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usb_delay_ms(usbd_bus_handle bus, u_int ms)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
/* Wait at least two clock ticks so we know the time has passed. */
|
2000-02-06 14:59:00 +00:00
|
|
|
if (bus->use_polling || cold)
|
1998-11-26 23:13:13 +00:00
|
|
|
delay((ms+1) * 1000);
|
|
|
|
else
|
|
|
|
tsleep(&ms, PRIBIO, "usbdly", (ms*hz+999)/1000 + 1);
|
|
|
|
}
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
/* Delay given a device handle. */
|
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_delay_ms(usbd_device_handle dev, u_int ms)
|
1999-01-07 23:07:57 +00:00
|
|
|
{
|
|
|
|
usb_delay_ms(dev->bus, ms);
|
|
|
|
}
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_reset_port(usbd_device_handle dev, int port, usb_port_status_t *ps)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
usb_device_request_t req;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
1998-11-26 23:13:13 +00:00
|
|
|
int n;
|
2003-07-04 01:50:39 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
req.bmRequestType = UT_WRITE_CLASS_OTHER;
|
|
|
|
req.bRequest = UR_SET_FEATURE;
|
|
|
|
USETW(req.wValue, UHF_PORT_RESET);
|
|
|
|
USETW(req.wIndex, port);
|
|
|
|
USETW(req.wLength, 0);
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_do_request(dev, &req, 0);
|
1999-10-07 19:26:38 +00:00
|
|
|
DPRINTFN(1,("usbd_reset_port: port %d reset done, error=%s\n",
|
1999-11-17 22:33:51 +00:00
|
|
|
port, usbd_errstr(err)));
|
|
|
|
if (err)
|
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
n = 10;
|
|
|
|
do {
|
|
|
|
/* Wait for device to recover from reset. */
|
1999-01-07 23:07:57 +00:00
|
|
|
usbd_delay_ms(dev, USB_PORT_RESET_DELAY);
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_get_port_status(dev, port, ps);
|
|
|
|
if (err) {
|
|
|
|
DPRINTF(("usbd_reset_port: get status failed %d\n",
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
err));
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
2002-04-07 10:57:42 +00:00
|
|
|
/* If the device disappeared, just give up. */
|
|
|
|
if (!(UGETW(ps->wPortStatus) & UPS_CURRENT_CONNECT_STATUS))
|
|
|
|
return (USBD_NORMAL_COMPLETION);
|
1998-11-26 23:13:13 +00:00
|
|
|
} while ((UGETW(ps->wPortChange) & UPS_C_PORT_RESET) == 0 && --n > 0);
|
2000-08-13 18:39:24 +00:00
|
|
|
if (n == 0)
|
|
|
|
return (USBD_TIMEOUT);
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_clear_port_feature(dev, port, UHF_C_PORT_RESET);
|
1998-11-26 23:13:13 +00:00
|
|
|
#ifdef USB_DEBUG
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err)
|
|
|
|
DPRINTF(("usbd_reset_port: clear port feature failed %d\n",
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
err));
|
1998-11-26 23:13:13 +00:00
|
|
|
#endif
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
|
|
/* Wait for the device to recover from reset. */
|
|
|
|
usbd_delay_ms(dev, USB_PORT_RESET_RECOVERY);
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usb_interface_descriptor_t *
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_find_idesc(usb_config_descriptor_t *cd, int ifaceidx, int altidx)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
char *p = (char *)cd;
|
|
|
|
char *end = p + UGETW(cd->wTotalLength);
|
|
|
|
usb_interface_descriptor_t *d;
|
1999-01-07 23:07:57 +00:00
|
|
|
int curidx, lastidx, curaidx = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
for (curidx = lastidx = -1; p < end; ) {
|
1998-11-26 23:13:13 +00:00
|
|
|
d = (usb_interface_descriptor_t *)p;
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(4,("usbd_find_idesc: idx=%d(%d) altidx=%d(%d) len=%d "
|
2003-07-04 01:50:39 +00:00
|
|
|
"type=%d\n",
|
1999-01-07 23:07:57 +00:00
|
|
|
ifaceidx, curidx, altidx, curaidx,
|
|
|
|
d->bLength, d->bDescriptorType));
|
|
|
|
if (d->bLength == 0) /* bad descriptor */
|
|
|
|
break;
|
|
|
|
p += d->bLength;
|
|
|
|
if (p <= end && d->bDescriptorType == UDESC_INTERFACE) {
|
|
|
|
if (d->bInterfaceNumber != lastidx) {
|
|
|
|
lastidx = d->bInterfaceNumber;
|
|
|
|
curidx++;
|
|
|
|
curaidx = 0;
|
|
|
|
} else
|
|
|
|
curaidx++;
|
|
|
|
if (ifaceidx == curidx && altidx == curaidx)
|
|
|
|
return (d);
|
|
|
|
}
|
|
|
|
}
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
return (NULL);
|
1999-01-07 23:07:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usb_endpoint_descriptor_t *
|
2003-07-04 01:50:39 +00:00
|
|
|
usbd_find_edesc(usb_config_descriptor_t *cd, int ifaceidx, int altidx,
|
2001-07-05 10:12:59 +00:00
|
|
|
int endptidx)
|
1999-01-07 23:07:57 +00:00
|
|
|
{
|
|
|
|
char *p = (char *)cd;
|
|
|
|
char *end = p + UGETW(cd->wTotalLength);
|
|
|
|
usb_interface_descriptor_t *d;
|
|
|
|
usb_endpoint_descriptor_t *e;
|
|
|
|
int curidx;
|
|
|
|
|
|
|
|
d = usbd_find_idesc(cd, ifaceidx, altidx);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (d == NULL)
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
return (NULL);
|
1999-01-07 23:07:57 +00:00
|
|
|
if (endptidx >= d->bNumEndpoints) /* quick exit */
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
return (NULL);
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
|
|
curidx = -1;
|
|
|
|
for (p = (char *)d + d->bLength; p < end; ) {
|
|
|
|
e = (usb_endpoint_descriptor_t *)p;
|
|
|
|
if (e->bLength == 0) /* bad descriptor */
|
|
|
|
break;
|
|
|
|
p += e->bLength;
|
|
|
|
if (p <= end && e->bDescriptorType == UDESC_INTERFACE)
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
return (NULL);
|
1999-01-07 23:07:57 +00:00
|
|
|
if (p <= end && e->bDescriptorType == UDESC_ENDPOINT) {
|
|
|
|
curidx++;
|
|
|
|
if (curidx == endptidx)
|
|
|
|
return (e);
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
return (NULL);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_fill_iface_data(usbd_device_handle dev, int ifaceidx, int altidx)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-01-07 23:07:57 +00:00
|
|
|
usbd_interface_handle ifc = &dev->ifaces[ifaceidx];
|
2001-07-05 10:12:59 +00:00
|
|
|
usb_interface_descriptor_t *idesc;
|
1998-11-26 23:13:13 +00:00
|
|
|
char *p, *end;
|
|
|
|
int endpt, nendpt;
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(4,("usbd_fill_iface_data: ifaceidx=%d altidx=%d\n",
|
|
|
|
ifaceidx, altidx));
|
2001-07-05 10:12:59 +00:00
|
|
|
idesc = usbd_find_idesc(dev->cdesc, ifaceidx, altidx);
|
|
|
|
if (idesc == NULL)
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_INVAL);
|
2001-07-05 10:12:59 +00:00
|
|
|
ifc->device = dev;
|
|
|
|
ifc->idesc = idesc;
|
1999-01-07 23:07:57 +00:00
|
|
|
ifc->index = ifaceidx;
|
|
|
|
ifc->altindex = altidx;
|
1998-11-26 23:13:13 +00:00
|
|
|
nendpt = ifc->idesc->bNumEndpoints;
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
DPRINTFN(4,("usbd_fill_iface_data: found idesc nendpt=%d\n", nendpt));
|
1998-11-26 23:13:13 +00:00
|
|
|
if (nendpt != 0) {
|
|
|
|
ifc->endpoints = malloc(nendpt * sizeof(struct usbd_endpoint),
|
|
|
|
M_USB, M_NOWAIT);
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
if (ifc->endpoints == NULL)
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_NOMEM);
|
|
|
|
} else
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
ifc->endpoints = NULL;
|
|
|
|
ifc->priv = NULL;
|
1998-11-26 23:13:13 +00:00
|
|
|
p = (char *)ifc->idesc + ifc->idesc->bLength;
|
|
|
|
end = (char *)dev->cdesc + UGETW(dev->cdesc->wTotalLength);
|
1999-01-07 23:07:57 +00:00
|
|
|
#define ed ((usb_endpoint_descriptor_t *)p)
|
1998-11-26 23:13:13 +00:00
|
|
|
for (endpt = 0; endpt < nendpt; endpt++) {
|
|
|
|
DPRINTFN(10,("usbd_fill_iface_data: endpt=%d\n", endpt));
|
|
|
|
for (; p < end; p += ed->bLength) {
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(10,("usbd_fill_iface_data: p=%p end=%p "
|
|
|
|
"len=%d type=%d\n",
|
1998-11-26 23:13:13 +00:00
|
|
|
p, end, ed->bLength, ed->bDescriptorType));
|
1999-01-07 23:07:57 +00:00
|
|
|
if (p + ed->bLength <= end && ed->bLength != 0 &&
|
1998-11-26 23:13:13 +00:00
|
|
|
ed->bDescriptorType == UDESC_ENDPOINT)
|
|
|
|
goto found;
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
if (ed->bLength == 0 ||
|
|
|
|
ed->bDescriptorType == UDESC_INTERFACE)
|
1998-11-26 23:13:13 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
/* passed end, or bad desc */
|
2002-04-25 12:49:38 +00:00
|
|
|
printf("usbd_fill_iface_data: bad descriptor(s): %s\n",
|
|
|
|
ed->bLength == 0 ? "0 length" :
|
|
|
|
ed->bDescriptorType == UDESC_INTERFACE ? "iface desc":
|
|
|
|
"out of data");
|
1998-11-26 23:13:13 +00:00
|
|
|
goto bad;
|
|
|
|
found:
|
|
|
|
ifc->endpoints[endpt].edesc = ed;
|
2002-04-25 12:49:38 +00:00
|
|
|
if (dev->speed == USB_SPEED_HIGH) {
|
|
|
|
u_int mps;
|
|
|
|
/* Control and bulk endpoints have max packet limits. */
|
|
|
|
switch (UE_GET_XFERTYPE(ed->bmAttributes)) {
|
|
|
|
case UE_CONTROL:
|
|
|
|
mps = USB_2_MAX_CTRL_PACKET;
|
|
|
|
goto check;
|
|
|
|
case UE_BULK:
|
|
|
|
mps = USB_2_MAX_BULK_PACKET;
|
|
|
|
check:
|
|
|
|
if (UGETW(ed->wMaxPacketSize) != mps) {
|
|
|
|
USETW(ed->wMaxPacketSize, mps);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("usbd_fill_iface_data: bad max "
|
|
|
|
"packet size\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
ifc->endpoints[endpt].refcnt = 0;
|
1999-01-07 23:07:57 +00:00
|
|
|
p += ed->bLength;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
#undef ed
|
1998-11-26 23:13:13 +00:00
|
|
|
LIST_INIT(&ifc->pipes);
|
|
|
|
return (USBD_NORMAL_COMPLETION);
|
1999-01-07 23:07:57 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
bad:
|
2001-07-05 10:12:59 +00:00
|
|
|
if (ifc->endpoints != NULL) {
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
free(ifc->endpoints, M_USB);
|
2001-07-05 10:12:59 +00:00
|
|
|
ifc->endpoints = NULL;
|
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
return (USBD_INVAL);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_free_iface_data(usbd_device_handle dev, int ifcno)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
usbd_interface_handle ifc = &dev->ifaces[ifcno];
|
|
|
|
if (ifc->endpoints)
|
|
|
|
free(ifc->endpoints, M_USB);
|
|
|
|
}
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_set_config(usbd_device_handle dev, int conf)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
usb_device_request_t req;
|
|
|
|
|
|
|
|
req.bmRequestType = UT_WRITE_DEVICE;
|
|
|
|
req.bRequest = UR_SET_CONFIG;
|
|
|
|
USETW(req.wValue, conf);
|
|
|
|
USETW(req.wIndex, 0);
|
|
|
|
USETW(req.wLength, 0);
|
|
|
|
return (usbd_do_request(dev, &req, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_set_config_no(usbd_device_handle dev, int no, int msg)
|
1999-01-07 23:07:57 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
usb_config_descriptor_t cd;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
2000-08-13 18:39:24 +00:00
|
|
|
if (no == USB_UNCONFIG_NO)
|
|
|
|
return (usbd_set_config_index(dev, USB_UNCONFIG_INDEX, msg));
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(5,("usbd_set_config_no: %d\n", no));
|
|
|
|
/* Figure out what config index to use. */
|
|
|
|
for (index = 0; index < dev->ddesc.bNumConfigurations; index++) {
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_get_config_desc(dev, index, &cd);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
1999-01-07 23:07:57 +00:00
|
|
|
if (cd.bConfigurationValue == no)
|
|
|
|
return (usbd_set_config_index(dev, index, msg));
|
|
|
|
}
|
|
|
|
return (USBD_INVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_set_config_index(usbd_device_handle dev, int index, int msg)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
usb_status_t ds;
|
|
|
|
usb_config_descriptor_t cd, *cdp;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
1999-01-07 23:07:57 +00:00
|
|
|
int ifcidx, nifc, len, selfpowered, power;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(5,("usbd_set_config_index: dev=%p index=%d\n", dev, index));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
/* XXX check that all interfaces are idle */
|
2000-08-13 18:39:24 +00:00
|
|
|
if (dev->config != USB_UNCONFIG_NO) {
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTF(("usbd_set_config_index: free old config\n"));
|
1998-11-26 23:13:13 +00:00
|
|
|
/* Free all configuration data structures. */
|
|
|
|
nifc = dev->cdesc->bNumInterface;
|
1999-01-07 23:07:57 +00:00
|
|
|
for (ifcidx = 0; ifcidx < nifc; ifcidx++)
|
|
|
|
usbd_free_iface_data(dev, ifcidx);
|
1998-11-26 23:13:13 +00:00
|
|
|
free(dev->ifaces, M_USB);
|
|
|
|
free(dev->cdesc, M_USB);
|
1999-11-28 20:55:22 +00:00
|
|
|
dev->ifaces = NULL;
|
|
|
|
dev->cdesc = NULL;
|
2000-08-13 18:39:24 +00:00
|
|
|
dev->config = USB_UNCONFIG_NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == USB_UNCONFIG_INDEX) {
|
|
|
|
/* We are unconfiguring the device, so leave unallocated. */
|
|
|
|
DPRINTF(("usbd_set_config_index: set config 0\n"));
|
|
|
|
err = usbd_set_config(dev, USB_UNCONFIG_NO);
|
|
|
|
if (err)
|
|
|
|
DPRINTF(("usbd_set_config_index: setting config=0 "
|
|
|
|
"failed, error=%s\n", usbd_errstr(err)));
|
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
2000-08-13 18:39:24 +00:00
|
|
|
/* Get the short descriptor. */
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_get_config_desc(dev, index, &cd);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
len = UGETW(cd.wTotalLength);
|
|
|
|
cdp = malloc(len, M_USB, M_NOWAIT);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (cdp == NULL)
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_NOMEM);
|
2000-08-13 18:39:24 +00:00
|
|
|
/* Get the full descriptor. */
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_get_desc(dev, UDESC_CONFIG, index, len, cdp);
|
|
|
|
if (err)
|
1998-11-26 23:13:13 +00:00
|
|
|
goto bad;
|
1999-01-07 23:07:57 +00:00
|
|
|
if (cdp->bDescriptorType != UDESC_CONFIG) {
|
|
|
|
DPRINTFN(-1,("usbd_set_config_index: bad desc %d\n",
|
|
|
|
cdp->bDescriptorType));
|
1999-11-17 22:33:51 +00:00
|
|
|
err = USBD_INVAL;
|
1999-01-07 23:07:57 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2000-08-13 18:39:24 +00:00
|
|
|
|
|
|
|
/* Figure out if the device is self or bus powered. */
|
1998-11-26 23:13:13 +00:00
|
|
|
selfpowered = 0;
|
1999-11-17 22:33:51 +00:00
|
|
|
if (!(dev->quirks->uq_flags & UQ_BUS_POWERED) &&
|
2000-08-13 18:39:24 +00:00
|
|
|
(cdp->bmAttributes & UC_SELF_POWERED)) {
|
1998-11-26 23:13:13 +00:00
|
|
|
/* May be self powered. */
|
|
|
|
if (cdp->bmAttributes & UC_BUS_POWERED) {
|
|
|
|
/* Must ask device. */
|
2002-04-01 18:22:31 +00:00
|
|
|
if (dev->quirks->uq_flags & UQ_POWER_CLAIM) {
|
|
|
|
/*
|
|
|
|
* Hub claims to be self powered, but isn't.
|
|
|
|
* It seems that the power status can be
|
|
|
|
* determined by the hub characteristics.
|
|
|
|
*/
|
|
|
|
usb_hub_descriptor_t hd;
|
|
|
|
usb_device_request_t req;
|
|
|
|
req.bmRequestType = UT_READ_CLASS_DEVICE;
|
|
|
|
req.bRequest = UR_GET_DESCRIPTOR;
|
|
|
|
USETW(req.wValue, 0);
|
|
|
|
USETW(req.wIndex, 0);
|
|
|
|
USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE);
|
|
|
|
err = usbd_do_request(dev, &req, &hd);
|
|
|
|
if (!err &&
|
|
|
|
(UGETW(hd.wHubCharacteristics) &
|
|
|
|
UHD_PWR_INDIVIDUAL))
|
|
|
|
selfpowered = 1;
|
|
|
|
DPRINTF(("usbd_set_config_index: charac=0x%04x"
|
|
|
|
", error=%s\n",
|
|
|
|
UGETW(hd.wHubCharacteristics),
|
|
|
|
usbd_errstr(err)));
|
|
|
|
} else {
|
|
|
|
err = usbd_get_device_status(dev, &ds);
|
|
|
|
if (!err &&
|
|
|
|
(UGETW(ds.wStatus) & UDS_SELF_POWERED))
|
|
|
|
selfpowered = 1;
|
|
|
|
DPRINTF(("usbd_set_config_index: status=0x%04x"
|
|
|
|
", error=%s\n",
|
|
|
|
UGETW(ds.wStatus), usbd_errstr(err)));
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
} else
|
|
|
|
selfpowered = 1;
|
|
|
|
}
|
2002-04-01 18:22:31 +00:00
|
|
|
DPRINTF(("usbd_set_config_index: (addr %d) cno=%d attr=0x%02x, "
|
|
|
|
"selfpowered=%d, power=%d\n",
|
2003-07-04 01:50:39 +00:00
|
|
|
cdp->bConfigurationValue, dev->address, cdp->bmAttributes,
|
1999-10-07 19:26:38 +00:00
|
|
|
selfpowered, cdp->bMaxPower * 2));
|
2000-08-13 18:39:24 +00:00
|
|
|
|
|
|
|
/* Check if we have enough power. */
|
1998-11-26 23:13:13 +00:00
|
|
|
#ifdef USB_DEBUG
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dev->powersrc == NULL) {
|
1999-10-07 19:26:38 +00:00
|
|
|
DPRINTF(("usbd_set_config_index: No power source?\n"));
|
1999-01-07 23:07:57 +00:00
|
|
|
return (USBD_IOERROR);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
power = cdp->bMaxPower * 2;
|
|
|
|
if (power > dev->powersrc->power) {
|
2002-04-25 12:58:30 +00:00
|
|
|
DPRINTF(("power exceeded %d %d\n", power,dev->powersrc->power));
|
1998-11-26 23:13:13 +00:00
|
|
|
/* XXX print nicer message. */
|
|
|
|
if (msg)
|
1999-01-07 23:07:57 +00:00
|
|
|
printf("%s: device addr %d (config %d) exceeds power "
|
|
|
|
"budget, %d mA > %d mA\n",
|
2003-07-04 01:50:39 +00:00
|
|
|
USBDEVNAME(dev->bus->bdev), dev->address,
|
|
|
|
cdp->bConfigurationValue,
|
1999-01-07 23:07:57 +00:00
|
|
|
power, dev->powersrc->power);
|
1999-11-17 22:33:51 +00:00
|
|
|
err = USBD_NO_POWER;
|
1998-11-26 23:13:13 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
dev->power = power;
|
|
|
|
dev->self_powered = selfpowered;
|
|
|
|
|
2000-08-13 18:39:24 +00:00
|
|
|
/* Set the actual configuration value. */
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTF(("usbd_set_config_index: set config %d\n",
|
|
|
|
cdp->bConfigurationValue));
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_set_config(dev, cdp->bConfigurationValue);
|
|
|
|
if (err) {
|
1999-10-07 19:26:38 +00:00
|
|
|
DPRINTF(("usbd_set_config_index: setting config=%d failed, "
|
|
|
|
"error=%s\n",
|
1999-11-17 22:33:51 +00:00
|
|
|
cdp->bConfigurationValue, usbd_errstr(err)));
|
1998-11-26 23:13:13 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2000-08-13 18:39:24 +00:00
|
|
|
|
|
|
|
/* Allocate and fill interface data. */
|
1998-11-26 23:13:13 +00:00
|
|
|
nifc = cdp->bNumInterface;
|
2003-07-04 01:50:39 +00:00
|
|
|
dev->ifaces = malloc(nifc * sizeof(struct usbd_interface),
|
1998-11-26 23:13:13 +00:00
|
|
|
M_USB, M_NOWAIT);
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
if (dev->ifaces == NULL) {
|
1999-11-17 22:33:51 +00:00
|
|
|
err = USBD_NOMEM;
|
1998-11-26 23:13:13 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(5,("usbd_set_config_index: dev=%p cdesc=%p\n", dev, cdp));
|
1998-11-26 23:13:13 +00:00
|
|
|
dev->cdesc = cdp;
|
|
|
|
dev->config = cdp->bConfigurationValue;
|
1999-01-07 23:07:57 +00:00
|
|
|
for (ifcidx = 0; ifcidx < nifc; ifcidx++) {
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_fill_iface_data(dev, ifcidx, 0);
|
|
|
|
if (err) {
|
1999-01-07 23:07:57 +00:00
|
|
|
while (--ifcidx >= 0)
|
|
|
|
usbd_free_iface_data(dev, ifcidx);
|
1998-11-26 23:13:13 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (USBD_NORMAL_COMPLETION);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
free(cdp, M_USB);
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX add function for alternate settings */
|
|
|
|
|
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_setup_pipe(usbd_device_handle dev, usbd_interface_handle iface,
|
|
|
|
struct usbd_endpoint *ep, int ival, usbd_pipe_handle *pipe)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-10-07 19:26:38 +00:00
|
|
|
usbd_pipe_handle p;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
DPRINTFN(1,("usbd_setup_pipe: dev=%p iface=%p ep=%p pipe=%p\n",
|
1999-10-07 19:26:38 +00:00
|
|
|
dev, iface, ep, pipe));
|
|
|
|
p = malloc(dev->bus->pipe_size, M_USB, M_NOWAIT);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (p == NULL)
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_NOMEM);
|
1999-10-07 19:26:38 +00:00
|
|
|
p->device = dev;
|
|
|
|
p->iface = iface;
|
|
|
|
p->endpoint = ep;
|
1998-11-26 23:13:13 +00:00
|
|
|
ep->refcnt++;
|
1999-10-07 19:26:38 +00:00
|
|
|
p->refcnt = 1;
|
1999-11-17 22:33:51 +00:00
|
|
|
p->intrxfer = 0;
|
1999-10-07 19:26:38 +00:00
|
|
|
p->running = 0;
|
Huge merge from NetBSD:
usbdi.c (1.61):
===================================================================
revision 1.61
date: 2000/01/31 20:13:07; author: augustss; lines: +20 -4
Change the way the HC done method is invoked a little.
===================================================================
usbdi.c (1.65):
===================================================================
revision 1.65
date: 2000/03/08 15:34:10; author: augustss; lines: +4 -2
Get the status right when a polled transfer times out.
===================================================================
ohci.c (1.79), uhci.c (1.89), uhcivar.h (1.24), usb_port.h (1.22),
usbdivar.h (1.48):
===================================================================
date: 2000/03/23 07:01:46; author: thorpej;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.
The old timeout()/untimeout() API has been removed from the kernel.
===================================================================
uhci.c (1.80), usbdi.c (1.66):
===================================================================
date: 2000/03/23 18:59:10; author: thorpej;
Shake out some bugs from the callout changes.
===================================================================
ohci.c (1.80), uhci.c (1.91), uhcivar.h (1.25), usb_port.h (1.23),
usbdi.c (1.67), usbdivar.h (1.49):
===================================================================
date: 2000/03/24 22:03:30; author: augustss;
Some cleanup and renaming of the callouts used in USB drivers.
===================================================================
uhci.c (1.92), uhcivar.h (1.26):
===================================================================
date: 2000/03/24 22:57:58; author: augustss;
Two major changes:
Make each xfer have its own intr_info. This is necessary if we want
to queue multiple xfers on an endpoint. This should get rid of the
(mostly harmless) DIAGNOSTICs about intr_infos (not) being done.
Change (again!) how xfers are aborted. Aborting a TD is a nightmare
on the braindead UHCI controller. (Unless you stop the HC, thereby
losing isoc traffic.) Hopefully I got it right this time.
===================================================================
usbdivar.h (1.50):
===================================================================
revision 1.50
date: 2000/03/25 00:10:19; author: augustss; lines: +4 -2
GC an unsued field and add some DIAGNOSTIC in xfer.
===================================================================
ums.c: Use the callout functions instead of the timeout ones.
uhci.c (1.93):
===================================================================
revision 1.93
date: 2000/03/25 00:11:21; author: augustss;
lines: +26 -1
Add more DIAGNOSTIC when aborting isoc.
===================================================================
uhci.c (1.94), usbdivar.h (1.51):
===================================================================
date: 2000/03/25 07:13:05; author: augustss;
More DIAGNOSTIC.
Initialize a callout handle I forgot.
===================================================================
uhci.c (1.95):
===================================================================
revision 1.95
date: 2000/03/25 07:23:12; author: augustss;
Exp; lines: +24 -7
Improve uhci_dump_ii().
===================================================================
ohci.c (1.81), uhci.c (1.96), uhcivar.h (1.27), usb_subr.c (1.68),
usbdi.c (1.68), usbdivar.h (1.52):
===================================================================
date: 2000/03/25 18:02:33; author: augustss;
Rename and move around callout handles to make it more sane.
Add some DIAGNOSTIC.
Fix buglet in isoc abort on UHCI.
===================================================================
uhci.c (1.98):
===================================================================
revision 1.98
date: 2000/03/27 07:39:48; author: augustss; lines: +12 -4
Make it compile without DIAGNOSTIC.
===================================================================
uhci.c (1.99):
===================================================================
revision 1.99
date: 2000/03/27 08:01:09; author: augustss; lines: +1 -5
Remove some debug nonsense.
===================================================================
uhci.c (1.100):
===================================================================
revision 1.100
date: 2000/03/27 09:41:36; author: augustss; lines: +13 -3
Don't mess with QH in bulk abort for the moment.
===================================================================
uhci.c (1.102):
===================================================================
revision 1.102
date: 2000/03/27 22:42:57; author: augustss; lines: +66 -26
Be a little more careful when aborting.
Preallocate some TDs for large buffers.
===================================================================
uhci.c (1.103):
===================================================================
date: 2000/03/28 09:47:10; author: augustss; lines: +11 -1
Another patch for xfer abort...
XXX The current xfer queueing and aborting semantics should really
XXX be changed. It cannot be implemented in a sane way on UHCI.
XXX One day when I have lots of time I'll redesign it...
===================================================================
uhci.c (1.104): Correct a debug message.
uhci.c (1.105): Be more defensive in a DIAGNOSTIC test.
uhci.c (1.106):
===================================================================
revision 1.106
date: 2000/03/29 01:49:13; author: augustss; lines: +14 -309
*SIGH* Revert back to the old method of aborting xfers.
I had tested the new stuff for two months now, but as soon as I commited
it the problems started to appear. Murphy, no doubt...
===================================================================
usb_subr.c (1.70), usbdi.c (1.71), usbdivar.h (1.53):
===================================================================
revision 1.70
date: 2000/03/29 01:45:20; author: augustss; lines: +2 -1
Do not accept new xfers for queuing while a pipe is aborting.
===================================================================
2002-03-16 12:06:01 +00:00
|
|
|
p->aborting = 0;
|
1999-10-07 19:26:38 +00:00
|
|
|
p->repeat = 0;
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
p->interval = ival;
|
1999-10-07 19:26:38 +00:00
|
|
|
SIMPLEQ_INIT(&p->queue);
|
1999-11-17 22:33:51 +00:00
|
|
|
err = dev->bus->methods->open_pipe(p);
|
|
|
|
if (err) {
|
1999-10-07 19:26:38 +00:00
|
|
|
DPRINTFN(-1,("usbd_setup_pipe: endpoint=0x%x failed, error="
|
|
|
|
"%s\n",
|
1999-11-17 22:33:51 +00:00
|
|
|
ep->edesc->bEndpointAddress, usbd_errstr(err)));
|
1999-10-07 19:26:38 +00:00
|
|
|
free(p, M_USB);
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-10-07 19:26:38 +00:00
|
|
|
/* Clear any stall and make sure DATA0 toggle will be used next. */
|
|
|
|
if (UE_GET_ADDR(ep->edesc->bEndpointAddress) != USB_CONTROL_ENDPOINT)
|
|
|
|
usbd_clear_endpoint_stall(p);
|
|
|
|
*pipe = p;
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_NORMAL_COMPLETION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Abort the device control pipe. */
|
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_kill_pipe(usbd_pipe_handle pipe)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
2002-04-02 14:16:06 +00:00
|
|
|
usbd_abort_pipe(pipe);
|
1998-11-26 23:13:13 +00:00
|
|
|
pipe->methods->close(pipe);
|
|
|
|
pipe->endpoint->refcnt--;
|
|
|
|
free(pipe, M_USB);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_getnewaddr(usbd_bus_handle bus)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
int addr;
|
|
|
|
|
|
|
|
for (addr = 1; addr < USB_MAX_DEVICES; addr++)
|
|
|
|
if (bus->devices[addr] == 0)
|
|
|
|
return (addr);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:26:38 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_probe_and_attach(device_ptr_t parent, usbd_device_handle dev,
|
|
|
|
int port, int addr)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
struct usb_attach_arg uaa;
|
|
|
|
usb_device_descriptor_t *dd = &dev->ddesc;
|
1999-11-17 22:33:51 +00:00
|
|
|
int found, i, confi, nifaces;
|
|
|
|
usbd_status err;
|
1999-10-07 19:26:38 +00:00
|
|
|
device_ptr_t dv;
|
1999-01-07 23:07:57 +00:00
|
|
|
usbd_interface_handle ifaces[256]; /* 256 is the absolute max */
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
2003-07-04 01:50:39 +00:00
|
|
|
/*
|
1999-10-07 19:26:38 +00:00
|
|
|
* XXX uaa is a static var. Not a problem as it _should_ be used only
|
|
|
|
* during probe and attach. Should be changed however.
|
|
|
|
*/
|
|
|
|
device_t bdev;
|
1999-12-03 08:41:24 +00:00
|
|
|
bdev = device_add_child(parent, NULL, -1);
|
1999-01-07 23:07:57 +00:00
|
|
|
if (!bdev) {
|
|
|
|
printf("%s: Device creation failed\n", USBDEVNAME(dev->bus->bdev));
|
|
|
|
return (USBD_INVAL);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
2002-06-17 20:52:26 +00:00
|
|
|
device_set_ivars(bdev, &uaa);
|
1999-06-21 21:32:15 +00:00
|
|
|
device_quiet(bdev);
|
1998-11-26 23:13:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
uaa.device = dev;
|
2000-08-13 18:39:24 +00:00
|
|
|
uaa.iface = NULL;
|
|
|
|
uaa.ifaces = NULL;
|
1999-01-07 23:07:57 +00:00
|
|
|
uaa.nifaces = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
uaa.usegeneric = 0;
|
1999-01-07 23:07:57 +00:00
|
|
|
uaa.port = port;
|
|
|
|
uaa.configno = UHUB_UNK_CONFIGURATION;
|
|
|
|
uaa.ifaceno = UHUB_UNK_INTERFACE;
|
1999-10-07 19:26:38 +00:00
|
|
|
uaa.vendor = UGETW(dd->idVendor);
|
|
|
|
uaa.product = UGETW(dd->idProduct);
|
|
|
|
uaa.release = UGETW(dd->bcdDevice);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
/* First try with device specific drivers. */
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
DPRINTF(("usbd_probe_and_attach: trying device specific drivers\n"));
|
1999-10-07 19:26:38 +00:00
|
|
|
dv = USB_DO_ATTACH(dev, bdev, parent, &uaa, usbd_print, usbd_submatch);
|
|
|
|
if (dv) {
|
|
|
|
dev->subdevs = malloc(2 * sizeof dv, M_USB, M_NOWAIT);
|
1999-11-28 20:55:22 +00:00
|
|
|
if (dev->subdevs == NULL)
|
1999-10-07 19:26:38 +00:00
|
|
|
return (USBD_NOMEM);
|
|
|
|
dev->subdevs[0] = dv;
|
|
|
|
dev->subdevs[1] = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_NORMAL_COMPLETION);
|
1999-10-07 19:26:38 +00:00
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTF(("usbd_probe_and_attach: no device specific driver found\n"));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
DPRINTF(("usbd_probe_and_attach: looping over %d configurations\n",
|
|
|
|
dd->bNumConfigurations));
|
1998-11-26 23:13:13 +00:00
|
|
|
/* Next try with interface drivers. */
|
|
|
|
for (confi = 0; confi < dd->bNumConfigurations; confi++) {
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(1,("usbd_probe_and_attach: trying config idx=%d\n",
|
|
|
|
confi));
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_set_config_index(dev, confi, 1);
|
|
|
|
if (err) {
|
1999-10-07 19:26:38 +00:00
|
|
|
#ifdef USB_DEBUG
|
|
|
|
DPRINTF(("%s: port %d, set config at addr %d failed, "
|
|
|
|
"error=%s\n", USBDEVPTRNAME(parent), port,
|
1999-11-17 22:33:51 +00:00
|
|
|
addr, usbd_errstr(err)));
|
1999-10-07 19:26:38 +00:00
|
|
|
#else
|
|
|
|
printf("%s: port %d, set config at addr %d failed\n",
|
|
|
|
USBDEVPTRNAME(parent), port, addr);
|
|
|
|
#endif
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
device_delete_child(parent, bdev);
|
|
|
|
#endif
|
1999-11-17 22:33:51 +00:00
|
|
|
|
|
|
|
return (err);
|
1999-01-07 23:07:57 +00:00
|
|
|
}
|
|
|
|
nifaces = dev->cdesc->bNumInterface;
|
|
|
|
uaa.configno = dev->cdesc->bConfigurationValue;
|
|
|
|
for (i = 0; i < nifaces; i++)
|
|
|
|
ifaces[i] = &dev->ifaces[i];
|
|
|
|
uaa.ifaces = ifaces;
|
|
|
|
uaa.nifaces = nifaces;
|
1999-10-07 19:26:38 +00:00
|
|
|
dev->subdevs = malloc((nifaces+1) * sizeof dv, M_USB,M_NOWAIT);
|
1999-11-28 20:55:22 +00:00
|
|
|
if (dev->subdevs == NULL) {
|
1999-10-07 19:26:38 +00:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
device_delete_child(parent, bdev);
|
|
|
|
#endif
|
|
|
|
return (USBD_NOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
found = 0;
|
1999-01-22 00:51:12 +00:00
|
|
|
for (i = 0; i < nifaces; i++) {
|
1999-11-17 22:33:51 +00:00
|
|
|
if (ifaces[i] == NULL)
|
1999-01-07 23:07:57 +00:00
|
|
|
continue; /* interface already claimed */
|
|
|
|
uaa.iface = ifaces[i];
|
|
|
|
uaa.ifaceno = ifaces[i]->idesc->bInterfaceNumber;
|
1999-10-07 19:26:38 +00:00
|
|
|
dv = USB_DO_ATTACH(dev, bdev, parent, &uaa, usbd_print,
|
|
|
|
usbd_submatch);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dv != NULL) {
|
1999-10-07 19:26:38 +00:00
|
|
|
dev->subdevs[found++] = dv;
|
|
|
|
dev->subdevs[found] = 0;
|
1999-01-07 23:07:57 +00:00
|
|
|
ifaces[i] = 0; /* consumed */
|
1999-05-30 18:49:17 +00:00
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
/* create another child for the next iface */
|
1999-12-03 08:41:24 +00:00
|
|
|
bdev = device_add_child(parent, NULL, -1);
|
1999-05-30 18:49:17 +00:00
|
|
|
if (!bdev) {
|
|
|
|
printf("%s: Device creation failed\n",
|
1999-10-07 19:26:38 +00:00
|
|
|
USBDEVNAME(dev->bus->bdev));
|
1999-05-30 18:49:17 +00:00
|
|
|
return (USBD_NORMAL_COMPLETION);
|
|
|
|
}
|
2002-06-17 20:52:26 +00:00
|
|
|
device_set_ivars(bdev, &uaa);
|
1999-06-21 21:32:15 +00:00
|
|
|
device_quiet(bdev);
|
1999-01-22 00:51:12 +00:00
|
|
|
#endif
|
1999-01-07 23:07:57 +00:00
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-05-30 18:49:17 +00:00
|
|
|
if (found != 0) {
|
|
|
|
#if defined(__FreeBSD__)
|
1999-10-07 19:26:38 +00:00
|
|
|
/* remove the last created child again; it is unused */
|
|
|
|
device_delete_child(parent, bdev);
|
1999-01-22 00:51:12 +00:00
|
|
|
#endif
|
1999-05-30 18:49:17 +00:00
|
|
|
return (USBD_NORMAL_COMPLETION);
|
|
|
|
}
|
1999-10-07 19:26:38 +00:00
|
|
|
free(dev->subdevs, M_USB);
|
|
|
|
dev->subdevs = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
/* No interfaces were attached in any of the configurations. */
|
1999-10-07 19:26:38 +00:00
|
|
|
|
|
|
|
if (dd->bNumConfigurations > 1) /* don't change if only 1 config */
|
1999-01-07 23:07:57 +00:00
|
|
|
usbd_set_config_index(dev, 0, 0);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTF(("usbd_probe_and_attach: no interface drivers found\n"));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
/* Finally try the generic driver. */
|
2000-08-13 18:39:24 +00:00
|
|
|
uaa.iface = NULL;
|
1998-11-26 23:13:13 +00:00
|
|
|
uaa.usegeneric = 1;
|
1999-01-07 23:07:57 +00:00
|
|
|
uaa.configno = UHUB_UNK_CONFIGURATION;
|
|
|
|
uaa.ifaceno = UHUB_UNK_INTERFACE;
|
1999-10-07 19:26:38 +00:00
|
|
|
dv = USB_DO_ATTACH(dev, bdev, parent, &uaa, usbd_print, usbd_submatch);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dv != NULL) {
|
1999-10-07 19:26:38 +00:00
|
|
|
dev->subdevs = malloc(2 * sizeof dv, M_USB, M_NOWAIT);
|
|
|
|
if (dev->subdevs == 0)
|
|
|
|
return (USBD_NOMEM);
|
|
|
|
dev->subdevs[0] = dv;
|
|
|
|
dev->subdevs[1] = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_NORMAL_COMPLETION);
|
1999-10-07 19:26:38 +00:00
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2003-07-04 01:50:39 +00:00
|
|
|
/*
|
1999-01-07 23:07:57 +00:00
|
|
|
* The generic attach failed, but leave the device as it is.
|
|
|
|
* We just did not find any drivers, that's all. The device is
|
|
|
|
* fully operational and not harming anyone.
|
1998-11-26 23:13:13 +00:00
|
|
|
*/
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTF(("usbd_probe_and_attach: generic attach failed\n"));
|
|
|
|
#if defined(__FreeBSD__)
|
1999-10-07 19:26:38 +00:00
|
|
|
device_delete_child(parent, bdev);
|
1999-01-07 23:07:57 +00:00
|
|
|
#endif
|
1999-10-07 19:26:38 +00:00
|
|
|
return (USBD_NORMAL_COMPLETION);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when a new device has been put in the powered state,
|
|
|
|
* but not yet in the addressed state.
|
|
|
|
* Get initial descriptor, set the address, get full descriptor,
|
|
|
|
* and attach a driver.
|
|
|
|
*/
|
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_new_device(device_ptr_t parent, usbd_bus_handle bus, int depth,
|
2002-04-01 18:22:31 +00:00
|
|
|
int speed, int port, struct usbd_port *up)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
usbd_device_handle dev;
|
2002-04-25 12:37:55 +00:00
|
|
|
struct usbd_device *hub;
|
1998-11-26 23:13:13 +00:00
|
|
|
usb_device_descriptor_t *dd;
|
2003-09-01 07:47:42 +00:00
|
|
|
usb_port_status_t ps;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
1998-11-26 23:13:13 +00:00
|
|
|
int addr;
|
|
|
|
int i;
|
|
|
|
|
2002-04-01 18:22:31 +00:00
|
|
|
DPRINTF(("usbd_new_device bus=%p port=%d depth=%d speed=%d\n",
|
|
|
|
bus, port, depth, speed));
|
1998-11-26 23:13:13 +00:00
|
|
|
addr = usbd_getnewaddr(bus);
|
|
|
|
if (addr < 0) {
|
2003-07-04 01:50:39 +00:00
|
|
|
printf("%s: No free USB addresses, new device ignored.\n",
|
1999-01-07 23:07:57 +00:00
|
|
|
USBDEVNAME(bus->bdev));
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_NO_ADDR);
|
|
|
|
}
|
|
|
|
|
2002-04-07 17:53:58 +00:00
|
|
|
dev = malloc(sizeof *dev, M_USB, M_NOWAIT|M_ZERO);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dev == NULL)
|
1998-11-26 23:13:13 +00:00
|
|
|
return (USBD_NOMEM);
|
|
|
|
|
|
|
|
dev->bus = bus;
|
|
|
|
|
|
|
|
/* Set up default endpoint handle. */
|
|
|
|
dev->def_ep.edesc = &dev->def_ep_desc;
|
|
|
|
|
|
|
|
/* Set up default endpoint descriptor. */
|
|
|
|
dev->def_ep_desc.bLength = USB_ENDPOINT_DESCRIPTOR_SIZE;
|
|
|
|
dev->def_ep_desc.bDescriptorType = UDESC_ENDPOINT;
|
|
|
|
dev->def_ep_desc.bEndpointAddress = USB_CONTROL_ENDPOINT;
|
|
|
|
dev->def_ep_desc.bmAttributes = UE_CONTROL;
|
|
|
|
USETW(dev->def_ep_desc.wMaxPacketSize, USB_MAX_IPACKET);
|
|
|
|
dev->def_ep_desc.bInterval = 0;
|
|
|
|
|
|
|
|
dev->quirks = &usbd_no_quirk;
|
|
|
|
dev->address = USB_START_ADDR;
|
|
|
|
dev->ddesc.bMaxPacketSize = 0;
|
|
|
|
dev->depth = depth;
|
|
|
|
dev->powersrc = up;
|
2002-04-25 12:37:55 +00:00
|
|
|
dev->myhub = up->parent;
|
|
|
|
for (hub = up->parent;
|
|
|
|
hub != NULL && hub->speed != USB_SPEED_HIGH;
|
|
|
|
hub = hub->myhub)
|
|
|
|
;
|
|
|
|
dev->myhighhub = hub;
|
2002-02-16 00:51:26 +00:00
|
|
|
dev->speed = speed;
|
2002-04-25 12:37:55 +00:00
|
|
|
dev->langid = USBD_NOLANG;
|
1999-11-17 22:33:51 +00:00
|
|
|
dev->cookie.cookie = ++usb_cookie_no;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2000-08-13 18:39:24 +00:00
|
|
|
/* Establish the default pipe. */
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
err = usbd_setup_pipe(dev, 0, &dev->def_ep, USBD_DEFAULT_INTERVAL,
|
|
|
|
&dev->default_pipe);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err) {
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_remove_device(dev, up);
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
up->device = dev;
|
|
|
|
dd = &dev->ddesc;
|
|
|
|
/* Try a few times in case the device is slow (i.e. outside specs.) */
|
2003-09-01 07:47:42 +00:00
|
|
|
for (i = 0; i < 15; i++) {
|
1998-11-26 23:13:13 +00:00
|
|
|
/* Get the first 8 bytes of the device descriptor. */
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_get_desc(dev, UDESC_DEVICE, 0, USB_MAX_IPACKET, dd);
|
|
|
|
if (!err)
|
1998-11-26 23:13:13 +00:00
|
|
|
break;
|
1999-01-07 23:07:57 +00:00
|
|
|
usbd_delay_ms(dev, 200);
|
2003-09-01 07:47:42 +00:00
|
|
|
if ((i & 3) == 3)
|
|
|
|
usbd_reset_port(up->parent, port, &ps);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err) {
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(-1, ("usbd_new_device: addr=%d, getting first desc "
|
1999-11-17 22:33:51 +00:00
|
|
|
"failed\n", addr));
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_remove_device(dev, up);
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
2002-04-25 12:49:38 +00:00
|
|
|
if (speed == USB_SPEED_HIGH) {
|
|
|
|
/* Max packet size must be 64 (sec 5.5.3). */
|
|
|
|
if (dd->bMaxPacketSize != USB_2_MAX_CTRL_PACKET) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("usbd_new_device: addr=%d bad max packet size\n",
|
|
|
|
addr);
|
|
|
|
#endif
|
|
|
|
dd->bMaxPacketSize = USB_2_MAX_CTRL_PACKET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:26:38 +00:00
|
|
|
DPRINTF(("usbd_new_device: adding unit addr=%d, rev=%02x, class=%d, "
|
2003-07-04 01:50:39 +00:00
|
|
|
"subclass=%d, protocol=%d, maxpacket=%d, len=%d, speed=%d\n",
|
1999-10-07 19:26:38 +00:00
|
|
|
addr,UGETW(dd->bcdUSB), dd->bDeviceClass, dd->bDeviceSubClass,
|
2003-07-04 01:50:39 +00:00
|
|
|
dd->bDeviceProtocol, dd->bMaxPacketSize, dd->bLength,
|
2002-02-16 00:51:26 +00:00
|
|
|
dev->speed));
|
1999-10-07 19:26:38 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
if (dd->bDescriptorType != UDESC_DEVICE) {
|
|
|
|
/* Illegal device descriptor */
|
|
|
|
DPRINTFN(-1,("usbd_new_device: illegal descriptor %d\n",
|
|
|
|
dd->bDescriptorType));
|
|
|
|
usbd_remove_device(dev, up);
|
|
|
|
return (USBD_INVAL);
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:26:38 +00:00
|
|
|
if (dd->bLength < USB_DEVICE_DESCRIPTOR_SIZE) {
|
|
|
|
DPRINTFN(-1,("usbd_new_device: bad length %d\n", dd->bLength));
|
|
|
|
usbd_remove_device(dev, up);
|
|
|
|
return (USBD_INVAL);
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
USETW(dev->def_ep_desc.wMaxPacketSize, dd->bMaxPacketSize);
|
|
|
|
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
err = usbd_reload_device_desc(dev);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err) {
|
1999-01-07 23:07:57 +00:00
|
|
|
DPRINTFN(-1, ("usbd_new_device: addr=%d, getting full desc "
|
|
|
|
"failed\n", addr));
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_remove_device(dev, up);
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the address */
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_set_address(dev, addr);
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
DPRINTFN(5,("usbd_new_device: setting device address=%d\n", addr));
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err) {
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
DPRINTFN(-1,("usb_new_device: set address %d failed\n", addr));
|
1999-11-17 22:33:51 +00:00
|
|
|
err = USBD_SET_ADDR_FAILED;
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_remove_device(dev, up);
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
/* Allow device time to set new address */
|
|
|
|
usbd_delay_ms(dev, USB_SET_ADDRESS_SETTLE);
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
dev->address = addr; /* New device address now */
|
|
|
|
bus->devices[addr] = dev;
|
|
|
|
|
|
|
|
/* Assume 100mA bus powered for now. Changed when configured. */
|
|
|
|
dev->power = USB_MIN_POWER;
|
|
|
|
dev->self_powered = 0;
|
|
|
|
|
2003-07-04 01:50:39 +00:00
|
|
|
DPRINTF(("usbd_new_device: new dev (addr %d), dev=%p, parent=%p\n",
|
1998-11-26 23:13:13 +00:00
|
|
|
addr, dev, parent));
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
err = usbd_probe_and_attach(parent, dev, port, addr);
|
|
|
|
if (err) {
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_remove_device(dev, up);
|
1999-11-17 22:33:51 +00:00
|
|
|
return (err);
|
1999-01-07 23:07:57 +00:00
|
|
|
}
|
2001-07-05 10:12:59 +00:00
|
|
|
|
2002-01-28 01:03:19 +00:00
|
|
|
usbd_add_dev_event(USB_EVENT_DEVICE_ATTACH, dev);
|
2003-07-04 01:50:39 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
return (USBD_NORMAL_COMPLETION);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
usbd_status
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_reload_device_desc(usbd_device_handle dev)
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
{
|
|
|
|
usbd_status err;
|
2003-01-08 05:03:35 +00:00
|
|
|
int i;
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
|
|
|
|
/* Get the full device descriptor. */
|
2003-01-08 05:03:35 +00:00
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
err = usbd_get_device_desc(dev, &dev->ddesc);
|
|
|
|
if (!err)
|
|
|
|
break;
|
|
|
|
usbd_delay_ms(dev, 200);
|
|
|
|
}
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
|
|
|
/* Figure out what's wrong with this device. */
|
|
|
|
dev->quirks = usbd_find_quirk(&dev->ddesc);
|
|
|
|
|
|
|
|
return (USBD_NORMAL_COMPLETION);
|
|
|
|
}
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_remove_device(usbd_device_handle dev, struct usbd_port *up)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
DPRINTF(("usbd_remove_device: %p\n", dev));
|
2003-07-04 01:50:39 +00:00
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dev->default_pipe != NULL)
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_kill_pipe(dev->default_pipe);
|
|
|
|
up->device = 0;
|
|
|
|
dev->bus->devices[dev->address] = 0;
|
|
|
|
|
|
|
|
free(dev, M_USB);
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:26:38 +00:00
|
|
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
1998-11-26 23:13:13 +00:00
|
|
|
int
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_print(void *aux, const char *pnp)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
|
|
|
struct usb_attach_arg *uaa = aux;
|
|
|
|
char devinfo[1024];
|
|
|
|
|
|
|
|
DPRINTFN(15, ("usbd_print dev=%p\n", uaa->device));
|
|
|
|
if (pnp) {
|
|
|
|
if (!uaa->usegeneric)
|
|
|
|
return (QUIET);
|
|
|
|
usbd_devinfo(uaa->device, 1, devinfo);
|
1998-12-13 22:27:42 +00:00
|
|
|
printf("%s, %s", devinfo, pnp);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
if (uaa->port != 0)
|
|
|
|
printf(" port %d", uaa->port);
|
1998-12-13 22:27:42 +00:00
|
|
|
if (uaa->configno != UHUB_UNK_CONFIGURATION)
|
|
|
|
printf(" configuration %d", uaa->configno);
|
|
|
|
if (uaa->ifaceno != UHUB_UNK_INTERFACE)
|
|
|
|
printf(" interface %d", uaa->ifaceno);
|
1999-10-07 19:26:38 +00:00
|
|
|
#if 0
|
2003-07-04 01:50:39 +00:00
|
|
|
/*
|
1999-10-07 19:26:38 +00:00
|
|
|
* It gets very crowded with these locators on the attach line.
|
|
|
|
* They are not really needed since they are printed in the clear
|
|
|
|
* by each driver.
|
|
|
|
*/
|
|
|
|
if (uaa->vendor != UHUB_UNK_VENDOR)
|
|
|
|
printf(" vendor 0x%04x", uaa->vendor);
|
|
|
|
if (uaa->product != UHUB_UNK_PRODUCT)
|
|
|
|
printf(" product 0x%04x", uaa->product);
|
|
|
|
if (uaa->release != UHUB_UNK_RELEASE)
|
|
|
|
printf(" release 0x%04x", uaa->release);
|
|
|
|
#endif
|
1998-11-26 23:13:13 +00:00
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
1999-10-07 19:26:38 +00:00
|
|
|
#if defined(__NetBSD__)
|
1998-11-26 23:13:13 +00:00
|
|
|
int
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_submatch(struct device *parent, struct cfdata *cf, void *aux)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-10-07 19:26:38 +00:00
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
int
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_submatch(struct device *parent, void *match, void *aux)
|
1999-10-07 19:26:38 +00:00
|
|
|
{
|
|
|
|
struct cfdata *cf = match;
|
|
|
|
#endif
|
1998-11-26 23:13:13 +00:00
|
|
|
struct usb_attach_arg *uaa = aux;
|
|
|
|
|
2000-08-13 18:39:24 +00:00
|
|
|
DPRINTFN(5,("usbd_submatch port=%d,%d configno=%d,%d "
|
|
|
|
"ifaceno=%d,%d vendor=%d,%d product=%d,%d release=%d,%d\n",
|
|
|
|
uaa->port, cf->uhubcf_port,
|
|
|
|
uaa->configno, cf->uhubcf_configuration,
|
|
|
|
uaa->ifaceno, cf->uhubcf_interface,
|
|
|
|
uaa->vendor, cf->uhubcf_vendor,
|
|
|
|
uaa->product, cf->uhubcf_product,
|
|
|
|
uaa->release, cf->uhubcf_release));
|
|
|
|
if (uaa->port != 0 && /* root hub has port 0, it should match */
|
|
|
|
((uaa->port != 0 &&
|
2001-07-05 10:12:59 +00:00
|
|
|
cf->uhubcf_port != UHUB_UNK_PORT &&
|
|
|
|
cf->uhubcf_port != uaa->port) ||
|
|
|
|
(uaa->configno != UHUB_UNK_CONFIGURATION &&
|
|
|
|
cf->uhubcf_configuration != UHUB_UNK_CONFIGURATION &&
|
|
|
|
cf->uhubcf_configuration != uaa->configno) ||
|
|
|
|
(uaa->ifaceno != UHUB_UNK_INTERFACE &&
|
|
|
|
cf->uhubcf_interface != UHUB_UNK_INTERFACE &&
|
|
|
|
cf->uhubcf_interface != uaa->ifaceno) ||
|
|
|
|
(uaa->vendor != UHUB_UNK_VENDOR &&
|
|
|
|
cf->uhubcf_vendor != UHUB_UNK_VENDOR &&
|
|
|
|
cf->uhubcf_vendor != uaa->vendor) ||
|
|
|
|
(uaa->product != UHUB_UNK_PRODUCT &&
|
|
|
|
cf->uhubcf_product != UHUB_UNK_PRODUCT &&
|
|
|
|
cf->uhubcf_product != uaa->product) ||
|
|
|
|
(uaa->release != UHUB_UNK_RELEASE &&
|
|
|
|
cf->uhubcf_release != UHUB_UNK_RELEASE &&
|
|
|
|
cf->uhubcf_release != uaa->release)
|
|
|
|
)
|
1999-10-07 19:26:38 +00:00
|
|
|
)
|
1998-11-26 23:13:13 +00:00
|
|
|
return 0;
|
2002-04-02 14:08:43 +00:00
|
|
|
if (cf->uhubcf_vendor != UHUB_UNK_VENDOR &&
|
|
|
|
cf->uhubcf_vendor == uaa->vendor &&
|
|
|
|
cf->uhubcf_product != UHUB_UNK_PRODUCT &&
|
|
|
|
cf->uhubcf_product == uaa->product) {
|
|
|
|
/* We have a vendor&product locator match */
|
|
|
|
if (cf->uhubcf_release != UHUB_UNK_RELEASE &&
|
|
|
|
cf->uhubcf_release == uaa->release)
|
|
|
|
uaa->matchlvl = UMATCH_VENDOR_PRODUCT_REV;
|
|
|
|
else
|
|
|
|
uaa->matchlvl = UMATCH_VENDOR_PRODUCT;
|
|
|
|
} else
|
|
|
|
uaa->matchlvl = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
return ((*cf->cf_attach->ca_match)(parent, cf, aux));
|
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usbd_fill_deviceinfo(usbd_device_handle dev, struct usb_device_info *di,
|
|
|
|
int usedev)
|
1999-01-07 23:07:57 +00:00
|
|
|
{
|
1999-10-07 19:26:38 +00:00
|
|
|
struct usbd_port *p;
|
1999-11-17 22:33:51 +00:00
|
|
|
int i, err, s;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
2002-02-20 20:47:21 +00:00
|
|
|
di->udi_bus = USBDEVUNIT(dev->bus->bdev);
|
|
|
|
di->udi_addr = dev->address;
|
|
|
|
di->udi_cookie = dev->cookie;
|
|
|
|
usbd_devinfo_vp(dev, di->udi_vendor, di->udi_product, usedev);
|
|
|
|
usbd_printBCD(di->udi_release, UGETW(dev->ddesc.bcdDevice));
|
|
|
|
di->udi_vendorNo = UGETW(dev->ddesc.idVendor);
|
|
|
|
di->udi_productNo = UGETW(dev->ddesc.idProduct);
|
|
|
|
di->udi_releaseNo = UGETW(dev->ddesc.bcdDevice);
|
|
|
|
di->udi_class = dev->ddesc.bDeviceClass;
|
|
|
|
di->udi_subclass = dev->ddesc.bDeviceSubClass;
|
|
|
|
di->udi_protocol = dev->ddesc.bDeviceProtocol;
|
|
|
|
di->udi_config = dev->config;
|
|
|
|
di->udi_power = dev->self_powered ? 0 : dev->power;
|
|
|
|
di->udi_speed = dev->speed;
|
1999-11-21 17:30:42 +00:00
|
|
|
|
2001-07-05 10:12:59 +00:00
|
|
|
if (dev->subdevs != NULL) {
|
|
|
|
for (i = 0; dev->subdevs[i] &&
|
2002-01-02 20:16:53 +00:00
|
|
|
i < USB_MAX_DEVNAMES; i++) {
|
2002-02-20 20:47:21 +00:00
|
|
|
strncpy(di->udi_devnames[i], USBDEVPTRNAME(dev->subdevs[i]),
|
2002-01-02 20:16:53 +00:00
|
|
|
USB_MAX_DEVNAMELEN);
|
2002-02-20 20:47:21 +00:00
|
|
|
di->udi_devnames[i][USB_MAX_DEVNAMELEN-1] = '\0';
|
2001-07-05 10:12:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i = 0;
|
|
|
|
}
|
2002-01-02 20:16:53 +00:00
|
|
|
for (/*i is set */; i < USB_MAX_DEVNAMES; i++)
|
2002-02-20 20:47:21 +00:00
|
|
|
di->udi_devnames[i][0] = 0; /* empty */
|
2001-07-05 10:12:59 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
if (dev->hub) {
|
2003-07-04 01:50:39 +00:00
|
|
|
for (i = 0;
|
2002-02-20 20:47:21 +00:00
|
|
|
i < sizeof(di->udi_ports) / sizeof(di->udi_ports[0]) &&
|
1999-01-07 23:07:57 +00:00
|
|
|
i < dev->hub->hubdesc.bNbrPorts;
|
|
|
|
i++) {
|
1999-10-07 19:26:38 +00:00
|
|
|
p = &dev->hub->ports[i];
|
|
|
|
if (p->device)
|
1999-11-17 22:33:51 +00:00
|
|
|
err = p->device->address;
|
1999-01-07 23:07:57 +00:00
|
|
|
else {
|
1999-10-07 19:26:38 +00:00
|
|
|
s = UGETW(p->status.wPortStatus);
|
1999-01-07 23:07:57 +00:00
|
|
|
if (s & UPS_PORT_ENABLED)
|
1999-11-17 22:33:51 +00:00
|
|
|
err = USB_PORT_ENABLED;
|
1999-01-07 23:07:57 +00:00
|
|
|
else if (s & UPS_SUSPEND)
|
1999-11-17 22:33:51 +00:00
|
|
|
err = USB_PORT_SUSPENDED;
|
1999-01-07 23:07:57 +00:00
|
|
|
else if (s & UPS_PORT_POWER)
|
1999-11-17 22:33:51 +00:00
|
|
|
err = USB_PORT_POWERED;
|
1999-01-07 23:07:57 +00:00
|
|
|
else
|
1999-11-17 22:33:51 +00:00
|
|
|
err = USB_PORT_DISABLED;
|
1999-01-07 23:07:57 +00:00
|
|
|
}
|
2002-02-20 20:47:21 +00:00
|
|
|
di->udi_ports[i] = err;
|
1999-01-07 23:07:57 +00:00
|
|
|
}
|
2002-02-20 20:47:21 +00:00
|
|
|
di->udi_nports = dev->hub->hubdesc.bNbrPorts;
|
1999-01-07 23:07:57 +00:00
|
|
|
} else
|
2002-02-20 20:47:21 +00:00
|
|
|
di->udi_nports = 0;
|
1999-01-07 23:07:57 +00:00
|
|
|
}
|
1999-04-11 20:50:33 +00:00
|
|
|
|
1999-10-07 19:26:38 +00:00
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usb_free_device(usbd_device_handle dev)
|
1999-10-07 19:26:38 +00:00
|
|
|
{
|
|
|
|
int ifcidx, nifc;
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dev->default_pipe != NULL)
|
1999-10-07 19:26:38 +00:00
|
|
|
usbd_kill_pipe(dev->default_pipe);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dev->ifaces != NULL) {
|
1999-10-07 19:26:38 +00:00
|
|
|
nifc = dev->cdesc->bNumInterface;
|
|
|
|
for (ifcidx = 0; ifcidx < nifc; ifcidx++)
|
|
|
|
usbd_free_iface_data(dev, ifcidx);
|
|
|
|
free(dev->ifaces, M_USB);
|
|
|
|
}
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dev->cdesc != NULL)
|
1999-10-07 19:26:38 +00:00
|
|
|
free(dev->cdesc, M_USB);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (dev->subdevs != NULL)
|
1999-10-07 19:26:38 +00:00
|
|
|
free(dev->subdevs, M_USB);
|
|
|
|
free(dev, M_USB);
|
|
|
|
}
|
1999-11-17 22:33:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The general mechanism for detaching drivers works as follows: Each
|
|
|
|
* driver is responsible for maintaining a reference count on the
|
|
|
|
* number of outstanding references to its softc (e.g. from
|
|
|
|
* processing hanging in a read or write). The detach method of the
|
|
|
|
* driver decrements this counter and flags in the softc that the
|
|
|
|
* driver is dying and then wakes any sleepers. It then sleeps on the
|
|
|
|
* softc. Each place that can sleep must maintain the reference
|
|
|
|
* count. When the reference count drops to -1 (0 is the normal value
|
|
|
|
* of the reference count) the a wakeup on the softc is performed
|
|
|
|
* signaling to the detach waiter that all references are gone.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called from process context when we discover that a port has
|
|
|
|
* been disconnected.
|
|
|
|
*/
|
|
|
|
void
|
2001-07-05 10:12:59 +00:00
|
|
|
usb_disconnect_port(struct usbd_port *up, device_ptr_t parent)
|
1999-11-17 22:33:51 +00:00
|
|
|
{
|
|
|
|
usbd_device_handle dev = up->device;
|
1999-11-28 20:55:22 +00:00
|
|
|
const char *hubname = USBDEVPTRNAME(parent);
|
1999-11-17 22:33:51 +00:00
|
|
|
int i;
|
|
|
|
|
2003-07-04 01:50:39 +00:00
|
|
|
DPRINTFN(3,("uhub_disconnect: up=%p dev=%p port=%d\n",
|
1999-11-17 22:33:51 +00:00
|
|
|
up, dev, up->portno));
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
1999-11-28 20:55:22 +00:00
|
|
|
if (dev == NULL) {
|
1999-11-17 22:33:51 +00:00
|
|
|
printf("usb_disconnect_port: no device\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (dev->subdevs != NULL) {
|
1999-11-28 20:55:22 +00:00
|
|
|
DPRINTFN(3,("usb_disconnect_port: disconnect subdevs\n"));
|
1999-11-17 22:33:51 +00:00
|
|
|
for (i = 0; dev->subdevs[i]; i++) {
|
2003-07-04 01:50:39 +00:00
|
|
|
printf("%s: at %s", USBDEVPTRNAME(dev->subdevs[i]),
|
1999-11-17 22:33:51 +00:00
|
|
|
hubname);
|
|
|
|
if (up->portno != 0)
|
|
|
|
printf(" port %d", up->portno);
|
|
|
|
printf(" (addr %d) disconnected\n", dev->address);
|
|
|
|
config_detach(dev->subdevs[i], DETACH_FORCE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-28 01:03:19 +00:00
|
|
|
/*usbd_add_dev_event(USB_EVENT_DEVICE_DETACH, dev);*/
|
1999-11-28 20:55:22 +00:00
|
|
|
dev->bus->devices[dev->address] = NULL;
|
|
|
|
up->device = NULL;
|
1999-11-17 22:33:51 +00:00
|
|
|
usb_free_device(dev);
|
|
|
|
}
|
|
|
|
|
1999-11-28 20:55:22 +00:00
|
|
|
#ifdef __OpenBSD__
|
2001-07-05 10:12:59 +00:00
|
|
|
void *usb_realloc(void *p, u_int size, int pool, int flags)
|
1999-11-28 20:55:22 +00:00
|
|
|
{
|
|
|
|
void *q;
|
|
|
|
|
|
|
|
q = malloc(size, pool, flags);
|
|
|
|
if (q == NULL)
|
|
|
|
return (NULL);
|
|
|
|
bcopy(p, q, size);
|
|
|
|
free(p, pool);
|
|
|
|
return (q);
|
|
|
|
}
|
|
|
|
#endif
|