aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/dev/usb/ohci.c10
-rw-r--r--sys/dev/usb/uhci.c18
-rw-r--r--sys/dev/usb/uhcireg.h4
-rw-r--r--sys/dev/usb/uhcivar.h22
-rw-r--r--sys/dev/usb/usb.c19
-rw-r--r--sys/dev/usb/usb_if.m2
-rw-r--r--sys/dev/usb/usb_subr.c241
-rw-r--r--sys/dev/usb/usbcdc.h2
-rw-r--r--sys/dev/usb/usbdi.c7
-rw-r--r--sys/dev/usb/usbdi.h1
-rw-r--r--sys/dev/usb/usbdivar.h2
11 files changed, 173 insertions, 155 deletions
diff --git a/sys/dev/usb/ohci.c b/sys/dev/usb/ohci.c
index cab9cd09f3a3..a3fc84a2d59f 100644
--- a/sys/dev/usb/ohci.c
+++ b/sys/dev/usb/ohci.c
@@ -812,7 +812,7 @@ ohci_ctrl_done(sc, reqh)
memcpy(reqh->buffer, KERNADDR(dma), len);
usb_freemem(sc->sc_dmatag, dma);
}
- usb_untimeout(ohci_timeout, reqh, reqh->timo_handle);
+ usb_untimeout(ohci_timeout, reqh, reqh->timeout_handle);
}
void
@@ -880,7 +880,7 @@ ohci_bulk_done(sc, reqh)
if (reqh->request.bmRequestType & UT_READ)
memcpy(reqh->buffer, KERNADDR(dma), reqh->actlen);
usb_freemem(sc->sc_dmatag, dma);
- usb_untimeout(ohci_timeout, reqh, reqh->timo_handle);
+ usb_untimeout(ohci_timeout, reqh, reqh->timeout_handle);
}
void
@@ -1091,7 +1091,7 @@ ohci_device_request(reqh)
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_CLF);
if (reqh->timeout && !sc->sc_bus.use_polling) {
usb_timeout(ohci_timeout, reqh,
- MS_TO_TICKS(reqh->timeout), reqh->timo_handle);
+ MS_TO_TICKS(reqh->timeout), reqh->timeout_handle);
}
splx(s);
@@ -1968,7 +1968,7 @@ ohci_device_bulk_start(reqh)
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_BLF);
if (reqh->timeout && !sc->sc_bus.use_polling) {
usb_timeout(ohci_timeout, reqh,
- MS_TO_TICKS(reqh->timeout), reqh->timo_handle);
+ MS_TO_TICKS(reqh->timeout), reqh->timeout_handle);
}
splx(s);
@@ -2099,7 +2099,7 @@ ohci_device_intr_start(reqh)
#if 0
if (reqh->timeout && !sc->sc_bus.use_polling) {
usb_timeout(ohci_timeout, reqh,
- MS_TO_TICKS(reqh->timeout), reqh->timo_handle);
+ MS_TO_TICKS(reqh->timeout), reqh->timeout_handle);
}
#endif
sed->ed->ed_flags &= LE(~OHCI_ED_SKIP);
diff --git a/sys/dev/usb/uhci.c b/sys/dev/usb/uhci.c
index b27cb00bd0d1..d9f4c8852a5f 100644
--- a/sys/dev/usb/uhci.c
+++ b/sys/dev/usb/uhci.c
@@ -97,7 +97,7 @@ int uhcidebug = 1;
struct uhci_pipe {
struct usbd_pipe pipe;
uhci_intr_info_t *iinfo;
- int newtoggle;
+ int nexttoggle;
/* Info needed for different pipe kinds. */
union {
/* Control pipe */
@@ -507,7 +507,7 @@ uhci_timo(addr)
reqh->xfercb(reqh);
}
if (reqh->pipe->intrreqh == reqh) {
- usb_timeout(uhci_timo, reqh, sc->sc_ival, reqh->timo_handle);
+ usb_timeout(uhci_timo, reqh, sc->sc_ival, reqh->timeout_handle);
} else {
usb_freemem(sc->sc_dmatag, &upipe->u.intr.datadma);
usb_start_next(reqh->pipe);
@@ -759,7 +759,7 @@ uhci_check_intr(sc, ii)
done:
usb_untimeout(uhci_timeout, ii, ii->timeout_handle);
upipe = (struct uhci_pipe *)ii->reqh->pipe;
- upipe->pipe.endpoint->toggle = upipe->newtoggle;
+ upipe->pipe.endpoint->toggle = upipe->nexttoggle;
uhci_ii_done(ii, 0);
}
@@ -1143,7 +1143,7 @@ uhci_alloc_std_chain(upipe, sc, len, rd, spd, dma, sp, ep)
tog = upipe->pipe.endpoint->toggle;
if (ntd % 2 == 0)
tog ^= 1;
- upipe->newtoggle = tog ^ 1;
+ upipe->nexttoggle = tog ^ 1;
lastp = 0;
lastlink = UHCI_PTR_T;
ntd--;
@@ -1179,7 +1179,7 @@ uhci_alloc_std_chain(upipe, sc, len, rd, spd, dma, sp, ep)
*sp = lastp;
/*upipe->pipe.endpoint->toggle = tog;*/
DPRINTFN(10, ("uhci_alloc_std_chain: oldtog=%d newtog=%d\n",
- upipe->pipe.endpoint->toggle, upipe->newtoggle));
+ upipe->pipe.endpoint->toggle, upipe->nexttoggle));
return (USBD_NORMAL_COMPLETION);
}
@@ -2570,7 +2570,7 @@ void
uhci_root_ctrl_close(pipe)
usbd_pipe_handle pipe;
{
- usb_untimeout(uhci_timo, pipe->intrreqh, pipe->intrreqh->timo_handle);
+ usb_untimeout(uhci_timo, pipe->intrreqh, pipe->intrreqh->timeout_handle);
DPRINTF(("uhci_root_ctrl_close\n"));
}
@@ -2579,7 +2579,7 @@ void
uhci_root_intr_abort(reqh)
usbd_request_handle reqh;
{
- usb_untimeout(uhci_timo, reqh, reqh->timo_handle);
+ usb_untimeout(uhci_timo, reqh, reqh->timeout_handle);
}
usbd_status
@@ -2624,7 +2624,7 @@ uhci_root_intr_start(reqh)
return (r);
sc->sc_ival = MS_TO_TICKS(reqh->pipe->endpoint->edesc->bInterval);
- usb_timeout(uhci_timo, reqh, sc->sc_ival, reqh->timo_handle);
+ usb_timeout(uhci_timo, reqh, sc->sc_ival, reqh->timeout_handle);
return (USBD_IN_PROGRESS);
}
@@ -2633,6 +2633,6 @@ void
uhci_root_intr_close(pipe)
usbd_pipe_handle pipe;
{
- usb_untimeout(uhci_timo, pipe->intrreqh, pipe->intrreqh->timo_handle);
+ usb_untimeout(uhci_timo, pipe->intrreqh, pipe->intrreqh->timeout_handle);
DPRINTF(("uhci_root_intr_close\n"));
}
diff --git a/sys/dev/usb/uhcireg.h b/sys/dev/usb/uhcireg.h
index bad7a4c81302..3dd9f02c7593 100644
--- a/sys/dev/usb/uhcireg.h
+++ b/sys/dev/usb/uhcireg.h
@@ -161,12 +161,12 @@ typedef struct {
#define UHCI_TD_SET_ENDPT(e) (((e)&0xf) << 15)
#define UHCI_TD_GET_ENDPT(s) (((s) >> 15) & 0xf)
#define UHCI_TD_SET_DT(t) ((t) << 19)
-#define UHCI_TD_GET_DT(s) (((s) >> 19) & 1)
+#define UHCI_TD_GET_DT(t) (((t) >> 19) & 1)
#define UHCI_TD_SET_MAXLEN(l) (((l)-1) << 21)
#define UHCI_TD_GET_MAXLEN(s) ((((s) >> 21) + 1) & 0x7ff)
#define UHCI_TD_MAXLEN_MASK 0xffe00000
u_int32_t td_buffer;
- uhci_soft_td_qh_t link; /* soft version of the td_link field */
+ uhci_soft_td_qh_t link; /* link to next TD (points to soft version of TD */
/* padding to 32 bytes */
} uhci_td_t;
#define UHCI_TD_SIZE 32
diff --git a/sys/dev/usb/uhcivar.h b/sys/dev/usb/uhcivar.h
index 816952623f7f..9af98b7df2de 100644
--- a/sys/dev/usb/uhcivar.h
+++ b/sys/dev/usb/uhcivar.h
@@ -39,17 +39,21 @@
*/
/*
+ * The framelist:
+ *
* To avoid having 1024 TDs for each isochronous transfer we introduce
- * a virtual frame list. Every UHCI_VFRAMELIST_COUNT entries in the real
- * frame list points to a non-active TD. These, in turn, which form the
- * starts of the virtual frame list. This also has the advantage that it
- * simplifies linking in/out TD/QH in the schedule.
- * Furthermore, initially each of the inactive TDs point to an inactive
- * QH that forms the start of the interrupt traffic for that slot.
- * Each of these QHs point to the same QH that is the start of control
- * traffic.
+ * a virtual frame list. Every UHCI_VFRAMELIST_COUNT'th entry in the real
+ * frame list points to a non-active TD. This TD is
+ * UHCI_FRAMELIST_COUNT/UHCI_VFRAMELIST_COUNT times the start of the
+ * virtual frame list for a queue of isochroneous transfers.
+ *
+ * The last isochroneous transfer in the list points to a QH for the
+ * interrupt transfer in that timeslot. The QHs for interrupt transfers
+ * all point to the single QH for control transfers, which in turn
+ * points at the QH for control transfers.
*
- * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
+ * UHCI_VFRAMELIST_COUNT should be a power of 2 and UHCI_FRAMELIST_COUNT
+ * should be a multiple of UHCI_VFRAMELIST_COUNT.
*/
#define UHCI_VFRAMELIST_COUNT 128
diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c
index 9165a4f0083d..c6b825df90e5 100644
--- a/sys/dev/usb/usb.c
+++ b/sys/dev/usb/usb.c
@@ -243,6 +243,7 @@ usbioctl(dev, cmd, data, flag, p)
if (sc == 0 || !sc->sc_running)
return (ENXIO);
+
switch (cmd) {
#ifdef USB_DEBUG
case USB_SETDEBUG:
@@ -345,23 +346,23 @@ usbpoll(dev, events, p)
int events;
struct proc *p;
{
- int revents, s;
+ int revents = 0;
+ int s;
+
USB_GET_SC(usb, USBUNIT(dev), sc);
- DPRINTFN(2, ("usbpoll: sc=%p events=0x%x\n", sc, events));
s = splusb();
- revents = 0;
+
if (events & (POLLOUT | POLLWRNORM))
if (sc->sc_bus->needs_explore)
revents |= events & (POLLOUT | POLLWRNORM);
- DPRINTFN(2, ("usbpoll: revents=0x%x\n", revents));
- if (revents == 0) {
- if (events & (POLLOUT | POLLWRNORM)) {
- DPRINTFN(2, ("usbpoll: selrecord\n"));
+
+ if (revents == 0)
+ if (events & (POLLOUT | POLLWRNORM))
selrecord(p, &sc->sc_consel);
- }
- }
+
splx(s);
+
return (revents);
}
diff --git a/sys/dev/usb/usb_if.m b/sys/dev/usb/usb_if.m
index c2e7f89fd435..8729f016ba17 100644
--- a/sys/dev/usb/usb_if.m
+++ b/sys/dev/usb/usb_if.m
@@ -25,7 +25,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-# $Id: usb_if.m,v 1.5 1999/04/16 21:22:03 peter Exp $
+# $FreeBSD$
#
# USB interface description
diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c
index 8baf304ec269..5279c8bd5891 100644
--- a/sys/dev/usb/usb_subr.c
+++ b/sys/dev/usb/usb_subr.c
@@ -111,16 +111,16 @@ usbd_get_string_desc(dev, sindex, langid, sdesc)
usb_string_descriptor_t *sdesc;
{
usb_device_request_t req;
- usbd_status r;
+ usbd_status err;
req.bmRequestType = UT_READ_DEVICE;
req.bRequest = UR_GET_DESCRIPTOR;
USETW2(req.wValue, UDESC_STRING, sindex);
USETW(req.wIndex, langid);
USETW(req.wLength, 1); /* only size byte first */
- r = usbd_do_request(dev, &req, sdesc);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usbd_do_request(dev, &req, sdesc);
+ if (err)
+ return (err);
USETW(req.wLength, sdesc->bLength); /* the whole string */
return (usbd_do_request(dev, &req, sdesc));
}
@@ -133,10 +133,10 @@ usbd_get_string(dev, si, buf)
{
int swap = dev->quirks->uq_flags & UQ_SWAP_UNICODE;
usb_string_descriptor_t us;
- char *s;
+ char *string;
int i, n;
u_int16_t c;
- usbd_status r;
+ usbd_status err;
if (si == 0)
return (0);
@@ -144,30 +144,30 @@ usbd_get_string(dev, si, buf)
return (0);
if (dev->langid == USBD_NOLANG) {
/* Set up default language */
- r = usbd_get_string_desc(dev, USB_LANGUAGE_TABLE, 0, &us);
- if (r != USBD_NORMAL_COMPLETION || us.bLength < 4) {
+ err = usbd_get_string_desc(dev, USB_LANGUAGE_TABLE, 0, &us);
+ if (err) {
dev->langid = 0; /* Well, just pick English then */
} else {
/* Pick the first language as the default. */
dev->langid = UGETW(us.bString[0]);
}
}
- r = usbd_get_string_desc(dev, si, dev->langid, &us);
- if (r != USBD_NORMAL_COMPLETION)
+ err = usbd_get_string_desc(dev, si, dev->langid, &us);
+ if (err)
return (0);
- s = buf;
+ string = buf;
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)
- *s++ = c;
+ *string++ = c;
else if ((c & 0x00ff) == 0 && swap)
- *s++ = c >> 8;
+ *string++ = c >> 8;
else
- *s++ = '?';
+ *string++ = '?';
}
- *s++ = 0;
+ *string++ = 0;
return buf;
}
@@ -275,7 +275,7 @@ usbd_reset_port(dev, port, ps)
usb_port_status_t *ps;
{
usb_device_request_t req;
- usbd_status r;
+ usbd_status err;
int n;
req.bmRequestType = UT_WRITE_CLASS_OTHER;
@@ -283,21 +283,21 @@ usbd_reset_port(dev, port, ps)
USETW(req.wValue, UHF_PORT_RESET);
USETW(req.wIndex, port);
USETW(req.wLength, 0);
- r = usbd_do_request(dev, &req, 0);
+ err = usbd_do_request(dev, &req, 0);
DPRINTFN(1,("usbd_reset_port: port %d reset done, %s\n",
- port, usbd_errstr(r)));
- if (r != USBD_NORMAL_COMPLETION)
- return(r);
+ port, usbd_errstr(err)));
+ if (err)
+ return(err);
n = 10;
do {
/* Wait for device to recover from reset. */
usbd_delay_ms(dev, USB_PORT_RESET_DELAY);
- r = usbd_get_port_status(dev, port, ps);
- if (r != USBD_NORMAL_COMPLETION) {
+ err = usbd_get_port_status(dev, port, ps);
+ if (err) {
DPRINTF(("usbd_reset_port: get port %d status failed %s\n",
- port, usbd_errstr(r)));
- return (r);
+ port, usbd_errstr(err)));
+ return (err);
}
} while ((UGETW(ps->wPortChange) & UPS_C_PORT_RESET) == 0 && --n > 0);
@@ -305,16 +305,16 @@ usbd_reset_port(dev, port, ps)
printf("usbd_reset_port: timeout\n");
return (USBD_IOERROR);
}
- r = usbd_clear_port_feature(dev, port, UHF_C_PORT_RESET);
+ err = usbd_clear_port_feature(dev, port, UHF_C_PORT_RESET);
#ifdef USB_DEBUG
- if (r != USBD_NORMAL_COMPLETION)
+ if (err)
DPRINTF(("usbd_reset_port: clear port %d feature failed %d\n",
- port, r));
+ port, err));
#endif
/* Wait for the device to recover from reset. */
usbd_delay_ms(dev, USB_PORT_RESET_RECOVERY);
- return (r);
+ return (err);
}
usb_interface_descriptor_t *
@@ -484,14 +484,14 @@ usbd_set_config_no(dev, no, msg)
{
int index;
usb_config_descriptor_t cd;
- usbd_status r;
+ usbd_status err;
DPRINTFN(5,("usbd_set_config_no: %d\n", no));
/* Figure out what config index to use. */
for (index = 0; index < dev->ddesc.bNumConfigurations; index++) {
- r = usbd_get_config_desc(dev, index, &cd);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usbd_get_config_desc(dev, index, &cd);
+ if (err)
+ return (err);
if (cd.bConfigurationValue == no)
return (usbd_set_config_index(dev, index, msg));
}
@@ -507,7 +507,7 @@ usbd_set_config_index(dev, index, msg)
usb_status_t ds;
usb_hub_status_t hs;
usb_config_descriptor_t cd, *cdp;
- usbd_status r;
+ usbd_status err;
int ifcidx, nifc, len, selfpowered, power;
DPRINTFN(5,("usbd_set_config_index: dev=%p index=%d\n", dev, index));
@@ -528,20 +528,20 @@ usbd_set_config_index(dev, index, msg)
}
/* Figure out what config number to use. */
- r = usbd_get_config_desc(dev, index, &cd);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usbd_get_config_desc(dev, index, &cd);
+ if (err)
+ return (err);
len = UGETW(cd.wTotalLength);
cdp = malloc(len, M_USB, M_NOWAIT);
if (cdp == 0)
return (USBD_NOMEM);
- r = usbd_get_desc(dev, UDESC_CONFIG, index, len, cdp);
- if (r != USBD_NORMAL_COMPLETION)
+ err = usbd_get_desc(dev, UDESC_CONFIG, index, len, cdp);
+ if (err)
goto bad;
if (cdp->bDescriptorType != UDESC_CONFIG) {
DPRINTFN(-1,("usbd_set_config_index: bad desc %d\n",
cdp->bDescriptorType));
- r = USBD_INVAL;
+ err = USBD_INVAL;
goto bad;
}
selfpowered = 0;
@@ -551,18 +551,18 @@ usbd_set_config_index(dev, index, msg)
/* Must ask device. */
if (dev->quirks->uq_flags & UQ_HUB_POWER) {
/* Buggy hub, use hub descriptor. */
- r = usbd_get_hub_status(dev, &hs);
- if (r == USBD_NORMAL_COMPLETION &&
+ err = usbd_get_hub_status(dev, &hs);
+ if (err == USBD_NORMAL_COMPLETION &&
!(UGETW(hs.wHubStatus) & UHS_LOCAL_POWER))
selfpowered = 1;
} else {
- r = usbd_get_device_status(dev, &ds);
- if (r == USBD_NORMAL_COMPLETION &&
+ err = usbd_get_device_status(dev, &ds);
+ if (err == USBD_NORMAL_COMPLETION &&
(UGETW(ds.wStatus) & UDS_SELF_POWERED))
selfpowered = 1;
}
DPRINTF(("usbd_set_config_index: status=0x%04x, %s\n",
- UGETW(ds.wStatus), usbd_errstr(r)));
+ UGETW(ds.wStatus), usbd_errstr(err)));
} else
selfpowered = 1;
}
@@ -586,7 +586,7 @@ usbd_set_config_index(dev, index, msg)
USBDEVNAME(dev->bus->bdev), dev->address,
cdp->bConfigurationValue,
power, dev->powersrc->power);
- r = USBD_NO_POWER;
+ err = USBD_NO_POWER;
goto bad;
}
dev->power = power;
@@ -594,10 +594,10 @@ usbd_set_config_index(dev, index, msg)
DPRINTF(("usbd_set_config_index: set config %d\n",
cdp->bConfigurationValue));
- r = usbd_set_config(dev, cdp->bConfigurationValue);
- if (r != USBD_NORMAL_COMPLETION) {
+ err = usbd_set_config(dev, cdp->bConfigurationValue);
+ if (err) {
DPRINTF(("usbd_set_config_index: setting config=%d failed, %s\n",
- cdp->bConfigurationValue, usbd_errstr(r)));
+ cdp->bConfigurationValue, usbd_errstr(err)));
goto bad;
}
DPRINTF(("usbd_set_config_index: setting new config %d\n",
@@ -606,7 +606,7 @@ usbd_set_config_index(dev, index, msg)
dev->ifaces = malloc(nifc * sizeof(struct usbd_interface),
M_USB, M_NOWAIT);
if (dev->ifaces == 0) {
- r = USBD_NOMEM;
+ err = USBD_NOMEM;
goto bad;
}
DPRINTFN(5,("usbd_set_config_index: dev=%p cdesc=%p\n", dev, cdp));
@@ -614,8 +614,8 @@ usbd_set_config_index(dev, index, msg)
dev->config = cdp->bConfigurationValue;
dev->state = USBD_DEVICE_CONFIGURED;
for (ifcidx = 0; ifcidx < nifc; ifcidx++) {
- r = usbd_fill_iface_data(dev, ifcidx, 0);
- if (r != USBD_NORMAL_COMPLETION) {
+ err = usbd_fill_iface_data(dev, ifcidx, 0);
+ if (err) {
while (--ifcidx >= 0)
usbd_free_iface_data(dev, ifcidx);
goto bad;
@@ -626,45 +626,48 @@ usbd_set_config_index(dev, index, msg)
bad:
free(cdp, M_USB);
- return (r);
+ return (err);
}
/* XXX add function for alternate settings */
usbd_status
-usbd_setup_pipe(dev, iface, ep, pipe)
+usbd_setup_pipe(dev, iface, ep, rpipe)
usbd_device_handle dev;
usbd_interface_handle iface;
struct usbd_endpoint *ep;
- usbd_pipe_handle *pipe;
+ usbd_pipe_handle *rpipe;
{
- usbd_pipe_handle p;
- usbd_status r;
+ usbd_pipe_handle pipe;
+ usbd_status err;
DPRINTFN(1,("usbd_setup_pipe: dev=%p iface=%p ep=%p pipe=%p\n",
- dev, iface, ep, pipe));
- p = malloc(dev->bus->pipe_size, M_USB, M_NOWAIT);
- if (p == 0)
+ dev, iface, ep, rpipe));
+ pipe = malloc(dev->bus->pipe_size, M_USB, M_NOWAIT);
+ if (!pipe)
return (USBD_NOMEM);
- p->device = dev;
- p->iface = iface;
- p->state = USBD_PIPE_ACTIVE;
- p->endpoint = ep;
+
+ pipe->device = dev;
+ pipe->iface = iface;
+ pipe->state = USBD_PIPE_ACTIVE;
+ pipe->endpoint = ep;
ep->refcnt++;
- p->refcnt = 1;
- p->intrreqh = 0;
- p->running = 0;
- p->disco = 0;
- p->discoarg = 0;
- SIMPLEQ_INIT(&p->queue);
- r = dev->bus->open_pipe(p);
- if (r != USBD_NORMAL_COMPLETION) {
+ pipe->refcnt = 1;
+ pipe->intrreqh = 0;
+ pipe->running = 0;
+ pipe->disco = 0;
+ pipe->discoarg = 0;
+ SIMPLEQ_INIT(&pipe->queue);
+
+ err = dev->bus->open_pipe(pipe);
+ if (err) {
DPRINTFN(-1,("usbd_setup_pipe: endpoint=0x%x failed, %s\n",
- ep->edesc->bEndpointAddress, usbd_errstr(r)));
- free(p, M_USB);
- return (r);
+ ep->edesc->bEndpointAddress, usbd_errstr(err)));
+ free(pipe, M_USB);
+ return (err);
}
- *pipe = p;
+
+ *rpipe = pipe;
return (USBD_NORMAL_COMPLETION);
}
@@ -687,6 +690,7 @@ usbd_getnewaddr(bus)
for (addr = 1; addr < USB_MAX_DEVICES; addr++)
if (bus->devices[addr] == 0)
return (addr);
+
return (-1);
}
@@ -700,7 +704,7 @@ usbd_probe_and_attach(parent, dev, port, addr)
struct usb_attach_arg uaa;
usb_device_descriptor_t *dd = &dev->ddesc;
int found = 0;
- int r, i, confi, nifaces;
+ int err, i, confi, nifaces;
usbd_interface_handle ifaces[256]; /* 256 is the absolute max */
#if defined(__FreeBSD__)
@@ -735,11 +739,11 @@ usbd_probe_and_attach(parent, dev, port, addr)
for (confi = 0; confi < dd->bNumConfigurations; confi++) {
DPRINTFN(1,("usbd_probe_and_attach: trying config idx=%d\n",
confi));
- r = usbd_set_config_index(dev, confi, 1);
- if (r != USBD_NORMAL_COMPLETION) {
+ err = usbd_set_config_index(dev, confi, 1);
+ if (err) {
printf("%s: port %d, set config at addr %d failed, %s\n",
- USBDEVNAME(*parent), port, addr, usbd_errstr(r));
- return (r);
+ USBDEVNAME(*parent), port, addr, usbd_errstr(err));
+ return (err);
}
nifaces = dev->cdesc->bNumInterface;
uaa.configno = dev->cdesc->bConfigurationValue;
@@ -826,7 +830,7 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up)
{
usbd_device_handle dev;
usb_device_descriptor_t *dd;
- usbd_status r;
+ usbd_status err;
int addr;
int i;
@@ -868,10 +872,10 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up)
dev->langid = USBD_NOLANG;
/* Establish the the default pipe. */
- r = usbd_setup_pipe(dev, 0, &dev->def_ep, &dev->default_pipe);
- if (r != USBD_NORMAL_COMPLETION) {
+ err = usbd_setup_pipe(dev, 0, &dev->def_ep, &dev->default_pipe);
+ if (err) {
usbd_remove_device(dev, up);
- return (r);
+ return (err);
}
up->device = dev;
@@ -879,17 +883,16 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up)
/* Try a few times in case the device is slow (i.e. outside specs.) */
for (i = 0; i < 5; i++) {
/* Get the first 8 bytes of the device descriptor. */
- r = usbd_get_desc(dev, UDESC_DEVICE, 0, USB_MAX_IPACKET, dd);
- if (r == USBD_NORMAL_COMPLETION)
+ err = usbd_get_desc(dev, UDESC_DEVICE, 0, USB_MAX_IPACKET, dd);
+ if (err == USBD_NORMAL_COMPLETION)
break;
usbd_delay_ms(dev, 200);
}
- if (r != USBD_NORMAL_COMPLETION) {
+ if (err) {
DPRINTFN(-1, ("usbd_new_device: addr=%d, getting first desc "
- "failed\n",
- addr));
+ "failed\n", addr));
usbd_remove_device(dev, up);
- return (r);
+ return (err);
}
if (dd->bDescriptorType != UDESC_DEVICE) {
@@ -908,24 +911,24 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up)
USETW(dev->def_ep_desc.wMaxPacketSize, dd->bMaxPacketSize);
/* Get the full device descriptor. */
- r = usbd_get_device_desc(dev, dd);
- if (r != USBD_NORMAL_COMPLETION) {
+ err = usbd_get_device_desc(dev, dd);
+ if (err) {
DPRINTFN(-1, ("usbd_new_device: addr=%d, getting full desc "
"failed\n", addr));
usbd_remove_device(dev, up);
- return (r);
+ return (err);
}
/* Figure out what's wrong with this device. */
dev->quirks = usbd_find_quirk(dd);
/* Set the address */
- r = usbd_set_address(dev, addr);
- if (r != USBD_NORMAL_COMPLETION) {
+ err = usbd_set_address(dev, addr);
+ if (err) {
DPRINTFN(-1,("usbd_new_device: set address %d failed\n",addr));
- r = USBD_SET_ADDR_FAILED;
+ err = USBD_SET_ADDR_FAILED;
usbd_remove_device(dev, up);
- return (r);
+ return (err);
}
/* Allow device time to set new address */
usbd_delay_ms(dev, USB_SET_ADDRESS_SETTLE);
@@ -941,10 +944,10 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up)
DPRINTF(("usbd_new_device: new dev (addr %d), dev=%p, parent=%p\n",
addr, dev, parent));
- r = usbd_probe_and_attach(parent, dev, port, addr);
- if (r != USBD_NORMAL_COMPLETION) {
+ err = usbd_probe_and_attach(parent, dev, port, addr);
+ if (err) {
usbd_remove_device(dev, up);
- return (r);
+ return (err);
}
return (USBD_NORMAL_COMPLETION);
@@ -959,6 +962,7 @@ usbd_remove_device(dev, up)
if (dev->default_pipe)
usbd_kill_pipe(dev->default_pipe);
+
up->device = 0;
dev->bus->devices[dev->address] = 0;
@@ -1012,6 +1016,11 @@ usbd_submatch(parent, cf, aux)
}
#endif
+
+/*
+ * Maintain a list of control transfers per pipe. As soon as the
+ * previous one for the queue is done the next one is submitted
+ */
usbd_status
usb_insert_transfer(reqh)
usbd_request_handle reqh;
@@ -1037,7 +1046,7 @@ usb_start_next(pipe)
usbd_pipe_handle pipe;
{
usbd_request_handle reqh;
- usbd_status r;
+ usbd_status err;
#ifdef DIAGNOSTIC
if (SIMPLEQ_FIRST(&pipe->queue) == 0) {
@@ -1046,7 +1055,7 @@ usb_start_next(pipe)
}
#endif
- /* First remove remove old */
+ /* First remove finished transfer */
#if defined(__NetBSD__)
SIMPLEQ_REMOVE_HEAD(&pipe->queue, SIMPLEQ_FIRST(&pipe->queue), next);
#elif defined(__FreeBSD__)
@@ -1061,9 +1070,9 @@ usb_start_next(pipe)
if (!reqh)
pipe->running = 0;
else {
- r = pipe->methods->start(reqh);
- if (r != USBD_IN_PROGRESS) {
- printf("usb_start_next: error=%d\n", r);
+ err = pipe->methods->start(reqh);
+ if (err != USBD_IN_PROGRESS) {
+ printf("usb_start_next: error=%d\n", err);
pipe->running = 0;
/* XXX do what? */
}
@@ -1075,8 +1084,8 @@ usbd_fill_deviceinfo(dev, di)
usbd_device_handle dev;
struct usb_device_info *di;
{
- struct usbd_port *p;
- int i, r, s;
+ struct usbd_port *port;
+ int i, err, s;
di->config = dev->config;
usbd_devinfo_vp(dev, di->vendor, di->product);
@@ -1092,21 +1101,21 @@ usbd_fill_deviceinfo(dev, di)
i < sizeof(di->ports) / sizeof(di->ports[0]) &&
i < dev->hub->hubdesc.bNbrPorts;
i++) {
- p = &dev->hub->ports[i];
- if (p->device)
- r = p->device->address;
+ port = &dev->hub->ports[i];
+ if (port->device)
+ err = port->device->address;
else {
- s = UGETW(p->status.wPortStatus);
+ s = UGETW(port->status.wPortStatus);
if (s & UPS_PORT_ENABLED)
- r = USB_PORT_ENABLED;
+ err = USB_PORT_ENABLED;
else if (s & UPS_SUSPEND)
- r = USB_PORT_SUSPENDED;
+ err = USB_PORT_SUSPENDED;
else if (s & UPS_PORT_POWER)
- r = USB_PORT_POWERED;
+ err = USB_PORT_POWERED;
else
- r = USB_PORT_DISABLED;
+ err = USB_PORT_DISABLED;
}
- di->ports[i] = r;
+ di->ports[i] = err;
}
di->nports = dev->hub->hubdesc.bNbrPorts;
} else
diff --git a/sys/dev/usb/usbcdc.h b/sys/dev/usb/usbcdc.h
index 5187a4a2851d..58b07061e87d 100644
--- a/sys/dev/usb/usbcdc.h
+++ b/sys/dev/usb/usbcdc.h
@@ -100,9 +100,9 @@ typedef struct {
#define UCDC_GET_ENCAPSULATED_RESPONSE 0x01
#define UCDC_SET_COMM_FEATURE 0x02
#define UCDC_GET_COMM_FEATURE 0x03
+#define UCDC_CLEAR_COMM_FEATURE 0x04
#define UCDC_ABSTRACT_STATE 0x01
#define UCDC_COUNTRY_SETTING 0x02
-#define UCDC_CLEAR_COMM_FEATURE 0x04
#define UCDC_SET_LINE_CODING 0x20
#define UCDC_GET_LINE_CODING 0x21
diff --git a/sys/dev/usb/usbdi.c b/sys/dev/usb/usbdi.c
index b148d894fa0d..ff50addaadcb 100644
--- a/sys/dev/usb/usbdi.c
+++ b/sys/dev/usb/usbdi.c
@@ -982,8 +982,7 @@ usbd_transfer_cb(reqh)
usbd_pipe_handle pipe = reqh->pipe;
/* Count completed transfers. */
- ++pipe->device->bus->stats.requests
- [pipe->endpoint->edesc->bmAttributes & UE_XFERTYPE];
+ ++pipe->device->bus->stats.requests[pipe->endpoint->edesc->bmAttributes & UE_XFERTYPE];
/* XXX check retry count */
reqh->done = 1;
@@ -994,6 +993,7 @@ usbd_transfer_cb(reqh)
reqh->actlen, reqh->length));
reqh->status = USBD_SHORT_XFER;
}
+
if (reqh->callback)
reqh->callback(reqh, reqh->priv, reqh->status);
}
@@ -1065,6 +1065,7 @@ usbd_do_request_flags(dev, req, data, flags, actlen)
if (r != USBD_NORMAL_COMPLETION)
goto bad;
r = usbd_sync_transfer(reqh);
+
#if defined(USB_DEBUG) || defined(DIAGNOSTIC)
if (reqh->actlen > reqh->length)
printf("usbd_do_request: overrun addr=%d type=0x%02x req=0x"
@@ -1075,8 +1076,10 @@ usbd_do_request_flags(dev, req, data, flags, actlen)
UGETW(reqh->request.wLength),
reqh->length, reqh->actlen);
#endif
+
if (actlen)
*actlen = reqh->actlen;
+
if (r == USBD_STALLED) {
/*
* The control endpoint has stalled. Control endpoints
diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h
index b8f63f88e902..19450dca540a 100644
--- a/sys/dev/usb/usbdi.h
+++ b/sys/dev/usb/usbdi.h
@@ -107,6 +107,7 @@ typedef void (*usbd_callback) __P((usbd_request_handle, usbd_private_handle,
/* Open flags */
#define USBD_EXCLUSIVE_USE 0x01
+/* XXX broken, should not use the same value */
/* Request flags */
#define USBD_XFER_OUT 0x01
#define USBD_XFER_IN 0x02
diff --git a/sys/dev/usb/usbdivar.h b/sys/dev/usb/usbdivar.h
index 8e61d8543b62..96354d1c38c9 100644
--- a/sys/dev/usb/usbdivar.h
+++ b/sys/dev/usb/usbdivar.h
@@ -170,7 +170,7 @@ struct usbd_request {
void *hcpriv; /* XXX private use by the HC driver */
#if defined(__FreeBSD__)
- struct callout_handle timo_handle;
+ struct callout_handle timeout_handle;
#endif
};