|
|
@@ -104,6 +104,7 @@ static unsigned int portsc_neutral(unsigned int ps)
|
|
|
#define TRB_DISABLE_SLOT 10
|
|
|
#define TRB_ADDR_DEV 11
|
|
|
#define TRB_CONFIG_EP 12
|
|
|
+#define TRB_EVAL_CTX 13
|
|
|
#define TRB_TRANSFER 32
|
|
|
#define TRB_COMPLETION 33
|
|
|
|
|
|
@@ -148,6 +149,7 @@ struct xhci_slot {
|
|
|
unsigned int ep0; /* EP0 transfer ring page */
|
|
|
unsigned int ep0_enq;
|
|
|
unsigned int ep0_cycle;
|
|
|
+ unsigned int ep0_mps; /* max packet size programmed into EP0 */
|
|
|
unsigned int ep_mask; /* configured endpoint flags */
|
|
|
};
|
|
|
|
|
|
@@ -194,6 +196,8 @@ 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;
|
|
|
|
|
|
@@ -265,6 +269,14 @@ static void dbg_hex(const char *s, unsigned int v) { (void)s; (void)v; }
|
|
|
static void dbg_dec(const char *s, unsigned int v) { (void)s; (void)v; }
|
|
|
#endif
|
|
|
|
|
|
+/* Always-on one-line diagnostics (COM1, mirrored to netmon). Only used on
|
|
|
+ * the init line and on failures, so a working machine stays quiet. */
|
|
|
+static void xlog_hex(const char *s, unsigned int v)
|
|
|
+{
|
|
|
+ serial_puts(SERIAL_COM1, s);
|
|
|
+ serial_puthex(SERIAL_COM1, v);
|
|
|
+}
|
|
|
+
|
|
|
static void delay_ms(unsigned int ms)
|
|
|
{
|
|
|
usb_delay_ms(ms); /* sleeps inside a sleepable scan */
|
|
|
@@ -601,6 +613,47 @@ static unsigned int ep0_mps_for_speed(unsigned int speed)
|
|
|
return 64; /* full speed (guess) and high speed */
|
|
|
}
|
|
|
|
|
|
+/* EP0 max packet size for Address Device. Low, high and SuperSpeed have
|
|
|
+ * one legal value, so the USB core's 8-byte first-read guess is replaced
|
|
|
+ * by it; only full speed (8/16/32/64) takes the caller's value and is
|
|
|
+ * corrected later by ep0_set_mps(). */
|
|
|
+static unsigned int ep0_mps_initial(unsigned int speed, unsigned int mps)
|
|
|
+{
|
|
|
+ if (!mps || speed != 1)
|
|
|
+ return ep0_mps_for_speed(speed);
|
|
|
+ return mps;
|
|
|
+}
|
|
|
+
|
|
|
+/* Evaluate Context: tell the xHC the device's real bMaxPacketSize0 once
|
|
|
+ * the first descriptor read has returned it. Without this the VL805 on
|
|
|
+ * the 970A-DS3P kept the 8-byte EP0 that SET_ADDRESS created, and the
|
|
|
+ * 18-byte device descriptor read of a high-speed stick failed with
|
|
|
+ * Babble Detected (the device answers in one 18-byte packet). */
|
|
|
+static int ep0_set_mps(struct xhci_slot *s, unsigned int mps)
|
|
|
+{
|
|
|
+ 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) = EP0_FLAG;
|
|
|
+ fill_ep0_ctx(mps, s->ep0, s->ep0_enq, s->ep0_cycle);
|
|
|
+ spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
+
|
|
|
+ rc = xhci_cmd(input_ctx, 0,
|
|
|
+ TRB_TYPE(TRB_EVAL_CTX) | (s->slot_id << 24), 0);
|
|
|
+ if (rc == 0) {
|
|
|
+ s->ep0_mps = mps;
|
|
|
+ } else {
|
|
|
+ xlog_hex("xhci: evaluate context failed slot ", s->slot_id);
|
|
|
+ xlog_hex(" mps ", mps);
|
|
|
+ xlog_hex(" cc ", cmd_status);
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
+ }
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
static int xhci_config_ep(struct xhci_slot *s, unsigned int ep_index,
|
|
|
unsigned int type, unsigned int mps,
|
|
|
unsigned int interval, unsigned int ring)
|
|
|
@@ -680,8 +733,8 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
|
|
|
s->ep_mask = 0;
|
|
|
s->dev_addr = 0;
|
|
|
ring_init(ep0, XHCI_EP0_TRBS, &s->ep0_enq, &s->ep0_cycle);
|
|
|
- if (!mps || s->speed >= 4)
|
|
|
- mps = ep0_mps_for_speed(s->speed);
|
|
|
+ mps = ep0_mps_initial(s->speed, mps);
|
|
|
+ s->ep0_mps = mps;
|
|
|
|
|
|
ram_wr64(dcbaa + slot_id * 8, dc);
|
|
|
|
|
|
@@ -697,8 +750,13 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
|
|
|
TRB_TYPE(TRB_ADDR_DEV) | (slot_id << 24) |
|
|
|
(bsr ? TRB_BSR : 0), 0);
|
|
|
if (rc != 0) {
|
|
|
- dbg(bsr ? "xhci: address default failed\n" :
|
|
|
- "xhci: address device failed\n");
|
|
|
+ xlog_hex(bsr ? "xhci: address default failed port " :
|
|
|
+ "xhci: address device failed port ", s->port);
|
|
|
+ xlog_hex(" spd ", s->speed);
|
|
|
+ xlog_hex(" cc ", cmd_status);
|
|
|
+ xlog_hex(" portsc ",
|
|
|
+ mmio_rd(op(XHCI_OP_PORTSC) + s->port * 0x10));
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
ram_wr64(dcbaa + slot_id * 8, 0);
|
|
|
xhci_cmd(0, 0,
|
|
|
TRB_TYPE(TRB_DISABLE_SLOT) | (slot_id << 24), 0);
|
|
|
@@ -777,10 +835,7 @@ static int set_address(unsigned int new_addr, unsigned int mps)
|
|
|
if (!s || new_addr == 0 || new_addr > 127)
|
|
|
return -1;
|
|
|
|
|
|
- /* The USB core's first SET_ADDRESS uses its high/full-speed 64-byte
|
|
|
- * guess; a SuperSpeed slot's EP0 is always 512 bytes. */
|
|
|
- if (s->speed >= 4)
|
|
|
- mps = ep0_mps_for_speed(s->speed);
|
|
|
+ mps = ep0_mps_initial(s->speed, mps);
|
|
|
|
|
|
spin_lock_irqsave(&xhci_lock, &flags);
|
|
|
zero_page(input_ctx, 4096);
|
|
|
@@ -799,6 +854,7 @@ static int set_address(unsigned int new_addr, unsigned int mps)
|
|
|
|
|
|
spin_lock_irqsave(&xhci_lock, &flags);
|
|
|
s->dev_addr = ((unsigned int *)s->dc)[3] & 0xFF;
|
|
|
+ s->ep0_mps = mps;
|
|
|
addr_slot[0] = 0;
|
|
|
s->addr = new_addr;
|
|
|
addr_slot[new_addr] = s->slot_id;
|
|
|
@@ -807,6 +863,32 @@ static int set_address(unsigned int new_addr, unsigned int mps)
|
|
|
}
|
|
|
|
|
|
/* ---- control transfers ------------------------------------------------- */
|
|
|
+/* One line per failed control transfer: the request, the completion code
|
|
|
+ * (0 = no event within the timeout), the root port's PORTSC, and the slot /
|
|
|
+ * EP0 states from the output device context (slot state 2 = Addressed,
|
|
|
+ * EP state 2 = Halted, 4 = Error). */
|
|
|
+static void ctl_fail_log(const struct xhci_slot *s, const unsigned char *setup,
|
|
|
+ unsigned int cc, unsigned int data_seen)
|
|
|
+{
|
|
|
+ const unsigned int *dc = (const unsigned int *)s->dc;
|
|
|
+ const unsigned int *ep0 = (const unsigned int *)(s->dc + ctx_size);
|
|
|
+
|
|
|
+ serial_puts(SERIAL_COM1, cc ? "xhci: ctl err" : "xhci: ctl timeout");
|
|
|
+ xlog_hex(" req ", (unsigned int)setup[0] | ((unsigned int)setup[1] << 8) |
|
|
|
+ ((unsigned int)setup[2] << 16) | ((unsigned int)setup[3] << 24));
|
|
|
+ xlog_hex(" cc ", cc);
|
|
|
+ xlog_hex(" data ", data_seen);
|
|
|
+ xlog_hex(" slot ", s->slot_id);
|
|
|
+ xlog_hex(" spd ", s->speed);
|
|
|
+ xlog_hex(" portsc ", mmio_rd(op(XHCI_OP_PORTSC) + s->port * 0x10));
|
|
|
+ xlog_hex(" sstate ", dc[3] >> 27);
|
|
|
+ xlog_hex(" dev ", dc[3] & 0xFF);
|
|
|
+ xlog_hex(" ep0 ", ep0[0] & 7);
|
|
|
+ xlog_hex(" mps ", ep0[1] >> 16);
|
|
|
+ xlog_hex(" sts ", mmio_rd(op(XHCI_OP_USBSTS)));
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
+}
|
|
|
+
|
|
|
static int control_transfer(unsigned int ctrl, unsigned int addr,
|
|
|
unsigned int mps, int low_speed,
|
|
|
const unsigned char *setup, unsigned char *data,
|
|
|
@@ -854,6 +936,14 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+ /* The core learned the real bMaxPacketSize0 from the first 8 bytes
|
|
|
+ * of the device descriptor; reprogram EP0 before using it. Only a
|
|
|
+ * full-speed EP0 can legally differ from the speed's fixed value. */
|
|
|
+ if (s->speed == 1 && (mps == 8 || mps == 16 || mps == 32 ||
|
|
|
+ mps == 64) && mps != s->ep0_mps &&
|
|
|
+ ep0_set_mps(s, mps) != 0)
|
|
|
+ return -1;
|
|
|
+
|
|
|
spin_lock_irqsave(&xhci_lock, &flags);
|
|
|
if (ctl_busy) {
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
@@ -875,7 +965,10 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
|
|
|
* transfer event is ever posted, while the per-stage encoding
|
|
|
* completes. */
|
|
|
setup_c = TRB_TYPE(TRB_SETUP) | TRB_IDT | TRB_IOC;
|
|
|
- if (len)
|
|
|
+ /* Transfer Type (TRT) only exists from xHCI 1.0 on; in a 0.96
|
|
|
+ * controller (Etron EJ168, early VIA/Renesas parts) bits 17:16 are
|
|
|
+ * reserved. Linux sets it only for hci_version >= 0x100 too. */
|
|
|
+ if (len && hci_version >= 0x100)
|
|
|
setup_c |= (dir_in ? 3u : 2u) << 16;
|
|
|
ctl_setup_trb = s->ep0 + s->ep0_enq * 16;
|
|
|
ring_queue(s->ep0, XHCI_EP0_TRBS, &s->ep0_enq, &s->ep0_cycle,
|
|
|
@@ -931,7 +1024,7 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
|
|
|
if (!ctl_done) {
|
|
|
ctl_busy = 0;
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
- dbg("xhci: control timeout\n");
|
|
|
+ ctl_fail_log(s, setup, 0, ctl_data_seen);
|
|
|
return -1;
|
|
|
}
|
|
|
rc = ctl_actual;
|
|
|
@@ -940,7 +1033,7 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
|
|
|
spin_unlock_irqrestore(&xhci_lock, flags);
|
|
|
|
|
|
if (st != CC_SUCCESS && st != CC_SHORT_PACKET) {
|
|
|
- dbg_hex("xhci: control status ", st);
|
|
|
+ ctl_fail_log(s, setup, st, ctl_data_seen);
|
|
|
return -1;
|
|
|
}
|
|
|
return (int)rc;
|
|
|
@@ -1258,8 +1351,12 @@ static int port_reset(unsigned int ctrl, unsigned int port)
|
|
|
|
|
|
/* Force the port into the Disabled state first: some xHCs ignore
|
|
|
* PR while the port is already enabled, leaving the device at its
|
|
|
- * firmware-assigned address instead of address 0. */
|
|
|
- if (ps & PORTSC_PED) {
|
|
|
+ * firmware-assigned address instead of address 0. USB2 ports only:
|
|
|
+ * on a SuperSpeed port PED=1 puts the link into SS.Disabled, which a
|
|
|
+ * hot reset (PR) does not leave -- software would have to write
|
|
|
+ * PLS=RxDetect -- so the BIOS-booted stick stayed unreachable. */
|
|
|
+ if ((ps & PORTSC_PED) &&
|
|
|
+ ((ps >> PORTSC_SPEED_SHIFT) & PORTSC_SPEED_MASK) < 4) {
|
|
|
mmio_wr(op(XHCI_OP_PORTSC) + port * 0x10,
|
|
|
portsc_neutral(ps) | PORTSC_PED);
|
|
|
t0 = get_ticks_ms();
|
|
|
@@ -1290,7 +1387,9 @@ static int port_reset(unsigned int ctrl, unsigned int port)
|
|
|
usb_poll_relax(t0);
|
|
|
}
|
|
|
if (!(ps & PORTSC_PRC)) {
|
|
|
- dbg_hex("xhci: port reset timeout ", port);
|
|
|
+ xlog_hex("xhci: port reset timeout port ", port);
|
|
|
+ xlog_hex(" portsc ", ps);
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
return -1;
|
|
|
}
|
|
|
mmio_wr(op(XHCI_OP_PORTSC) + port * 0x10,
|
|
|
@@ -1304,7 +1403,9 @@ static int port_reset(unsigned int ctrl, unsigned int port)
|
|
|
usb_poll_relax(t0);
|
|
|
}
|
|
|
if (!(ps & PORTSC_PED)) {
|
|
|
- dbg_hex("xhci: port not enabled ", port);
|
|
|
+ xlog_hex("xhci: port not enabled port ", port);
|
|
|
+ xlog_hex(" portsc ", ps);
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
@@ -1485,7 +1586,9 @@ found_xhci:
|
|
|
mmio_base = bar;
|
|
|
paging_map_mmio(mmio_base, 0x10000);
|
|
|
|
|
|
+ pci_id = pci_cfg_read32(pci_bus, pci_dev, pci_func, 0x00);
|
|
|
cap_len = mmio_rd(0) & 0xFF;
|
|
|
+ hci_version = mmio_rd(0) >> 16;
|
|
|
hcs1 = mmio_rd(XHCI_CAP_HCSPARAMS1);
|
|
|
hcs2 = mmio_rd(XHCI_CAP_HCSPARAMS2);
|
|
|
hcc_params = mmio_rd(XHCI_CAP_HCCPARAMS1);
|
|
|
@@ -1656,7 +1759,13 @@ found_xhci:
|
|
|
* while commands complete normally. */
|
|
|
|
|
|
scan_protocols();
|
|
|
- dbg_hex("xhci: ports ", port_mask);
|
|
|
+ xlog_hex("xhci: ", pci_id);
|
|
|
+ xlog_hex(" hci ", hci_version);
|
|
|
+ xlog_hex(" mmio ", mmio_base);
|
|
|
+ xlog_hex(" ports ", port_mask);
|
|
|
+ xlog_hex(" csz ", ctx_size);
|
|
|
+ xlog_hex(" scratch ", n);
|
|
|
+ serial_putc(SERIAL_COM1, '\n');
|
|
|
|
|
|
/* Power every root port. VBus is supposed to come up after HCRST,
|
|
|
* but some firmware/PPC combinations leave PP clear; the USB3
|