From nobody Wed Feb 5 20:37:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E055A1DB138 for ; Wed, 15 Jan 2025 10:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736936253; cv=none; b=J8gjI8EcceES2PrqEeD0ZwacAhERIFz0aery0InBdhj/Rr1II+lnkZKQWR8B+BhcQy2kurNvgS0Dzu5uu8v4EBj6D+xr10i9fwEQUILAjQhiI+D/eEJANLa42iMopbYIfuquVZW5I3dF7ZpUZYeMA2GaphUfLNoIKtZtM9sjv+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736936253; c=relaxed/simple; bh=S08ExAXa20SGQ/rudOb5j8oKW2KeqlRexrLWwGdLH1w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GFu71byMvVpoHbV9DJ2i5FAVSeTlnw0DH8BcG7LZtX9V4If09cIuMEiSbg+B+00o27ghXyW82MeokxRIS0QaXaeCrx78akto9aotRTZV7dn9vLUrvnpZwGRZhyRj5KRpcoC5fRKN977c/lLsUSQi0Xue/pUPNbI5F8Vi/RAUYzU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lJ+tLSBt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lJ+tLSBt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA206C4CEDF; Wed, 15 Jan 2025 10:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736936252; bh=S08ExAXa20SGQ/rudOb5j8oKW2KeqlRexrLWwGdLH1w=; h=From:To:Cc:Subject:Date:From; b=lJ+tLSBtcpbIIhom1mBZ9KrtmZjRZYllZc8UPr26wEHc3rKviGLeuqk9DD3WpLDEd yimET+xWgCDf3jFs8hPZ6cN21RYB9NaVM9U5KESQ35x78j7lCn4dYY38ra6GQFjHsf K4qWM9fxN8toCP14MShR8yP/VU9vjgdeMiUrllb+/ja0dPx/gj1CrIzHm0jCsysNgt uJht+S9X8C0Dtk0teQoqU5zWYo8kwn6BfaL9SWACFTOJtsDaOlnG/WsgAIZADIBISG TuKhA5mgBQdDLByDjY6u8U5Wf7EuThkV5DSFkkpiphk5olUrDHqS/EsiJ55Ia1Epq2 wk8UFoRAoIl8Q== From: Pratyush Yadav To: Tudor Ambarus , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Cheng Ming Lin , Alexander Stein Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, alvinzhou@mxic.com.tw, leoyu@mxic.com.tw, Cheng Ming Lin Subject: [PATCH] Revert "mtd: spi-nor: core: replace dummy buswidth from addr to data" Date: Wed, 15 Jan 2025 10:16:52 +0000 Message-ID: <20250115101659.55882-1-pratyush@kernel.org> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit 98d1fb94ce75f39febd456d6d3cbbe58b6678795. The commit uses data nbits instead of addr nbits for dummy phase. This causes a regression for all boards where spi-tx-bus-width is smaller than spi-rx-bus-width. It is a common pattern for boards to have spi-tx-bus-width =3D=3D 1 and spi-rx-bus-width > 1. The regression causes all reads with a dummy phase to become unavailable for such boards, leading to a usually slower 0-dummy-cycle read being selected. Most controllers' supports_op hooks call spi_mem_default_supports_op(). In spi_mem_default_supports_op(), spi_mem_check_buswidth() is called to check if the buswidths for the op can actually be supported by the board's wiring. This wiring information comes from (among other things) the spi-{tx,rx}-bus-width DT properties. Based on these properties, SPI_TX_* or SPI_RX_* flags are set by of_spi_parse_dt(). spi_mem_check_buswidth() then uses these flags to make the decision whether an op can be supported by the board's wiring (in a way, indirectly checking against spi-{rx,tx}-bus-width). Now the tricky bit here is that spi_mem_check_buswidth() does: if (op->dummy.nbytes && spi_check_buswidth_req(mem, op->dummy.buswidth, true)) return false; The true argument to spi_check_buswidth_req() means the op is treated as a TX op. For a board that has say 1-bit TX and 4-bit RX, a 4-bit dummy TX is considered as unsupported, and the op gets rejected. The commit being reverted uses the data buswidth for dummy buswidth. So for reads, the RX buswidth gets used for the dummy phase, uncovering this issue. In reality, a dummy phase is neither RX nor TX. As the name suggests, these are just dummy cycles that send or receive no data, and thus don't really need to have any buswidth at all. Ideally, dummy phases should not be checked against the board's wiring capabilities at all, and should only be sanity-checked for having a sane buswidth value. Since we are now at rc7 and such a change might introduce many unexpected bugs, revert the commit for now. It can be sent out later along with the spi_mem_check_buswidth() fix. Reported-by: Alexander Stein Closes: https://lore.kernel.org/linux-mtd/3342163.44csPzL39Z@steina-w/ Signed-off-by: Pratyush Yadav Reviewed-by: Tudor Ambarus Tested-by: Alexander Stein --- I have only compile-tested this patch. Alexander, if you can send your Test= ed-by it would be great! Miquel, since the bug was introduced in v6.13-rc1, I want to have this patc= h go in v6.13. So you would have to send Linus a pull request before he likely releases it this Sunday. How do you want to take the patch? Do you want to = apply it directly to mtd/fixes or should I send out a pull request from a spi-nor/fixes branch? drivers/mtd/spi-nor/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 66949d9f0cc5a..b6f374ded390a 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -89,7 +89,7 @@ void spi_nor_spimem_setup_op(const struct spi_nor *nor, op->addr.buswidth =3D spi_nor_get_protocol_addr_nbits(proto); =20 if (op->dummy.nbytes) - op->dummy.buswidth =3D spi_nor_get_protocol_data_nbits(proto); + op->dummy.buswidth =3D spi_nor_get_protocol_addr_nbits(proto); =20 if (op->data.nbytes) op->data.buswidth =3D spi_nor_get_protocol_data_nbits(proto); --=20 2.40.1