From patchwork Tue Sep 10 09:20:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 826946 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp205827wrc; Tue, 10 Sep 2024 02:21:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUkQs9Zlr3QWGJo8JNCivHjQrP/45H567q6wLv0I9+ANQUMuvmj7x6wYg74qzLcrORNjz3DMw==@linaro.org X-Google-Smtp-Source: AGHT+IEwQ4FYTw34eMLGxqOmRMktTPEU1+bPDn6a1X5MLn9RJetstknDgUFBx69ZJ8qt7ksAGZtO X-Received: by 2002:a05:600c:358a:b0:42c:ba1f:5482 with SMTP id 5b1f17b1804b1-42cba1f598fmr34697895e9.35.1725960067074; Tue, 10 Sep 2024 02:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725960067; cv=none; d=google.com; s=arc-20240605; b=l1BjEWWDbs6rJ7/8caxLd4oT3sDwlKAWag65Jqo8WS90p5Pat2s8G6/YOwGmhjQ7uE IP+suZxwvDKIksh1+n9uT4A7zKDn0HOjAQQtegK2ZI4E92v4kwAVSTQcrr2H9iRUy8An RP8/7lWsgLrQwAiaRDecYYYZXO+l+MkTmifB5p8uGc4bBANaw+Xuwh352A2n0fQnoDpH gd1Q528eqmvJOPG2PSicpNvqKgkCPBrx0xr8BkWO0+lwVR+cMhhro24WWGTomNewpj6r +bQ+8ywWk7JOaE2d93wu2RbZPJIFMx5gQnzNynEBg2eCwyH02jn/ZPNJqoxKp/vciArw mYUQ== 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=oqKlusR5GPCCrTUypghPMVt4yqn9KaI81pA8qZgjw04=; fh=MpQxDFwiapfMzPUCjtB/tGQ74Yoee5eRTjQ1h4khh8w=; b=ec/kWCW54lAMcQmSU5GZFNZg+XnQOvU97kfVdTTR0dBVeJgWxF08CO90JZ5shBsqaP gn/MK6CJMuHJObWI8CqQArMksWsWF0wvGRSe7UK3DV3cn4O6Ofxx25bv1YBznMCM62x2 WZkM1QEcFLDzAhxRv8XTj6QuWANVxUOEfNNOxtvWvUFXi4kCedzslUmAn6w1c8jIdWiQ lX1q+kGHQygimUxDatCJjXfhUGWyd5EcKwW1ABuDU715cyWsIRH8kQkJJ6sL2buBJxj8 ceOSeLUwSwteE2Ql8wHad7dUhrSW3goZc2QpfxtB3+WatTIDWixV0NlWnETwDML+m/wG hSsA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z1aFuhwi; 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 5b1f17b1804b1-42cb4f1f2ecsi24719105e9.87.2024.09.10.02.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 02:21:07 -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=z1aFuhwi; 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 EB43A88F90; Tue, 10 Sep 2024 11:20:40 +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="z1aFuhwi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8738B88F8C; Tue, 10 Sep 2024 11:20:39 +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-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 D47DF88F75 for ; Tue, 10 Sep 2024 11:20:35 +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-x32a.google.com with SMTP id 5b1f17b1804b1-42cafda818aso27663305e9.2 for ; Tue, 10 Sep 2024 02:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725960031; x=1726564831; 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=oqKlusR5GPCCrTUypghPMVt4yqn9KaI81pA8qZgjw04=; b=z1aFuhwiiaX4GJxZdcaXmA6X78ZsjAfBcMkDtReeSIHjULpf3YJWsXBHaGOODdMeE/ FMXE1gtjqdkLHYp0rOD3Ue6o9rIOLieRJhk2UIR4WOC66OS6pzvd21qXXvJ74ldFjMK6 E7RTooowCKHR767WtWTA77CA5hyGuxP8HGz7q8y4XaDs/K74VlFYTuv+0xKq45imJ3c6 NPpSw2gXl3+Mmyqf6125YAEcaCydaOJWnBK9XAjLM45Gth3DEBE5ANjCzSCXWOVN68N9 LtcGZe8RQgbIpu+eP5R0xJ9ID+m3nZFqaEE6xVxtJI0yaEPKwTvPLj4Q0/EjPtS1pfME 7PQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725960031; x=1726564831; 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=oqKlusR5GPCCrTUypghPMVt4yqn9KaI81pA8qZgjw04=; b=r/SbP4ERSLt/HPhXaMzK77bQ7tH86g0zkUD4XPX3a3j5L+cIIKQWiom7FiHc7UiG+2 lDuQtxKWNz+oEqTSnPI9b586p8BTz3UT2lL3f7RM9XodrKlE+umMzev+3/xnGPnmP2Yv 7nF+l3uU9YNrI9r9Bvye68BBdIl2JbBowc0vPPsxcx+xyJ+9kDg/HA4r8K8injDSEHYI QJ9OMFrBFbMBYbYu5uIxidScgB0pW+9Ad4gKrw9GniQGX0LKi19R/MyyzNEVdQ2AOhRm +fGVLAL4RqDnC4X+edb7Ni4moaFj407NkB8tgaUEpLbUjs3XELhiSyb86slZO5DaoxXP Bkqw== X-Gm-Message-State: AOJu0Yz2H8C+W2e3kO19nx2Rk9l5ku2SgqljEm0UUTUs17P84KrUTMbh bR/6Fm8K/kD8cgN0fAlawajUbzBbMr4c5sQef1myzLRM5+bhwtnca4ytREcxW0g= X-Received: by 2002:a7b:c345:0:b0:42c:b6e4:e3aa with SMTP id 5b1f17b1804b1-42cb6e4e445mr51403875e9.5.1725960031359; Tue, 10 Sep 2024 02:20:31 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb099acf6sm101256245e9.9.2024.09.10.02.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 02:20:31 -0700 (PDT) From: Neil Armstrong Date: Tue, 10 Sep 2024 11:20:21 +0200 Subject: [PATCH 04/13] ufs: use dcache helpers for scsi_cmd data and only invalidate if necessary MIME-Version: 1.0 Message-Id: <20240910-topic-ufs-enhancements-v1-4-3ee0bffacc64@linaro.org> References: <20240910-topic-ufs-enhancements-v1-0-3ee0bffacc64@linaro.org> In-Reply-To: <20240910-topic-ufs-enhancements-v1-0-3ee0bffacc64@linaro.org> To: Tom Rini , Bhupesh Sharma , Neha Malcom Francis Cc: u-boot@lists.denx.de, u-boot-qcom@groups.io, Neil Armstrong X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1884; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=lxI4HS7I1NPzQe4WEGjAEWu+wJ/tDWmbIzQmUpETYAY=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBm4A9XKZOOFnS0AMMQKlbGWz/p83lvY6NFAV9oBlUm sbFm7juJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZuAPVwAKCRB33NvayMhJ0R9VEA CMpaNJQFU69INFouPBXUVEgJr3sjbVCzjeo3yZelU+m6KHNDt5qOcscvyRvOj8fNpRfDfPSkCcGtT6 FUa9PR36vf83JX1jAvW/IQvdEzuaiK0lPelOJr0gqw79cNslPTI67LFAHIvFS80GDHBE0H79p3la9g IJmX1+tQK7uvHtUDa5QCHi3VuRZXqC14yOkSqo6MlRRDTfLRhmAWh24ikWGIilwz2+5fa8S2HYrD4J 9hw4vqhGCLRYIgts6lv2PL29RhYBv8rRdTIXAbnFpz6QApY8q6o+/aihQk0531zu8lBs+uR/OqGYR+ 1C46MWCOMB8hRv90bHvNVHxTZbWMjcV2OJVh7crOeCjw5ulxWVwJNkh4DE8WOcYFnBKufJihbPsADT 9MliClw3+rXW0G0uaklFtGyDqc4fFNCTrMCWy3Mtg4ikAZ08sSlKe/GM2hx6SRQF1oUI5QwhXYyyLm MAm4OYLJZPjfNUsb/oP+88Kuhjg9rnPauJlq/k6Bvg0qyCCdpqMWsmHt5HVI/SLDrIl7dxlu2OvsUY +ls15c7qSkcH3mq7zOxVE6bo2CTFWxYQi29oOz4rPhEJnIzJqU48DoE1ZJi7bMKCbbI9dGuOQsCWGq 4Fe4vqw4Di2TmmSa5GyZ+iOAqJWpQuNT3mvHm3EJnVbcDtou/fwffB2s8ssA== 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 Now we have proper flush and invalidate helpers, we can use them directly to operate on the scsi_cmd data. Likewise, we do not need to flush then invalidate, just flush _or_ invalidate depending on the data direction. Signed-off-by: Neil Armstrong Reviewed-by: Neha Malcom Francis --- drivers/ufs/ufs.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c index 5845fd694d3..d99dcdef7d0 100644 --- a/drivers/ufs/ufs.c +++ b/drivers/ufs/ufs.c @@ -1468,7 +1468,6 @@ static void prepare_prdt_table(struct ufs_hba *hba, struct scsi_cmd *pccb) { struct utp_transfer_req_desc *req_desc = hba->utrdl; struct ufshcd_sg_entry *prd_table = hba->ucd_prdt_ptr; - uintptr_t aaddr = (uintptr_t)(pccb->pdata) & ~(ARCH_DMA_MINALIGN - 1); ulong datalen = pccb->datalen; int table_length; u8 *buf; @@ -1480,15 +1479,6 @@ static void prepare_prdt_table(struct ufs_hba *hba, struct scsi_cmd *pccb) return; } - if (pccb->dma_dir == DMA_TO_DEVICE) { /* Write to device */ - flush_dcache_range(aaddr, - ALIGN((uintptr_t)pccb->pdata + datalen, ARCH_DMA_MINALIGN)); - } - - /* In any case, invalidate cache to avoid stale data in it. */ - invalidate_dcache_range(aaddr, - ALIGN((uintptr_t)pccb->pdata + datalen, ARCH_DMA_MINALIGN)); - table_length = DIV_ROUND_UP(pccb->datalen, MAX_PRDT_ENTRY); buf = pccb->pdata; i = table_length; @@ -1517,8 +1507,12 @@ static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb) ufshcd_prepare_utp_scsi_cmd_upiu(hba, pccb, upiu_flags); prepare_prdt_table(hba, pccb); + ufshcd_cache_flush(pccb->pdata, pccb->datalen); + ufshcd_send_command(hba, TASK_TAG); + ufshcd_cache_invalidate(pccb->pdata, pccb->datalen); + ocs = ufshcd_get_tr_ocs(hba); switch (ocs) { case OCS_SUCCESS: