summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Saenz Julienne <nsaenzjulienne@suse.de>2019-04-26 09:23:29 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-04-27 08:53:58 -0400
commit33e39350ebd20fe6a77a51b8c21c3aa6b4a208cf (patch)
treef39027fadd5dee7fd06773613f20c429ce3a90e1
parent95e060e68bd98f28763adbc311797eebc4d31e0c (diff)
usb: xhci: add Immediate Data Transfer support
Immediate data transfers (IDT) allow the HCD to copy small chunks of data (up to 8bytes) directly into its output transfer TRBs. This avoids the somewhat expensive DMA mappings that are performed by default on most URBs submissions. In the case an URB was suitable for IDT. The data is directly copied into the "Data Buffer Pointer" region of the TRB and the IDT flag is set. Instead of triggering memory accesses the HC will use the data directly. The implementation could cover all kind of output endpoints. Yet Isochronous endpoints are bypassed as I was unable to find one that matched IDT's constraints. As we try to bypass the default DMA mappings on URB buffers we'd need to find a Isochronous device with an urb->transfer_buffer_length <= 8 bytes. The implementation takes into account that the 8 byte buffers provided by the URB will never cross a 64KB boundary. Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de> Reviewed-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/host/xhci-ring.c12
-rw-r--r--drivers/usb/host/xhci.c16
-rw-r--r--drivers/usb/host/xhci.h17
3 files changed, 45 insertions, 0 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 9215a28dad40..28250319d0b8 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3275,6 +3275,12 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
3275 field |= TRB_IOC; 3275 field |= TRB_IOC;
3276 more_trbs_coming = false; 3276 more_trbs_coming = false;
3277 td->last_trb = ring->enqueue; 3277 td->last_trb = ring->enqueue;
3278
3279 if (xhci_urb_suitable_for_idt(urb)) {
3280 memcpy(&send_addr, urb->transfer_buffer,
3281 trb_buff_len);
3282 field |= TRB_IDT;
3283 }
3278 } 3284 }
3279 3285
3280 /* Only set interrupt on short packet for IN endpoints */ 3286 /* Only set interrupt on short packet for IN endpoints */
@@ -3414,6 +3420,12 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
3414 if (urb->transfer_buffer_length > 0) { 3420 if (urb->transfer_buffer_length > 0) {
3415 u32 length_field, remainder; 3421 u32 length_field, remainder;
3416 3422
3423 if (xhci_urb_suitable_for_idt(urb)) {
3424 memcpy(&urb->transfer_dma, urb->transfer_buffer,
3425 urb->transfer_buffer_length);
3426 field |= TRB_IDT;
3427 }
3428
3417 remainder = xhci_td_remainder(xhci, 0, 3429 remainder = xhci_td_remainder(xhci, 0,
3418 urb->transfer_buffer_length, 3430 urb->transfer_buffer_length,
3419 urb->transfer_buffer_length, 3431 urb->transfer_buffer_length,
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 7fa58c99f126..255f93f741a0 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1238,6 +1238,21 @@ EXPORT_SYMBOL_GPL(xhci_resume);
1238 1238
1239/*-------------------------------------------------------------------------*/ 1239/*-------------------------------------------------------------------------*/
1240 1240
1241/*
1242 * Bypass the DMA mapping if URB is suitable for Immediate Transfer (IDT),
1243 * we'll copy the actual data into the TRB address register. This is limited to
1244 * transfers up to 8 bytes on output endpoints of any kind with wMaxPacketSize
1245 * >= 8 bytes. If suitable for IDT only one Transfer TRB per TD is allowed.
1246 */
1247static int xhci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1248 gfp_t mem_flags)
1249{
1250 if (xhci_urb_suitable_for_idt(urb))
1251 return 0;
1252
1253 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
1254}
1255
1241/** 1256/**
1242 * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and 1257 * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and
1243 * HCDs. Find the index for an endpoint given its descriptor. Use the return 1258 * HCDs. Find the index for an endpoint given its descriptor. Use the return
@@ -5154,6 +5169,7 @@ static const struct hc_driver xhci_hc_driver = {
5154 /* 5169 /*
5155 * managing i/o requests and associated device resources 5170 * managing i/o requests and associated device resources
5156 */ 5171 */
5172 .map_urb_for_dma = xhci_map_urb_for_dma,
5157 .urb_enqueue = xhci_urb_enqueue, 5173 .urb_enqueue = xhci_urb_enqueue,
5158 .urb_dequeue = xhci_urb_dequeue, 5174 .urb_dequeue = xhci_urb_dequeue,
5159 .alloc_dev = xhci_alloc_dev, 5175 .alloc_dev = xhci_alloc_dev,
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 9334cdee382a..abbd4813e8a2 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1303,6 +1303,8 @@ enum xhci_setup_dev {
1303#define TRB_IOC (1<<5) 1303#define TRB_IOC (1<<5)
1304/* The buffer pointer contains immediate data */ 1304/* The buffer pointer contains immediate data */
1305#define TRB_IDT (1<<6) 1305#define TRB_IDT (1<<6)
1306/* TDs smaller than this might use IDT */
1307#define TRB_IDT_MAX_SIZE 8
1306 1308
1307/* Block Event Interrupt */ 1309/* Block Event Interrupt */
1308#define TRB_BEI (1<<9) 1310#define TRB_BEI (1<<9)
@@ -2149,6 +2151,21 @@ static inline struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
2149 urb->stream_id); 2151 urb->stream_id);
2150} 2152}
2151 2153
2154/*
2155 * TODO: As per spec Isochronous IDT transmissions are supported. We bypass
2156 * them anyways as we where unable to find a device that matches the
2157 * constraints.
2158 */
2159static inline bool xhci_urb_suitable_for_idt(struct urb *urb)
2160{
2161 if (!usb_endpoint_xfer_isoc(&urb->ep->desc) && usb_urb_dir_out(urb) &&
2162 usb_endpoint_maxp(&urb->ep->desc) >= TRB_IDT_MAX_SIZE &&
2163 urb->transfer_buffer_length <= TRB_IDT_MAX_SIZE)
2164 return true;
2165
2166 return false;
2167}
2168
2152static inline char *xhci_slot_state_string(u32 state) 2169static inline char *xhci_slot_state_string(u32 state)
2153{ 2170{
2154 switch (state) { 2171 switch (state) {