0
votes

I have looked into couple USB device driver code looks like they have to associates with PCI device(s) and when usb_submit_urb() is called in USB device driver, the urb structure has already been associated with specific HCI driver, then when usb_submit_urb() calls usb_hcd_submit_urb (), usb_hcd_submit_urb() will fetch hcd from the parameter urb then calls urb->enqueue() which maps to the specific HCI driver.

int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
{
    int         status;
    struct usb_hcd      *hcd = bus_to_hcd(urb->dev->bus);

    ......
    ......
        if (likely(status == 0)) {
            status = hcd->driver->urb_enqueue(hcd, urb, mem_flags);

In my case I need to write a USB HCI driver that talks to a hardware which needs to be hidden from USB device driver, so I cannot change USB device driver to search for PCI ids for the hardware... In this case is there any way to force a specific device driver to associate with the USB HCI driver?

Update:

I have created two diagrams based on the discussion.

Diagram #1 shows the current USB model in kernel, I see from 'lspci' output that xHCI is the only host controller driver that is being used in my system.

Diagram #2 is a proposed design. While still allows NCM CDC device driver to work as a driver for current devices listed in its PCI tables, I would like to register my customized HCI with USB core for NCM CDC device driver. The customized HCI talks to customized hardware driver which hides the customized hardware info from user space (meaning there is no PCI probe).

My customized HCI needs to parse URB messages passed down from USB core and map them to corresponding APIs provided by customized hardware driver.

The problems I am having is that it looks like xHCI is by default used by all USB device drivers, I am not sure how can I tell USB core to use my customized HCI at all... even if I maybe able to hardcode USB core to force all traffics from NCM CDC USB device driver to customized HCI, because I won't be able to provide PCI productID/vendorID to NCM CDC device driver, how can I trigger NCM CDC device driver's probe() function to start at all?

Diagram #1 (Current kernel USB model):
  -----------------           ------------------           -------------------             -------------------
  |    NCM CDC    |  <---->   |    USB Core    |   <---->  |       xHCI      |    <---->   |   USB devices   |
  -----------------           ------------------           -------------------             -------------------





Diagram #2 (proposed design):
  -----------------           ------------------           -----------------------------             --------------------------------            --------------------
  |    NCM CDC    |  <---->   |    USB Core    |   <----->  |       Customized HCI      |    <---->  |   Customized Hardware driver |    <---->  |   Customized HW  |
  -----------------           ------------------      |     -----------------------------            --------------------------------            --------------------
                                                      |
                                                      |
                                                      |
                                                      |    -------------------             -------------------
                                                      |--->|       xHCI      |    <---->   |   USB devices   |
                                                           -------------------             -------------------
1

1 Answers

1
votes

If I understood properly your needs: you need to write a HCI driver which will be working outside of standard USB stack in Linux? So you don't want to register your HCI in Linux usb-core? If yes - just write HCI driver and don't register his API into usb-core. AFAIK which USB HCI driver (and HCI HW) is used only depends on the physical USB port you connected. So if you have system with more than one USB HCI then you can select HCI just by plugging USB device to given physical port. As I remember in USB 2.0 (ehci + companion controller) there was possibility to assign some USB port to either ehci or uhci/ohci (with some kind of mux) but now with xhci - I don't think it is possible. Mainly because xhci doesn't need any companion controller.