From patchwork Wed Oct 2 14:39:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 832219 Delivered-To: patch@linaro.org Received: by 2002:a5d:43d2:0:b0:367:895a:4699 with SMTP id v18csp799252wrr; Wed, 2 Oct 2024 07:40:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUQG1SV90g8QUjLA1b6gBxYmhn49sPe02zG8HFNB9tLW/LyEoj96mguDKiK74hOCeEgk3BR0g==@linaro.org X-Google-Smtp-Source: AGHT+IEQd5JZRYXjDVTOeuJ3md68uJpRO63bJrUiE92xZEWZ/AEzdPMKiZxyReYiuOXtw68rWKKT X-Received: by 2002:a05:6e02:4aa:b0:3a0:a0a1:650c with SMTP id e9e14a558f8ab-3a365953623mr25730885ab.22.1727880003021; Wed, 02 Oct 2024 07:40:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727880003; cv=none; d=google.com; s=arc-20240605; b=a4UZW+m4X/grvl7H2oo3i1ACd1wuqqdbdNnPyGtlDJ2a9Uny1RkPxkkxXPca5mjmLV th73tKw0OSTE2OH8WA2PqaMgIMcU/iBdEEpMxEIfVLb7lmz4AQL7uOvo8Fms37oBYJfc PsNzRqjG6gLaO2URo+bH1ugbuQzg4luIXCBKa4Crvc1u2drEAz7eGHopAfnHsbeuzxJV vXGhZstsGH07WfiBANrhVx1xx9prI6+WTQthzADbTkZJpvNJJG9ZDXHXzqqh3PDQnlmf yQIxFGjfUx1a9dSMfdh5dM6OFd1Yeh8ylmXM943GaaSLeQmWw+Nek6PQ2qFHWDmWJ5AH BvJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=XbaWVpPZ0AENYL/jANVAHR/JFi93NTFANsG7ICTg4Ck=; fh=vCjtuMMb4aauC6lvV1Mwl4KM6dUuulRWNuIR3XESpcQ=; b=kH5iTsJ/GZRtxrRwCKGBhBvCldfXVvBSY3tIlUs128OSWiGKjggEF85Pym9Wujrb/b cCZC2LhFZ/WGEqv8/cP+6BZLofB7VBCo8uqvDiJ8MTzRzUMAJFx/qu1xlo3IDyVtoXNH kJnI21j2U29mPNq7tHOUQCZM+Rx179DbMQALCzKnDfxaq5N600G11IwfC3WzwteytaZH B7Cy6skwgJr+RAl7ZTQXqlNZJ4btu2R8PXXSnUMjeTDS1SreI4ojLrS17i77pBtnPtnn lOTVXlW4TOluDhQNU11fzxb2bF6Tl/US1jZ1gcaRhs81H9i2/mdLLqAZ2U6z+eELa3FG Utsw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yZhOz94h; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id e9e14a558f8ab-3a35eabebf4si21773465ab.172.2024.10.02.07.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 07:40:02 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yZhOz94h; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 122DF890CE; Wed, 2 Oct 2024 16:39:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="yZhOz94h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8711B890CE; Wed, 2 Oct 2024 16:39:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0532D890B7 for ; Wed, 2 Oct 2024 16:39:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=neil.armstrong@linaro.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42cde6b5094so61107235e9.3 for ; Wed, 02 Oct 2024 07:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727879977; x=1728484777; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=XbaWVpPZ0AENYL/jANVAHR/JFi93NTFANsG7ICTg4Ck=; b=yZhOz94hDVulakdphKEbPgiqPI5b0VSuxpX0g24u1KrvYxHvL+mRsPP2TgIaoVNN2X n3IyQ8IqcSkL5drtbeoUOskPUAQVbxFRfALdEQmWKE6xxEPClQfkFw9K6Aw5v/nyFPy0 bReF7zLxnXeZ6HZ4+fXS38EVaCqq8djsFowS2MWjFNLv3vJsoK9qXT7g8FjXfXdo4B4z FevOuWP2pAPfTIdFJYFBlcTEWuffuCWfVAjZsJPDXeKl5/KtxoayMRCq3oAgcW9Gyi1j miPqYCw44stRF6LRBETeFv/77O4XnX38a8gUKXioKidOSs1VJpBx3eKSu9jplxMml4N4 fVkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727879977; x=1728484777; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XbaWVpPZ0AENYL/jANVAHR/JFi93NTFANsG7ICTg4Ck=; b=De03viTK2gcshzDyI4cQFR/hZ5iV8/oOqm8Qytzdqfy/mHmS0qfIVTlw25Y967RZYj SnIM5bYJUnfoS6+ixYXZxFJvIbh4JuU3RIGrt0nGDklAW+UopsWD1h1lTKbVl1lrR90b 6pCT1Iajc+vDYOHunAdrnt8ZeZvndB0942WR1KQ4NaZ2RZ8YPUE7PacCKb8spoez4Q2b wcaa69VMp2+wpD7LnLJ1rB4yi4tspdYlRIukjEjbKlDuuv263cPOsN3ZPDviwxjr9X1s tW8mjTtUPWLBBo9/EckA4gPHcU00kdOPRXiEsypytGwqiRE3OMoG4qJXibZRnCHsFa6O Z7wA== X-Forwarded-Encrypted: i=1; AJvYcCXxhgXdtyRz+bA25jWq1pMz4EINWDWKV9XEkRnlnDjpse4GJwsKTmR/gwK3snXoR4VfHZFcfJ0=@lists.denx.de X-Gm-Message-State: AOJu0YwWhGpir032b8oVtP0DKBJK5fougiIot6TSKOcj/lFM2Bgwdl8b 4U9MSUPZgUBoCcLLJShB7FYTVc6QZvm4V7aansFWQE9ZOvcGfFJ0jTSogISo41s= X-Received: by 2002:a05:600c:230c:b0:42c:bdb0:c61e with SMTP id 5b1f17b1804b1-42f7a12bb01mr19673815e9.13.1727879977397; Wed, 02 Oct 2024 07:39:37 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm14056083f8f.60.2024.10.02.07.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 07:39:37 -0700 (PDT) From: Neil Armstrong Date: Wed, 02 Oct 2024 16:39:32 +0200 Subject: [PATCH v3 1/3] usb: dwc3: allocate setup_buf with dma_alloc_coherent() MIME-Version: 1.0 Message-Id: <20241002-u-boot-dwc3-gadget-dcache-fixup-v3-1-5398088ef93c@linaro.org> References: <20241002-u-boot-dwc3-gadget-dcache-fixup-v3-0-5398088ef93c@linaro.org> In-Reply-To: <20241002-u-boot-dwc3-gadget-dcache-fixup-v3-0-5398088ef93c@linaro.org> To: Marek Vasut , Tom Rini , Lukasz Majewski , Mattijs Korpershoek , Bin Meng Cc: Caleb Connolly , u-boot-qcom@groups.io, u-boot@lists.denx.de, Neil Armstrong X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3246; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=7pM47L/QmRm9ChxWkiFFuxDhel4FJ1Ku0kJr5Fv5KHY=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBm/VsmIEV//DLEZz7b/K39kxJw68uPbJ8t21e0Tg70 +wkNZHKJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZv1bJgAKCRB33NvayMhJ0e+wEA CHn2XDc0OWWLvEQ5O4CYmT8/HKJ0n/r5uVsp01piH+539J5NtxlglVBRo2+pUVDEE+AiKNFDVu2nlp SoV+iRomjaRUwNTzVW6jWrFVkuYYgV/Tw7Pm6zp/4SqA7K+9FT3JWOikQKr4Wlh0O9iBol/PwN1+Q2 5DrteMwlDAhFRC/UMsAU52pgF5cIk8vFEV9Jk+C+hmfodC/IWRWn47uTnkxjLFQW6/BZmpcgOwnmds WsKsWXvao/k5yPWc1kBvklDJit7zt3jh938mOe5FTGwgZ1NvEGPgb/L9WmN9H0YJS3TtABie7FFDuC pXKYse1I5PRPO/80kWgYntEwBFW7UlpSnjYUkiuE5BK1ea45kUupLwio0MCDkIaw8EKXhxQ8sI/54o RzYGSivNz7Nl6HTNIANnGfHOYerjkko8fVJdtAhdu95oVMbKvlqh3CJpcXH5usNt+mmG1Rk4AssoVQ ba935NN1kb67b0aH60ls+qYQHIrJRWsS9atFx+/C69U0m0dl8yIeE9nyZrickzMziOEGAyk47vhCfk EePW5sX/LQ0LPiC3tJKXPvmmEFLexz5KosXhngb0NAhBNiTX23NE8gPl3gH/aAxdkAnZ/mhNVUlj8t nJ5V3HzuNRRqEgr1yAnxRdfpqOdhWp4Ur81fPQ8H3ZiCtSFEdNGYaq8MKvCg== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Since setup_buf is also consumed by hardware DMA, aligns it's allocation like other hardware buffers by introduce setup_buf_addr populated by dma_alloc_coherent(), and use it to pass the physical address of the buffer to the hardware. Reviewed-by: Mattijs Korpershoek Signed-off-by: Neil Armstrong Reviewed-by: Marek Vasut --- drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/ep0.c | 4 ++-- drivers/usb/dwc3/gadget.c | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 7374ce950da..b572ea340c8 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -670,6 +670,7 @@ struct dwc3_scratchpad_array { * @ep0_trb: dma address of ep0_trb * @ep0_usb_req: dummy req used while handling STD USB requests * @ep0_bounce_addr: dma address of ep0_bounce + * @setup_buf_addr: dma address of setup_buf * @scratch_addr: dma address of scratchbuf * @lock: for synchronizing * @dev: pointer to our struct device @@ -757,6 +758,7 @@ struct dwc3 { dma_addr_t ep0_trb_addr; dma_addr_t ep0_bounce_addr; dma_addr_t scratch_addr; + dma_addr_t setup_buf_addr; struct dwc3_request ep0_usb_req; /* device lock */ diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 24f516a131b..8ba5fcd5312 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -380,7 +380,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc, dep = dwc->eps[0]; dwc->ep0_usb_req.dep = dep; dwc->ep0_usb_req.request.length = sizeof(*response_pkt); - dwc->ep0_usb_req.request.buf = dwc->setup_buf; + dwc->ep0_usb_req.request.buf = (void *)dwc->setup_buf_addr; dwc->ep0_usb_req.request.complete = dwc3_ep0_status_cmpl; return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); @@ -662,7 +662,7 @@ static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) dep = dwc->eps[0]; dwc->ep0_usb_req.dep = dep; dwc->ep0_usb_req.request.length = dep->endpoint.maxpacket; - dwc->ep0_usb_req.request.buf = dwc->setup_buf; + dwc->ep0_usb_req.request.buf = (void *)dwc->setup_buf_addr; dwc->ep0_usb_req.request.complete = dwc3_ep0_set_sel_cmpl; return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index fe33e307d3e..19c3a5f5e58 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2653,8 +2653,8 @@ int dwc3_gadget_init(struct dwc3 *dwc) goto err1; } - dwc->setup_buf = memalign(CONFIG_SYS_CACHELINE_SIZE, - DWC3_EP0_BOUNCE_SIZE); + dwc->setup_buf = dma_alloc_coherent(DWC3_EP0_BOUNCE_SIZE, + (unsigned long *)&dwc->setup_buf_addr); if (!dwc->setup_buf) { ret = -ENOMEM; goto err2; @@ -2701,7 +2701,7 @@ err4: dma_free_coherent(dwc->ep0_bounce); err3: - kfree(dwc->setup_buf); + dma_free_coherent(dwc->setup_buf); err2: dma_free_coherent(dwc->ep0_trb); @@ -2723,7 +2723,7 @@ void dwc3_gadget_exit(struct dwc3 *dwc) dma_free_coherent(dwc->ep0_bounce); - kfree(dwc->setup_buf); + dma_free_coherent(dwc->setup_buf); dma_free_coherent(dwc->ep0_trb);