From 0324d54acbb3350347bb128d8ce259d08f648ddb Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Mon, 1 Oct 2012 05:42:43 +0000 Subject: [PATCH] Inherit USB mode from RootHUB port where the USB device is connected. Only RootHUB ports can be dual mode. Disallow OTG ports on external HUBs. This simplifies some checks in the USB controller drivers. MFC after: 1 week --- sys/dev/usb/controller/at91dci.c | 4 ---- sys/dev/usb/controller/atmegadci.c | 4 ---- sys/dev/usb/controller/avr32dci.c | 4 ---- sys/dev/usb/controller/ehci.c | 4 ---- sys/dev/usb/controller/musb_otg.c | 4 ---- sys/dev/usb/controller/ohci.c | 5 +---- sys/dev/usb/controller/uhci.c | 4 ---- sys/dev/usb/controller/uss820dci.c | 4 ---- sys/dev/usb/controller/xhci.c | 4 ---- sys/dev/usb/usb_hub.c | 5 ++++- sys/mips/cavium/usb/octusb.c | 4 ---- 11 files changed, 5 insertions(+), 41 deletions(-) diff --git a/sys/dev/usb/controller/at91dci.c b/sys/dev/usb/controller/at91dci.c index 8d3c1cb967b..55688d98f6d 100644 --- a/sys/dev/usb/controller/at91dci.c +++ b/sys/dev/usb/controller/at91dci.c @@ -2277,10 +2277,6 @@ at91dci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, if (udev->device_index != sc->sc_rt_addr) { - if (udev->flags.usb_mode != USB_MODE_DEVICE) { - /* not supported */ - return; - } if (udev->speed != USB_SPEED_FULL) { /* not supported */ return; diff --git a/sys/dev/usb/controller/atmegadci.c b/sys/dev/usb/controller/atmegadci.c index d8f9111a43f..132fd481ddc 100644 --- a/sys/dev/usb/controller/atmegadci.c +++ b/sys/dev/usb/controller/atmegadci.c @@ -2112,10 +2112,6 @@ atmegadci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc if (udev->device_index != sc->sc_rt_addr) { - if (udev->flags.usb_mode != USB_MODE_DEVICE) { - /* not supported */ - return; - } if (udev->speed != USB_SPEED_FULL) { /* not supported */ return; diff --git a/sys/dev/usb/controller/avr32dci.c b/sys/dev/usb/controller/avr32dci.c index 7a672f690f7..14b4f643cd5 100644 --- a/sys/dev/usb/controller/avr32dci.c +++ b/sys/dev/usb/controller/avr32dci.c @@ -2056,10 +2056,6 @@ avr32dci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, if (udev->device_index != sc->sc_rt_addr) { - if (udev->flags.usb_mode != USB_MODE_DEVICE) { - /* not supported */ - return; - } if ((udev->speed != USB_SPEED_FULL) && (udev->speed != USB_SPEED_HIGH)) { /* not supported */ diff --git a/sys/dev/usb/controller/ehci.c b/sys/dev/usb/controller/ehci.c index a6470b88eab..8131f60926a 100644 --- a/sys/dev/usb/controller/ehci.c +++ b/sys/dev/usb/controller/ehci.c @@ -3701,10 +3701,6 @@ ehci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, edesc->bEndpointAddress, udev->flags.usb_mode, sc->sc_addr); - if (udev->flags.usb_mode != USB_MODE_HOST) { - /* not supported */ - return; - } if (udev->device_index != sc->sc_addr) { if ((udev->speed != USB_SPEED_HIGH) && diff --git a/sys/dev/usb/controller/musb_otg.c b/sys/dev/usb/controller/musb_otg.c index 858cd0f0c96..627b40ba2ac 100644 --- a/sys/dev/usb/controller/musb_otg.c +++ b/sys/dev/usb/controller/musb_otg.c @@ -2748,10 +2748,6 @@ musbotg_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, if (udev->device_index != sc->sc_rt_addr) { - if (udev->flags.usb_mode != USB_MODE_DEVICE) { - /* not supported */ - return; - } if ((udev->speed != USB_SPEED_FULL) && (udev->speed != USB_SPEED_HIGH)) { /* not supported */ diff --git a/sys/dev/usb/controller/ohci.c b/sys/dev/usb/controller/ohci.c index a3179f181e1..89517f3de79 100644 --- a/sys/dev/usb/controller/ohci.c +++ b/sys/dev/usb/controller/ohci.c @@ -2315,6 +2315,7 @@ ohci_roothub_exec(struct usb_device *udev, } v = OREAD4(sc, OHCI_RH_PORT_STATUS(index)); DPRINTFN(9, "port status=0x%04x\n", v); + v &= ~UPS_PORT_MODE_DEVICE; /* force host mode */ USETW(sc->sc_hub_desc.ps.wPortStatus, v); USETW(sc->sc_hub_desc.ps.wPortChange, v >> 16); len = sizeof(sc->sc_hub_desc.ps); @@ -2551,10 +2552,6 @@ ohci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, edesc->bEndpointAddress, udev->flags.usb_mode, sc->sc_addr); - if (udev->flags.usb_mode != USB_MODE_HOST) { - /* not supported */ - return; - } if (udev->device_index != sc->sc_addr) { switch (edesc->bmAttributes & UE_XFERTYPE) { case UE_CONTROL: diff --git a/sys/dev/usb/controller/uhci.c b/sys/dev/usb/controller/uhci.c index c7a8c194b8f..680aac26c42 100644 --- a/sys/dev/usb/controller/uhci.c +++ b/sys/dev/usb/controller/uhci.c @@ -3030,10 +3030,6 @@ uhci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, edesc->bEndpointAddress, udev->flags.usb_mode, sc->sc_addr); - if (udev->flags.usb_mode != USB_MODE_HOST) { - /* not supported */ - return; - } if (udev->device_index != sc->sc_addr) { switch (edesc->bmAttributes & UE_XFERTYPE) { case UE_CONTROL: diff --git a/sys/dev/usb/controller/uss820dci.c b/sys/dev/usb/controller/uss820dci.c index 5bd479d50fa..bbb9f75fb96 100644 --- a/sys/dev/usb/controller/uss820dci.c +++ b/sys/dev/usb/controller/uss820dci.c @@ -2333,10 +2333,6 @@ uss820dci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc if (udev->device_index != sc->sc_rt_addr) { - if (udev->flags.usb_mode != USB_MODE_DEVICE) { - /* not supported */ - return; - } if (udev->speed != USB_SPEED_FULL) { /* not supported */ return; diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c index 985efc8663e..2b8f0f35479 100644 --- a/sys/dev/usb/controller/xhci.c +++ b/sys/dev/usb/controller/xhci.c @@ -3712,10 +3712,6 @@ xhci_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, DPRINTFN(2, "endpoint=%p, addr=%d, endpt=%d, mode=%d\n", ep, udev->address, edesc->bEndpointAddress, udev->flags.usb_mode); - if (udev->flags.usb_mode != USB_MODE_HOST) { - /* not supported */ - return; - } if (udev->parent_hub == NULL) { /* root HUB has special endpoint handling */ return; diff --git a/sys/dev/usb/usb_hub.c b/sys/dev/usb/usb_hub.c index 2f3dbe52607..0686bdf766c 100644 --- a/sys/dev/usb/usb_hub.c +++ b/sys/dev/usb/usb_hub.c @@ -518,7 +518,10 @@ repeat: * * NOTE: This part is currently FreeBSD specific. */ - if (sc->sc_st.port_status & UPS_PORT_MODE_DEVICE) + if (udev->parent_hub != NULL) { + /* inherit mode from the parent HUB */ + mode = udev->parent_hub->flags.usb_mode; + } else if (sc->sc_st.port_status & UPS_PORT_MODE_DEVICE) mode = USB_MODE_DEVICE; else mode = USB_MODE_HOST; diff --git a/sys/mips/cavium/usb/octusb.c b/sys/mips/cavium/usb/octusb.c index 01328c5b70a..cad3ef5ef21 100644 --- a/sys/mips/cavium/usb/octusb.c +++ b/sys/mips/cavium/usb/octusb.c @@ -1860,10 +1860,6 @@ octusb_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc, ep, udev->address, edesc->bEndpointAddress, udev->flags.usb_mode, sc->sc_addr); - if (udev->flags.usb_mode != USB_MODE_HOST) { - /* not supported */ - return; - } if (udev->device_index != sc->sc_addr) { switch (edesc->bmAttributes & UE_XFERTYPE) { case UE_CONTROL: