Skip to content

Commit 395f540

Browse files
matnymangregkh
authored andcommitted
xhci: support new USB 3.1 hub request to get extended port status
USB 3.1 adds different types of Get Port Status request. The Get Extended Port Status request returns 4 additional bytes after the normal portstatus and portchange words containing link speed and lane information about a connected enhanced super speed device Signed-off-by: Mathias Nyman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b50107b commit 395f540

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

drivers/usb/host/xhci-hub.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,22 @@ static void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status,
659659
}
660660
}
661661

662+
static u32 xhci_get_ext_port_status(u32 raw_port_status, u32 port_li)
663+
{
664+
u32 ext_stat = 0;
665+
int speed_id;
666+
667+
/* only support rx and tx lane counts of 1 in usb3.1 spec */
668+
speed_id = DEV_PORT_SPEED(raw_port_status);
669+
ext_stat |= speed_id; /* bits 3:0, RX speed id */
670+
ext_stat |= speed_id << 4; /* bits 7:4, TX speed id */
671+
672+
ext_stat |= PORT_RX_LANES(port_li) << 8; /* bits 11:8 Rx lane count */
673+
ext_stat |= PORT_TX_LANES(port_li) << 12; /* bits 15:12 Tx lane count */
674+
675+
return ext_stat;
676+
}
677+
662678
/*
663679
* Converts a raw xHCI port status into the format that external USB 2.0 or USB
664680
* 3.0 hubs use.
@@ -874,6 +890,19 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
874890
xhci_dbg(xhci, "Get port status returned 0x%x\n", status);
875891

876892
put_unaligned(cpu_to_le32(status), (__le32 *) buf);
893+
/* if USB 3.1 extended port status return additional 4 bytes */
894+
if (wValue == 0x02) {
895+
u32 port_li;
896+
897+
if (hcd->speed < HCD_USB31 || wLength != 8) {
898+
xhci_err(xhci, "get ext port status invalid parameter\n");
899+
retval = -EINVAL;
900+
break;
901+
}
902+
port_li = readl(port_array[wIndex] + PORTLI);
903+
status = xhci_get_ext_port_status(temp, port_li);
904+
put_unaligned_le32(cpu_to_le32(status), &buf[4]);
905+
}
877906
break;
878907
case SetPortFeature:
879908
if (wValue == USB_PORT_FEAT_LINK_STATE)

drivers/usb/host/xhci.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ struct xhci_op_regs {
335335
#define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
336336
#define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP)
337337
#define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS)
338+
#define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f)
338339

339340
/* Bits 20:23 in the Slot Context are the speed for the device */
340341
#define SLOT_SPEED_FS (XDEV_FS << 10)
@@ -419,6 +420,9 @@ struct xhci_op_regs {
419420
#define PORT_L1DS(p) (((p) & 0xff) << 8)
420421
#define PORT_HLE (1 << 16)
421422

423+
/* USB3 Protocol PORTLI Port Link Information */
424+
#define PORT_RX_LANES(p) (((p) >> 16) & 0xf)
425+
#define PORT_TX_LANES(p) (((p) >> 20) & 0xf)
422426

423427
/* USB2 Protocol PORTHLPMC */
424428
#define PORT_HIRDM(p)((p) & 3)

0 commit comments

Comments
 (0)