Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/nick-nhusb]: src/sys Rework roothub control transfers so that much of th...
details: https://anonhg.NetBSD.org/src/rev/3d57fe8f90a5
branches: nick-nhusb
changeset: 334075:3d57fe8f90a5
user: skrll <skrll%NetBSD.org@localhost>
date: Thu Dec 04 08:04:31 2014 +0000
description:
Rework roothub control transfers so that much of the code is shared
across HCDs.
I have retained the vendor/product reporting for each HCD for now,
but it maybe get removed later.
ahci(4) now reports a language table and uses the usb_makestrdesc
function instead of rolling its own version.
diffstat:
sys/arch/mips/adm5120/dev/ahci.c | 379 ++++--------------------------
sys/arch/mips/conf/files.adm5120 | 4 +-
sys/dev/ic/sl811hs.c | 225 +++++-------------
sys/dev/ic/sl811hsvar.h | 4 +-
sys/dev/usb/ehci.c | 393 +++++---------------------------
sys/dev/usb/ehcivar.h | 4 +-
sys/dev/usb/motg.c | 361 +++++------------------------
sys/dev/usb/motgvar.h | 4 +-
sys/dev/usb/ohci.c | 367 ++++++------------------------
sys/dev/usb/ohcivar.h | 4 +-
sys/dev/usb/uhci.c | 366 +++++------------------------
sys/dev/usb/uhcivar.h | 5 +-
sys/dev/usb/usbdivar.h | 7 +-
sys/dev/usb/usbroothub.c | 437 +++++++++++++++++++++++++++++++++++-
sys/dev/usb/usbroothub.h | 41 +++-
sys/dev/usb/xhci.c | 362 ++++-------------------------
sys/dev/usb/xhcivar.h | 5 +-
sys/external/bsd/dwc2/dwc2.c | 260 +-------------------
sys/external/bsd/dwc2/dwc2var.h | 7 +-
sys/rump/dev/lib/libugenhc/ugenhc.c | 250 +++----------------
20 files changed, 1000 insertions(+), 2485 deletions(-)
diffs (truncated from 5055 to 300 lines):
diff -r a1d841daa5e0 -r 3d57fe8f90a5 sys/arch/mips/adm5120/dev/ahci.c
--- a/sys/arch/mips/adm5120/dev/ahci.c Thu Dec 04 07:53:46 2014 +0000
+++ b/sys/arch/mips/adm5120/dev/ahci.c Thu Dec 04 08:04:31 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ahci.c,v 1.12.6.9 2014/12/03 22:40:54 skrll Exp $ */
+/* $NetBSD: ahci.c,v 1.12.6.10 2014/12/04 08:04:31 skrll Exp $ */
/*-
* Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.12.6.9 2014/12/03 22:40:54 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.12.6.10 2014/12/04 08:04:31 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -81,6 +81,7 @@
#include <dev/usb/usbdivar.h>
#include <dev/usb/usb_mem.h>
#include <dev/usb/usbdevs.h>
+#include <dev/usb/usbroothub.h>
#include <mips/adm5120/include/adm5120reg.h>
#include <mips/adm5120/include/adm5120var.h>
@@ -98,14 +99,8 @@
static void ahci_freex(struct usbd_bus *, usbd_xfer_handle);
static void ahci_get_lock(struct usbd_bus *, kmutex_t **);
-
-static int ahci_str(usb_string_descriptor_t *, int, const char *);
-
-static usbd_status ahci_root_ctrl_transfer(usbd_xfer_handle);
-static usbd_status ahci_root_ctrl_start(usbd_xfer_handle);
-static void ahci_root_ctrl_abort(usbd_xfer_handle);
-static void ahci_root_ctrl_close(usbd_pipe_handle);
-static void ahci_root_ctrl_done(usbd_xfer_handle);
+static int ahci_roothub_ctrl(struct usbd_bus *, usb_device_request_t *,
+ void *, int);
static usbd_status ahci_root_intr_transfer(usbd_xfer_handle);
static usbd_status ahci_root_intr_start(usbd_xfer_handle);
@@ -150,9 +145,6 @@
#define AHCI_DEBUG
-/* For root hub */
-#define AHCI_INTR_ENDPT (1)
-
#ifdef AHCI_DEBUG
#define D_TRACE (0x0001) /* function trace */
#define D_MSG (0x0002) /* debug messages */
@@ -177,15 +169,7 @@
.ubm_allocx = ahci_allocx,
.ubm_freex = ahci_freex,
.ubm_getlock = ahci_get_lock,
-};
-
-struct usbd_pipe_methods ahci_root_ctrl_methods = {
- .upm_transfer = ahci_root_ctrl_transfer,
- .upm_start = ahci_root_ctrl_start,
- .upm_abort = ahci_root_ctrl_abort,
- .upm_close = ahci_root_ctrl_close,
- .upm_cleartoggle = ahci_noop,
- .upm_done = ahci_root_ctrl_done,
+ .ubm_rhctrl = ahci_roothub_ctrl,
};
struct usbd_pipe_methods ahci_root_intr_methods = {
@@ -368,21 +352,21 @@
ahci_open(usbd_pipe_handle pipe)
{
usbd_device_handle dev = pipe->up_dev;
- struct ahci_softc *sc = (struct ahci_softc *)dev->ud_bus;
struct ahci_pipe *apipe = (struct ahci_pipe *)pipe;
usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc;
+ uint8_t rhaddr = dev->ud_bus->ub_rhaddr;
DPRINTF(D_TRACE, ("ahci_open(addr=%d,ep=%d,scaddr=%d)",
- dev->ud_addr, ed->bEndpointAddress, sc->sc_addr));
+ dev->ud_addr, ed->bEndpointAddress, rhaddr));
apipe->toggle=0;
- if (dev->ud_addr == sc->sc_addr) {
+ if (dev->ud_addr == rhaddr) {
switch (ed->bEndpointAddress) {
case USB_CONTROL_ENDPOINT:
- pipe->up_methods = &ahci_root_ctrl_methods;
+ pipe->up_methods = &roothub_ctrl_methods;
break;
- case UE_DIR_IN | AHCI_INTR_ENDPT:
+ case UE_DIR_IN | USBROOTHUB_INTR_ENDPT:
pipe->up_methods = &ahci_root_intr_methods;
break;
default:
@@ -531,275 +515,52 @@
/*
* Data structures and routines to emulate the root hub.
*/
-usb_device_descriptor_t ahci_devd = {
- .bLength = USB_DEVICE_DESCRIPTOR_SIZE,
- .bDescriptorType = UDESC_DEVICE,
- .bcdUSB = {0x01, 0x01},
- .bDeviceClass = UDCLASS_HUB,
- .bDeviceSubClass = UDSUBCLASS_HUB,
- .bDeviceProtocol = 0,
- .bMaxPacketSize = 64,
- .idVendor = {
- USB_VENDOR_SCANLOGIC & 0xff,
- USB_VENDOR_SCANLOGIC >> 8
- },
- .idProduct = {0},
- .bcdDevice = {0},
- .iManufacturer = 1,
- .iProduct = 2,
- .iSerialNumber = 0,
- .bNumConfigurations = 1
-};
-
-usb_config_descriptor_t ahci_confd = {
- .bLength = USB_CONFIG_DESCRIPTOR_SIZE,
- .bDescriptorType = UDESC_CONFIG,
- .wTotalLength = USETWD(
- USB_CONFIG_DESCRIPTOR_SIZE +
- USB_INTERFACE_DESCRIPTOR_SIZE +
- USB_ENDPOINT_DESCRIPTOR_SIZE),
- .bNumInterface = 1,
- .bConfigurationValue = 1,
- .iConfiguration = 0,
- .bmAttributes = UC_SELF_POWERED,
- .bMaxPower = 250
-};
-
-usb_interface_descriptor_t ahci_ifcd = {
- .bLength = USB_INTERFACE_DESCRIPTOR_SIZE,
- .bDescriptorType = UDESC_INTERFACE,
- .bInterfaceNumber = 0,
- .bAlternateSetting = 0,
- .bNumEndpoints = 1,
- .bInterfaceClass = UICLASS_HUB,
- .bInterfaceSubClass = UISUBCLASS_HUB,
- .bInterfaceProtocol = 0,
- .iInterface = 0
-};
-
-usb_endpoint_descriptor_t ahci_endpd = {
- .bLength = USB_ENDPOINT_DESCRIPTOR_SIZE,
- .bDescriptorType = UDESC_ENDPOINT,
- .bEndpointAddress = UE_DIR_IN | AHCI_INTR_ENDPT,
- .bmAttributes = UE_INTERRUPT,
- .wMaxPacketSize = USETWD(8),
- .bInterval = 255
-};
-
-usb_hub_descriptor_t ahci_hubd = {
- .bDescLength = USB_HUB_DESCRIPTOR_SIZE,
- .bDescriptorType = UDESC_HUB,
- .bNbrPorts = 2,
- .wHubCharacteristics = USETWD(0),
- .bPwrOn2PwrGood = 0,
- .bHubContrCurrent = 0,
- .DeviceRemovable = { 0x00 },
- .PortPowerCtrlMask = { 0x00 }
-};
static int
-ahci_str(usb_string_descriptor_t *p, int l, const char *s)
-{
- int i;
-
- if (l == 0)
- return 0;
- p->bLength = 2 * strlen(s) + 2;
- if (l == 1)
- return 1;
- p->bDescriptorType = UDESC_STRING;
- l -= 2;
- for (i = 0; s[i] && l > 1; i++, l -= 2)
- USETW2(p->bString[i], 0, s[i]);
- return 2 * i + 2;
-}
-
-usbd_status
-ahci_root_ctrl_transfer(usbd_xfer_handle xfer)
+ahci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
+ void *buf, int buflen)
{
- struct ahci_softc *sc = (struct ahci_softc *)xfer->ux_pipe->up_dev->ud_bus;
- usbd_status error;
-
- DPRINTF(D_TRACE, ("SLRCtrans "));
-
- /* Insert last in queue */
- mutex_enter(&sc->sc_lock);
- error = usb_insert_transfer(xfer);
- mutex_exit(&sc->sc_lock);
- if (error) {
- DPRINTF(D_MSG, ("usb_insert_transfer returns err! "));
- return error;
- }
-
- /*
- * Pipe isn't running (otherwise error would be USBD_INPROG),
- * so start it first.
- */
- return ahci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
-}
-
-usbd_status
-ahci_root_ctrl_start(usbd_xfer_handle xfer)
-{
- struct ahci_softc *sc = (struct ahci_softc *)xfer->ux_pipe->up_dev->ud_bus;
- usb_device_request_t *req;
- int len, value, index, l, status;
+ struct ahci_softc *sc = bus->ub_hcpriv;
+ uint16_t len, value, index;
+ usb_port_status_t ps;
int totlen = 0;
- void *buf = NULL;
- usb_port_status_t ps;
- usbd_status error;
-
+ int status;
DPRINTF(D_TRACE, ("SLRCstart "));
- req = &xfer->ux_request;
-
len = UGETW(req->wLength);
value = UGETW(req->wValue);
index = UGETW(req->wIndex);
- if (len)
- buf = KERNADDR(&xfer->ux_dmabuf, 0);
-
-#ifdef AHCI_DEBUG
- if ((ahci_debug & D_TRACE))
- print_req_hub(req);
-#endif
-
#define C(x,y) ((x) | ((y) << 8))
switch (C(req->bRequest, req->bmRequestType)) {
- case C(UR_CLEAR_FEATURE, UT_WRITE_DEVICE):
- DPRINTF(D_MSG, ("UR_CLEAR_FEATURE(DEVICE)XXX "));
- break;
- case C(UR_CLEAR_FEATURE, UT_WRITE_INTERFACE):
- DPRINTF(D_MSG, ("UR_CLEAR_FEATURE(INTERFACE)XXX "));
- break;
- case C(UR_CLEAR_FEATURE, UT_WRITE_ENDPOINT):
- DPRINTF(D_MSG, ("UR_CLEAR_FEATURE(ENDPOINT)XXX "));
- break;
- case C(UR_GET_CONFIG, UT_READ_DEVICE):
- DPRINTF(D_MSG, ("UR_GET_CONFIG "));
- if (len > 0) {
- *(uint8_t *)buf = sc->sc_conf;
- totlen = 1;
- }
- break;
case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE):
- switch (value >> 8) {
- case UDESC_DEVICE:
+ switch (value) {
+ case C(0, UDESC_DEVICE): {
+ usb_device_descriptor_t devd;
+
DPRINTF(D_MSG, ("UDESC_DEVICE "));
- if ((value & 0xff) != 0) {
- error = USBD_IOERROR;
- goto ret;
- }
- totlen = l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
- memcpy(buf, &ahci_devd, l);
+ totlen = min(buflen, sizeof(devd));
+ memcpy(&devd, buf, totlen);
+ USETW(devd.idVendor, USB_VENDOR_SCANLOGIC);
+ memcpy(buf, &devd, totlen);
break;
- case UDESC_CONFIG:
- DPRINTF(D_MSG, ("UDESC_CONFIG "));
- if ((value & 0xff) != 0) {
- error = USBD_IOERROR;
- goto ret;
- }
- totlen = l = min(len, USB_CONFIG_DESCRIPTOR_SIZE);
- memcpy(buf, &ahci_confd, l);
- buf = (char *)buf + l;
- len -= l;
-
- l = min(len, USB_INTERFACE_DESCRIPTOR_SIZE);
- totlen += l;
- memcpy(buf, &ahci_ifcd, l);
- buf = (char *)buf + l;
- len -= l;
-
- l = min(len, USB_ENDPOINT_DESCRIPTOR_SIZE);
- totlen += l;
- memcpy(buf, &ahci_endpd, l);
+ }
Home |
Main Index |
Thread Index |
Old Index