summaryrefslogtreecommitdiffstats
path: root/sys/dev/usb/usb_subr.c
diff options
context:
space:
mode:
authorn_hibma <n_hibma@FreeBSD.org>2001-07-05 10:12:59 +0000
committern_hibma <n_hibma@FreeBSD.org>2001-07-05 10:12:59 +0000
commit60099359c243e7eea92b1b5c026a423abd00b595 (patch)
tree0df10f0e8ccd9a71f18fdbed27992d4e568b0bdb /sys/dev/usb/usb_subr.c
parent50549aff55be61754ae5f0d122d4a46e81618888 (diff)
downloadFreeBSD-src-60099359c243e7eea92b1b5c026a423abd00b595.zip
FreeBSD-src-60099359c243e7eea92b1b5c026a423abd00b595.tar.gz
Pull in the most recent version of usb_quirks.h and propagate the necessary
changes to the various files. Also, pull in most of the current usb_subr.c file.
Diffstat (limited to 'sys/dev/usb/usb_subr.c')
-rw-r--r--sys/dev/usb/usb_subr.c288
1 files changed, 118 insertions, 170 deletions
diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c
index 8b467f3..f14c02a 100644
--- a/sys/dev/usb/usb_subr.c
+++ b/sys/dev/usb/usb_subr.c
@@ -75,19 +75,21 @@ extern int usbdebug;
#define DPRINTFN(n,x)
#endif
-Static usbd_status usbd_set_config(usbd_device_handle, int);
+Static usbd_status usbd_set_config(usbd_device_handle, int);
+Static void usbd_devinfo_vp(usbd_device_handle, char *, char *, int);
Static char *usbd_get_string(usbd_device_handle, int, char *);
Static int usbd_getnewaddr(usbd_bus_handle bus);
#if defined(__NetBSD__)
Static int usbd_print(void *aux, const char *pnp);
Static int usbd_submatch(device_ptr_t, struct cfdata *cf, void *);
#elif defined(__OpenBSD__)
+Static int usbd_print(void *aux, const char *pnp);
Static int usbd_submatch(device_ptr_t, void *, void *);
#endif
Static void usbd_free_iface_data(usbd_device_handle dev, int ifcno);
Static void usbd_kill_pipe(usbd_pipe_handle);
-Static usbd_status usbd_probe_and_attach
- (device_ptr_t parent, usbd_device_handle dev, int port, int addr);
+Static usbd_status usbd_probe_and_attach(device_ptr_t parent,
+ usbd_device_handle dev, int port, int addr);
Static u_int32_t usb_cookie_no = 0;
@@ -109,7 +111,7 @@ struct usb_knowndev {
#include <dev/usb/usbdevs_data.h>
#endif /* USBVERBOSE */
-Static const char *usbd_error_strs[] = {
+Static const char * const usbd_error_strs[] = {
"NORMAL_COMPLETION",
"IN_PROGRESS",
"PENDING_REQUESTS",
@@ -133,8 +135,7 @@ Static const char *usbd_error_strs[] = {
};
const char *
-usbd_errstr(err)
- usbd_status err;
+usbd_errstr(usbd_status err)
{
static char buffer[5];
@@ -147,11 +148,8 @@ usbd_errstr(err)
}
usbd_status
-usbd_get_string_desc(dev, sindex, langid, sdesc)
- usbd_device_handle dev;
- int sindex;
- int langid;
- usb_string_descriptor_t *sdesc;
+usbd_get_string_desc(usbd_device_handle dev, int sindex, int langid,
+ usb_string_descriptor_t *sdesc)
{
usb_device_request_t req;
usbd_status err;
@@ -169,10 +167,7 @@ usbd_get_string_desc(dev, sindex, langid, sdesc)
}
char *
-usbd_get_string(dev, si, buf)
- usbd_device_handle dev;
- int si;
- char *buf;
+usbd_get_string(usbd_device_handle dev, int si, char *buf)
{
int swap = dev->quirks->uq_flags & UQ_SWAP_UNICODE;
usb_string_descriptor_t us;
@@ -214,15 +209,29 @@ usbd_get_string(dev, si, buf)
return (buf);
}
-void
-usbd_devinfo_vp(dev, v, p)
- usbd_device_handle dev;
- char *v, *p;
+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)
{
usb_device_descriptor_t *udd = &dev->ddesc;
char *vendor = 0, *product = 0;
#ifdef USBVERBOSE
- struct usb_knowndev *kdp;
+ const struct usb_knowndev *kdp;
#endif
if (dev == NULL) {
@@ -230,8 +239,15 @@ usbd_devinfo_vp(dev, v, p)
return;
}
- vendor = usbd_get_string(dev, udd->iManufacturer, v);
- product = usbd_get_string(dev, udd->iProduct, p);
+ 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);
+ } else {
+ vendor = NULL;
+ product = NULL;
+ }
#ifdef USBVERBOSE
if (vendor == NULL || product == NULL) {
for(kdp = usb_knowndevs;
@@ -243,44 +259,39 @@ usbd_devinfo_vp(dev, v, p)
break;
}
if (kdp->vendorname != NULL) {
- if (!vendor)
- vendor = kdp->vendorname;
- if (!product)
- product = (kdp->flags & USB_KNOWNDEV_NOPROD) == 0 ?
+ if (vendor == NULL)
+ vendor = kdp->vendorname;
+ if (product == NULL)
+ product = (kdp->flags & USB_KNOWNDEV_NOPROD) == 0 ?
kdp->productname : NULL;
}
}
#endif
- if (vendor != NULL)
+ if (vendor != NULL && *vendor)
strcpy(v, vendor);
else
sprintf(v, "vendor 0x%04x", UGETW(udd->idVendor));
- if (product != NULL)
+ if (product != NULL && *product)
strcpy(p, product);
else
sprintf(p, "product 0x%04x", UGETW(udd->idProduct));
}
int
-usbd_printBCD(cp, bcd)
- char *cp;
- int bcd;
+usbd_printBCD(char *cp, int bcd)
{
return (sprintf(cp, "%x.%02x", bcd >> 8, bcd & 0xff));
}
void
-usbd_devinfo(dev, showclass, cp)
- usbd_device_handle dev;
- int showclass;
- char *cp;
+usbd_devinfo(usbd_device_handle dev, int showclass, char *cp)
{
usb_device_descriptor_t *udd = &dev->ddesc;
char vendor[USB_MAX_STRING_LEN];
char product[USB_MAX_STRING_LEN];
int bcdDevice, bcdUSB;
- usbd_devinfo_vp(dev, vendor, product);
+ usbd_devinfo_vp(dev, vendor, product, 1);
cp += sprintf(cp, "%s %s", vendor, product);
if (showclass)
cp += sprintf(cp, ", class %d/%d",
@@ -297,9 +308,7 @@ usbd_devinfo(dev, showclass, cp)
/* Delay for a certain number of ms */
void
-usb_delay_ms(bus, ms)
- usbd_bus_handle bus;
- u_int ms;
+usb_delay_ms(usbd_bus_handle bus, u_int ms)
{
/* Wait at least two clock ticks so we know the time has passed. */
if (bus->use_polling || cold)
@@ -310,18 +319,13 @@ usb_delay_ms(bus, ms)
/* Delay given a device handle. */
void
-usbd_delay_ms(dev, ms)
- usbd_device_handle dev;
- u_int ms;
+usbd_delay_ms(usbd_device_handle dev, u_int ms)
{
usb_delay_ms(dev->bus, ms);
}
usbd_status
-usbd_reset_port(dev, port, ps)
- usbd_device_handle dev;
- int port;
- usb_port_status_t *ps;
+usbd_reset_port(usbd_device_handle dev, int port, usb_port_status_t *ps)
{
usb_device_request_t req;
usbd_status err;
@@ -363,10 +367,7 @@ usbd_reset_port(dev, port, ps)
}
usb_interface_descriptor_t *
-usbd_find_idesc(cd, ifaceidx, altidx)
- usb_config_descriptor_t *cd;
- int ifaceidx;
- int altidx;
+usbd_find_idesc(usb_config_descriptor_t *cd, int ifaceidx, int altidx)
{
char *p = (char *)cd;
char *end = p + UGETW(cd->wTotalLength);
@@ -397,11 +398,8 @@ usbd_find_idesc(cd, ifaceidx, altidx)
}
usb_endpoint_descriptor_t *
-usbd_find_edesc(cd, ifaceidx, altidx, endptidx)
- usb_config_descriptor_t *cd;
- int ifaceidx;
- int altidx;
- int endptidx;
+usbd_find_edesc(usb_config_descriptor_t *cd, int ifaceidx, int altidx,
+ int endptidx)
{
char *p = (char *)cd;
char *end = p + UGETW(cd->wTotalLength);
@@ -433,21 +431,20 @@ usbd_find_edesc(cd, ifaceidx, altidx, endptidx)
}
usbd_status
-usbd_fill_iface_data(dev, ifaceidx, altidx)
- usbd_device_handle dev;
- int ifaceidx;
- int altidx;
+usbd_fill_iface_data(usbd_device_handle dev, int ifaceidx, int altidx)
{
usbd_interface_handle ifc = &dev->ifaces[ifaceidx];
+ usb_interface_descriptor_t *idesc;
char *p, *end;
int endpt, nendpt;
DPRINTFN(4,("usbd_fill_iface_data: ifaceidx=%d altidx=%d\n",
ifaceidx, altidx));
- ifc->device = dev;
- ifc->idesc = usbd_find_idesc(dev->cdesc, ifaceidx, altidx);
- if (ifc->idesc == 0)
+ idesc = usbd_find_idesc(dev->cdesc, ifaceidx, altidx);
+ if (idesc == NULL)
return (USBD_INVAL);
+ ifc->device = dev;
+ ifc->idesc = idesc;
ifc->index = ifaceidx;
ifc->altindex = altidx;
nendpt = ifc->idesc->bNumEndpoints;
@@ -493,15 +490,15 @@ usbd_fill_iface_data(dev, ifaceidx, altidx)
return (USBD_NORMAL_COMPLETION);
bad:
- if (ifc->endpoints != NULL)
+ if (ifc->endpoints != NULL) {
free(ifc->endpoints, M_USB);
+ ifc->endpoints = NULL;
+ }
return (USBD_INVAL);
}
void
-usbd_free_iface_data(dev, ifcno)
- usbd_device_handle dev;
- int ifcno;
+usbd_free_iface_data(usbd_device_handle dev, int ifcno)
{
usbd_interface_handle ifc = &dev->ifaces[ifcno];
if (ifc->endpoints)
@@ -509,9 +506,7 @@ usbd_free_iface_data(dev, ifcno)
}
Static usbd_status
-usbd_set_config(dev, conf)
- usbd_device_handle dev;
- int conf;
+usbd_set_config(usbd_device_handle dev, int conf)
{
usb_device_request_t req;
@@ -524,10 +519,7 @@ usbd_set_config(dev, conf)
}
usbd_status
-usbd_set_config_no(dev, no, msg)
- usbd_device_handle dev;
- int no;
- int msg;
+usbd_set_config_no(usbd_device_handle dev, int no, int msg)
{
int index;
usb_config_descriptor_t cd;
@@ -549,10 +541,7 @@ usbd_set_config_no(dev, no, msg)
}
usbd_status
-usbd_set_config_index(dev, index, msg)
- usbd_device_handle dev;
- int index;
- int msg;
+usbd_set_config_index(usbd_device_handle dev, int index, int msg)
{
usb_status_t ds;
usb_config_descriptor_t cd, *cdp;
@@ -634,6 +623,7 @@ usbd_set_config_index(dev, index, msg)
#endif
power = cdp->bMaxPower * 2;
if (power > dev->powersrc->power) {
+ DPRINTF(("power exceeded %d %d\n", power,dev->powersrc->power));
/* XXX print nicer message. */
if (msg)
printf("%s: device addr %d (config %d) exceeds power "
@@ -688,12 +678,8 @@ usbd_set_config_index(dev, index, msg)
/* XXX add function for alternate settings */
usbd_status
-usbd_setup_pipe(dev, iface, ep, ival, pipe)
- usbd_device_handle dev;
- usbd_interface_handle iface;
- struct usbd_endpoint *ep;
- int ival;
- usbd_pipe_handle *pipe;
+usbd_setup_pipe(usbd_device_handle dev, usbd_interface_handle iface,
+ struct usbd_endpoint *ep, int ival, usbd_pipe_handle *pipe)
{
usbd_pipe_handle p;
usbd_status err;
@@ -730,8 +716,7 @@ usbd_setup_pipe(dev, iface, ep, ival, pipe)
/* Abort the device control pipe. */
void
-usbd_kill_pipe(pipe)
- usbd_pipe_handle pipe;
+usbd_kill_pipe(usbd_pipe_handle pipe)
{
pipe->methods->close(pipe);
pipe->endpoint->refcnt--;
@@ -739,8 +724,7 @@ usbd_kill_pipe(pipe)
}
int
-usbd_getnewaddr(bus)
- usbd_bus_handle bus;
+usbd_getnewaddr(usbd_bus_handle bus)
{
int addr;
@@ -752,11 +736,8 @@ usbd_getnewaddr(bus)
usbd_status
-usbd_probe_and_attach(parent, dev, port, addr)
- device_ptr_t parent;
- usbd_device_handle dev;
- int port;
- int addr;
+usbd_probe_and_attach(device_ptr_t parent, usbd_device_handle dev,
+ int port, int addr)
{
struct usb_attach_arg uaa;
usb_device_descriptor_t *dd = &dev->ddesc;
@@ -923,13 +904,8 @@ usbd_probe_and_attach(parent, dev, port, addr)
* and attach a driver.
*/
usbd_status
-usbd_new_device(parent, bus, depth, lowspeed, port, up)
- device_ptr_t parent;
- usbd_bus_handle bus;
- int depth;
- int lowspeed;
- int port;
- struct usbd_port *up;
+usbd_new_device(device_ptr_t parent, usbd_bus_handle bus, int depth,
+ int lowspeed, int port, struct usbd_port *up)
{
usbd_device_handle dev;
usb_device_descriptor_t *dd;
@@ -1057,12 +1033,12 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up)
}
usbd_add_event(USB_EVENT_ATTACH, dev);
+
return (USBD_NORMAL_COMPLETION);
}
usbd_status
-usbd_reload_device_desc(dev)
- usbd_device_handle dev;
+usbd_reload_device_desc(usbd_device_handle dev)
{
usbd_status err;
@@ -1078,9 +1054,7 @@ usbd_reload_device_desc(dev)
}
void
-usbd_remove_device(dev, up)
- usbd_device_handle dev;
- struct usbd_port *up;
+usbd_remove_device(usbd_device_handle dev, struct usbd_port *up)
{
DPRINTF(("usbd_remove_device: %p\n", dev));
@@ -1094,9 +1068,7 @@ usbd_remove_device(dev, up)
#if defined(__NetBSD__) || defined(__OpenBSD__)
int
-usbd_print(aux, pnp)
- void *aux;
- const char *pnp;
+usbd_print(void *aux, const char *pnp)
{
struct usb_attach_arg *uaa = aux;
char devinfo[1024];
@@ -1132,17 +1104,11 @@ usbd_print(aux, pnp)
#if defined(__NetBSD__)
int
-usbd_submatch(parent, cf, aux)
- struct device *parent;
- struct cfdata *cf;
- void *aux;
+usbd_submatch(struct device *parent, struct cfdata *cf, void *aux)
{
#elif defined(__OpenBSD__)
int
-usbd_submatch(parent, match, aux)
- struct device *parent;
- void *match;
- void *aux;
+usbd_submatch(struct device *parent, void *match, void *aux)
{
struct cfdata *cf = match;
#endif
@@ -1158,24 +1124,24 @@ usbd_submatch(parent, match, aux)
uaa->release, cf->uhubcf_release));
if (uaa->port != 0 && /* root hub has port 0, it should match */
((uaa->port != 0 &&
- 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)
- )
+ 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)
+ )
)
return 0;
return ((*cf->cf_attach->ca_match)(parent, cf, aux));
@@ -1184,30 +1150,15 @@ usbd_submatch(parent, match, aux)
#endif
void
-usbd_fill_deviceinfo(dev, di)
- usbd_device_handle dev;
- struct usb_device_info *di;
+usbd_fill_deviceinfo(usbd_device_handle dev, struct usb_device_info *di,
+ int usedev)
{
struct usbd_port *p;
int i, err, s;
di->bus = USBDEVUNIT(dev->bus->bdev);
di->addr = dev->address;
-
- if (dev->subdevs) {
- for (i = 0; dev->subdevs[i] &&
- i < MAXDEVNAMES; i++) {
- strncpy(di->devnames[i], USBDEVPTRNAME(dev->subdevs[i]),
- MAXDEVNAMELEN);
- di->devnames[i][MAXDEVNAMELEN-1] = '\0'; /* terminate */
- }
- } else {
- i = 0;
- }
- for (/*i is set */; i < MAXDEVNAMES; i++)
- di->devnames[i][0] = 0; /* empty */
-
- usbd_devinfo_vp(dev, di->vendor, di->product);
+ usbd_devinfo_vp(dev, di->vendor, di->product, usedev);
usbd_printBCD(di->release, UGETW(dev->ddesc.bcdDevice));
di->vendorNo = UGETW(dev->ddesc.idVendor);
di->productNo = UGETW(dev->ddesc.idProduct);
@@ -1219,6 +1170,19 @@ usbd_fill_deviceinfo(dev, di)
di->power = dev->self_powered ? 0 : dev->power;
di->lowspeed = dev->lowspeed;
+ if (dev->subdevs != NULL) {
+ for (i = 0; dev->subdevs[i] &&
+ i < MAXDEVNAMES; i++) {
+ strncpy(di->devnames[i], USBDEVPTRNAME(dev->subdevs[i]),
+ MAXDEVNAMELEN);
+ di->devnames[i][MAXDEVNAMELEN-1] = '\0';
+ }
+ } else {
+ i = 0;
+ }
+ for (/*i is set */; i < MAXDEVNAMES; i++)
+ di->devnames[i][0] = 0; /* empty */
+
if (dev->hub) {
for (i = 0;
i < sizeof(di->ports) / sizeof(di->ports[0]) &&
@@ -1246,8 +1210,7 @@ usbd_fill_deviceinfo(dev, di)
}
void
-usb_free_device(dev)
- usbd_device_handle dev;
+usb_free_device(usbd_device_handle dev)
{
int ifcidx, nifc;
@@ -1284,9 +1247,7 @@ usb_free_device(dev)
* been disconnected.
*/
void
-usb_disconnect_port(up, parent)
- struct usbd_port *up;
- device_ptr_t parent;
+usb_disconnect_port(struct usbd_port *up, device_ptr_t parent)
{
usbd_device_handle dev = up->device;
const char *hubname = USBDEVPTRNAME(parent);
@@ -1302,15 +1263,6 @@ usb_disconnect_port(up, parent)
}
#endif
- if (dev->cdesc == NULL) {
- /* Partially attached device, just drop it. */
- dev->bus->devices[dev->address] = 0;
- up->device = 0;
- return;
- }
-
- usbd_add_event(USB_EVENT_DETACH, dev);
-
if (dev->subdevs != NULL) {
DPRINTFN(3,("usb_disconnect_port: disconnect subdevs\n"));
for (i = 0; dev->subdevs[i]; i++) {
@@ -1336,11 +1288,7 @@ usb_disconnect_port(up, parent)
}
#ifdef __OpenBSD__
-void *usb_realloc(p, size, pool, flags)
- void *p;
- u_int size;
- int pool;
- int flags;
+void *usb_realloc(void *p, u_int size, int pool, int flags)
{
void *q;
OpenPOWER on IntegriCloud