From patchwork Wed Mar 26 12:24:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 876315 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f4c:0:b0:38f:210b:807b with SMTP id cm12csp3141827wrb; Wed, 26 Mar 2025 05:24:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU2UZnWBswV5rSlIVfNXK4hCqXAbxMt/0dvKNy7y5ZeRmhPggZ9wx/X9luEMP88txIBiRMbOg==@linaro.org X-Google-Smtp-Source: AGHT+IE3vtJwJKDLIV2b9O9+9gyRgxhcZ+xlLQzNrU551XMg/I9Ckiyt+Tu2qd4QDn8JcjXuPIjE X-Received: by 2002:a05:6122:2884:b0:50d:39aa:7881 with SMTP id 71dfb90a1353d-525f08a2c62mr3168230e0c.0.1742991875654; Wed, 26 Mar 2025 05:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742991875; cv=none; d=google.com; s=arc-20240605; b=G2PEbDA+IYtlhGt1KSkImgbvgaw4iD3V2tPHSJlAAT5d22QzVGlTaEG/FU6jT+mvm8 M0XOPVFQ9yXMnNyJX65SAqoEkYI+Jyw+i4vFuEmFQG3ay/Y/yPqvgR0XlpNUaYk+t1Sb Ck+nFWVFRDzAlVEc8wx3sMyC9Agd0wz9N1W9fEZrBNwndb3MY3QgxqxSsf6Cc4B//Arl LaJI58KNxtXEE+7wbtnUbKQOzPTyzArkVWPnnf3VlWaahUIKRHHZ89iZtBuLjNJmeMBL GHs/WBrJNaFCH7+vxogm0CB27bcFjD8G5hkriroqrFUuaxn6qoxVFLCgWCk3KN7pAYqD 8j5Q== 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=grFI+AyTJ1nFnkkagj0GQ+g43+wP0+4Jplv53heM3CA=; fh=iaBe6cohSX+BSDVYaVdGqBsRofmld6IHIiW1JCR8iRo=; b=WbIL9F2XnpojmAS8HSAeZPEmEsbw3bzlylVTkPWHuPfFxfbJZai3Vxsh+5R7Cb9HhT j2182ydbUax5OCp6jDN2kSz+IsNNgjtw73nTPY89bVJoPdci5BY1yRMs4d7rGKIA4aYE Wp8lnMqYdrpU3G25E6+cBccEEyKvVd7EpuHPjVLqPTgVAfB5f4f0cwjndkxHtMZv4B7u d656PPIdVHSdNiqYTIABxjC7jtpFlS8ZzafUwP8s32cfV4aiaSOAxLfGeki/LjqpD/F4 FycWdpU8hRpaXNMpKmOKKBjXQlZETxRp9o4FXic+LIIICpLBCoD3qmDRB9nZPyCzy7tf B9/w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KRZ6FqjM; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 71dfb90a1353d-525a7642898si2866092e0c.119.2025.03.26.05.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Mar 2025 05:24:35 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KRZ6FqjM; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 8759281D25; Wed, 26 Mar 2025 13:24:21 +0100 (CET) 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="KRZ6FqjM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4D74A81D25; Wed, 26 Mar 2025 13:24:18 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (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 F00B381B4B for ; Wed, 26 Mar 2025 13:24:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=caleb.connolly@linaro.org Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3912baafc58so5357217f8f.1 for ; Wed, 26 Mar 2025 05:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742991855; x=1743596655; 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=grFI+AyTJ1nFnkkagj0GQ+g43+wP0+4Jplv53heM3CA=; b=KRZ6FqjMxwVX/r5+xPDGDOSVIV9SI0tLcRD9923rWnlikx+EFHHlqaG0mHVYJNYFWi VdGa8f3jyNuLcJwQN/x+tHU0bbZskn7Hl2KOgoYNZ28Sg7g9Slmjo3Uwakdbz95nIErs e7CAXAIH88HDred+kOjDito9SWmX/bKzxtR9rSNC0Q97Ds/TsLN0rDsED2OiIUe2YsYS lD0Dcl22nTz7iE+AbH7hijFhRp7pK1jnOx0VGTiilCrOM+qiWqx1kXflw0ftHzLx71n9 K3v076vR83PP/PQXF7gzAMWDD/pk3uAxcN67TDUhMgqNhiNAy44Ds/yvZhnOp4fsr2pW 38uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742991855; x=1743596655; 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=grFI+AyTJ1nFnkkagj0GQ+g43+wP0+4Jplv53heM3CA=; b=A3gHHuIN6vRX9jU7sevjAtZ86lCIENGa02r/3MT5nCEcvkcTJH6m2ZbHchKodqikMG YON6UUPOGdXFELBXXpupNNwtxj8QPZ31BXB8MWbz/o/z7h7dH0Rjff3+VCzUwSmrPBKY U7GY2GtBu5EEzFbAIWwEOHQe63IAzjNRhpLbyolMtiYjMIs4GJV6Epo5n2Ky2n1KCLcW 4rGCfNa4X6/+H5T2UxXXQ8GRcLn4+9Jwg1JGjXZI8FCS+CMbHDHOCHEwnMIQ/rIafsxF p3Z4SSX29pMcDZZpN9mYlnB47OEcLhZ4v2r/aDT0Us2toj0XO0T+SSPNIWiJprUz1+x3 BFCg== X-Forwarded-Encrypted: i=1; AJvYcCVdLiinGpgjt2W+N6dEveSgiCDwQmYwrQWXwzuRr7q+Eo/HtApYNbciFw7quScZdWpufTCYp7Q=@lists.denx.de X-Gm-Message-State: AOJu0YyGkbt9bS/C9fU3/TouDhTBe5gaMwIx5tgEJ3EDul+n73xzJAVz wwAz/tC7bmLBAm2hBmMt+CI6YWUE/1EYr5yLplTpLItSMzglcTjqBWAsq5TajfQ= X-Gm-Gg: ASbGncsTKdaCToybLuGDiEcaBhmhtJm0sLxM1xxWgsbH4EkY1C21wgjS1mrGvtxKeie w0abkrI6MBxGT0lVqPpTEsZU0kCi6Gxpzm7+FFtLJLekZ2OxyweVyGb2wq/BIMlhKibmrGIGBEI lDOnAI3sKZBZHvg0Waor47BUPAPT0EYSIzY+H2u2zrcurB1svRhqpjEVMrq1WkD0+gWapWSbhOo ux4Gv2C2EMs4hbqAuqS8WBMxbb3m/FNYmVfc5JPJ9af4zBcV/q79id1PMur0w291w2Q31XaDvmO 6ERDVZQiMCJwtRvEVyXK03N4g9/cA5RfOrJdbbhOex8M2FUKya9/RkSXsjThT+1gQAlFjWgrVSH DfswYaY1gBNFZB1PgS8GCWB8= X-Received: by 2002:a5d:47c1:0:b0:391:13d6:c9f0 with SMTP id ffacd0b85a97d-3997f940829mr19977205f8f.47.1742991855363; Wed, 26 Mar 2025 05:24:15 -0700 (PDT) Received: from toyger.tail248178.ts.net (i5E863BED.versanet.de. [94.134.59.237]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3997f9e65casm16923921f8f.69.2025.03.26.05.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Mar 2025 05:24:14 -0700 (PDT) From: Caleb Connolly Date: Wed, 26 Mar 2025 13:24:09 +0100 Subject: [PATCH v2 2/3] scsi: sync cache on write MIME-Version: 1.0 Message-Id: <20250326-scsi-sync-on-write-v2-2-12ab05bd464b@linaro.org> References: <20250326-scsi-sync-on-write-v2-0-12ab05bd464b@linaro.org> In-Reply-To: <20250326-scsi-sync-on-write-v2-0-12ab05bd464b@linaro.org> To: Tom Rini Cc: Neil Armstrong , Marek Vasut , u-boot@lists.denx.de, u-boot-qcom@groups.io, Caleb Connolly X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2214; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=K1MLG5iZvnzW5TaW3VDS+A8H2nx905ReNYUkQyhxbaw=; b=owEBbQKS/ZANAwAKAQWDMSsZX2S2AcsmYgBn4/HqqWIcnL0qRGwXEKPseS61SsBVaJ+c8lrNr XElimYlVtWJAjMEAAEKAB0WIQS2UaFGPGq+0GkMVc0FgzErGV9ktgUCZ+Px6gAKCRAFgzErGV9k tmXAD/43Lo1kUY8rDtkXUmuvnlh44AWzF0q5eM5glq+4VjZZGwl24BJK6Xy6i0WBbRLESXBBsZI dL2tzpglRxAb1WA2ONU9ExfVSfwa4WJLfmibv+cIeHzm+Z/JZ+60npcYU37r5DHH54SHKCceriW bMNWGYT3NaA3yw41QufX/1RJczIBJ3/ApY8ENhZqk1oCdZzh5SB8FNXMQO11dnXff42jREnC+N8 E7/SK5jRbwJfPsYqKn3D7fhvxPMXi+yJBbDEsXq0flBdE3B+iX0y6V7xFPHArf1su3yOowDRKfX BAgEkPuGb1LLtN/adJK0eiwPrHc1monRTxln7D5r7acqBQHQ5mbsTboRKHPvwt9zSFPCpg8OW3X ne6OwDzreuG9w89GlW9EUVtt1+5F86t0jFH5duwRGLyKzQ8ofyC6cONh235L/2iIp9w/nb1KyDS Apt93S4O5I+nWIEiOmJfX5xSpB5pNZHsPlSpXarmpMwBQ9WTtsN4D1h3kZFLJIeb8dxSjKcld9j XgOrkcPy3mbi9wS8Hcvmxu/DeoQ2MglS41NXwpGCQJcSwC2ehwhtV08YJXav7vfTOD00TV1O6Cx c1ix/5h++tfkDmev9WCxUfdSl3eviq1HBUIbrOXzKD+STStbejEAzD5/vm/oTo801ct1Ha96fyp nwCQPAmjJ+xM7CA== X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 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 We don't have a mechanism to safely shutdown block devices prior to a baord reset or driver removal. Prevent data loss by synchronizing the SCSI cache after every write. In particular this solves the issue of capsule updates looping on some devices because the board resets immediately after deleting the capsule file and this write wouldn't be flushed in time. This may impact NAND wear, but should be negligible given the usecases for disk write in U-Boot. Signed-off-by: Caleb Connolly Reviewed-by: Neil Armstrong --- drivers/scsi/scsi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 34ac47c03ab397ca999abf130d84ccbd3be4c419..3e556540cae46734d3b13a72cf279905134336f3 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -77,8 +77,25 @@ static void scsi_setup_inquiry(struct scsi_cmd *pccb) pccb->cmdlen = 6; pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ } +static void scsi_setup_sync_cache(struct scsi_cmd *pccb, lbaint_t start, + unsigned short blocks) +{ + pccb->cmd[0] = SCSI_SYNC_CACHE; + pccb->cmd[1] = 0; + pccb->cmd[2] = (unsigned char)(start >> 24) & 0xff; + pccb->cmd[3] = (unsigned char)(start >> 16) & 0xff; + pccb->cmd[4] = (unsigned char)(start >> 8) & 0xff; + pccb->cmd[5] = (unsigned char)start & 0xff; + pccb->cmd[6] = 0; + pccb->cmd[7] = (unsigned char)(blocks >> 8) & 0xff; + pccb->cmd[8] = (unsigned char)blocks & 0xff; + pccb->cmd[9] = 0; + pccb->cmdlen = 10; + pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */ +} + static void scsi_setup_read_ext(struct scsi_cmd *pccb, lbaint_t start, unsigned short blocks) { pccb->cmd[0] = SCSI_READ10; @@ -239,8 +256,14 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, break; } buf_addr += pccb->datalen; } while (blks != 0); + + /* Flush the SCSI cache so we don't lose data on board reset. */ + scsi_setup_sync_cache(pccb, 0, 0); + if (scsi_exec(bdev, pccb)) + scsi_print_error(pccb); + debug("%s: end startblk " LBAF ", blccnt %x buffer %lX\n", __func__, start, smallblks, buf_addr); return blkcnt; }