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: 1992047 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=yZhOz94h; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XJcsc0fksz1xtY for ; Thu, 3 Oct 2024 00:40:04 +1000 (AEST) 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-Google-Smtp-Source: AGHT+IHnUz08VDsFm9VAJmWKew0h+88kQ6PtZK2naRD0H/+1AlsmVQX6rcYWXv/sICu5bn64WAORMg== 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); From patchwork Wed Oct 2 14:39:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 1992046 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=WesUoDMY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XJcsS4Ldrz1xtY for ; Thu, 3 Oct 2024 00:39:56 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BC27989034; Wed, 2 Oct 2024 16:39:42 +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="WesUoDMY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 805C8890F3; 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-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 C1E7E890CE 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-x331.google.com with SMTP id 5b1f17b1804b1-42cd46f3a26so55310675e9.2 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=1727879978; x=1728484778; 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=Kw110bgQIB++mEZ/IhsEoAMkwIQOj/pRBnQftJzGOqk=; b=WesUoDMY3K30sWUQGG+OvFNWSpuKn5mhUvN7h2da81QaA3T2JBgHPF5LhXsLuvRwKR ZiEgozRIQk2rWn2Qidkv1eNvced1U86Nt2Jz+jWyKqGIr1ca/9cr8UDqhOmf8Rf+dM51 WABrDtfg28kaSi6QKRZDZbdYo1jMS+mATQkrcmPPIU4n9pAbMQt2Gi70sJ1qUY4zfZIf 1JJYM2bf6ybUlUg8Q89tQoJx+m7O0p0W5TR0DTsDQVRodlSq5afvME22GPwO98wlM8at YVf17tIe3qRN5SSJfc/IgWDH+4f/AYXGIcZGdoXb8pzEMxtdAtFwfAg1KrtA9r/mvHQj 8wdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727879978; x=1728484778; 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=Kw110bgQIB++mEZ/IhsEoAMkwIQOj/pRBnQftJzGOqk=; b=wzjHa3FuwaVzRA7B5AhWwhNa668GtDXBkWKXPxlQls2cFLFHHndYnodtHWnLwdqMy/ PfhmtRdRqVcQ23994Z4pXeGf0CMaCJZQZKx7INRTgq52FDb7J++MGabXLVqu0Nht7vmL iz0KUNquQi8ZMrtOJXvzyrePctpKYtwNNISFb8GujXGBxh2Qf9WJivvss9gk58vyYJO4 zTH31JqcqSmyQnmMm9IbhCSVBDpnDJKjgt1Si/zslRmVs2oU7trWzIW0lLPxdu0KNKz+ sVTwLjSgripLjOSlelcDGy8avY8J1CG+uWm78qTITKzfZa3eTczg136zbnTQ/Xz69r1f Fjag== X-Forwarded-Encrypted: i=1; AJvYcCWAXMNMgRtMowzV6m4rI9I1mTxHLYmuYSZb/1N8+5dZJ4ji2gpDNz+X42LBVG7qwYTMm7toVgc=@lists.denx.de X-Gm-Message-State: AOJu0YzdE9q0tNit5vcqU/9FSf5OULIlL6h/Mp+ueR7xtv/MwCSmpD3+ F4Vih4smtxrqNtEzCdVfdjb20s4rVQFNpFlAp9acJQdO3qCypJJFtAdLZMIJelU= X-Google-Smtp-Source: AGHT+IHaCo7KnIIYzC5zjoVW7e/TAKzY3txwz2SYHgvUr7a08ELVpYIeRoXKMXWvSYonHTk1aF68PQ== X-Received: by 2002:a05:600c:4454:b0:42f:68e8:d874 with SMTP id 5b1f17b1804b1-42f778fa3c7mr23965155e9.31.1727879978166; Wed, 02 Oct 2024 07:39:38 -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.37 (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:33 +0200 Subject: [PATCH v3 2/3] usb: dwc3: fix dcache flush range calculation MIME-Version: 1.0 Message-Id: <20241002-u-boot-dwc3-gadget-dcache-fixup-v3-2-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=1510; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=y5L/ah81b52wg2BmUIBDjC9IK51neBebBKPXX2bS1kY=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBm/VsncgLj8ZE6ED+Md4TtA91Kn2hdkE1XO7lhZWvK WjJbWUqJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZv1bJwAKCRB33NvayMhJ0XQOD/ 4zFItGtjvmgfMrc4tdNBqGcrgt3ca2zr57HvavxIadd8tHujqtoqxaWHHqCjIO0gvg+9fAC8lDmns2 6vCEmMsGJlLEtjztYRJGYQvRdcvqetzdwPAUGLdRWvM4TM22+m8DEFdP7fhAHbFVJFufvr+pAFQySc 2Kky04jHSJry+UhYSyTbQHPUTtXpCW7JGxlk7ScS8w0O5Y0bwRgdjk60eOICT66y3cRoZSoDErfIjb yLh3mzOZPYznEEyjfQSeq1Y7dSvedjuatxdXZtTf+LpHp/tBU/XMhtlO2d/fFL8RxDromOF3l25z0a 5pEQ93lGtnzeNZEpACPJ+W13n+YBlkIB3IljXCldt8+YN78fw1nWo0/lSt6JS+6GnmwsKKJPC1/lmM HOyRyVy4yilAf0iwkNEOoV6zwGale+3HXuOmBIJl9Ao++xFx1szK1jWTjoQAhMN5hdndptsG0SlgNU dgsDuXYK5UNRQC9G7buIjRRMcDyc/rqfnchmnei3w3R/06TbBYuXUXvTklNlUij+kEuILjv9c/e0VW 4lZE6c1Zll6TioiQQTBNCwaDTHHFfCQDlMvYkDTO+YFeA4BoauucBJgN1qMpwEI80/wZoPn+J0RE8m POM5wPmbnoT3pX4oGklZwqarSJTuI1e0xhnILhc3pzQrFSUrngHtLzdzcKnQ== 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 The current flush operation will omit doing a flush/invalidate on the first and last bytes if the base address and size are not aligned with DMA_MINALIGN. This causes operation failures Qualcomm platforms. Take in account the alignment and size of the buffer and also flush the previous and last cacheline. Remove CACHELINE_SIZE which was the same as DMA_MINALIGN. Reviewed-by: Mattijs Korpershoek Signed-off-by: Neil Armstrong --- drivers/usb/dwc3/io.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h index 04791d4c9be..a6c2bb0f47d 100644 --- a/drivers/usb/dwc3/io.h +++ b/drivers/usb/dwc3/io.h @@ -20,7 +20,6 @@ #include #include -#define CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE static inline u32 dwc3_readl(void __iomem *base, u32 offset) { unsigned long offs = offset - DWC3_GLOBALS_REGS_START; @@ -50,6 +49,9 @@ static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value) static inline void dwc3_flush_cache(uintptr_t addr, int length) { - flush_dcache_range(addr, addr + ROUND(length, CACHELINE_SIZE)); + uintptr_t start_addr = (uintptr_t)addr & ~(ARCH_DMA_MINALIGN - 1); + uintptr_t end_addr = ALIGN((uintptr_t)addr + length, ARCH_DMA_MINALIGN); + + flush_dcache_range((unsigned long)start_addr, (unsigned long)end_addr); } #endif /* __DRIVERS_USB_DWC3_IO_H */ From patchwork Wed Oct 2 14:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 1992048 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=GnqFawC8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XJcsr0YRQz1xtY for ; Thu, 3 Oct 2024 00:40:16 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 60EEC89001; Wed, 2 Oct 2024 16:39:45 +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="GnqFawC8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD3D288DD4; Wed, 2 Oct 2024 16:39:44 +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=unavailable autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 8DA67890DF for ; Wed, 2 Oct 2024 16:39:39 +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-wr1-x431.google.com with SMTP id ffacd0b85a97d-37cdb6ebc1cso2808280f8f.1 for ; Wed, 02 Oct 2024 07:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727879979; x=1728484779; 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=HXGHuBI7DESo+MXQROKR49q8aImAvCPU6dR7n5FZxQs=; b=GnqFawC8L5Hqm/oohzb7qb7wC9EXpF1rbKkE+yHFYyccS3E/sgh6nHcz8u9TaGZPYF JlaSRF+qWALD6uX+xCc2DN/XzvDhxlLNjqVD/N+2JowY5HzV4rEJoPruwCTaupcuTyKQ gzz3/AKeWNOivfbGJ0xkXw3aJBGlGLt3HLsxO1fGuo1Jv+o6wrD2qcTHAGQSJQQJQC0Z 49ywofNcE1hHhkc9YaM7zZ0efEDTEGwKA3OuRMWiVb+u2mdgia0tsPjfCKzfVGV9X/Yw hYPUXE95Uavr4VeBMhpls+cf/Y+1ASmU5cHlmQ4gHVsRoz2zj8xSDblkVNti5y8ldAAH KgPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727879979; x=1728484779; 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=HXGHuBI7DESo+MXQROKR49q8aImAvCPU6dR7n5FZxQs=; b=vfUfrwJAZ+a8peAJzevSkA/U9IrwyFRkogQff0++jy/g+kbT14aMeDdmoIb5mKrm9s +xjEoAdVPV/KtodC5FKq3Q06KFsJ0ez6zyReYLMysgtB2eb2iZQHgHsz5T/152KOUU3Y RWKk8leIbCtai/G/RJ+WGm2evNo452G8sQ6kW7pcqhYzukZblz02Qu9K8XrGt88SjlMq IA+bn1/5Vsb/wMd871lmo+njJ/77fJIHSEv/VYk/aieC49eOGGvhzyYdIDh68PpOq9O1 NEJ+5/1QSiew8SkHxb4aAaRV2YM3q/nfQuYCE4q4qtsiW/w/UqUz2Vokw37SI9ITYhsB +kFA== X-Forwarded-Encrypted: i=1; AJvYcCU/XbL5jbuxG6ObAjQBupw25lckS/LJWKtTUyC2X5B5taenrOxvckH8udx2hXeoDtmv2uNGmvk=@lists.denx.de X-Gm-Message-State: AOJu0Yyghmj+fj9F9EEMs7eGmjNi+SfJklwTwuf0ClYTrdmQqATNRi7H qP9QbNiiURncgvj+b17TODmPxaGvWxiV1M+DLIBqzI6FzomXLE6ShF3k+lTuMuI= X-Google-Smtp-Source: AGHT+IHuTHlB+UTttxLT9ZtGXGtAPCfnLKXwdr7Wufpul83RmuYVUn92Pmwl69MFTSGlIJX1YrNbxg== X-Received: by 2002:a5d:540e:0:b0:37c:cdcd:689e with SMTP id ffacd0b85a97d-37cfb9d4541mr1868481f8f.31.1727879978946; Wed, 02 Oct 2024 07:39:38 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 07:39:38 -0700 (PDT) From: Neil Armstrong Date: Wed, 02 Oct 2024 16:39:34 +0200 Subject: [PATCH v3 3/3] usb: dwc3: invalidate dcache on buffer used in interrupt handling MIME-Version: 1.0 Message-Id: <20241002-u-boot-dwc3-gadget-dcache-fixup-v3-3-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=2493; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=a5B8p3C7xIZv9mgyWkU0YkXLsCnCIPXjs/MTJ6LPpa0=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBm/VsnPRxaGopPKsFMdfeqrjFH1wyDJ7rDBeYGGQCE 2sRf7kiJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZv1bJwAKCRB33NvayMhJ0d6JEA C09w7wvW04GbO4Ick0NQdlB8QQptBIGnqvDVfv5fzmfwGf78A9Evl9W3URJWGmXBDCiiA+CDVdpKw8 5Z+41HYRJDttWJ7mB9SBqJOTkC912jgLrgKkZDKlXS1DWwOhw3ev5NSrX/0ASHN8wjkKjJzPy1iSXE oLQdOh1LOCB2nO0aJxL3EuMOjCp2+u5vBGON2fe2dxNCnWJrvwt/0n2EEEVPhlM2c4t8pfPTsYiFYn zvdfnS+/VwZmUGOqyrDVk6zxQnbtPzt2TbLFC7tPwncLdi/5aaoGNYBD+VRXOFyNpu+xO1pnjE0Mlu wnzKFFXstKhhXc5BRElkVH1hf68IbMmU0zgLBqJ5vLfEXnug5d6UWNSy+tOxHI0bvJljbghXPcfU6x ukJk4oC/wskr9HYnvXuANqqqRBlPv5CnwaFISICkF295dtYqmkyOmCnPZWfFAdGFZ8rL5huwzLcXpu BtHDgRbhZVlsWR8hhaqbuzz9/c1JSsWyEsxMAJxceXRahS4ztxTcho90iCLBy6XExukMVbgQbJpNJU s11dYvAHqXx0wvzpBqGba9RyikNpKI5O+widNJybs/Rx+aPka1+uoINMYkstTBtHRNMzhseEuyk1Qe ooCOEPaMa3e3NS03kwZQrnl9EFxGbd9gKgX1mHvLtpImOdcwKuavs3Vgl23g== 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 On Qualcomm systems, the setup buffer and even buffers are in a bad state at interrupt handling, so invalidate the dcache lines for the setup_buf and event buffer to make sure we read correct data written by the hardware. This fixes the following error: dwc3-generic-peripheral usb@a600000: UNKNOWN IRQ type -1 dwc3-generic-peripheral usb@a600000: UNKNOWN IRQ type 4673109 and invalid situation in dwc3_gadget_giveback() because setup_buf content is read at 0s and leads to fatal crash fixed by [1]. [1] https://lore.kernel.org/all/20240528-topic-sm8x50-dwc3-gadget-crash-fix-v1-1-58434ab4b3d3@linaro.org/ Reviewed-by: Mattijs Korpershoek Signed-off-by: Neil Armstrong --- drivers/usb/dwc3/ep0.c | 2 ++ drivers/usb/dwc3/gadget.c | 2 ++ drivers/usb/dwc3/io.h | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 8ba5fcd5312..531f0b522af 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -742,6 +742,8 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, if (!dwc->gadget_driver) goto out; + dwc3_invalidate_cache((uintptr_t)ctrl, sizeof(*ctrl)); + len = le16_to_cpu(ctrl->wLength); if (!len) { dwc->three_stage_setup = false; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 19c3a5f5e58..e5a383407a2 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2534,6 +2534,8 @@ static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf) while (left > 0) { union dwc3_event event; + dwc3_invalidate_cache((uintptr_t)evt->buf, evt->length); + event.raw = *(u32 *) (evt->buf + evt->lpos); dwc3_process_event_entry(dwc, &event); diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h index a6c2bb0f47d..b347a7f1fc1 100644 --- a/drivers/usb/dwc3/io.h +++ b/drivers/usb/dwc3/io.h @@ -54,4 +54,12 @@ static inline void dwc3_flush_cache(uintptr_t addr, int length) flush_dcache_range((unsigned long)start_addr, (unsigned long)end_addr); } + +static inline void dwc3_invalidate_cache(uintptr_t addr, int length) +{ + uintptr_t start_addr = (uintptr_t)addr & ~(ARCH_DMA_MINALIGN - 1); + uintptr_t end_addr = ALIGN((uintptr_t)addr + length, ARCH_DMA_MINALIGN); + + invalidate_dcache_range((unsigned long)start_addr, (unsigned long)end_addr); +} #endif /* __DRIVERS_USB_DWC3_IO_H */