From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796007561; b=uYZWh4/AisGENvb+L4deHrkMUZ7J3mWGu3eobKUNleSn/edvJfx0qOU16gEQfQiy8pue PVkonnsEpOpFubd2c3UpONHjbkQTQfwbWpM8lfd4aEJc20kNsBxOmmk15qUXFjJ4EXEXT Zf+ermb9FUot6zK0opevIJ/MqXr7fAMsE3UO2yUezkt88D6n049GXALEL4kiCSM3qOzWG 2MuZSov2b0xCyo064jzFtoFoH1GFHmHP6sjDn4Cq7DoCDw+qswUIqZ++xBKW0dRtNss7o 3QSwJ/0S3ofNe0Ee4IQWdUEMIMyrEcLslqHxoNS5PWLV9ZeDOTtYqErW7HlmO6zeCrw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796007561; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=BYI5Temt3ZF17uiTybSy9wnnm6v2cyftCCdyPCxsuv8=; b=WzMrq4gKEotoFT5RcFfB8d1/N1mRbo15NiI1D3hSnbcoxYn14n7BOwuIx9wvrBuhxoaT 5xSj6gBbckJjxAhosWrVnbCEe2qQnjbWMCdNriM7Ly8W4oDNmtFAOeUN6WkG7iycQSWRa bG5SDF7ZnV7Ortwgf6jLlXxs/g74vckZz393vkJuMrBzGn1Rf3cwJ6x9UyznSH7er60ta KHgTZ891LsjrRdloJ2iIAS2inuk4wA5f5uwb9VHou8FsTtmCIZAh3aw0sW5EUdCtDoLyw KQgRliKFZmUimevhiaiLMtJroVNNidg5aQTsmW0ddiIoLt7IHfB+O815SurIzlEktjg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CSS4+ijb; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BBE4606A327 for ; Mon, 30 Nov 2026 02:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CSS4+ijb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90ACE1F000C1; Mon, 30 Nov 2026 02:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796007560; bh=BYI5Temt3ZF17uiTybSy9wnnm6v2cyftCCdyPCxsuv8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CSS4+ijbvL2FWWlxE44DEtspOnP7o57oqTprIAk83CZpiHoqYDRcJBJ7sIWSks9Tn m6aeu8JHrNhXx8W2zLYXE5YsBpmfYZ7WnS4DcA9IAAncO5ZLgNBEBczwHXVDCnZ5ks nvjJLNi+0BgjPn/6Xdpr16b9wXlCKBv1gnuLVOqC5JDdHLuY5BNqJIaq2skamWr8PI SFLT9QWL2MEKIZXxrU5TSprQkq+5kNlVz/LKUqQTKs68Lyh1uIndX4z/nYKwpEKT7z bLvCgaIsTPM4XaavB2LWYGjt+4BRvHOixX+DhxZB7ozp7SuT8Mn0qpZZyJoEvtbqoo 8dn48LmTgzs7g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 4/5] spi: dw-g2: Add support for SPI-NAND devices Reply-To: sashiko-reviews@lists.linux.dev To: "Prakriti Sharma" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <5f3488118892b90457aeb5696b7a003e4cef274a.1795683279.git.prakriti@synopsys.com> References: <5f3488118892b90457aeb5696b7a003e4cef274a.1795683279.git.prakriti@synopsys.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 02:59:20 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] spi: dw-g2: dw_spi_g2_adjust_mem_op_size() misroutes 1-1-1 reads to RO mode - [Medium] spi: dw-g2: clamping reads to fifo_len breaks SPI-NAND continuous reads - [Medium] spi: dw-g2: misplaced SPI-NAND delay after CS assert in dw_spi_g2_reg_op() - [Medium] spi: dw-g2: broken op validation in dw_spi_g2_supports_mem_ops() -- commit 693b6c9d55f285455a0b9914fa2d4d0ffd449b31 Author: Prakriti Sharma spi: dw-g2: Add support for SPI-NAND devices This commit adds a post-CS delay for SPI-NAND register operations, DTR and transfer-type checks in dw_spi_g2_supports_mem_ops(), and RX FIFO read size clamping in dw_spi_g2_adjust_mem_op_size(). > diff --git a/drivers/spi/spi-dw-g2-core.c b/drivers/spi/spi-dw-g2-core.c > index 88766706ef525..f50dcfe2d854c 100644 > --- a/drivers/spi/spi-dw-g2-core.c > +++ b/drivers/spi/spi-dw-g2-core.c > @@ -339,6 +339,12 @@ static inline bool dw_spi_g2_is_reg_op(struct dw_spi= _g2 *dws, > op->data.nbytes > 0 && total <=3D limit; > } > =20 > +static bool dw_spi_g2_spi_is_nand(struct spi_device *spi) > +{ > + return spi && spi->dev.of_node && > + of_device_is_compatible(spi->dev.of_node, "spi-nand"); > +} > + > /** > * dw_spi_g2_xfer_timeout_us - Timeout for clocking a number of bytes > * @dws: Driver state > @@ -675,6 +681,15 @@ static int dw_spi_g2_reg_op(struct dw_spi_g2 *dws, c= onst struct spi_mem_op *op) > =20 > dw_spi_g2_cs_assert(dws, dws->cs); > =20 > + /* > + * SPI-NAND: short settle after CS before ID/feature reads. > + * Check the current device (not a sticky controller flag). > + */ > + if (dw_spi_g2_spi_is_nand(dws->curr_spi)) { > + (void)dw_spi_g2_readl(dws->regs, DW_SPI_G2_SR); > + usleep_range(10, 20); > + } [Severity: Medium] Does usleep_range() here actually delay SCLK after CS assertion on the bus? Before dw_spi_g2_cs_assert() writes BIT(cs) to DW_SPI_G2_SER, the controller is already enabled and all len bytes of the transfer have been pre-filled i= nto DW_SPI_G2_DR0: drivers/spi/spi-dw-g2-core.c:dw_spi_g2_reg_op() { ... dw_spi_g2_target_enable(dws, dws->cs); dw_spi_g2_enable(dws, true); /* dw_spi_g2_is_reg_op() guarantees the whole stream fits the FIFO */ for (i =3D 0; i < len; i++) dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, buf[i]); dw_spi_g2_cs_assert(dws, dws->cs); ... } In DWC_ssi hardware, writing SER while SSIENR is set and the TX FIFO is non-empty starts shifting out the queued frames immediately and deasserts CS as soon as the TX FIFO drains. Sleeping after writing SER does not insert = any CS-to-SCLK setup time on the wire, and instead adds a 10-20 us CPU stall to every SPI-NAND register operation, including every status poll iteration in spi_mem_poll_status() and DATA_OUT feature writes. > @@ -1049,13 +1064,62 @@ static int dw_spi_g2_indirect_write(struct dw_spi= _g2 *dws, > static bool dw_spi_g2_supports_mem_ops(struct spi_mem *mem, > const struct spi_mem_op *op) > { > + bool op_is_dtr =3D > + op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr; > + > + if (op_is_dtr) { > + /* > + * DTR requires enhanced SPI modes (Dual/Quad/Octal). > + * Reject standard-width DTR since it has no practical use > + * and the hardware doesn't support it meaningfully. > + */ > + if (op->data.nbytes && op->data.buswidth =3D=3D 1) > + return false; > + > + /* > + * In DTR mode all phases must agree on DTR =E2=80=94 reject > + * mixed STR/DTR within a single operation. > + */ > + if (op->addr.nbytes && op->addr.dtr !=3D op->cmd.dtr) > + return false; > + if (op->data.nbytes && op->data.dtr !=3D op->cmd.dtr) > + return false; > + if (op->dummy.nbytes && op->dummy.dtr !=3D op->cmd.dtr) > + return false; > + } > + > + /* > + * cmd_only / indirect_write stay FRF_STANDARD. Reject multi-wire > + * or DTR data-out and command-only so spi-mem falls back to 1-1-1. > + * Multi-wire reads use the enhanced RO path when get_tt() works. > + */ > + if (op->data.dir =3D=3D SPI_MEM_DATA_OUT || > + op->data.dir =3D=3D SPI_MEM_NO_DATA) { > + if (!dw_spi_g2_op_is_std_spi(op)) > + return false; > + } else if (!dw_spi_g2_op_is_std_spi(op) && > + dw_spi_g2_get_tt(op) < 0) { > + return false; > + } > + > return spi_mem_default_supports_op(mem, op); > } [Severity: Medium] Does dw_spi_g2_supports_mem_ops() match the operations that the controller = and dw_spi_g2_indirect_read() actually support? There are three mismatches in this validation: 1. In this commit, ctlr->mem_caps is not set until the later commit "spi: dw-g2: Add support for memory-mapped XIP" in this series, so spi_mem_default_supports_op() rejects all DTR operations. Even once mem_ca= ps is wired up, requiring addr.dtr, dummy.dtr, and data.dtr to equal cmd.dtr rejects all 1S-xD-xD mixed STR/DTR operations (even though dw_spi_g2_indirect_read_setup() programs INST_DDR_EN and DDR_EN independently), while checking only op->data.buswidth =3D=3D 1 fails to rej= ect 1-wire DTR command or address phases. 2. Both dw_spi_g2_supports_mem_ops() and dw_spi_g2_op_is_std_spi() guard da= ta phase checks with op->data.nbytes instead of op->data.dir !=3D SPI_MEM_NO_D= ATA. When spi_mem_dirmap_create() checks a template with op->data.nbytes =3D=3D = 0 (such as a 1S-1S-4S page read or program load template), dw_spi_g2_op_is_std_spi() returns true, misclassifying multi-wire templates as standard 1-1-1 SPI and accepting unsupported multi-wire SPI_MEM_DATA_OUT dirmap templates. 3. For enhanced reads, checking only dw_spi_g2_get_tt(op) < 0 does not veri= fy that op->data.buswidth > 1 and matches any multi-wire command or address phase (since CTRLR0.FRF selects a single enhanced buswidth), that dummy cyc= les fit within DW_SPI_G2_SPI_CTRLR0_WAIT_CYCLES_MAX (31) before dw_spi_g2_indirect_read_setup() fails at runtime with -EINVAL, or that op->addr.nbytes <=3D 4 for the 32-bit address write to DW_SPI_G2_DR0. > int dw_spi_g2_adjust_mem_op_size(struct spi_mem *mem, struct spi_mem_op = *op) > { > + struct dw_spi_g2 *dws =3D spi_controller_get_devdata(mem->spi->controll= er); > + u32 limit =3D DW_G2_MAX_CHUNK; > + > + /* > + * Reads must fit one CS assertion (RX FIFO depth). Hidden > + * driver-side chunking would toggle CS and break SPI-NAND > + * continuous reads; let spi-mem / spinand advance the address. > + */ > + if (op->data.dir =3D=3D SPI_MEM_DATA_IN && dws->fifo_len) > + limit =3D min(limit, dws->fifo_len); [Severity: Medium] Doesn't clamping SPI_MEM_DATA_IN reads to dws->fifo_len (one CS assertion p= er 256-byte FIFO) still break SPI-NAND continuous reads? A SPI-NAND continuous read requires reading across multiple pages under a single uninterrupted CS assertion because deasserting CS terminates continu= ous read mode on the flash chip. When a read is clamped to dws->fifo_len and r= eturns after 256 bytes, spinand_read_from_cache_op() sees remaining bytes with req->continuous set, treats the controller as broken, sets spinand->cont_read_possible =3D false, and returns -EAGAIN: drivers/mtd/nand/spi/core.c:spinand_read_from_cache_op() { ... if (nbytes && req->continuous) { spinand->cont_read_possible =3D false; return -EAGAIN; } ... } If the controller must deassert CS after every dws->fifo_len bytes in FIFO mode, should ctlr->mem_caps set .no_cs_assertion =3D true so SPI-NAND does = not attempt continuous reads in the first place? > + > if (op->data.nbytes) > - op->data.nbytes =3D min_t(u32, op->data.nbytes, DW_G2_MAX_CHUNK); > + op->data.nbytes =3D min_t(u32, op->data.nbytes, limit); [Severity: High] Does clamping op->data.nbytes to dws->fifo_len here misroute standard 1-1-1 reads into dw_spi_g2_indirect_read()? For a 1-1-1 read larger than dws->fifo_len, dw_spi_g2_adjust_mem_op_size() clamps op->data.nbytes to dws->fifo_len (for example, 256 bytes) without subtracting op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes or bounding= by DW_SPI_G2_REG_OP_BUF_SIZE. When dw_spi_g2_exec_mem_op() then checks dw_spi_g2_is_reg_op(): drivers/spi/spi-dw-g2-core.c:dw_spi_g2_is_reg_op() { u32 total =3D op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes + op->data.nbytes; u32 limit =3D min_t(u32, dws->fifo_len, DW_SPI_G2_REG_OP_BUF_SIZE); return dw_spi_g2_op_is_std_spi(op) && op->data.nbytes > 0 && total <=3D limit; } total is 256 + cmd + addr + dummy, which exceeds limit, so dw_spi_g2_is_reg_op() returns false and dw_spi_g2_exec_mem_op() falls throu= gh to dw_spi_g2_indirect_read(). However, dw_spi_g2_indirect_read_setup() programs TMOD_RO with DW_SPI_G2_FRF_STANDARD for 1-1-1 operations; in stand= ard SPI mode the DWC_ssi hardware ignores SPI_CTRLR0 instruction/address/wait-c= ycle framing, truncates the 32-bit address write to DW_SPI_G2_DR0 to 8 bits, and clocks in receive bytes in TMOD_RO without transmitting the command, addres= s, or dummy phases on MOSI. For standard 1-1-1 reads (dw_spi_g2_op_is_std_spi(op)), should limit in dw_spi_g2_adjust_mem_op_size() be capped at min(dws->fifo_len, DW_SPI_G2_REG_OP_BUF_SIZE) - (op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes)? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1795683279.gi= t.prakriti@synopsys.com?part=3D4