Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp403476ima; Fri, 1 Feb 2019 05:14:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IZf1sMjPe4cxJPHMHvW8za5frav8k4xdhpejgT9x1ce1PNyH7AA2a5y2uuKE577cPf5db98 X-Received: by 2002:a63:4706:: with SMTP id u6mr2120456pga.95.1549026877671; Fri, 01 Feb 2019 05:14:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549026877; cv=none; d=google.com; s=arc-20160816; b=p6PJ+LKdVMatdWxJWApsa3WwRsbt9KaJfRA5bDKfHvt1n+SsssgDVmw+9OP67VvEXn glQuPkxuU+avEf3ocZwCiJ8T704oeLw6UnlBmnAAGFFzibi/7V7wRlHb8V5grpsQ+Cfh ZEaLTS+oGoijANRX/f3pm/eIdLwkNQ1SOtZkJBNtjWIiAltHei+B+MOWvBtMJxVAZUYs Ttm1zwSE6PidKsjwXxUZKlCvI2eecYxXZL3saIqA4Apl7rPMB4ME1wx9EiSIM24SQWoP eZ+FnYuhGjCq1aTBKKaDsdMfYACeL75ZNmYGKKPXrQ1rEmIC+acqFJahUVhX9dQWDZth oAIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=XGnOO5ssKFVUMtoRGriu8kRC8ohsjZCAyEdm7mFXpzM=; b=iVdC1jc/L38vk5yy90h557uiynBSZD8JEyZdB2pWSlMZbWkz+o6+/hPeBdcXoM6eaq OERZw7YJhqzZ+NEWcjSqzIJkFwPrRfHLSNn/VgRZR5bkpbWr9uYfo8mohXZajy1pDUi/ 45LHkZkwQxTftSdPBmqrBTFXeKIvQA+Z+TSaLQU+36hPiTLSa5RmpkjjzXCKGtKZxs5f nQ9Etxtkdvsu+NqacROEHl21ybFh129OUCoK+7/oOLZE9V219LoESqjoXFnIRA0bGvjT y5MbiBpu8rX+bQ21a382EMin3Czcp3J9kKOtGqpvCNoxJythjSXATYSeac9nt73HHRIO GqNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si7704596pfg.280.2019.02.01.05.14.22; Fri, 01 Feb 2019 05:14:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729097AbfBANGK (ORCPT + 99 others); Fri, 1 Feb 2019 08:06:10 -0500 Received: from mx2.suse.de ([195.135.220.15]:36176 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727690AbfBANGK (ORCPT ); Fri, 1 Feb 2019 08:06:10 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3AAFEAD7B; Fri, 1 Feb 2019 13:06:08 +0000 (UTC) From: Nicolas Saenz Julienne To: oneukum@suse.com, Mathias Nyman , Greg Kroah-Hartman Cc: Nicolas Saenz Julienne , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC] usb: xhci: add Immediate Data Transfers support Date: Fri, 1 Feb 2019 14:06:02 +0100 Message-Id: <20190201130602.9171-1-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Immediate data transfers (IDT) allow the HCD to copy small chunks of data (up to 8bits) 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. An additional URB flag was created to mark whenever the URB doesn't need any DMA mapping. Ideally it would have been nice to use a private flag as this is specific to XHCI. Yet it's not possible as the URB private area is allocated only after the DMA mapping is done. Isochronous transfers are not implemented so far as it's hard to find a device that will send such small packets. This was tested using USB/serial adapter and by controlling the leds on an XBOX controller. There where no disruptions on the rest of USB devices attached on the system. Signed-off-by: Nicolas Saenz Julienne --- drivers/usb/host/xhci-ring.c | 6 ++++++ drivers/usb/host/xhci.c | 37 ++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 2 ++ include/linux/usb.h | 2 ++ 4 files changed, 47 insertions(+) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 40fa25c4d041..dd9805fb0566 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3272,6 +3272,12 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, field |= TRB_IOC; more_trbs_coming = false; td->last_trb = ring->enqueue; + + if (urb->transfer_flags & URB_NO_DMA_MAP) { + memcpy(&send_addr, urb->transfer_buffer, + full_len); + field |= TRB_IDT; + } } /* Only set interrupt on short packet for IN endpoints */ diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 005e65922608..ce3b6663f940 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1238,6 +1238,41 @@ EXPORT_SYMBOL_GPL(xhci_resume); /*-------------------------------------------------------------------------*/ +static void xhci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) +{ + if (urb->transfer_flags & URB_NO_DMA_MAP) + urb->transfer_flags &= ~URB_NO_DMA_MAP; + else + usb_hcd_unmap_urb_for_dma(hcd, urb); +} + +static int xhci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, + gfp_t mem_flags) +{ + int maxp = usb_endpoint_maxp(&urb->ep->desc); + int len = urb->transfer_buffer_length; + int ret = 0; + + /* + * Checks if URB is suitable for Immediate Transfer (IDT): instead of + * mapping the buffer for DMA and passing the address to the host + * controller, we copy the actual data into the TRB address register. + * This is limited to transfers up to 8 bytes. + * + * IDT is only supported for Bulk and Interrupt endpoints. Apart from + * the size constraints special care is taken to avoid cases where + * wMaxPacketSize is smaller than 8 bytes as it's not supported. + */ + if ((usb_endpoint_is_int_out(&urb->ep->desc) || + usb_endpoint_is_bulk_out(&urb->ep->desc)) && + maxp >= TRB_IDT_MAX_SIZE && len <= TRB_IDT_MAX_SIZE) + urb->transfer_flags |= URB_NO_DMA_MAP; + else + ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); + + return ret; +} + /** * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and * HCDs. Find the index for an endpoint given its descriptor. Use the return @@ -5155,6 +5190,8 @@ static const struct hc_driver xhci_hc_driver = { /* * managing i/o requests and associated device resources */ + .map_urb_for_dma = xhci_map_urb_for_dma, + .unmap_urb_for_dma = xhci_unmap_urb_for_dma, .urb_enqueue = xhci_urb_enqueue, .urb_dequeue = xhci_urb_dequeue, .alloc_dev = xhci_alloc_dev, diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 652dc36e3012..1b51999794b3 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1295,6 +1295,8 @@ enum xhci_setup_dev { #define TRB_IOC (1<<5) /* The buffer pointer contains immediate data */ #define TRB_IDT (1<<6) +/* TDs smaller 64bits this might use immediate data */ +#define TRB_IDT_MAX_SIZE 8 /* Block Event Interrupt */ #define TRB_BEI (1<<9) diff --git a/include/linux/usb.h b/include/linux/usb.h index 5e49e82c4368..1a6b2dfe7c72 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -1331,6 +1331,8 @@ extern int usb_disabled(void); #define URB_SETUP_MAP_LOCAL 0x00200000 /* HCD-local setup packet */ #define URB_DMA_SG_COMBINED 0x00400000 /* S-G entries were combined */ #define URB_ALIGNED_TEMP_BUFFER 0x00800000 /* Temp buffer was alloc'd */ +#define URB_NO_DMA_MAP 0x01000000 /* Data directly transferred to + * HC */ struct usb_iso_packet_descriptor { unsigned int offset; -- 2.20.1