Re-establish the default pipe after the initial reading of the device

descriptor.

This fixes usbd_new_device so that there is no really need to touch
QHs/EDs in [eo]hci_device_request.

KASSERT the address and maximum packet length now.
This commit is contained in:
skrll 2014-02-17 07:34:21 +00:00
parent cdcd95784d
commit fa1f86b552
3 changed files with 34 additions and 37 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ehci.c,v 1.224 2013/12/16 10:04:20 skrll Exp $ */
/* $NetBSD: ehci.c,v 1.225 2014/02/17 07:34:21 skrll Exp $ */
/*
* Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@ -53,7 +53,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.224 2013/12/16 10:04:20 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.225 2014/02/17 07:34:21 skrll Exp $");
#include "ohci.h"
#include "uhci.h"
@ -3364,7 +3364,6 @@ ehci_device_request(usbd_xfer_handle xfer)
usb_device_request_t *req = &xfer->request;
usbd_device_handle dev = epipe->pipe.device;
ehci_softc_t *sc = dev->bus->hci_private;
int addr = dev->address;
ehci_soft_qtd_t *setup, *stat, *next;
ehci_soft_qh_t *sqh;
int isread;
@ -3377,7 +3376,7 @@ ehci_device_request(usbd_xfer_handle xfer)
DPRINTFN(3,("ehci_device_request: type=0x%02x, request=0x%02x, "
"wValue=0x%04x, wIndex=0x%04x len=%d, addr=%d, endpt=%d\n",
req->bmRequestType, req->bRequest, UGETW(req->wValue),
UGETW(req->wIndex), len, addr,
UGETW(req->wIndex), len, dev->address,
epipe->pipe.endpoint->edesc->bEndpointAddress));
setup = ehci_alloc_sqtd(sc);
@ -3395,18 +3394,14 @@ ehci_device_request(usbd_xfer_handle xfer)
sqh = epipe->sqh;
/*
* Update device address and length since they may have changed
* during the setup of the control pipe in usbd_new_device().
*/
/* XXX This only needs to be done once, but it's too early in open. */
/* XXXX Should not touch ED here! */
sqh->qh.qh_endp =
(sqh->qh.qh_endp & htole32(~(EHCI_QH_ADDRMASK | EHCI_QH_MPLMASK))) |
htole32(
EHCI_QH_SET_ADDR(addr) |
EHCI_QH_SET_MPL(UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize))
);
KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->address,
"address QH %d pipe %d\n",
EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->address);
KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) ==
UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize),
"MPS QH %d pipe %d\n",
EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)),
UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize));
/* Set up data transaction */
if (len != 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: ohci.c,v 1.249 2014/01/28 17:24:42 skrll Exp $ */
/* $NetBSD: ohci.c,v 1.250 2014/02/17 07:34:21 skrll Exp $ */
/*
* Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.249 2014/01/28 17:24:42 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.250 2014/02/17 07:34:21 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1695,7 +1695,6 @@ ohci_device_request(usbd_xfer_handle xfer)
usb_device_request_t *req = &xfer->request;
usbd_device_handle dev = opipe->pipe.device;
ohci_softc_t *sc = dev->bus->hci_private;
int addr = dev->address;
ohci_soft_td_t *setup, *stat, *next, *tail;
ohci_soft_ed_t *sed;
int isread;
@ -1710,7 +1709,7 @@ ohci_device_request(usbd_xfer_handle xfer)
DPRINTFN(3,("ohci_device_control type=0x%02x, request=0x%02x, "
"wValue=0x%04x, wIndex=0x%04x len=%d, addr=%d, endpt=%d\n",
req->bmRequestType, req->bRequest, UGETW(req->wValue),
UGETW(req->wIndex), len, addr,
UGETW(req->wIndex), len, dev->address,
opipe->pipe.endpoint->edesc->bEndpointAddress));
setup = opipe->tail.td;
@ -1729,21 +1728,14 @@ ohci_device_request(usbd_xfer_handle xfer)
sed = opipe->sed;
opipe->u.ctl.length = len;
/* Update device address and length since they may have changed
during the setup of the control pipe in usbd_new_device(). */
/* XXX This only needs to be done once, but it's too early in open. */
/* XXXX Should not touch ED here! */
usb_syncmem(&sed->dma, sed->offs + offsetof(ohci_ed_t, ed_flags),
sizeof(sed->ed.ed_flags),
BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
sed->ed.ed_flags = HTOO32(
(O32TOH(sed->ed.ed_flags) & ~(OHCI_ED_ADDRMASK | OHCI_ED_MAXPMASK)) |
OHCI_ED_SET_FA(addr) |
OHCI_ED_SET_MAXP(UGETW(opipe->pipe.endpoint->edesc->wMaxPacketSize)));
usb_syncmem(&sed->dma, sed->offs + offsetof(ohci_ed_t, ed_flags),
sizeof(sed->ed.ed_flags),
BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
KASSERTMSG(OHCI_ED_GET_FA(O32TOH(sed->ed.ed_flags)) == dev->address,
"address ED %d pipe %d\n",
OHCI_ED_GET_FA(O32TOH(sed->ed.ed_flags)), dev->address);
KASSERTMSG(OHCI_ED_GET_MAXP(O32TOH(sed->ed.ed_flags)) ==
UGETW(opipe->pipe.endpoint->edesc->wMaxPacketSize),
"MPL ED %d pipe %d\n",
OHCI_ED_GET_MAXP(O32TOH(sed->ed.ed_flags)),
UGETW(opipe->pipe.endpoint->edesc->wMaxPacketSize));
next = stat;

View File

@ -1,4 +1,4 @@
/* $NetBSD: usb_subr.c,v 1.195 2013/10/03 07:35:37 skrll Exp $ */
/* $NetBSD: usb_subr.c,v 1.196 2014/02/17 07:34:21 skrll Exp $ */
/* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */
/*
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.195 2013/10/03 07:35:37 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.196 2014/02/17 07:34:21 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -1237,6 +1237,16 @@ usbd_new_device(device_t parent, usbd_bus_handle bus, int depth,
USETW(dev->def_ep_desc.wMaxPacketSize, dd->bMaxPacketSize);
/* Re-establish the default pipe with the new MPS. */
usbd_kill_pipe(dev->default_pipe);
err = usbd_setup_pipe_flags(dev, 0, &dev->def_ep, USBD_DEFAULT_INTERVAL,
&dev->default_pipe, USBD_MPSAFE);
if (err) {
DPRINTFN(-1, ("usbd_new_device: setup default pipe failed\n"));
usbd_remove_device(dev, up);
return err;
}
/* Set the address */
DPRINTFN(5, ("usbd_new_device: setting device address=%d\n", addr));
err = usbd_set_address(dev, addr);