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=1796007819; b=n8ojSKyvfkXRbTcKoJXX/p5L1EBmL6D6wxT0scCw/V8neLGZmI05+fPehOaAo7m39Mtn L/0iALvmXztt0Y7YEwLlnoBPdUQhnSWehtlgSmyP+iKCEYm6LNPwQ6bLzP3/xti6BU71O iAam3ZiZfga5i/2ayISaiIgSF7akWjCDHtSindkzyXWszTbZ8RB+khrkOUgXU4w/GNWbe gYmeP7/kWsCBtDi67voz+11Kponb3kcui1ZqwUctat2HIXYKgcbiPFmst8gYELCC+7ytz LMg4cExb+mQI4UpbfxzEomC8ls/MxXTaMnQlgcHP9VY2FUEyHUkc2XNF9ULczStzQwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796007819; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=cS/TsGKKfWepsaEigURfbM9Kje20nQbEShUAGyvOfug=; b=vZj107hHqxA3fBBxeBhumlcfZG2vnzNIkZpL8TW2ixk7ijKYoF5HEZBV4BfVhM7J/ztS YW5oT0hKS80w9+h8Q34sea2cEd2raUvqA1tiAM2dzj8mFRdB1RDWY3yGNLeCiz3pP2Egt 19Zpc4e2Qd6PVQEUjpYXu4aIrLY/I1t+MsAljoM1Jm2A8JzN3p1qUmqwWzHbN5mfTnAeG 0NvtDz/OYDr/KGfn1lbkeoMue+3l+qL7y8wfw5aXFkEzPeJ/JfJQOXduwrIEVxiQcRkiB ei5P6VBg6RzbO6Sw1psbZ22SvQTdDHGanWMbN0CJuEWBB328/TlxTPcLFsmk/mgekJQ== 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=fVXC104n; 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 31FB5606A332 for ; Mon, 30 Nov 2026 03:03:39 +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=fVXC104n Received: by smtp.kernel.org (Postfix) with ESMTPSA id B38111F0089B; Mon, 30 Nov 2026 03:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796007818; bh=cS/TsGKKfWepsaEigURfbM9Kje20nQbEShUAGyvOfug=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=fVXC104nPf4k7w8ZROxyfNEa2fiI0s9nyPmBN6YjX1XM6KY66GSyTcv2pPYltfr9L FNSJ8x5R5vYwXOTmLt3/OlsgG4dmodLA81SH4grHMV7dIlHOBYf4y6fgmNjD6M1iZG xIrNFRXrNufudnJkxBa2vQvJnZdZ/UdzGeacT3zKgPRMiHWoiWfqy8wjzfqdWVmrKi +g2uZdTFtdziaTo2dTn7re76KOs53eKhUajIuGiLsYsf9UOzQxixgMnY3JvBcY0CMW Q8+zXbx+yoxxC9DojBFaFfZhq9NL4Mh/WxFtyyLi91Mu44iqgDvS/4WpxJ7vqkfkBL wdZGDx+r2WoDg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 3/5] spi: dw-g2: Add support for indirect read and write for spi-mem transfers 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: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 03:03:38 +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 6 potential issues to consider: - [High] spi: dw-g2: 1-1-1 reads misconfigured with TMOD_RO in dw_spi_g2_indirect_read() - [High] spi: dw-g2: premature TX completion in dw_spi_g2_indirect_write() - [Medium] spi: dw-g2: 64-bit address truncated to u32 in dw_spi_g2_indirect_read() - [Medium] spi: dw-g2: missing CPOL/CPHA setup in dw_spi_g2_build_ctrlr0() - [Medium] spi: dw-g2: missing TX FIFO prefill before CS in dw_spi_g2_indirect_write() - [Medium] spi: dw-g2: broken transfer type and buswidth checks in dw_spi_g2_get_tt() -- commit 1790b23a62fec2a1f2834ed7c77750ccba4ceadb Author: Prakriti Sharma spi: dw-g2: Add support for indirect read and write for spi-mem transfers This commit adds FIFO indirect read and write helpers for spi-mem data transfers on the DesignWare SPI G2 controller. > diff --git a/drivers/spi/spi-dw-g2-core.c b/drivers/spi/spi-dw-g2-core.c > index b2a3e3e8670eb..88766706ef525 100644 > --- a/drivers/spi/spi-dw-g2-core.c > +++ b/drivers/spi/spi-dw-g2-core.c [ ... ] > @@ -199,6 +236,63 @@ static void dw_spi_g2_controller_reset(struct dw_spi= _g2 *dws) > } > } > =20 > +/** > + * dw_spi_g2_get_frf - Determine frame format from operation bus widths > + * @op: SPI memory operation > + * > + * Examines the command, address, and data bus widths to determine the > + * widest mode in use, which defines the frame format. > + * > + * Return: Frame format > + */ > +static u32 dw_spi_g2_get_frf(const struct spi_mem_op *op) > +{ > + /* Use the widest bus mode across cmd/addr/data phases */ > + u32 width =3D max3(op->cmd.buswidth, > + op->addr.buswidth ? op->addr.buswidth : 1, > + op->data.buswidth ? op->data.buswidth : 1); > + > + switch (width) { > + case 2: > + return DW_SPI_G2_FRF_DUAL; > + case 4: > + return DW_SPI_G2_FRF_QUAD; > + case 8: > + return DW_SPI_G2_FRF_OCTAL; > + default: > + return DW_SPI_G2_FRF_STANDARD; > + } > +} > + > +/** > + * dw_spi_g2_get_tt - Determine transfer type from operation bus widths > + * @op: SPI memory operation > + * > + * TRANS_TYPE in SPI_CTRLR0 / XIP_CTRL controls only the instruction and > + * address phases. Data always uses the enhanced mode set by SPI_FRF in > + * CTRLR0 (or FRF in XIP_CTRL). > + * > + * TT0 (0x0): instruction standard, address standard (1-1-x) > + * TT1 (0x1): instruction standard, address enhanced (1-x-x) > + * TT2 (0x2): instruction enhanced, address enhanced (x-x-x) > + * > + * Return: Transfer type value (0-2), or -EOPNOTSUPP for unsupported pat= terns > + */ > +static int dw_spi_g2_get_tt(const struct spi_mem_op *op) > +{ > + bool cmd_m =3D (op->cmd.buswidth > 1); > + bool addr_m =3D (op->addr.nbytes && op->addr.buswidth > 1); > + > + if (!cmd_m && !addr_m) > + return DW_SPI_G2_TRANS_TYPE_TT0; /* 1-1-x */ > + if (!cmd_m && addr_m) > + return DW_SPI_G2_TRANS_TYPE_TT1; /* 1-x-x */ > + if (cmd_m && addr_m) > + return DW_SPI_G2_TRANS_TYPE_TT2; /* x-x-x */ > + > + return -EOPNOTSUPP; > +} [Severity: Medium] Does dw_spi_g2_get_tt() reject valid multi-wire reads that have no address phase? When op->cmd.buswidth > 1 and op->addr.nbytes =3D=3D 0 (such as 4-0= -4 or 8D-0-8D status and ID reads), cmd_m is true and addr_m is false, so dw_spi_g2_get_tt() returns -EOPNOTSUPP instead of DW_SPI_G2_TRANS_TYPE_TT2. Also, because dw_spi_g2_get_frf() programs a single SPI_FRF from the widest phase, dw_spi_g2_get_tt() does not verify that all multi-wire phases share the same buswidth as op->data.buswidth. > @@ -664,6 +758,294 @@ void dw_spi_g2_program_baudr(struct dw_spi_g2 *dws,= u32 freq) > dw_spi_g2_baudr(dws, freq)); > } [ ... ] > +static int dw_spi_g2_indirect_read_setup(struct dw_spi_g2 *dws, > + const struct spi_mem_op *op) > +{ > + u32 ctrlr0 =3D dw_spi_g2_build_ctrlr0(dws, DW_SPI_G2_CTRLR0_TMOD_RO, > + dw_spi_g2_get_frf(op)); [Severity: Medium] Does dw_spi_g2_indirect_read_setup() (and dw_spi_g2_indirect_write_setup() below) omit SPI_CPOL and SPI_CPHA when programming DW_SPI_G2_CTRLR0? dw_spi_g2_build_ctrlr0() only sets the DFS, TMOD, and FRF fields (unlike dw_spi_g2_transfer_one(), which ORs in DW_SPI_G2_CTRLR0_SCPOL and DW_SPI_G2_CTRLR0_SCPHA afterwards), so indirect spi-mem operations always run in SPI Mode 0 even when dws->curr_spi->mode selects Mode 3. [ ... ] > +static int dw_spi_g2_indirect_read(struct dw_spi_g2 *dws, > + const struct spi_mem_op *op) > +{ [ ... ] > + ret =3D dw_spi_g2_indirect_read_setup(dws, op); > + if (ret) > + return ret; > + > + dw_spi_g2_target_enable(dws, dws->cs); > + dw_spi_g2_enable(dws, true); > + > + dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, op->cmd.opcode); > + if (op->addr.nbytes) > + dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, (u32)op->addr.val); [Severity: High] Can standard 1-1-1 SPI reads work when routed through dw_spi_g2_indirect_read()? When a 1-1-1 read has op->data.nbytes =3D=3D dws->fifo_len, cmd + addr + dummy + data exceeds dws->fifo_len, so dw_spi_g2_is_reg_op() returns false and dw_spi_g2_exec_mem_op() dispatches the read here. For a 1-1-1 op, dw_spi_g2_get_frf() returns DW_SPI_G2_FRF_STANDARD, pairing DW_SPI_G2_CTRLR0_TMOD_RO with standard frame format while relying on SPI_CTRLR0 instruction, address, and wait-cycle framing that only operates in enhanced multi-wire modes. [Severity: Medium] Does casting op->addr.val to u32 and writing DW_SPI_G2_DR0 once truncate addresses longer than 4 bytes? dw_spi_g2_exec_mem_op() allows op->addr.nbytes up to DW_SPI_G2_ADDR_L_MAX_BITS / 8 (7 bytes) and dw_spi_g2_indirect_read_setup() programs DW_SPI_G2_SPI_CTRLR0_ADDR_L_MASK for the full address length. When op->addr.nbytes > 4, the controller expects two 32-bit address entries in the TX FIFO, so writing a single 32-bit word drops the upper address bits and leaves the transfer waiting until dw_spi_g2_xfer_fifo() times out. [ ... ] > +static int dw_spi_g2_indirect_write(struct dw_spi_g2 *dws, > + const struct spi_mem_op *op) > +{ [ ... ] > + dw_spi_g2_fill_tx_buf(tx_buf, op, true); > + > + dw_spi_g2_target_enable(dws, dws->cs); > + dw_spi_g2_cs_assert(dws, dws->cs); > + dw_spi_g2_enable(dws, true); > + > + ret =3D dw_spi_g2_xfer_fifo(dws, tx_buf, tx_total, NULL, 0); > + if (ret) { > + dev_err(dws->dev, > + "indirect_write: xfer_fifo failed: %d\n", ret); > + dw_spi_g2_transfer_end(dws); > + dw_spi_g2_controller_reset(dws); > + kfree(tx_buf); > + return ret; > + } > + > + dw_spi_g2_transfer_end(dws); [Severity: Medium] Can asserting CS and enabling SSI before prefilling the TX FIFO cause CS to deassert mid-write? Unlike dw_spi_g2_reg_op() and dw_spi_g2_indirect_read(), which prefill DW_SPI_G2_DR0 before calling dw_spi_g2_cs_assert(), this path enables the controller with SER asserted and an empty FIFO. Once dw_spi_g2_xfer_fifo() writes the first byte, hardware immediately moves it to the shift register, so any interrupt or scheduling delay longer than one byte time drains the shifter with an empty TX FIFO and deasserts CS in the middle of the page program. [Severity: High] Can dw_spi_g2_indirect_write() call dw_spi_g2_transfer_end() before the TX FIFO has drained? For a TX-only transfer, dw_spi_g2_xfer_fifo() finishes by calling dw_spi_g2_wait_idle(), which only polls !(sr & DW_SPI_G2_SR_BUSY) without checking (sr & DW_SPI_G2_SR_TFE) as dw_spi_g2_reg_op() does. If SR_BUSY reads 0 while queued bytes are still in the TX FIFO, dw_spi_g2_transfer_end() disables SSI and deasserts CS before the remaining bytes are shifted out. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1795683279.gi= t.prakriti@synopsys.com?part=3D3