Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
USB device not enumerated by iPXE USB stack
2016-09-29, 07:53
Post: #4
RE: USB device not enumerated by iPXE USB stack
Hi all,

The USB enumeration process failed because the device failed enumeration as a USB 2.0 device, so the iPXE EHCI USB stack handed ownership of the USB port to the iPXE UHCI USB stack, but the enumeration also failed as a USB 1.x device.

So I took a look at the UHCI source code of iPXE. I think that I have found a bug in three functions of the UHCI code. The functions are called uhci_root_enable, uhci_root_speed and uhci_root_poll.

Below you can find the three functions with the changes I have made to solve this enumeration problem.

static int uhci_root_enable ( struct usb_hub *hub, struct usb_port *port ) {
struct uhci_device *uhci = usb_hub_get_drvdata ( hub );
uint16_t portsc;
unsigned int i;

/* Reset port */
portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
portsc |= UHCI_PORTSC_PR;
outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
mdelay ( USB_RESET_DELAY_MS );
portsc &= ~UHCI_PORTSC_PR;
outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
mdelay ( USB_RESET_RECOVER_DELAY_MS );

/* Enable port */
portsc |= UHCI_PORTSC_PED;
outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
mdelay ( USB_RESET_RECOVER_DELAY_MS );

/* Wait for port to become enabled */
for ( i = 0 ; i < UHCI_PORT_ENABLE_MAX_WAIT_MS ; i++ ) {

/* Check port status */
portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
if ( portsc & UHCI_PORTSC_PED && portsc & UHCI_PORTSC_CCS )
{
port->disconnected = 0;
return 0;
}

/* Delay */
mdelay ( 1 );
}

DBGC ( uhci, "UHCI %s-%d timed out waiting for port to enable "
"(status %04x)\n", uhci->name, port->address, portsc );
return -ETIMEDOUT;
}

static int uhci_root_speed ( struct usb_hub *hub, struct usb_port *port ) {
struct uhci_device *uhci = usb_hub_get_drvdata ( hub );
struct pci_device pci;
uint16_t portsc;
unsigned int speed;

/* Read port status */
portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
if ( ! ( portsc & UHCI_PORTSC_CCS ) ) {
/* Port not connected */
speed = USB_SPEED_NONE;
} else if ( uhci->companion &&
! find_usb_bus_by_location ( BUS_TYPE_PCI,
uhci->companion ) ) {
/* Defer connection detection until companion
* controller has been enumerated.
*/
pci_init ( &pci, uhci->companion );
DBGC ( uhci, "UHCI %s-%d deferring for companion " PCI_FMT "\n",
uhci->name, port->address, PCI_ARGS ( &pci ) );
speed = USB_SPEED_NONE;
} else if ( portsc & UHCI_PORTSC_LS ) {
/* Low-speed device */
speed = USB_SPEED_LOW;
} else {
/* Full-speed device */
speed = USB_SPEED_FULL;
}
port->speed = speed;

/* Record disconnections and clear changes */
port->disconnected |= ( (portsc & UHCI_PORTSC_CCS) == 0 );
outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );

return 0;
}

static void uhci_root_poll ( struct usb_hub *hub, struct usb_port *port ) {
struct uhci_device *uhci = usb_hub_get_drvdata ( hub );
uint16_t portsc;
uint16_t change;

/* Do nothing unless something has changed */
portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
change = ( portsc & UHCI_PORTSC_CHANGE );
if ( ! change )
return;

/* Record disconnections and clear changes */
port->disconnected |= ( (portsc & UHCI_PORTSC_CCS) == 0 );
outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );

/* Report port status change */
usb_port_changed ( port );
}

In the function uhci_root_enable I initialize with 0 the disconnected variable of the port structure when the port is enabled and the current connect status bit is set. This part was using the UHCI_PORTSC_CSC mask instead of the UHCI_PORTSC_CCS mask I have put into the code.

The only change to the other two functions is the use of the UHCI_PORTSC_CCS mask instead of the UHCI_PORTSC_CSC mask.

I am not an expert on the iPXE source code, so some with deep knowledge of the iPXE USB stack could take a look at the changes I have made and integrate them into the codebase if they are deemed worthy.

Thanks in advance and execuse my English.

Eugenio
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: USB device not enumerated by iPXE USB stack - eugenio - 2016-09-29 07:53



User(s) browsing this thread: 3 Guest(s)