usb: xhci: Fix bounce_buf dma map error

The xhci-mem driver uses the xhci_to_hcd(xhci)->self.sysdev
to alloc bounce_buf, it's right. But the xhci-ring driver
uses the xhci_to_hcd(xhci)->self.controller to do dma_map
and dma_unmap for bounce_buf. Because the dma_ops of the
xhci_to_hcd(xhci)->self.controller maybe NULL, it will use
dummy_dma_ops which actually do nothing on arm64 platform,
and cause dma mapping error in xhci_align_td().

I test read/write CHIPFANCIER USB3.0 Disk (idVendor=174c,
idProduct=55aa) on RK3399 EVB, without this patch, it
will continuously print the following error logs.

console:/ # dd if=/dev/zero of=/dev/block/sda bs=64K count=64K
[  131.802717] xhci-hcd xhci-hcd.7.auto: Failed mapping bounce buffer, not aligning
[  131.803721] xhci-hcd xhci-hcd.7.auto: Failed mapping bounce buffer, not aligning
[  131.805069] xhci-hcd xhci-hcd.7.auto: Failed mapping bounce buffer, not aligning
[  131.805683] xhci-hcd xhci-hcd.7.auto: Failed mapping bounce buffer, not aligning
[  131.807131] xhci-hcd xhci-hcd.7.auto: Failed mapping bounce buffer, not aligning

Change-Id: I5d6f35d7103ff076c7d06c5807b75ae84a2ffff1
Signed-off-by: William Wu <william.wu@rock-chips.com>
This commit is contained in:
William Wu
2023-03-29 17:06:47 +08:00
committed by Tao Huang
parent 73dfca5958
commit dba57c8616

View File

@ -689,7 +689,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;
@ -3194,7 +3194,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;