Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752708AbdHKKQq (ORCPT ); Fri, 11 Aug 2017 06:16:46 -0400 Received: from mail-co1nam03on0051.outbound.protection.outlook.com ([104.47.40.51]:59008 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751873AbdHKKQn (ORCPT ); Fri, 11 Aug 2017 06:16:43 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: To: , , Rob Herring , Mark Rutland , Russell King , Felipe Balbi CC: open list , open list , moderated list , open list , Laurent Pinchart , Stefano Stabellini , Catalin Marinas , Bart Van Assche , Doug Ledford , Greg Kroah-Hartman , Rajesh Bhagat Subject: [PATCH 2/3] usb: dwc3 : Add support for USB snooping Date: Fri, 11 Aug 2017 17:59:56 +0800 Message-ID: <1502445596-33716-1-git-send-email-yinbo.zhu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131469202010660964;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.158.2;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(336005)(39380400002)(39860400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(305945005)(107886003)(106466001)(2906002)(77096006)(8676002)(36756003)(4326008)(5003940100001)(2876002)(69596002)(68736007)(81166006)(81156014)(626005)(105606002)(50986999)(50226002)(50466002)(356003)(498600001)(8656003)(575784001)(86152003)(54906002)(104016004)(5660300001)(97736004)(86362001)(8936002)(7416002)(189998001)(85426001)(47776003)(6666003)(53936002)(33646002)(48376002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR03MB3318;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BL2FFO11FD021;1:TXOuuIGo48/A3WiLkKCScjjpyB8HNAj3voM6C/e/wE?= =?us-ascii?Q?giZdtPWtwEKZzroDB9U7UiBzInHxSJ3SA/4W1jgIf/EYw+jq+SfbMnttzVRX?= =?us-ascii?Q?uew9vncK9/azoKq4fLJt0h2rYKw8Tzf5qxJvHDQEooSKwBhrITFEyA5BfKM6?= =?us-ascii?Q?km/hCmUsDFPBtwdJYvc4T4YrrfKkqBzOSG7WfyKASdvMQTfBVwOAqoUgXIdz?= =?us-ascii?Q?AsGBb5NS26H+MeBpSCf00dSY2DHqP5iC0cR2L3Eceo+xL4GC6VCBRmhH16kz?= =?us-ascii?Q?HmF96HGREZ68UidF23K+ucOcXWZxJkuDbFkrdYgRYoPlCb5Wpi//SC4cANM2?= =?us-ascii?Q?3Li6Rgb4iO/h5K0Nr94PYAgJtr/3pj0LujtI+DauwRmkxKVRsaVljKVVjWp8?= =?us-ascii?Q?luF8cs9FEsnRE8q85JKTwVnLJM1uB67TZdg5cyt4ofd2CFNZYCx+QiKsXpKi?= =?us-ascii?Q?8nfp3hHKQPOZwrbcwf4XzTOG1sUGRoH6xSj5eEF7G8DttWYKN9jCKTM9UZCY?= =?us-ascii?Q?repvI/6HkodCXfHKLgnUcMXDfc/ZJfMSCc2EYYM+GukPxpR7K28bgSIImo48?= =?us-ascii?Q?cYmAYD78hYEkiA4BxfB4/FzGDjwG+bWsot0SKw6OMvGTjRZYVfSaUByBTo+N?= =?us-ascii?Q?tXQSVnXC0GWsIfZoC3JXE//wcQA+t/+OQyVMxfWEiHJnX0NLwwqSvb0u/oYQ?= =?us-ascii?Q?HW14KeS7Kle5+lxFs7tUR4BKZ7MtET4O8d9rUxo/rG4h8LD/vwOsfmEh4Cg5?= =?us-ascii?Q?XM/53PePss4tGn/lHufk18rG3JRS7aKUCADxiDL+M3xYuAiCaGinXGZdoH+9?= =?us-ascii?Q?KXvIM09dXYkC7yD8J+C42NlTuwwwJlWBQFN8brgNJzWTMIoo5zMR56tA/Yka?= =?us-ascii?Q?xL7hnryaW4Fn0YWN+Kl2yVk7a6Gni1TxsvA9v1LRc+Y6VCM2xd+YZOlx7Pnu?= =?us-ascii?Q?9mgE1oDhYvtEcgC+c28rr/R3VPkUASvZxsVvh6XvrBrIN5ia43GqGD2rGR+x?= =?us-ascii?Q?EY0JWRgaYr3zPHyTHrioYQ?= MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ade1d8e-dff4-4455-7404-08d4e0a20f21 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(300000503095)(300135400095)(2017052603031)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CY4PR03MB3318; X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB3318;3:KAWjkvBvfYQ4QoOqyVNh2shP5a2Kp08r2WD/ACuNSJTclPQTbyixeOFqzQqB47ZyHBqEFa0rRRUY1VZKJnsTZBb2/vKe9TmKDBN3UUMr5JSod7aHAZ18nDGkG1EOo1kiCoPNcxAOkS8FZsqROc/g3ZWKKPME7KMOPqeolEruDkZNCCUGQIn6yLSeezB/6cm16UKeKsQV3ldnClpUq/UI7OKthOXqAP4lmJDZv0a8RMSqemRwTfwEDzGZ9+MiKhjmsv/9DwtjsaeaigHrijeq97zEM2Nh8t3PfxAuqKMp8n0TIR+LOWRZrBuRlTbv/TABtU3xtZLXhxIrfUCsnO0FF8BAcA00xWR348N0h0ErOd8=;25:9B0zXRn5yEWEEm9JMz/O+NevfFg8eEONYbZnXDIukQH0ecsSnh/KfAwBbRZz2TpAwcZqi1GGKdD0ysHxlVPuYDQbt9r4Z0s2a/n/wqIJFcZDdJV8DBPUF61gvxiN8ZsBc4m/ImcdVnH1H2A1TlQcAMY1B8DXxn6QdBWrdefhmC14vvrXSYw0Bntx4g7zWwdE+JfDyz+p22SWQthuXQixN0OYgesaTA8MbQ9mgnhRSDG+pd67W5B6zwgL5Zwuz7dP2shCbgGXrf+uqETFoutXIB0V29PM5wIR2c2japsmzzVtkfPdc2+WQrVBpbA4bHkbViLyRNSjYTw/22qdBzZXtg== X-MS-TrafficTypeDiagnostic: CY4PR03MB3318: X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB3318;31:dcN8nRS7BNFZWUuqATHBX3VVrtGFOYh7B/XebllSKeqKGdHr/RPVG8QtHh762nJH3pHxvRkHyNuX/sKRMZBGgYO60ULJXcmgcmFPcyp0znJUIIvtvHUj3jwZ4CRafJbogPgAgaBciEB07RPupf6zrn4kum81/78Oj3nv56ZkNo4UsUmnARHM2oGdvhyh3j3mA/5f5SJ/0l2d9jnKSie5lpFxbVWO0czdYYfawL/+Ltc=;4:jQi38jVgemnjTaOzZBZTTwaYRymIJkysdB7GGVhurK8SbEGLTG3Jygps2RzXXaJ52IQ/cTuGsHZWWr9VoArxBbbm0b4VzRoZe8joPPjxJD/6P6kAXaNrQR7O9dmYHBSUr2nN/8y+9KLPUDr2IHk+m7OiYaQS7ylG/WWNywyNxxBD2Q3Rc8ez3wa5csrby6PfjSoQKOsOnuzw34l7ROltimSrGOZnzKUqUPDVDndWg6NnyQOEr0Ii0bD+y58zMbQFKuIz7CcFlOsdYkdXG4A4K+MGhK2IhexWxPNH5yVMFAir4bcY0bAgl7naUlccYLxKlQsCigpRLMtX9XLAuz2HRQ== X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(101931422205132); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(601004)(2401047)(5005006)(13016025)(13018025)(8121501046)(10201501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6096035)(20161123559100)(20161123563025)(201703131430075)(201703131441075)(201703131448075)(201703131433075)(201703161259150)(20161123556025)(20161123561025)(20161123565025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR03MB3318;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR03MB3318; X-Forefront-PRVS: 03965EFC76 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR03MB3318;23:Cqvi4UKQEYRrQwyhJJNWLwknflHohvOn9Zj2bLN+F?= =?us-ascii?Q?zqr8/kPORlEnipp2Cuh04F6W4K698TjObUensEJFQcnNRGBi6/cQuUmzy/Sl?= =?us-ascii?Q?AfcS/TMcM/7LdUz1vrtkpMH5PF848TfqpV6xHonnuWCy8Qaq5XoBbc5e4geF?= =?us-ascii?Q?YgsT1yr8ymIyu3YbKQV8mdE0tBfPj7z6Jp28YRve66xVTY2OGqNZcVXnlumE?= =?us-ascii?Q?8/oUV4TfTp8wgXJpTwWbsF+6x6T6iGoINAFERb2/qk5IpcnRxgGkXK/n7jIG?= =?us-ascii?Q?Y0SiHKVLTJWSLB0oXimJSNeY9WA7VP5IW8JcHYL8rvFlLasawFFtIp70pYQT?= =?us-ascii?Q?1RXN+H2MW0V90QWs3WKXy+Ig/gvKhkXbKnaiBxD8v0I++1nMieuEM4ms58/l?= =?us-ascii?Q?fsDPFA3vB3GOZD+R/cfs27kYSSuBd+sJaluQXexkVpKFpFkViSpmgaBlYuRs?= =?us-ascii?Q?kB+zA2BWHkKBRMr1kY4ppB1f3/81lfaAG9HIEkDoXzLwu92iFqXYskqO5ApD?= =?us-ascii?Q?2eH/PGUr/Fr3rvLaknZa1mSkjvHsnRsrj2KZiXUEY8CgVS1+mZ71DMxJ2lp2?= =?us-ascii?Q?i5I6HACz+XnwAWOyAAUmNj8kZRg7wMFwhzZQYQMvkgklFzXnpVQB+x8+AvJz?= =?us-ascii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WgnjelbXCoe7sVKw3NPvnCzBOdVb1lZXOMuK1GYe1wvBWg0K7681PPm4HjQQpLSfGq2cRP09ZT2FySVNjnofcMF32Mvvn6nGqRs0fmdO44A==;24:mCcBRSd4F6kSK7u5CAzCs7ED4IY8gWAvKHAm3QEAwUfct+SFku42f8jLPxxZlCq8Q3/8yE3NU7kPmzJP/RiaDpPGZw0Cj46hTYamzoQl5ek=;7:tDwY5QHLCTbC+2gXIFK4Y0joBqIYUUDxJZmRcVEA2M0Sz+bGeypm1T9d4dtEyo7DA1hRaD6UOX+kW9lUQQNnbqMCDmJtm0VpNMr/phYT+Oeng1Yl2veX0itekQ5t/VlNlQDwIDegoP5EdvECLBLCrmGqqFyh0P9NX4XqSmMI93ilHVL0zLDjaQBg+J+sZDZyHX9wGhD7nFBkit++o+nS2kB/djmW2ehakeiuBKFFu98= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2017 10:16:40.6448 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR03MB3318 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5472 Lines: 183 From: Rajesh Bhagat Add support for USB3 snooping by asserting bits in register DWC3_GSBUSCFG0 for data and descriptor Signed-off-by: Nikhil Badola Signed-off-by: Rajesh Bhagat Signed-off-by: yinbo.zhu --- drivers/usb/dwc3/core.c | 71 ++++++++++++++++++++++++++++++++++++------------- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/host.c | 8 +++++- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 02a534a..b51b0d8 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -90,6 +90,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc) if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) mode = USB_DR_MODE_HOST; + else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) mode = USB_DR_MODE_PERIPHERAL; } @@ -305,14 +306,27 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc) */ static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) { - struct dwc3_event_buffer *evt; + int num; + int i; + + num = DWC3_NUM_INT(dwc->hwparams.hwparams1); + dwc->num_event_buffers = num; + + dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num, + GFP_KERNEL); + if (!dwc->ev_buffs) + return -ENOMEM; - evt = dwc3_alloc_one_event_buffer(dwc, length); - if (IS_ERR(evt)) { - dev_err(dwc->dev, "can't allocate event buffer\n"); - return PTR_ERR(evt); + for (i = 0; i < num; i++) { + struct dwc3_event_buffer *evt; + + evt = dwc3_alloc_one_event_buffer(dwc, length); + if (IS_ERR(evt)) { + dev_err(dwc->dev, "can't allocate event buffer\n"); + return PTR_ERR(evt); + } + dwc->ev_buffs[i] = evt; } - dwc->ev_buf = evt; return 0; } @@ -325,17 +339,25 @@ static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) */ static int dwc3_event_buffers_setup(struct dwc3 *dwc) { - struct dwc3_event_buffer *evt; - - evt = dwc->ev_buf; - evt->lpos = 0; - dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), - lower_32_bits(evt->dma)); - dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), - upper_32_bits(evt->dma)); - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), - DWC3_GEVNTSIZ_SIZE(evt->length)); - dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); + struct dwc3_event_buffer *evt; + int n; + + for (n = 0; n < dwc->num_event_buffers; n++) { + evt = dwc->ev_buffs[n]; + dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n", + evt->buf, (unsigned long long) evt->dma, + evt->length); + + evt->lpos = 0; + + dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), + lower_32_bits(evt->dma)); + dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), + upper_32_bits(evt->dma)); + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), + DWC3_GEVNTSIZ_SIZE(evt->length)); + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0); + } return 0; } @@ -1181,6 +1203,7 @@ static void dwc3_check_params(struct dwc3 *dwc) static int dwc3_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct device_node *node = dev->of_node; struct resource *res; struct dwc3 *dwc; @@ -1188,7 +1211,6 @@ static int dwc3_probe(struct platform_device *pdev) void __iomem *regs; - struct device_node *node = dev->of_node; dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); if (!dwc) return -ENOMEM; @@ -1260,6 +1282,19 @@ static int dwc3_probe(struct platform_device *pdev) goto err2; } + /* Change burst beat and outstanding pipelined transfers requests */ + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, + (dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) & ~0xff) | 0xf); + dwc3_writel(dwc->regs, DWC3_GSBUSCFG1, + dwc3_readl(dwc->regs, DWC3_GSBUSCFG1) | 0xf00); + + /* Enable Snooping */ + if (node && of_dma_is_coherent(node)) { + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, + dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) | 0x22220000); + dev_dbg(dev, "enabled snooping for usb\n"); + } + ret = dwc3_get_dr_mode(dwc); if (ret) goto err3; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index b83388f..e075665 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -913,6 +914,7 @@ struct dwc3 { struct platform_device *xhci; struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM]; + struct dwc3_event_buffer **ev_buffs; struct dwc3_event_buffer *ev_buf; struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; @@ -946,6 +948,7 @@ struct dwc3 { u32 incrx_type[2]; u32 irq_gadget; u32 nr_scratch; + u32 num_event_buffers; u32 u1u2; u32 maximum_speed; diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index 3e85616..0f2b86c 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -93,8 +93,14 @@ int dwc3_host_init(struct dwc3 *dwc) dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask); xhci->dev.parent = dwc->dev; - xhci->dev.dma_mask = dwc->dev->dma_mask; + xhci->dev.dma_parms = dwc->dev->dma_parms; + + /* set DMA operations */ + if (dwc->dev->of_node && of_dma_is_coherent(dwc->dev->of_node)) { + xhci->dev.archdata.dma_ops = dwc->dev->archdata.dma_ops; + dev_dbg(dwc->dev, "set dma_ops for usb\n"); + } dwc->xhci = xhci; -- 2.1.0.27.g96db324