Skip to contentSkip to conversation

BugFix in XHCI controller driver for scatter gather DMA

PATCH In review Vikas Bansal 2 participants 2 messages Dec 21, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 BugFix in XHCI controller driver for scatter gather DMA

From: Sumit Batra <[email protected]>

Pre-Condition
URB with Scatter Gather list is queued to bulk OUT endpoint.
Every buffer in scatter gather list is not a multiple of maximum packet size for that endpoint(short packet). CHAIN bit is set for all TRBs in a TD so that the DMA happens to all of them at once.

Issue
DMA operation copies all the CHAINED TRBs at contiguous device memory.
But since the original packet was a short packet, so the actual data is re-aligned after this DMA operation. At device end this re-aligned data causes data integrity issue with applications like ICMP ping.

Solution
Don't set the CHAINED bit for these TRBs, if their buffers are not a multiple of maximum packet size.
This will reduce the benefit in throughput as required from a scatter gather implementation, but this reduces the CPU utilization. And solves the data integrity issue on Device End

drivers/usb/host/xhci-ring.c +2 -1
index 7d34cbf..862d7cd 100644
@@ -3110,7 +3110,8 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
 		 * TRB to indicate it's the last TRB in the chain.
 		 */
 		if (num_trbs > 1) {
-			field |= TRB_CHAIN;
+			if(this_sg_len % usb_endpoint_maxp(&urb->ep->desc) == 0)
+				field |= TRB_CHAIN;
 		} else {
 			/* FIXME - add check for ZERO_PACKET flag before this */
 			td->last_trb = ep_ring->enqueue;
#1 lore raw

Hello.

Quoted 25 lines · Vikas Bansal

From: Sumit Batra <[email protected]>

Pre-Condition
URB with Scatter Gather list is queued to bulk OUT endpoint.
Every buffer in scatter gather list is not a multiple of maximum packet size for that endpoint(short packet). CHAIN bit is set for all TRBs in a TD so that the DMA happens to all of them at once.

Issue
DMA operation copies all the CHAINED TRBs at contiguous device memory.
But since the original packet was a short packet, so the actual data is re-aligned after this DMA operation. At device end this re-aligned data causes data integrity issue with applications like ICMP ping.

Solution
Don't set the CHAINED bit for these TRBs, if their buffers are not a multiple of maximum packet size.
This will reduce the benefit in throughput as required from a scatter gather implementation, but this reduces the CPU utilization. And solves the data integrity issue on Device End

drivers/usb/host/xhci-ring.c +0 -0
index 7d34cbf..862d7cd 100644

drivers/usb/host/xhci-ring.c static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, · line 3113

Quoted 5 lines
drivers/usb/host/xhci-ring.c +1 -1
@@ -3110,7 +3110,8 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
  		 * TRB to indicate it's the last TRB in the chain.
  		 */
  		if (num_trbs > 1) {
-			field |= TRB_CHAIN;
+			if(this_sg_len % usb_endpoint_maxp(&urb->ep->desc) == 0)

Space needed after *if*. Please run your patches thru scripts/checkpatch.pl.

[...]

MBR, Sergei