diff options
author | Paul Zimmerman <Paul.Zimmerman@synopsys.com> | 2011-02-12 17:06:44 -0500 |
---|---|---|
committer | Sarah Sharp <sarah.a.sharp@linux.intel.com> | 2011-02-20 10:01:27 -0500 |
commit | a2490187011cc2263117626615a581927d19f1d3 (patch) | |
tree | 32e60d30546512b1c38259558954462c6a81f6bb /drivers | |
parent | 68e41c5d032668e2905404afbef75bc58be179d6 (diff) |
xhci: Clarify some expressions in the TRB math
This makes it easier to spot some problems, which will be fixed by the
next patch in the series. Also change dev_dbg to dev_err in
check_trb_math(), so any math errors will be visible even when running
with debug disabled.
Note: This patch changes the expressions containing
"((1 << TRB_MAX_BUFF_SHIFT) - 1)" to use the equivalent
"(TRB_MAX_BUFF_SIZE - 1)". No change in behavior is intended for
those expressions.
This patch should be queued for stable kernels back to 2.6.31.
Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: stable@kernel.org
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/host/xhci-ring.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 2a87231d588d..1071411d6dfc 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -2368,7 +2368,7 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb) | |||
2368 | 2368 | ||
2369 | /* Scatter gather list entries may cross 64KB boundaries */ | 2369 | /* Scatter gather list entries may cross 64KB boundaries */ |
2370 | running_total = TRB_MAX_BUFF_SIZE - | 2370 | running_total = TRB_MAX_BUFF_SIZE - |
2371 | (sg_dma_address(sg) & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); | 2371 | (sg_dma_address(sg) & (TRB_MAX_BUFF_SIZE - 1)); |
2372 | if (running_total != 0) | 2372 | if (running_total != 0) |
2373 | num_trbs++; | 2373 | num_trbs++; |
2374 | 2374 | ||
@@ -2399,11 +2399,11 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb) | |||
2399 | static void check_trb_math(struct urb *urb, int num_trbs, int running_total) | 2399 | static void check_trb_math(struct urb *urb, int num_trbs, int running_total) |
2400 | { | 2400 | { |
2401 | if (num_trbs != 0) | 2401 | if (num_trbs != 0) |
2402 | dev_dbg(&urb->dev->dev, "%s - ep %#x - Miscalculated number of " | 2402 | dev_err(&urb->dev->dev, "%s - ep %#x - Miscalculated number of " |
2403 | "TRBs, %d left\n", __func__, | 2403 | "TRBs, %d left\n", __func__, |
2404 | urb->ep->desc.bEndpointAddress, num_trbs); | 2404 | urb->ep->desc.bEndpointAddress, num_trbs); |
2405 | if (running_total != urb->transfer_buffer_length) | 2405 | if (running_total != urb->transfer_buffer_length) |
2406 | dev_dbg(&urb->dev->dev, "%s - ep %#x - Miscalculated tx length, " | 2406 | dev_err(&urb->dev->dev, "%s - ep %#x - Miscalculated tx length, " |
2407 | "queued %#x (%d), asked for %#x (%d)\n", | 2407 | "queued %#x (%d), asked for %#x (%d)\n", |
2408 | __func__, | 2408 | __func__, |
2409 | urb->ep->desc.bEndpointAddress, | 2409 | urb->ep->desc.bEndpointAddress, |
@@ -2538,8 +2538,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
2538 | sg = urb->sg; | 2538 | sg = urb->sg; |
2539 | addr = (u64) sg_dma_address(sg); | 2539 | addr = (u64) sg_dma_address(sg); |
2540 | this_sg_len = sg_dma_len(sg); | 2540 | this_sg_len = sg_dma_len(sg); |
2541 | trb_buff_len = TRB_MAX_BUFF_SIZE - | 2541 | trb_buff_len = TRB_MAX_BUFF_SIZE - (addr & (TRB_MAX_BUFF_SIZE - 1)); |
2542 | (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); | ||
2543 | trb_buff_len = min_t(int, trb_buff_len, this_sg_len); | 2542 | trb_buff_len = min_t(int, trb_buff_len, this_sg_len); |
2544 | if (trb_buff_len > urb->transfer_buffer_length) | 2543 | if (trb_buff_len > urb->transfer_buffer_length) |
2545 | trb_buff_len = urb->transfer_buffer_length; | 2544 | trb_buff_len = urb->transfer_buffer_length; |
@@ -2577,7 +2576,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
2577 | (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1), | 2576 | (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1), |
2578 | (unsigned int) addr + trb_buff_len); | 2577 | (unsigned int) addr + trb_buff_len); |
2579 | if (TRB_MAX_BUFF_SIZE - | 2578 | if (TRB_MAX_BUFF_SIZE - |
2580 | (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)) < trb_buff_len) { | 2579 | (addr & (TRB_MAX_BUFF_SIZE - 1)) < trb_buff_len) { |
2581 | xhci_warn(xhci, "WARN: sg dma xfer crosses 64KB boundaries!\n"); | 2580 | xhci_warn(xhci, "WARN: sg dma xfer crosses 64KB boundaries!\n"); |
2582 | xhci_dbg(xhci, "Next boundary at %#x, end dma = %#x\n", | 2581 | xhci_dbg(xhci, "Next boundary at %#x, end dma = %#x\n", |
2583 | (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1), | 2582 | (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1), |
@@ -2621,7 +2620,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
2621 | } | 2620 | } |
2622 | 2621 | ||
2623 | trb_buff_len = TRB_MAX_BUFF_SIZE - | 2622 | trb_buff_len = TRB_MAX_BUFF_SIZE - |
2624 | (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); | 2623 | (addr & (TRB_MAX_BUFF_SIZE - 1)); |
2625 | trb_buff_len = min_t(int, trb_buff_len, this_sg_len); | 2624 | trb_buff_len = min_t(int, trb_buff_len, this_sg_len); |
2626 | if (running_total + trb_buff_len > urb->transfer_buffer_length) | 2625 | if (running_total + trb_buff_len > urb->transfer_buffer_length) |
2627 | trb_buff_len = | 2626 | trb_buff_len = |
@@ -2661,7 +2660,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
2661 | num_trbs = 0; | 2660 | num_trbs = 0; |
2662 | /* How much data is (potentially) left before the 64KB boundary? */ | 2661 | /* How much data is (potentially) left before the 64KB boundary? */ |
2663 | running_total = TRB_MAX_BUFF_SIZE - | 2662 | running_total = TRB_MAX_BUFF_SIZE - |
2664 | (urb->transfer_dma & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); | 2663 | (urb->transfer_dma & (TRB_MAX_BUFF_SIZE - 1)); |
2665 | 2664 | ||
2666 | /* If there's some data on this 64KB chunk, or we have to send a | 2665 | /* If there's some data on this 64KB chunk, or we have to send a |
2667 | * zero-length transfer, we need at least one TRB | 2666 | * zero-length transfer, we need at least one TRB |
@@ -2705,8 +2704,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
2705 | /* How much data is in the first TRB? */ | 2704 | /* How much data is in the first TRB? */ |
2706 | addr = (u64) urb->transfer_dma; | 2705 | addr = (u64) urb->transfer_dma; |
2707 | trb_buff_len = TRB_MAX_BUFF_SIZE - | 2706 | trb_buff_len = TRB_MAX_BUFF_SIZE - |
2708 | (urb->transfer_dma & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); | 2707 | (urb->transfer_dma & (TRB_MAX_BUFF_SIZE - 1)); |
2709 | if (urb->transfer_buffer_length < trb_buff_len) | 2708 | if (trb_buff_len > urb->transfer_buffer_length) |
2710 | trb_buff_len = urb->transfer_buffer_length; | 2709 | trb_buff_len = urb->transfer_buffer_length; |
2711 | 2710 | ||
2712 | first_trb = true; | 2711 | first_trb = true; |
@@ -2884,8 +2883,7 @@ static int count_isoc_trbs_needed(struct xhci_hcd *xhci, | |||
2884 | addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset); | 2883 | addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset); |
2885 | td_len = urb->iso_frame_desc[i].length; | 2884 | td_len = urb->iso_frame_desc[i].length; |
2886 | 2885 | ||
2887 | running_total = TRB_MAX_BUFF_SIZE - | 2886 | running_total = TRB_MAX_BUFF_SIZE - (addr & (TRB_MAX_BUFF_SIZE - 1)); |
2888 | (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); | ||
2889 | if (running_total != 0) | 2887 | if (running_total != 0) |
2890 | num_trbs++; | 2888 | num_trbs++; |
2891 | 2889 | ||