|
|
@@ -23,7 +23,7 @@
|
|
|
#define XHCI_DEBUG 0
|
|
|
|
|
|
/* ---- controller limits ------------------------------------------------- */
|
|
|
-#define XHCI_MAX_SLOTS 4
|
|
|
+#define XHCI_MAX_SLOTS 8
|
|
|
#define XHCI_MAX_PORTS 32
|
|
|
#define XHCI_EVT_TRBS 256
|
|
|
#define XHCI_CMD_TRBS 32
|
|
|
@@ -145,6 +145,9 @@ struct xhci_slot {
|
|
|
unsigned int addr; /* logical address used by usb.c */
|
|
|
unsigned int dev_addr; /* address assigned by the xHC */
|
|
|
unsigned int port;
|
|
|
+ unsigned int route; /* xHCI route string (0 for a root-port device) */
|
|
|
+ unsigned int tt_slot; /* parent high-speed hub slot (TT) */
|
|
|
+ unsigned int tt_port; /* downstream port on that hub */
|
|
|
unsigned int speed;
|
|
|
unsigned int dc; /* device context page */
|
|
|
unsigned int ep0; /* EP0 transfer ring page */
|
|
|
@@ -166,7 +169,7 @@ struct xhci_int {
|
|
|
unsigned int pending_len;
|
|
|
int pending;
|
|
|
int error;
|
|
|
- unsigned char buf[8] __attribute__((aligned(16)));
|
|
|
+ unsigned char buf[USB_INT_MAX] __attribute__((aligned(16)));
|
|
|
};
|
|
|
|
|
|
struct xhci_bulk {
|
|
|
@@ -187,64 +190,162 @@ struct xhci_bulk {
|
|
|
int error;
|
|
|
};
|
|
|
|
|
|
-static unsigned int mmio_base; /* kernel mapping of BAR0 */
|
|
|
-static unsigned int mmio_phys; /* BAR0 itself (logged, reported) */
|
|
|
-static unsigned int cap_len;
|
|
|
-static unsigned int rt_off;
|
|
|
-static unsigned int db_off;
|
|
|
-static unsigned int max_slots;
|
|
|
-static unsigned int max_ports;
|
|
|
-static unsigned int ctx_size;
|
|
|
-static unsigned int port_mask;
|
|
|
-static unsigned int hcc_params;
|
|
|
-static unsigned int pci_bus, pci_dev, pci_func;
|
|
|
-static unsigned int pci_id;
|
|
|
-static unsigned int hci_version;
|
|
|
-static int found;
|
|
|
-static int last_port = -1;
|
|
|
-
|
|
|
-static unsigned int dcbaa;
|
|
|
-static unsigned int input_ctx;
|
|
|
-static unsigned int cmd_ring;
|
|
|
-static unsigned int evt_ring;
|
|
|
-static unsigned int erst;
|
|
|
-static unsigned int cmd_enq;
|
|
|
-static unsigned int cmd_cycle;
|
|
|
-static unsigned int evt_idx;
|
|
|
-static unsigned int evt_cycle;
|
|
|
-
|
|
|
-static unsigned int cmd_busy;
|
|
|
-static unsigned int cmd_done;
|
|
|
-static unsigned int cmd_status;
|
|
|
-static unsigned int cmd_slot;
|
|
|
-static unsigned int cmd_trb_addr;
|
|
|
-
|
|
|
-static unsigned int ctl_busy;
|
|
|
-static unsigned int ctl_done;
|
|
|
-static unsigned int ctl_slot;
|
|
|
-static unsigned int ctl_status;
|
|
|
-static unsigned int ctl_req_len;
|
|
|
-static unsigned int ctl_actual;
|
|
|
-static unsigned int ctl_data_seen;
|
|
|
-static unsigned int ctl_setup_trb;
|
|
|
-static unsigned int ctl_data_trb;
|
|
|
-static unsigned int ctl_status_trb;
|
|
|
-
|
|
|
-static struct xhci_bulk bulk_in;
|
|
|
-static struct xhci_bulk bulk_out;
|
|
|
-static unsigned int out_busy;
|
|
|
-static unsigned int out_done;
|
|
|
-static unsigned int out_status;
|
|
|
-static unsigned int out_slot;
|
|
|
-static unsigned int out_trb;
|
|
|
-
|
|
|
-static struct xhci_slot slots[XHCI_MAX_SLOTS + 1];
|
|
|
-static unsigned int addr_slot[128];
|
|
|
-static unsigned int port_slot[XHCI_MAX_PORTS];
|
|
|
-static struct xhci_int ints[USB_HCD_INT_SLOTS];
|
|
|
+#define XHCI_MAX_HCD 2
|
|
|
+
|
|
|
+/* One xHCI instance. The Yoga 720 has two: the Sunrise Point-LP PCH
|
|
|
+ * controller (camera, Bluetooth, card reader) and the Alpine Ridge
|
|
|
+ * USB-C/Thunderbolt controller that carries the Lenovo hub and the
|
|
|
+ * Logitech receiver. The driver used to stop at the first one. */
|
|
|
+struct xhci_hcd {
|
|
|
+ unsigned int mmio_base; /* kernel mapping of BAR0 */
|
|
|
+ unsigned int mmio_phys; /* BAR0 itself (logged, reported) */
|
|
|
+ unsigned int cap_len;
|
|
|
+ unsigned int rt_off;
|
|
|
+ unsigned int db_off;
|
|
|
+ unsigned int max_slots;
|
|
|
+ unsigned int max_ports;
|
|
|
+ unsigned int ctx_size;
|
|
|
+ unsigned int port_mask;
|
|
|
+ unsigned int hcc_params;
|
|
|
+ unsigned int bus_no, dev_no, func_no;
|
|
|
+ unsigned int pci_id;
|
|
|
+ unsigned int hci_version;
|
|
|
+ int present;
|
|
|
+ int last_port_num;
|
|
|
+
|
|
|
+ unsigned int dcbaa;
|
|
|
+ unsigned int input_ctx;
|
|
|
+ unsigned int cmd_ring;
|
|
|
+ unsigned int evt_ring;
|
|
|
+ unsigned int erst;
|
|
|
+ unsigned int cmd_enq;
|
|
|
+ unsigned int cmd_cycle;
|
|
|
+ unsigned int evt_idx;
|
|
|
+ unsigned int evt_cycle;
|
|
|
+
|
|
|
+ unsigned int cmd_busy;
|
|
|
+ unsigned int cmd_done;
|
|
|
+ unsigned int cmd_status;
|
|
|
+ unsigned int cmd_slot;
|
|
|
+ unsigned int cmd_trb_addr;
|
|
|
+
|
|
|
+ unsigned int ctl_busy;
|
|
|
+ unsigned int ctl_done;
|
|
|
+ unsigned int ctl_slot;
|
|
|
+ unsigned int ctl_status;
|
|
|
+ unsigned int ctl_req_len;
|
|
|
+ unsigned int ctl_actual;
|
|
|
+ unsigned int ctl_data_seen;
|
|
|
+ unsigned int ctl_setup_trb;
|
|
|
+ unsigned int ctl_data_trb;
|
|
|
+ unsigned int ctl_status_trb;
|
|
|
+
|
|
|
+ struct xhci_bulk bulk_in;
|
|
|
+ struct xhci_bulk bulk_out;
|
|
|
+ unsigned int out_busy;
|
|
|
+ unsigned int out_done;
|
|
|
+ unsigned int out_status;
|
|
|
+ unsigned int out_slot;
|
|
|
+ unsigned int out_trb;
|
|
|
+
|
|
|
+ struct xhci_slot slots[XHCI_MAX_SLOTS + 1];
|
|
|
+ unsigned int addr_slot[128];
|
|
|
+ unsigned int port_slot[XHCI_MAX_PORTS];
|
|
|
+ struct xhci_int ints[USB_HCD_INT_SLOTS];
|
|
|
+
|
|
|
+ unsigned int enum_port;
|
|
|
+ unsigned int enum_route;
|
|
|
+ unsigned int enum_parent_addr;
|
|
|
+ unsigned int enum_tt_slot;
|
|
|
+ unsigned int enum_speed_hint;
|
|
|
+};
|
|
|
+
|
|
|
+/* Page-allocated: two full instances would otherwise add ~2 KB to the
|
|
|
+ * kernel BSS, which is already close to the 0x90000 wall. */
|
|
|
+static struct xhci_hcd *xhci_hcds;
|
|
|
+static struct xhci_hcd *xh; /* instance of the current call */
|
|
|
+static unsigned int xhci_nctrl;
|
|
|
+/* int_in_poll()/stop() get only the slot, not the controller index. */
|
|
|
+static unsigned int int_ctrl[USB_HCD_INT_SLOTS];
|
|
|
+
|
|
|
+#define mmio_base (xh->mmio_base)
|
|
|
+#define mmio_phys (xh->mmio_phys)
|
|
|
+#define cap_len (xh->cap_len)
|
|
|
+#define rt_off (xh->rt_off)
|
|
|
+#define db_off (xh->db_off)
|
|
|
+#define max_slots (xh->max_slots)
|
|
|
+#define max_ports (xh->max_ports)
|
|
|
+#define ctx_size (xh->ctx_size)
|
|
|
+#define port_mask (xh->port_mask)
|
|
|
+#define hcc_params (xh->hcc_params)
|
|
|
+#define pci_bus (xh->bus_no)
|
|
|
+#define pci_dev (xh->dev_no)
|
|
|
+#define pci_func (xh->func_no)
|
|
|
+#define pci_id (xh->pci_id)
|
|
|
+#define hci_version (xh->hci_version)
|
|
|
+#define found (xh->present)
|
|
|
+#define last_port (xh->last_port_num)
|
|
|
+#define dcbaa (xh->dcbaa)
|
|
|
+#define input_ctx (xh->input_ctx)
|
|
|
+#define cmd_ring (xh->cmd_ring)
|
|
|
+#define evt_ring (xh->evt_ring)
|
|
|
+#define erst (xh->erst)
|
|
|
+#define cmd_enq (xh->cmd_enq)
|
|
|
+#define cmd_cycle (xh->cmd_cycle)
|
|
|
+#define evt_idx (xh->evt_idx)
|
|
|
+#define evt_cycle (xh->evt_cycle)
|
|
|
+#define cmd_busy (xh->cmd_busy)
|
|
|
+#define cmd_done (xh->cmd_done)
|
|
|
+#define cmd_status (xh->cmd_status)
|
|
|
+#define cmd_slot (xh->cmd_slot)
|
|
|
+#define cmd_trb_addr (xh->cmd_trb_addr)
|
|
|
+#define ctl_busy (xh->ctl_busy)
|
|
|
+#define ctl_done (xh->ctl_done)
|
|
|
+#define ctl_slot (xh->ctl_slot)
|
|
|
+#define ctl_status (xh->ctl_status)
|
|
|
+#define ctl_req_len (xh->ctl_req_len)
|
|
|
+#define ctl_actual (xh->ctl_actual)
|
|
|
+#define ctl_data_seen (xh->ctl_data_seen)
|
|
|
+#define ctl_setup_trb (xh->ctl_setup_trb)
|
|
|
+#define ctl_data_trb (xh->ctl_data_trb)
|
|
|
+#define ctl_status_trb (xh->ctl_status_trb)
|
|
|
+#define bulk_in (xh->bulk_in)
|
|
|
+#define bulk_out (xh->bulk_out)
|
|
|
+#define out_busy (xh->out_busy)
|
|
|
+#define out_done (xh->out_done)
|
|
|
+#define out_status (xh->out_status)
|
|
|
+#define out_slot (xh->out_slot)
|
|
|
+#define out_trb (xh->out_trb)
|
|
|
+#define slots (xh->slots)
|
|
|
+#define addr_slot (xh->addr_slot)
|
|
|
+#define port_slot (xh->port_slot)
|
|
|
+#define ints (xh->ints)
|
|
|
+#define enum_port (xh->enum_port)
|
|
|
+#define enum_route (xh->enum_route)
|
|
|
+#define enum_parent_addr (xh->enum_parent_addr)
|
|
|
+#define enum_tt_slot (xh->enum_tt_slot)
|
|
|
+#define enum_speed_hint (xh->enum_speed_hint)
|
|
|
|
|
|
static spinlock_t xhci_lock;
|
|
|
|
|
|
+/* Select the instance for a vtable call (ctrl is the local index that
|
|
|
+ * usb.c registered). */
|
|
|
+static int xhci_use(unsigned int ctrl)
|
|
|
+{
|
|
|
+ if (!xhci_hcds || ctrl >= XHCI_MAX_HCD ||
|
|
|
+ !xhci_hcds[ctrl].present)
|
|
|
+ return 0;
|
|
|
+ xh = &xhci_hcds[ctrl];
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+static int xhci_use_slot(unsigned int slot)
|
|
|
+{
|
|
|
+ if (slot >= USB_HCD_INT_SLOTS || int_ctrl[slot] >= XHCI_MAX_HCD)
|
|
|
+ return 0;
|
|
|
+ return xhci_use(int_ctrl[slot]);
|
|
|
+}
|
|
|
+
|
|
|
/* ---- debug ------------------------------------------------------------- */
|
|
|
#if XHCI_DEBUG
|
|
|
static void dbg(const char *s)
|
|
|
@@ -491,7 +592,7 @@ static void xhci_poll_locked(void)
|
|
|
|
|
|
/* ---- commands ---------------------------------------------------------- */
|
|
|
static int xhci_cmd(unsigned int p0, unsigned int p1, unsigned int control,
|
|
|
- unsigned int *out_slot)
|
|
|
+ unsigned int *slot_out)
|
|
|
{
|
|
|
unsigned int flags, t0, rc;
|
|
|
|
|
|
@@ -533,8 +634,8 @@ static int xhci_cmd(unsigned int p0, unsigned int p1, unsigned int control,
|
|
|
dbg("xhci: command timeout\n");
|
|
|
return -1;
|
|
|
}
|
|
|
- if (out_slot)
|
|
|
- *out_slot = cmd_slot;
|
|
|
+ if (slot_out)
|
|
|
+ *slot_out = cmd_slot;
|
|
|
rc = cmd_status;
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
if (rc != CC_SUCCESS) {
|
|
|
@@ -546,13 +647,15 @@ static int xhci_cmd(unsigned int p0, unsigned int p1, unsigned int control,
|
|
|
|
|
|
/* ---- contexts ---------------------------------------------------------- */
|
|
|
static void fill_slot_ctx(unsigned int addr, unsigned int port,
|
|
|
- unsigned int speed, unsigned int last_ctx)
|
|
|
+ unsigned int route, unsigned int tt_slot,
|
|
|
+ unsigned int tt_port, unsigned int speed,
|
|
|
+ unsigned int last_ctx)
|
|
|
{
|
|
|
unsigned int *p = (unsigned int *)(input_ctx + ctx_size);
|
|
|
|
|
|
- p[0] = (speed << 20) | (last_ctx << 27);
|
|
|
- p[1] = (port + 1) << 16;
|
|
|
- p[2] = 0;
|
|
|
+ p[0] = (route & 0xFFFFFu) | (speed << 20) | (last_ctx << 27);
|
|
|
+ p[1] = (port + 1) << 16; /* root hub port, max exit latency 0 */
|
|
|
+ p[2] = (tt_slot & 0xFFu) | ((tt_port & 0xFFu) << 8); /* tt_info */
|
|
|
p[3] = addr;
|
|
|
}
|
|
|
|
|
|
@@ -665,26 +768,93 @@ static int xhci_config_ep(struct xhci_slot *s, unsigned int ep_index,
|
|
|
unsigned int i, flags;
|
|
|
int rc;
|
|
|
|
|
|
+ /* Last Valid Endpoint is the highest DCI in the slot, including the
|
|
|
+ * one being added now. Scanning only the existing mask and assigning
|
|
|
+ * it unconditionally used to lower it again (EP1 IN = DCI 3 already
|
|
|
+ * configured, then adding EP2 IN = DCI 5 sent LVE 3 and the xHC
|
|
|
+ * rejected the command with Parameter Error). */
|
|
|
for (i = 1; i < 32; i++)
|
|
|
- if (s->ep_mask & (1u << i))
|
|
|
+ if ((s->ep_mask & (1u << i)) && i > last)
|
|
|
last = i;
|
|
|
|
|
|
spin_lock_irqsave(&xhci_lock, &flags);
|
|
|
zero_page(input_ctx, 4096);
|
|
|
*(unsigned int *)input_ctx = 0;
|
|
|
*(unsigned int *)(input_ctx + 4) = SLOT_FLAG | ep_flag;
|
|
|
- fill_slot_ctx(s->dev_addr, s->port, s->speed, last);
|
|
|
+ fill_slot_ctx(s->dev_addr, s->port, s->route, s->tt_slot,
|
|
|
+ s->tt_port, s->speed, last);
|
|
|
fill_ep_ctx(ep_index, type, mps, interval, ring);
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
|
|
|
rc = xhci_cmd(input_ctx, 0,
|
|
|
TRB_TYPE(TRB_CONFIG_EP) | (s->slot_id << 24), 0);
|
|
|
- if (rc == 0)
|
|
|
+ if (rc == 0) {
|
|
|
s->ep_mask |= ep_flag;
|
|
|
+ } else {
|
|
|
+ xlog_hex("xhci: configure ep failed ep ", ep_index);
|
|
|
+ xlog_hex(" cc ", cmd_status);
|
|
|
+ xlog_hex(" slot ", s->slot_id);
|
|
|
+ xlog_hex(" spd ", s->speed);
|
|
|
+ xlog_hex(" route ", s->route);
|
|
|
+ xlog_hex(" tt ", s->tt_slot);
|
|
|
+ xlog_hex(" ttp ", s->tt_port);
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
+ }
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
/* ---- slots ------------------------------------------------------------- */
|
|
|
+static void set_route(unsigned int ctrl, unsigned int port,
|
|
|
+ unsigned int route, unsigned int parent_addr,
|
|
|
+ unsigned int speed_hint)
|
|
|
+{
|
|
|
+ struct xhci_slot *hs;
|
|
|
+
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return;
|
|
|
+ enum_port = port;
|
|
|
+ enum_route = route & 0xFFFFFu;
|
|
|
+ enum_parent_addr = parent_addr;
|
|
|
+ enum_speed_hint = speed_hint;
|
|
|
+ enum_tt_slot = 0;
|
|
|
+ if (parent_addr) {
|
|
|
+ hs = slot_by_addr(parent_addr);
|
|
|
+ if (hs && hs->speed == 3)
|
|
|
+ enum_tt_slot = hs->slot_id;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* Move an Addressed slot to Configured. The xHC does not do this from the
|
|
|
+ * USB SET_CONFIGURATION request; a Configure Endpoint command is required.
|
|
|
+ * A high-speed hub used as a TT must be Configured before a downstream
|
|
|
+ * Address Device, otherwise the xHC rejects the child with Parameter Error
|
|
|
+ * (cc 0x11). Only the slot context is added; EP0 is already in the device
|
|
|
+ * context. */
|
|
|
+static int xhci_configure_slot(struct xhci_slot *s)
|
|
|
+{
|
|
|
+ unsigned int flags;
|
|
|
+ int rc;
|
|
|
+
|
|
|
+ spin_lock_irqsave(&xhci_lock, &flags);
|
|
|
+ zero_page(input_ctx, 4096);
|
|
|
+ *(unsigned int *)input_ctx = 0;
|
|
|
+ *(unsigned int *)(input_ctx + 4) = SLOT_FLAG;
|
|
|
+ fill_slot_ctx(s->dev_addr, s->port, s->route, s->tt_slot,
|
|
|
+ s->tt_port, s->speed, 1);
|
|
|
+ spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
+
|
|
|
+ rc = xhci_cmd(input_ctx, 0,
|
|
|
+ TRB_TYPE(TRB_CONFIG_EP) | (s->slot_id << 24), 0);
|
|
|
+ if (rc != 0) {
|
|
|
+ xlog_hex("xhci: configure slot failed cc ", cmd_status);
|
|
|
+ xlog_hex(" slot ", s->slot_id);
|
|
|
+ xlog_hex(" spd ", s->speed);
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
/* Create a slot. bsr=1: Address Device with Block Set Address Request,
|
|
|
* leaving the slot in the Default state at device address 0 (new
|
|
|
* enumeration scheme). bsr=0: the command carries target_addr and moves
|
|
|
@@ -698,15 +868,18 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
|
|
|
unsigned int slot_id, dc, ep0, flags;
|
|
|
int rc;
|
|
|
|
|
|
- if (last_port < 0 || last_port >= (int)max_ports)
|
|
|
+ if (enum_port >= max_ports)
|
|
|
return 0;
|
|
|
- if (port_slot[last_port])
|
|
|
+ if (enum_route == 0 && port_slot[enum_port])
|
|
|
return 0;
|
|
|
|
|
|
slot_id = 0;
|
|
|
rc = xhci_cmd(0, 0, TRB_TYPE(TRB_ENABLE_SLOT), &slot_id);
|
|
|
if (rc != 0 || slot_id == 0 || slot_id > max_slots) {
|
|
|
- dbg("xhci: enable slot failed\n");
|
|
|
+ xlog_hex("xhci: enable slot failed rc ", rc);
|
|
|
+ xlog_hex(" cc ", cmd_status);
|
|
|
+ xlog_hex(" slot ", slot_id);
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -726,8 +899,18 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
|
|
|
s->used = 1;
|
|
|
s->slot_id = slot_id;
|
|
|
s->addr = 0;
|
|
|
- s->port = (unsigned int)last_port;
|
|
|
- s->speed = port_speed((unsigned int)last_port);
|
|
|
+ s->port = enum_port;
|
|
|
+ s->route = enum_route;
|
|
|
+ s->speed = enum_speed_hint ? enum_speed_hint :
|
|
|
+ port_speed(enum_port);
|
|
|
+ if (enum_route && (s->speed == 1 || s->speed == 2)) {
|
|
|
+ s->tt_slot = enum_tt_slot;
|
|
|
+ s->tt_port = enum_route & 0xFu;
|
|
|
+ } else {
|
|
|
+ /* High/SuperSpeed devices do not go through a TT. */
|
|
|
+ s->tt_slot = 0;
|
|
|
+ s->tt_port = 0;
|
|
|
+ }
|
|
|
s->dc = dc;
|
|
|
s->ep0 = ep0;
|
|
|
s->ep0_enq = 0;
|
|
|
@@ -744,7 +927,8 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
|
|
|
zero_page(input_ctx, 4096);
|
|
|
*(unsigned int *)input_ctx = 0;
|
|
|
*(unsigned int *)(input_ctx + 4) = SLOT_FLAG | EP0_FLAG;
|
|
|
- fill_slot_ctx(0, s->port, s->speed, 1);
|
|
|
+ fill_slot_ctx(0, s->port, s->route, s->tt_slot, s->tt_port,
|
|
|
+ s->speed, 1);
|
|
|
fill_ep0_ctx(mps, ep0, s->ep0_enq, s->ep0_cycle);
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
|
|
|
@@ -755,6 +939,9 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
|
|
|
xlog_hex(bsr ? "xhci: address default failed port " :
|
|
|
"xhci: address device failed port ", s->port);
|
|
|
xlog_hex(" spd ", s->speed);
|
|
|
+ xlog_hex(" route ", s->route);
|
|
|
+ xlog_hex(" tt ", s->tt_slot);
|
|
|
+ xlog_hex(" ttp ", s->tt_port);
|
|
|
xlog_hex(" cc ", cmd_status);
|
|
|
xlog_hex(" portsc ",
|
|
|
mmio_rd(op(XHCI_OP_PORTSC) + s->port * 0x10));
|
|
|
@@ -773,7 +960,10 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
|
|
|
s->dev_addr = ((unsigned int *)s->dc)[3] & 0xFF;
|
|
|
s->addr = bsr ? 0 : target_addr;
|
|
|
addr_slot[s->addr] = slot_id;
|
|
|
- port_slot[s->port] = slot_id;
|
|
|
+ if (s->route == 0)
|
|
|
+ port_slot[s->port] = slot_id;
|
|
|
+ if (!bsr)
|
|
|
+ (void)xhci_configure_slot(s);
|
|
|
return s;
|
|
|
}
|
|
|
|
|
|
@@ -820,7 +1010,7 @@ static void free_slot(struct xhci_slot *s)
|
|
|
bulk_reset(&bulk_in);
|
|
|
if (bulk_out.active && bulk_out.slot == s->slot_id)
|
|
|
bulk_reset(&bulk_out);
|
|
|
- if (s->port < XHCI_MAX_PORTS)
|
|
|
+ if (s->route == 0 && s->port < XHCI_MAX_PORTS)
|
|
|
port_slot[s->port] = 0;
|
|
|
s->used = 0;
|
|
|
s->addr = 0;
|
|
|
@@ -843,7 +1033,8 @@ static int set_address(unsigned int new_addr, unsigned int mps)
|
|
|
zero_page(input_ctx, 4096);
|
|
|
*(unsigned int *)input_ctx = 0;
|
|
|
*(unsigned int *)(input_ctx + 4) = SLOT_FLAG | EP0_FLAG;
|
|
|
- fill_slot_ctx(0, s->port, s->speed, 1);
|
|
|
+ fill_slot_ctx(0, s->port, s->route, s->tt_slot, s->tt_port,
|
|
|
+ s->speed, 1);
|
|
|
fill_ep0_ctx(mps, s->ep0, s->ep0_enq, s->ep0_cycle);
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
|
|
|
@@ -861,6 +1052,7 @@ static int set_address(unsigned int new_addr, unsigned int mps)
|
|
|
s->addr = new_addr;
|
|
|
addr_slot[new_addr] = s->slot_id;
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
+ (void)xhci_configure_slot(s);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -901,10 +1093,9 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
|
|
|
unsigned int setup_c, data_c, status_c;
|
|
|
unsigned int last_bell;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
(void)low_speed;
|
|
|
|
|
|
- if (!found)
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
return -1;
|
|
|
|
|
|
/* xHCI owns SET_ADDRESS: it is an Address Device command, not a
|
|
|
@@ -1044,22 +1235,29 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
|
|
|
/* ---- HID interrupt endpoint -------------------------------------------- */
|
|
|
static int int_in_start(unsigned int ctrl, unsigned int slot,
|
|
|
unsigned int addr, unsigned int ep,
|
|
|
- unsigned int mps, int low_speed)
|
|
|
+ unsigned int mps, unsigned int len, int low_speed)
|
|
|
{
|
|
|
- struct xhci_slot *s = slot_by_addr(addr);
|
|
|
+ struct xhci_slot *s;
|
|
|
struct xhci_int *in;
|
|
|
unsigned int ep_index, ep_id, ring, flags;
|
|
|
int rc;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
(void)low_speed;
|
|
|
|
|
|
- if (!found || !s || slot >= USB_HCD_INT_SLOTS || ep < 1 || ep > 15)
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return -1;
|
|
|
+ s = slot_by_addr(addr);
|
|
|
+ if (!s || slot >= USB_HCD_INT_SLOTS || ep < 1 || ep > 15)
|
|
|
return -1;
|
|
|
+ int_ctrl[slot] = ctrl;
|
|
|
if (mps < 1)
|
|
|
mps = 8;
|
|
|
- if (mps > 8)
|
|
|
- mps = 8;
|
|
|
+ if (mps > 64)
|
|
|
+ mps = 64;
|
|
|
+ if (len < 1)
|
|
|
+ len = mps;
|
|
|
+ if (len > USB_INT_MAX)
|
|
|
+ len = USB_INT_MAX;
|
|
|
|
|
|
if (ints[slot].active)
|
|
|
stop_int(slot);
|
|
|
@@ -1078,7 +1276,7 @@ static int int_in_start(unsigned int ctrl, unsigned int slot,
|
|
|
in->ring = ring;
|
|
|
in->enq = 0;
|
|
|
in->cycle = 1;
|
|
|
- in->trb_len = mps;
|
|
|
+ in->trb_len = len;
|
|
|
in->pending = 0;
|
|
|
in->error = 0;
|
|
|
in->active = 0;
|
|
|
@@ -1109,7 +1307,7 @@ static int int_in_poll(unsigned int slot, unsigned char *buf, unsigned int len)
|
|
|
struct xhci_int *in;
|
|
|
unsigned int flags, n, i;
|
|
|
|
|
|
- if (!found || slot >= USB_HCD_INT_SLOTS)
|
|
|
+ if (!xhci_use_slot(slot))
|
|
|
return 0;
|
|
|
|
|
|
in = &ints[slot];
|
|
|
@@ -1163,6 +1361,13 @@ static void stop_int(unsigned int slot)
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
}
|
|
|
|
|
|
+static void int_in_stop(unsigned int slot)
|
|
|
+{
|
|
|
+ if (!xhci_use_slot(slot))
|
|
|
+ return;
|
|
|
+ stop_int(slot);
|
|
|
+}
|
|
|
+
|
|
|
/* ---- bulk transfers ---------------------------------------------------- */
|
|
|
static void bulk_reset(struct xhci_bulk *b)
|
|
|
{
|
|
|
@@ -1181,13 +1386,16 @@ static void bulk_reset(struct xhci_bulk *b)
|
|
|
static int xhci_bulk_in(unsigned int ctrl, unsigned int addr, unsigned int ep,
|
|
|
unsigned int mps, unsigned char *buf, unsigned int len)
|
|
|
{
|
|
|
- struct xhci_slot *s = slot_by_addr(addr);
|
|
|
- struct xhci_bulk *b = &bulk_in;
|
|
|
+ struct xhci_slot *s;
|
|
|
+ struct xhci_bulk *b;
|
|
|
unsigned int ep_index, ep_id, ring, flags, n, err;
|
|
|
int rc;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
- if (!found || !s || ep < 1 || ep > 15 || !buf || !len)
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return -1;
|
|
|
+ b = &bulk_in;
|
|
|
+ s = slot_by_addr(addr);
|
|
|
+ if (!s || ep < 1 || ep > 15 || !buf || !len)
|
|
|
return -1;
|
|
|
if (mps < 1)
|
|
|
mps = 512;
|
|
|
@@ -1254,12 +1462,15 @@ static int xhci_bulk_in(unsigned int ctrl, unsigned int addr, unsigned int ep,
|
|
|
static void xhci_bulk_reset(unsigned int ctrl, unsigned int addr,
|
|
|
unsigned int ep, int dir_in)
|
|
|
{
|
|
|
- struct xhci_slot *s = slot_by_addr(addr);
|
|
|
- struct xhci_bulk *b = dir_in ? &bulk_in : &bulk_out;
|
|
|
+ struct xhci_slot *s;
|
|
|
+ struct xhci_bulk *b;
|
|
|
unsigned int flags, slot, ep_id;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
- if (!found || !s)
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return;
|
|
|
+ s = slot_by_addr(addr);
|
|
|
+ b = dir_in ? &bulk_in : &bulk_out;
|
|
|
+ if (!s)
|
|
|
return;
|
|
|
|
|
|
spin_lock_irqsave(&xhci_lock, &flags);
|
|
|
@@ -1284,13 +1495,16 @@ static int xhci_bulk_out(unsigned int ctrl, unsigned int addr, unsigned int ep,
|
|
|
unsigned int mps, const unsigned char *buf,
|
|
|
unsigned int len)
|
|
|
{
|
|
|
- struct xhci_slot *s = slot_by_addr(addr);
|
|
|
- struct xhci_bulk *b = &bulk_out;
|
|
|
+ struct xhci_slot *s;
|
|
|
+ struct xhci_bulk *b;
|
|
|
unsigned int ep_index, ep_id, ring, flags, t0, done, status;
|
|
|
int rc;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
- if (!found || !s || ep < 1 || ep > 15 || !buf || !len)
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return -1;
|
|
|
+ b = &bulk_out;
|
|
|
+ s = slot_by_addr(addr);
|
|
|
+ if (!s || ep < 1 || ep > 15 || !buf || !len)
|
|
|
return -1;
|
|
|
if (mps < 1)
|
|
|
mps = 512;
|
|
|
@@ -1371,13 +1585,21 @@ static int port_reset(unsigned int ctrl, unsigned int port)
|
|
|
{
|
|
|
unsigned int ps, t0;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
- if (!found || port >= max_ports ||
|
|
|
- !(port_mask & (1u << port)))
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return -1;
|
|
|
+ if (port >= max_ports || !(port_mask & (1u << port)))
|
|
|
return -1;
|
|
|
|
|
|
if (port_slot[port])
|
|
|
free_slot(&slots[port_slot[port]]);
|
|
|
+ {
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+ for (i = 1; i <= max_slots && i <= XHCI_MAX_SLOTS; i++)
|
|
|
+ if (slots[i].used && slots[i].route == 0 &&
|
|
|
+ slots[i].port == port)
|
|
|
+ free_slot(&slots[i]);
|
|
|
+ }
|
|
|
|
|
|
ps = mmio_rd(op(XHCI_OP_PORTSC) + port * 0x10);
|
|
|
if (!(ps & PORTSC_CCS))
|
|
|
@@ -1455,9 +1677,9 @@ static int port_connected(unsigned int ctrl, unsigned int port)
|
|
|
{
|
|
|
unsigned int ps;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
- if (!found || port >= max_ports ||
|
|
|
- !(port_mask & (1u << port)))
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return 0;
|
|
|
+ if (port >= max_ports || !(port_mask & (1u << port)))
|
|
|
return 0;
|
|
|
ps = mmio_rd(op(XHCI_OP_PORTSC) + port * 0x10);
|
|
|
return (ps & PORTSC_CCS) ? 1 : 0;
|
|
|
@@ -1467,8 +1689,9 @@ static int port_low_speed(unsigned int ctrl, unsigned int port)
|
|
|
{
|
|
|
unsigned int ps;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
- if (!found || port >= max_ports)
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return 0;
|
|
|
+ if (port >= max_ports)
|
|
|
return 0;
|
|
|
ps = mmio_rd(op(XHCI_OP_PORTSC) + port * 0x10);
|
|
|
return ((ps >> PORTSC_SPEED_SHIFT) & PORTSC_SPEED_MASK) == 2;
|
|
|
@@ -1478,8 +1701,9 @@ static int port_take_change(unsigned int ctrl, unsigned int port)
|
|
|
{
|
|
|
unsigned int ps;
|
|
|
|
|
|
- (void)ctrl;
|
|
|
- if (!found || port >= max_ports)
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return 0;
|
|
|
+ if (port >= max_ports)
|
|
|
return 0;
|
|
|
ps = mmio_rd(op(XHCI_OP_PORTSC) + port * 0x10);
|
|
|
if (!(ps & PORTSC_CSC))
|
|
|
@@ -1575,52 +1799,23 @@ static void scan_protocols(void)
|
|
|
((1u << max_ports) - 1);
|
|
|
}
|
|
|
|
|
|
-static int xhci_init(void)
|
|
|
+static int xhci_init_one(unsigned int bus, unsigned int dev,
|
|
|
+ unsigned int func, unsigned int bar)
|
|
|
{
|
|
|
- unsigned int bus, dev, func, id, class_rev, bar, bar_hi, cmd;
|
|
|
+ unsigned int cmd;
|
|
|
unsigned int hcs1, hcs2, t0, i, n, scratch;
|
|
|
|
|
|
- if (found)
|
|
|
- return 1;
|
|
|
-
|
|
|
- for (bus = 0; bus < 256; bus++) {
|
|
|
- for (dev = 0; dev < 32; dev++) {
|
|
|
- for (func = 0; func < 8; func++) {
|
|
|
- id = pci_cfg_read32(bus, dev, func, 0x00);
|
|
|
- if (id == 0xFFFFFFFFu || id == 0)
|
|
|
- continue;
|
|
|
- class_rev = pci_cfg_read32(bus, dev, func, 0x08);
|
|
|
- if ((class_rev >> 16) != 0x0C03)
|
|
|
- continue;
|
|
|
- if (((class_rev >> 8) & 0xFF) != 0x30)
|
|
|
- continue;
|
|
|
- bar = pci_cfg_read32(bus, dev, func, 0x10);
|
|
|
- if (bar & 1)
|
|
|
- continue;
|
|
|
- bar_hi = 0;
|
|
|
- if ((bar & 0x6) == 0x4)
|
|
|
- bar_hi = pci_cfg_read32(bus, dev,
|
|
|
- func, 0x14);
|
|
|
- bar &= 0xFFFFFFF0u;
|
|
|
- if (!bar || bar_hi)
|
|
|
- continue;
|
|
|
- pci_bus = bus;
|
|
|
- pci_dev = dev;
|
|
|
- pci_func = func;
|
|
|
- goto found_xhci;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return 0;
|
|
|
-
|
|
|
-found_xhci:
|
|
|
+ pci_bus = bus;
|
|
|
+ pci_dev = dev;
|
|
|
+ pci_func = func;
|
|
|
+ last_port = -1;
|
|
|
cmd = pci_cfg_read32(pci_bus, pci_dev, pci_func, 0x04);
|
|
|
pci_cfg_write32(pci_bus, pci_dev, pci_func, 0x04, cmd | 0x0006);
|
|
|
|
|
|
mmio_phys = bar;
|
|
|
mmio_base = (unsigned int)ioremap(bar, 0x10000, IOREMAP_MMIO);
|
|
|
if (!mmio_base)
|
|
|
- return -1;
|
|
|
+ return 0;
|
|
|
|
|
|
pci_id = pci_cfg_read32(pci_bus, pci_dev, pci_func, 0x00);
|
|
|
cap_len = mmio_rd(0) & 0xFF;
|
|
|
@@ -1820,16 +2015,93 @@ found_xhci:
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+static int xhci_seen(unsigned int bus, unsigned int dev, unsigned int func)
|
|
|
+{
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+ for (i = 0; i < xhci_nctrl; i++)
|
|
|
+ if (xhci_hcds[i].bus_no == bus &&
|
|
|
+ xhci_hcds[i].dev_no == dev &&
|
|
|
+ xhci_hcds[i].func_no == func)
|
|
|
+ return 1;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static int xhci_init(void)
|
|
|
+{
|
|
|
+ unsigned int bus, dev, func, id, class_rev, bar, bar_hi;
|
|
|
+
|
|
|
+ if (xhci_nctrl)
|
|
|
+ return (int)xhci_nctrl;
|
|
|
+
|
|
|
+ if (!xhci_hcds) {
|
|
|
+ unsigned int pages = (XHCI_MAX_HCD * sizeof(*xhci_hcds) +
|
|
|
+ 4095u) / 4096u;
|
|
|
+
|
|
|
+ xhci_hcds = (struct xhci_hcd *)mm_alloc_pages(pages);
|
|
|
+ if (!xhci_hcds)
|
|
|
+ return 0;
|
|
|
+ zero_page((unsigned int)xhci_hcds, pages * 4096);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (bus = 0; bus < 256; bus++) {
|
|
|
+ for (dev = 0; dev < 32; dev++) {
|
|
|
+ for (func = 0; func < 8; func++) {
|
|
|
+ id = pci_cfg_read32(bus, dev, func, 0x00);
|
|
|
+ if (id == 0xFFFFFFFFu || id == 0)
|
|
|
+ continue;
|
|
|
+ class_rev = pci_cfg_read32(bus, dev, func, 0x08);
|
|
|
+ if ((class_rev >> 16) != 0x0C03)
|
|
|
+ continue;
|
|
|
+ if (((class_rev >> 8) & 0xFF) != 0x30)
|
|
|
+ continue;
|
|
|
+ if (xhci_seen(bus, dev, func))
|
|
|
+ continue;
|
|
|
+ bar = pci_cfg_read32(bus, dev, func, 0x10);
|
|
|
+ if (bar & 1)
|
|
|
+ continue;
|
|
|
+ bar_hi = 0;
|
|
|
+ if ((bar & 0x6) == 0x4)
|
|
|
+ bar_hi = pci_cfg_read32(bus, dev,
|
|
|
+ func, 0x14);
|
|
|
+ bar &= 0xFFFFFFF0u;
|
|
|
+ xlog_hex("xhci: pci ", id);
|
|
|
+ xlog_hex(" loc ",
|
|
|
+ (bus << 16) | (dev << 11) |
|
|
|
+ (func << 8));
|
|
|
+ xlog_hex(" bar ", bar);
|
|
|
+ xlog_hex(" hi ", bar_hi);
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
+ if (!bar || bar_hi)
|
|
|
+ continue;
|
|
|
+ if (xhci_nctrl >= XHCI_MAX_HCD)
|
|
|
+ return (int)xhci_nctrl;
|
|
|
+ xh = &xhci_hcds[xhci_nctrl];
|
|
|
+ zero_page((unsigned int)xh, sizeof(*xh));
|
|
|
+ xh->last_port_num = -1;
|
|
|
+ if (xhci_init_one(bus, dev, func, bar))
|
|
|
+ xhci_nctrl++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return (int)xhci_nctrl;
|
|
|
+}
|
|
|
+
|
|
|
static unsigned int xhci_count(void)
|
|
|
{
|
|
|
- return found ? 1u : 0u;
|
|
|
+ return xhci_nctrl;
|
|
|
}
|
|
|
|
|
|
static void xhci_info(unsigned int ctrl, unsigned int *bus,
|
|
|
unsigned int *dev, unsigned int *func,
|
|
|
unsigned int *base, int *mmio)
|
|
|
{
|
|
|
- (void)ctrl;
|
|
|
+ if (!xhci_use(ctrl)) {
|
|
|
+ *bus = *dev = *func = 0;
|
|
|
+ *base = 0;
|
|
|
+ *mmio = 1;
|
|
|
+ return;
|
|
|
+ }
|
|
|
*bus = pci_bus;
|
|
|
*dev = pci_dev;
|
|
|
*func = pci_func;
|
|
|
@@ -1839,8 +2111,9 @@ static void xhci_info(unsigned int ctrl, unsigned int *bus,
|
|
|
|
|
|
static unsigned int xhci_port_count(unsigned int ctrl)
|
|
|
{
|
|
|
- (void)ctrl;
|
|
|
- return found ? max_ports : 0;
|
|
|
+ if (!xhci_use(ctrl))
|
|
|
+ return 0;
|
|
|
+ return max_ports;
|
|
|
}
|
|
|
|
|
|
const struct usb_hcd_ops usb_xhci_ops = {
|
|
|
@@ -1856,9 +2129,10 @@ const struct usb_hcd_ops usb_xhci_ops = {
|
|
|
port_take_change,
|
|
|
int_in_start,
|
|
|
int_in_poll,
|
|
|
- stop_int,
|
|
|
+ int_in_stop,
|
|
|
xhci_bulk_out,
|
|
|
xhci_bulk_in,
|
|
|
xhci_bulk_reset,
|
|
|
0,
|
|
|
+ set_route,
|
|
|
};
|