65 if ( ( (
phys +
len - 1 ) & ~0xffffffffULL ) == 0 )
120 DBGC ( uhci,
"UHCI %s timed out waiting for stop\n", uhci->
name );
158 DBGC ( uhci,
"UHCI %s timed out waiting for reset\n", uhci->
name );
179 memset ( ring, 0,
sizeof ( *ring ) );
183 if ( ! ring->
head ) {
188 sizeof ( *ring->
head ) ) ) != 0 )
189 goto err_unreachable;
228 unsigned int count ) {
249 goto err_unreachable_iobuf;
252 xfer =
malloc (
sizeof ( *xfer ) );
267 if ( ! xfer->
desc ) {
272 goto err_unreachable_desc;
301 err_unreachable_desc:
306 err_unreachable_iobuf:
329 if ( frag_len > ring->
mtu )
330 frag_len = ring->
mtu;
424 for ( i = ring->
cons ; i != ring->
prod ; i++ ) {
428 for ( j = 0 ; j < xfer->
prod ; j++ ) {
536 unsigned int max_interval;
544 DBGCP ( uhci,
"UHCI %s periodic schedule: ", uhci->
name );
554 DBGCP ( uhci,
"\n" );
557 DBGCP ( uhci,
"UHCI %s periodic frame list:", uhci->
name );
568 max_interval = ( 1 << (
ffs ( i ) - 1 ) );
572 max_interval = ( ( max_interval << 1 ) - 1 );
580 if ( endpoint->
ep->
interval <= max_interval ) {
583 DBGCP ( uhci,
" %d:%d",
591 DBGCP ( uhci,
"\n" );
602 unsigned int interval = endpoint->
ep->
interval;
606 if (
before->ep->interval < interval )
686 endpoint =
zalloc (
sizeof ( *endpoint ) );
799 len = (
iob_len ( iobuf ) -
sizeof ( *packet ) );
801 ( (
len + ring->
mtu - 1 ) / ring->
mtu ) +
809 packet = iobuf->
data;
812 iob_pull ( iobuf,
sizeof ( *packet ) );
852 count = ( ( (
len + ring->
mtu - 1 ) / ring->
mtu ) + ( zlp ? 1 : 0 ) );
931 DBGC ( uhci,
"UHCI %s %s completion %d.%d failed " 932 "(status %02x)\n", usb->
name,
988 }
else if ( xfer->
cons == xfer->
prod ) {
1064 DBGC (
uhci,
"UHCI %s could not allocate address: %s\n",
1066 goto err_alloc_address;
1071 goto err_set_address;
1181 DBGC ( uhci,
"UHCI %s-%d timed out waiting for port to enable " 1182 "(status %04x)\n", uhci->
name,
port->address, portsc );
1230 DBGC ( uhci,
"UHCI %s-%d deferring for companion " PCI_FMT "\n",
1240 port->speed = speed;
1262 DBGC ( uhci,
"UHCI %s-%d nonsensical CLEAR_TT for %s %s\n", uhci->
name,
1316 if ( ! uhci->
head ) {
1318 goto err_alloc_head;
1321 goto err_unreachable_head;
1328 sizeof ( *uhci->
frame ) );
1329 if ( ! uhci->
frame ) {
1331 goto err_alloc_frame;
1334 sizeof ( *uhci->
frame ) ) ) != 0 )
1335 goto err_unreachable_frame;
1345 err_unreachable_frame:
1348 err_unreachable_head:
1473 uhci =
zalloc (
sizeof ( *uhci ) );
1496 if ( ! uhci->
regs ) {
1508 if ( ! uhci->
bus ) {
1559 PCI_ROM ( 0xffff, 0xffff,
"uhci",
"UHCI", 0 ),
#define UHCI_USBCMD_HCRESET
Host controller reset.
#define iob_pull(iobuf, len)
unsigned int cons
Consumer counter.
#define UHCI_PORTSC_PED
Port enabled.
static int uhci_device_open(struct usb_device *usb)
Open device.
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
unsigned int prod
Producer counter.
#define PCI_CLASS_ID(base, sub, progif)
Construct PCI class ID.
struct arbelprm_rc_send_wqe rc
#define UHCI_FL_CERR_MAX
Error counter maximum value.
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
#define UHCI_FL_IOC
Interrupt on completion.
static void uhci_run(struct uhci_device *uhci)
Start UHCI device.
#define UHCI_CONTROL_ENDPOINT(address)
Endpoint address.
static void uhci_async_add(struct uhci_endpoint *endpoint)
Add endpoint to asynchronous schedule.
USB Universal Host Controller Interface (UHCI) driver.
struct uhci_frame_list * frame
Frame list.
static int uhci_endpoint_mtu(struct usb_endpoint *ep)
Update MTU.
static void uhci_periodic_del(struct uhci_endpoint *endpoint)
Remove endpoint from periodic schedule.
static void uhci_restart(struct uhci_ring *ring, uint32_t toggle)
Restart ring.
struct uhci_queue_head * head
Asynchronous queue head.
#define le32_to_cpu(value)
struct usb_bus * find_usb_bus_by_location(unsigned int bus_type, unsigned int location)
Find USB bus by device location.
#define outw(data, io_addr)
#define UHCI_STATUS_ACTIVE
Active.
unsigned long ioaddr
I/O address.
uint32_t first
First block in range.
struct usb_bus * alloc_usb_bus(struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
Allocate USB bus.
#define USB_RESET_RECOVER_DELAY_MS
Reset recovery time.
struct list_head async
Asynchronous schedule.
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
__weak unsigned int ehci_companion(struct pci_device *pci __unused)
Locate EHCI companion controller (when no EHCI support is present)
struct uhci_device * uhci
UHCI device.
struct pci_device_id * ids
PCI ID table.
uint64_t address
Base address.
static void uhci_root_close(struct usb_hub *hub __unused)
Close root hub.
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
uint8_t attr
Type and attributes.
#define UHCI_PORTSC(port)
Port status and control register.
uint64_t desc
Microcode descriptor list physical address.
#define UHCI_USBCMD_RUN
Run/stop.
#define USB_RESET_DELAY_MS
Minimum reset time.
#define UHCI_USBSTS
USB status register.
int32_t before
Initial microcode version.
static unsigned int uhci_ring_remaining(struct uhci_ring *ring)
Calculate space remaining in transfer ring.
static void uhci_async_del(struct uhci_endpoint *endpoint)
Remove endpoint from asynchronous schedule.
static int uhci_endpoint_message(struct usb_endpoint *ep, struct io_buffer *iobuf)
Enqueue message transfer.
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
#define UHCI_MTU
Maximum transfer size.
#define UHCI_PORTSC_CSC
Connect status change.
static int uhci_root_speed(struct usb_hub *hub, struct usb_port *port)
Update root hub port speed.
#define UHCI_CONTROL_DEVICE(address)
Device address.
uint32_t current
Current transfer descriptor.
unsigned int prod
Producer counter.
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
struct device dev
Generic device.
static int uhci_enqueue(struct uhci_ring *ring, struct io_buffer *iobuf, unsigned int count)
Enqueue new transfer.
unsigned int address
Device address, if assigned.
uint32_t link[UHCI_FRAMES]
Link pointer.
unsigned int speed
Device speed.
#define ECANCELED
Operation canceled.
#define ENOTSUP
Operation not supported.
void usb_port_changed(struct usb_port *port)
Report port status change.
Dynamic memory allocation.
static int uhci_endpoint_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
Enqueue stream transfer.
struct list_head periodic
Periodic schedule.
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
#define UHCI_PORTSC_CCS
Current connect status.
#define list_empty(list)
Test whether a list is empty.
static int usb_set_address(struct usb_device *usb, unsigned int address)
Set address.
struct io_buffer ** iobuf
I/O buffers.
static int uhci_endpoint_open(struct usb_endpoint *ep)
Open endpoint.
#define list_del(list)
Delete an entry from a list.
#define UHCI_PORTSC_PR
Port reset.
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
#define ENOMEM
Not enough space.
static int uhci_device_address(struct usb_device *usb)
Assign device address.
static void uhci_periodic_schedule(struct uhci_device *uhci)
(Re)build periodic schedule
#define UHCI_PORT_ENABLE_MAX_WAIT_MS
Maximum time to wait for a port to be enabled.
static signed char phys[4]
static void uhci_schedule_del(struct uhci_endpoint *endpoint)
Remove endpoint from appropriate schedule.
static struct usb_host_operations uhci_operations
USB host controller operations.
#define BUS_TYPE_PCI
PCI bus type.
static int uhci_hub_open(struct usb_hub *hub __unused)
Open hub.
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
struct usb_port * port
USB port.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void uhci_async_schedule(struct uhci_device *uhci)
(Re)build asynchronous schedule
struct uhci_queue_head * head
Queue head.
struct uhci_ring ring
Transfer ring.
#define UHCI_PORTSC_LS
Low-speed device attached.
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
#define __unused
Declare a variable or data structure as unused.
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
static struct io_buffer * uhci_dequeue(struct uhci_ring *ring)
Dequeue transfer.
static void uhci_endpoint_close(struct usb_endpoint *ep)
Close endpoint.
unsigned int companion
EHCI companion controller bus:dev.fn address (if any)
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
#define UHCI_USBSTS_HCHALTED
Host controller halted.
u32 link
Link to next descriptor.
uint16_t count
Number of entries.
unsigned long regs
Registers.
static struct pci_device_id uhci_ids[]
UHCI PCI device IDs.
#define USB_DIR_IN
Data transfer is from device to host.
#define UHCI_STATUS_STALLED
Stalled.
#define UHCI_USBCMD
USB command register.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define cpu_to_le32(value)
struct list_head endpoints
List of all endpoints.
#define UHCI_CONTROL_TOGGLE
Data toggle.
static struct usb_endpoint * usb_endpoint(struct usb_device *usb, unsigned int address)
Get USB endpoint.
static void uhci_hub_close(struct usb_hub *hub __unused)
Close hub.
USB Enhanced Host Controller Interface (EHCI) driver.
#define iob_unput(iobuf, len)
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
static int uhci_is_message(struct uhci_transfer *xfer)
Check if transfer is a message transfer.
#define UHCI_CONTROL_PID_MASK
Packet ID mask.
#define UHCI_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
char * strerror(int errno)
Retrieve string representation of error number.
static void(* free)(struct refcnt *refcnt))
#define UHCI_USBLEGSUP
USB legacy support register (in PCI configuration space)
static int uhci_root_open(struct usb_hub *hub __unused)
Open root hub.
void * zalloc(size_t size)
Allocate cleared memory.
#define PCI_CLASS_SERIAL_USB
#define PCI_FMT
PCI device debug message format.
#define outl(data, io_addr)
#define UHCI_FRAMES
Number of frames in frame list.
static int uhci_ring_alloc(struct uhci_ring *ring)
Allocate transfer ring.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
static void uhci_endpoint_poll(struct uhci_endpoint *endpoint)
Poll for completions.
struct io_buffer * iobuf
I/O buffer.
size_t len
Completed data length.
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
#define ENODEV
No such device.
static int uhci_root_clear_tt(struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
Clear transaction translator buffer.
#define UHCI_LINK_DEPTH_FIRST
Depth-first processing.
struct uhci_transfer * xfer[UHCI_RING_COUNT]
Transfers.
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
struct list_head schedule
Endpoint schedule.
#define UHCI_LINK_TERMINATE
List terminator.
static int uhci_root_enable(struct usb_hub *hub, struct usb_port *port)
Enable port.
A PCI device ID list entry.
#define le16_to_cpu(value)
#define ffs(x)
Find first (i.e.
void * malloc(size_t size)
Allocate memory.
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
static void uhci_periodic_add(struct uhci_endpoint *endpoint)
Add endpoint to periodic schedule.
#define UHCI_FL_LS
Low speed device.
size_t mtu
Maximum transfer size.
#define UHCI_PORTSC_CHANGE
Port status change mask.
struct usb_endpoint * ep
USB endpoint.
static int uhci_reset(struct uhci_device *uhci)
Reset UHCI device.
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
#define UHCI_DATA_PACKET(control)
Check for data packet.
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
#define INIT_LIST_HEAD(list)
Initialise a list head.
static void uhci_describe(struct uhci_ring *ring, void *data, size_t len, uint8_t pid)
Describe transfer.
uint32_t control
Base control word.
struct uhci_transfer * end
End of transfer ring (if non-empty)
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
#define UHCI_USBLEGSUP_DEFAULT
USB legacy support default value.
#define UHCI_STOP_MAX_WAIT_MS
Maximum time to wait for host controller to stop.
#define ENOBUFS
No buffer space available.
Universal Serial Bus (USB)
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
#define UHCI_SHORT_PACKET(control, actual)
Check for short packet.
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
static int uhci_bus_open(struct usb_bus *bus)
Open USB bus.
#define UHCI_LINK_TYPE_QH
Queue head type.
void * data
Start of data.
struct usb_hub * hub
USB hub.
#define EIO
Input/output error.
static void uhci_schedule_add(struct uhci_endpoint *endpoint)
Add endpoint to appropriate schedule.
#define UHCI_USBCMD_MAX64
Max packet is 64 bytes.
struct usb_endpoint * ep[32]
Endpoint list.
static void uhci_bus_close(struct usb_bus *bus)
Close USB bus.
#define PCI_ARGS(pci)
PCI device debug message arguments.
unsigned int interval
Interval (in microframes)
struct usb_endpoint_host_operations endpoint
Endpoint operations.
#define cpu_to_le16(value)
static void uhci_root_poll(struct usb_hub *hub, struct usb_port *port)
Poll for port status changes.
uint32_t end
Ending offset.
uint8_t data[48]
Additional event data.
#define PCI_CLASS_SERIAL_USB_UHCI
UHCI USB controller.
USB host controller operations.
uint32_t link
Horizontal link pointer.
#define __weak
Declare a function as weak (use before the definition)
static void uhci_remove(struct pci_device *pci)
Remove PCI device.
struct list_head list
List of all endpoints.
struct usb_hub * hub
Root hub.
struct pci_driver uhci_driver __pci_driver
UHCI PCI driver.
static int uhci_endpoint_reset(struct usb_endpoint *ep)
Reset endpoint.
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
struct usb_device * usb
USB device.
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
#define UHCI_CONTROL_PID(pid)
Packet ID.
static int uhci_reachable(void *addr, size_t len)
Check that address is reachable.
int(* open)(struct usb_endpoint *ep)
Open endpoint.
unsigned int cons
Consumer counter.
struct uhci_transfer_descriptor * desc
Transfer descriptors.
static int uhci_root_disable(struct usb_hub *hub, struct usb_port *port)
Disable port.
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
#define UHCI_ALIGN
Minimum alignment required for data structures.
struct usb_bus * bus
USB bus.
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
static void uhci_ring_free(struct uhci_ring *ring)
Free transfer ring.
#define USB_EP0_ADDRESS
Control endpoint address.
static uint32_t uhci_link_qh(struct uhci_queue_head *queue)
Get link value for a queue head.
#define NULL
NULL pointer (VOID *)
size_t mtu
Maximum packet length.
#define UHCI_CONTROL_LEN(len)
Data length.
#define ETIMEDOUT
Connection timed out.
int usb_alloc_address(struct usb_bus *bus)
Allocate device address.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
unsigned int attributes
Attributes.
#define UHCI_FL_SPD
Short packet detect.
static void uhci_device_close(struct usb_device *usb)
Close device.
unsigned int address
Endpoint address.
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
static void uhci_bus_poll(struct usb_bus *bus)
Poll USB bus.
#define UHCI_ACTUAL_LEN(actual)
Actual length.
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
static int uhci_probe(struct pci_device *pci)
Probe PCI device.
static int uhci_stop(struct uhci_device *uhci)
Stop UHCI device.
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
struct usb_bus * bus
USB bus.
#define UHCI_FLBASEADD
Frame list base address register.
void * memset(void *dest, int character, size_t len) __nonnull
#define UHCI_PORTS
Number of ports.