xhci fixes for usb-linus
Subsystems (3)
cover xhci fixes for usb-linus
Hi Greg
A few small xhci fixes for 6.6
Use correct dev in dma bounce buffer mapping, fix event handling issues, and track suspended ports correctly in software
Thanks
Mathias
Lukas Wunner (2):
xhci: Clear EHB bit only at end of interrupt handler
xhci: Preserve RsvdP bits in ERSTBA register correctly
Mathias Nyman (1):
xhci: track port suspend state correctly in unsuccessful resume cases
Wesley Cheng (1):
usb: xhci: xhci-ring: Use sysdev for mapping bounce buffer
drivers/usb/host/xhci-hub.c | 19 ++++++++++--------- drivers/usb/host/xhci-mem.c | 4 ++-- drivers/usb/host/xhci-ring.c | 16 +++++++++------- drivers/usb/host/xhci.h | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/4 usb: xhci: xhci-ring: Use sysdev for mapping bounce buffer
From: Wesley Cheng <[email protected]>
As mentioned in:
commit 474ed23a6257 ("xhci: align the last trb before link if it is
easily splittable.")
A bounce buffer is utilized for ensuring that transfers that span across ring segments are aligned to the EP's max packet size. However, the device that is used to map the DMA buffer to is currently using the XHCI HCD, which does not carry any DMA operations in certain configrations. Migration to using the sysdev entry was introduced for DWC3 based implementations where the IOMMU operations are present.
Replace the reference to the controller device to sysdev instead. This allows the bounce buffer to be properly mapped to any implementations that have an IOMMU involved.
--- drivers/usb/host/xhci-ring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-ring.c +2 -2
@@ -798,7 +798,7 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,static void xhci_unmap_td_bounce_buffer (struct xhci_hcd *xhci,struct xhci_ring *ring,struct xhci_td *td) { -struct device *dev =xhci_to_hcd (xhci)->self.controller; +struct device *dev =xhci_to_hcd (xhci)->self.sysdev;struct xhci_segment *seg = td->bounce_seg;struct urb *urb = td->urb;size_t len;
@@ -3469,7 +3469,7 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred,static int xhci_align_td (struct xhci_hcd *xhci,struct urb *urb,u32 enqd_len,u32 *trb_buff_len,struct xhci_segment *seg) { -struct device *dev =xhci_to_hcd (xhci)->self.controller; +struct device *dev =xhci_to_hcd (xhci)->self.sysdev;unsigned int unalign;unsigned int max_pkt;u32 new_buff_len;
Signature · 1 line
2.25.1
PATCH 2/4 xhci: track port suspend state correctly in unsuccessful resume cases
In reply to Mathias Nymanxhci-hub.c tracks suspended ports in a suspended_port bitfield. This is checked when responding to a Get_Status(PORT) request to see if a port in running U0 state was recently resumed, and adds the required USB_PORT_STAT_C_SUSPEND change bit in those cases.
The suspended_port bit was left uncleared if a device is disconnected during suspend. The bit remained set even when a new device was connected and enumerated. The set bit resulted in a incorrect Get_Status(PORT) response with a bogus USB_PORT_STAT_C_SUSPEND change
bit set once the new device reached U0 link state.
USB_PORT_STAT_C_SUSPEND change bit is only used for USB2 ports, but xhci-hub keeps track of both USB2 and USB3 suspended ports.
--- drivers/usb/host/xhci-hub.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-hub.c +10 -9
@@ -1062,19 +1062,19 @@ static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status, *status |=USB_PORT_STAT_C_CONFIG_ERROR <<16 ;/* USB3 specific wPortStatus bits */ -if (portsc &PORT_POWER ) { +if (portsc &PORT_POWER ) *status |=USB_SS_PORT_STAT_POWER ; -/* link state handling */ -if (link_state ==XDEV_U0 ) - bus_state->suspended_ports &= ~(1 << portnum); - } -/* remote wake resume signaling complete */ -if (bus_state->port_remote_wakeup & (1 << portnum) && +/* no longer suspended or resuming */ +if (link_state !=XDEV_U3 && link_state !=XDEV_RESUME && link_state !=XDEV_RECOVERY ) { - bus_state->port_remote_wakeup &= ~(1 << portnum); -usb_hcd_end_port_resume (&hcd->self, portnum); +/* remote wake resume signaling complete */ +if (bus_state->port_remote_wakeup & (1 << portnum)) { + bus_state->port_remote_wakeup &= ~(1 << portnum); +usb_hcd_end_port_resume (&hcd->self, portnum); + } + bus_state->suspended_ports &= ~(1 << portnum); }xhci_hub_report_usb3_link_state (xhci, status, portsc);
@@ -1131,6 +1131,7 @@ static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status,usb_hcd_end_port_resume (&port->rhub->hcd->self, portnum); } port->rexit_active =0 ; + bus_state->suspended_ports &= ~(1 << portnum); } }
Signature · 1 line
2.25.1
PATCH 3/4 xhci: Clear EHB bit only at end of interrupt handler
In reply to Mathias NymanFrom: Lukas Wunner <[email protected]>
The Event Handler Busy bit shall be cleared by software when the Event Ring is empty. The xHC is thereby informed that it may raise another interrupt once it has enqueued new events (sec 4.17.2).
However since commit dc0ffbea5729 ("usb: host: xhci: update event ring dequeue pointer on purpose"), the EHB bit is already cleared after half a segment has been processed.
As a result, spurious interrupts may occur:
- xhci_irq() processes half a segment, clears EHB, continues processing remaining events.
- xHC enqueues new events. Because EHB has been cleared, xHC sets Interrupt Pending bit. Interrupt moderation countdown begins.
- Meanwhile xhci_irq() continues processing events. Interrupt moderation countdown reaches zero, so an MSI interrupt is signaled.
- xhci_irq() empties the Event Ring, clears EHB again and is done.
- Because an MSI interrupt has been signaled, xhci_irq() is run again. It discovers there's nothing to do and returns IRQ_NONE.
Avoid by clearing the EHB bit only at the end of xhci_irq().
--- drivers/usb/host/xhci-ring.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/usb/host/xhci-ring.c +7 -5
@@ -2996,7 +2996,8 @@ static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir)*/ static void xhci_update_erst_dequeue (struct xhci_hcd *xhci,struct xhci_interrupter *ir, -union xhci_trb *event_ring_deq) +union xhci_trb *event_ring_deq, +bool clear_ehb) {u64 temp_64;dma_addr_t deq;
@@ -3017,12 +3018,13 @@ static void xhci_update_erst_dequeue(struct xhci_hcd *xhci,return ;/* Update HC event ring dequeue pointer */ - temp_64 &=ERST_PTR_MASK ; + temp_64 &=ERST_DESI_MASK ; temp_64 |= ((u64 ) deq & (u64 ) ~ERST_PTR_MASK ); }/* Clear the event handler busy flag (RW1C) */ - temp_64 |=ERST_EHB ; +if (clear_ehb) + temp_64 |=ERST_EHB ;xhci_write_64 (xhci, temp_64, &ir->ir_set->erst_dequeue); }
@@ -3103,7 +3105,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)while (xhci_handle_event (xhci, ir) >0 ) {if (event_loop++ <TRBS_PER_SEGMENT /2 )continue ; -xhci_update_erst_dequeue (xhci, ir, event_ring_deq); +xhci_update_erst_dequeue (xhci, ir, event_ring_deq, false); event_ring_deq = ir->event_ring->dequeue;/* ring is half-full, force isoc trbs to interrupt more often */
@@ -3113,7 +3115,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) event_loop =0 ; } -xhci_update_erst_dequeue (xhci, ir, event_ring_deq); +xhci_update_erst_dequeue (xhci, ir, event_ring_deq, true); ret =IRQ_HANDLED ; out:
Signature · 1 line
2.25.1
PATCH 4/4 xhci: Preserve RsvdP bits in ERSTBA register correctly
In reply to Mathias NymanFrom: Lukas Wunner <[email protected]>
xhci_add_interrupter() erroneously preserves only the lowest 4 bits when writing the ERSTBA register, not the lowest 6 bits. Fix it.
Migrate the ERST_BASE_RSVDP macro to the modern GENMASK_ULL() syntax to avoid a u64 cast.
This was previously fixed by commit 8c1cbec9db1a ("xhci: fix event ring segment table related masks and variables in header"), but immediately undone by commit b17a57f89f69 ("xhci: Refactor interrupter code for initial multi interrupter support.").
--- drivers/usb/host/xhci-mem.c | 4 ++-- drivers/usb/host/xhci.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/usb/host/xhci-mem.c +2 -2
@@ -2285,8 +2285,8 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir,writel (erst_size, &ir->ir_set->erst_size); erst_base =xhci_read_64 (xhci, &ir->ir_set->erst_base); - erst_base &=ERST_PTR_MASK ; - erst_base |= (ir->erst.erst_dma_addr & (u64 ) ~ERST_PTR_MASK ); + erst_base &=ERST_BASE_RSVDP ; + erst_base |= ir->erst.erst_dma_addr & ~ERST_BASE_RSVDP ;xhci_write_64 (xhci, erst_base, &ir->ir_set->erst_base);/* Set the event ring dequeue address of this interrupter */
drivers/usb/host/xhci.h +1 -1
@@ -514,7 +514,7 @@ struct xhci_intr_reg {#define ERST_SIZE_MASK (0xffff << 16)/* erst_base bitmasks */ -#define ERST_BASE_RSVDP (0x3f) +#define ERST_BASE_RSVDP (GENMASK_ULL(5, 0))/* erst_dequeue bitmasks */ /* Dequeue ERST Segment Index (DESI) - Segment number (or alias)
Signature · 1 line
2.25.1