Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jyothi Kumar Seerapu" <jyothi.seerapu@oss.qualcomm.com>
Cc: dmaengine@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, vkoul@kernel.org,
	Frank.Li@kernel.org
Subject: Re: [PATCH v2 6/6] spi: spi-geni-qcom: Add QSPI support over GPI DMA
Date: Tue, 24 Nov 2026 12:41:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-231162@kernel.org> (raw)
In-Reply-To: <20261124-qspi_qup_upstream-v2-6-cd69894107c8@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] spi: spi-geni-qcom: dummy_data len treated as cycles in
  setup_gsi_xfer()
- [Medium] spi: spi-geni-qcom: uncombined dummy_data sent as TX in
  setup_gsi_xfer()
- [Medium] spi: spi-geni-qcom: unvalidated tx_nbits and phase split in
  setup_gsi_xfer()
- [Medium] spi: spi-geni-qcom: unreset started flag in
  spi_geni_transfer_one_message()
--

commit 3cee624932aec05c72fd7f3325666f8b401b4c9e
Author: Jyothi Kumar Seerapu <jyothi.seerapu@oss.qualcomm.com>

spi: spi-geni-qcom: Add QSPI support over GPI DMA

This commit adds QSPI controller support over GPI DMA for the
qcom,geni-qspi compatible, combining TX, optional dummy, and RX phases into
a single SPI_TX_RX hardware command.

> diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
> index 631908522957a..c2f14554c4a1e 100644
> --- a/drivers/spi/spi-geni-qcom.c
> +++ b/drivers/spi/spi-geni-qcom.c
[ ... ]
> @@ -418,27 +427,50 @@ spi_gsi_callback_result(void *cb, const struct dmaengine_result *result)
[ ... ]
>  static int setup_gsi_xfer(struct spi_transfer *xfer, struct spi_geni_master *mas,
> -			  struct spi_device *spi_slv, struct spi_controller *spi)
> +			  struct spi_device *spi_slv, struct spi_controller *spi,
> +			  struct spi_transfer *tx_rx_xfer)
>  {
>  	unsigned long flags = DMA_PREP_INTERRUPT | DMA_CTRL_ACK;
>  	struct dma_slave_config config = {};
>  	struct gpi_spi_config peripheral = {};
> -	struct dma_async_tx_descriptor *tx_desc, *rx_desc;
> +	struct dma_async_tx_descriptor *tx_desc, *rx_desc = NULL;
> +	struct spi_transfer *last = tx_rx_xfer ?: xfer;
>  	int ret;
>  
> +	/* QSPI receives data only as part of a combined TX-then-RX command. */
> +	if (mas->dev_data->is_qspi && xfer->rx_buf && !tx_rx_xfer)
> +		return -EOPNOTSUPP;
> +
>  	config.peripheral_config = &peripheral;
>  	config.peripheral_size = sizeof(peripheral);
>  	peripheral.set_config = true;
> @@ -449,20 +481,21 @@ static int setup_gsi_xfer(struct spi_transfer *xfer, struct spi_geni_master *mas
>  		mas->cur_speed_hz = xfer->speed_hz;
>  	}
>  
> -	if (xfer->tx_buf && xfer->rx_buf) {
> +	if (mas->dev_data->is_qspi && tx_rx_xfer) {
> +		/* Combine the command and data phases into one hardware command. */
> +		peripheral.cmd = SPI_TX_RX;
> +		peripheral.rx_len = get_xfer_len_in_words(tx_rx_xfer, mas);
> +	} else if (xfer->tx_buf && xfer->rx_buf) {
>  		peripheral.cmd = SPI_DUPLEX;
>  	} else if (xfer->tx_buf) {
>  		peripheral.cmd = SPI_TX;
>  		peripheral.rx_len = 0;
>  	} else if (xfer->rx_buf) {
>  		peripheral.cmd = SPI_RX;
> -		if (!(mas->cur_bits_per_word % MIN_WORD_LEN)) {
> -			peripheral.rx_len = ((xfer->len << 3) / mas->cur_bits_per_word);
> -		} else {
> -			int bytes_per_word = (mas->cur_bits_per_word / BITS_PER_BYTE) + 1;
> -
> -			peripheral.rx_len = (xfer->len / bytes_per_word);
> -		}
> +		peripheral.rx_len = get_xfer_len_in_words(xfer, mas);
> +	} else {
> +		dev_err(mas->dev, "Invalid transfer: no tx_buf or rx_buf\n");
> +		return -EINVAL;
>  	}

[Severity: Medium]
Can an uncombined dummy_data transfer be sent onto the wire as an active
SPI_TX transfer here?

In GENI_GPI_DMA mode, spi_geni_probe() sets SPI_CONTROLLER_MUST_TX, so
spi_map_msg() populates xfer->tx_buf = ctlr->dummy_tx for any non-empty
transfer without a TX buffer (and callers such as spi_mem_exec_op() also
set tx_buf on dummy transfers).  When a dummy_data transfer is not paired
into a [TX, dummy, RX] sequence by spi_geni_transfer_one_message(),
setup_gsi_xfer() does not reject xfer->dummy_data and instead takes the
else if (xfer->tx_buf) branch with dummy_cycles = 0, actively driving dummy
bytes on the bus instead of tri-stating for dummy clock cycles or returning
-EOPNOTSUPP.

Because SPI_CONTROLLER_MUST_TX always populates xfer->tx_buf, bufferless
transfers with len > 0 also take the SPI_TX branch instead of failing with
-EINVAL, and non-QSPI RX-only transfers take SPI_DUPLEX, leaving the SPI_RX
and else branches unreachable.

[ ... ]
> @@ -1056,7 +1149,7 @@ static int spi_geni_transfer_one_message(struct spi_controller *spi,
>  {
>  	struct spi_geni_master *mas = spi_controller_get_devdata(spi);
>  	struct spi_device *spi_slv = msg->spi;
> -	struct spi_transfer *xfer, *next_xfer;
> +	struct spi_transfer *xfer, *next_xfer, *last_xfer;
>  	bool keep_cs = false;
>  	bool dma_synced = false;
>  	bool started = false;
> @@ -1066,6 +1159,54 @@ static int spi_geni_transfer_one_message(struct spi_controller *spi,
>  	spi_geni_set_cs(spi_slv, !xfer->cs_off);
>  
>  	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
> +		mas->dummy_len = 0;
> +		last_xfer = xfer;
> +
> +		/*
> +		 * Combine a TX phase, optional dummy phase and RX phase into
> +		 * one QSPI command.
> +		 */
> +		if (mas->dev_data->is_qspi && mas->cur_xfer_mode == GENI_GPI_DMA &&
> +		    xfer->len && xfer->tx_buf && xfer->tx_buf != spi->dummy_tx &&
> +		    !xfer->rx_buf && !xfer->dummy_data &&
> +		    !list_is_last(&xfer->transfer_list, &msg->transfers)) {
> +			next_xfer = list_next_entry(xfer, transfer_list);
> +
> +			if (next_xfer->dummy_data &&
> +			    !list_is_last(&next_xfer->transfer_list, &msg->transfers)) {
> +				/* The current client supplies the dummy length in cycles. */
> +				mas->dummy_len = next_xfer->len;
> +				next_xfer = list_next_entry(next_xfer, transfer_list);
> +			}

[Severity: High]
Does assigning next_xfer->len directly to mas->dummy_len program the wrong
number of dummy clock cycles for standard SPI clients?

In struct spi_transfer, len is in bytes, and callers such as
spi_mem_exec_op() set dummy_data transfer len to op->dummy.nbytes and
tx_nbits to op->dummy.buswidth:

drivers/spi/spi-mem.c:spi_mem_exec_op() {
    ...
	if (op->dummy.nbytes) {
		xfers[xferpos].tx_buf = tmpbuf + op->cmd.nbytes +
					op->addr.nbytes;
		xfers[xferpos].len = op->dummy.nbytes;
		xfers[xferpos].tx_nbits = op->dummy.buswidth;
		xfers[xferpos].dummy_data = 1;
    ...
}

setup_gsi_xfer() writes mas->dummy_len directly into
peripheral.dummy_cycles (TRE_SPI_C0_DUMMY_CYCLES) without converting from
bytes via (next_xfer->len * BITS_PER_BYTE) / next_xfer->tx_nbits, while
spi_geni_transfer_one_message() also adds next_xfer->len as bytes into
msg->actual_length.  As a result, standard QSPI reads with a dummy phase
program 8x, 4x, or 2x too few dummy cycles in single, dual, or quad mode,
corrupting the read data.

> +
> +			/* Ignore the TX buffer inserted by SPI_CONTROLLER_MUST_TX. */
> +			if (next_xfer->len && next_xfer->rx_buf && !next_xfer->dummy_data &&
> +			    (!next_xfer->tx_buf || next_xfer->tx_buf == spi->dummy_tx)) {
> +				last_xfer = next_xfer;
> +			} else {
> +				mas->dummy_len = 0;
> +			}
> +		}
> +
> +		if (last_xfer != xfer) {
> +			next_xfer = xfer;
> +			for (;;) {
> +				/* A combined command cannot change timing or CS between phases. */
> +				if (next_xfer->speed_hz != xfer->speed_hz ||
> +				    next_xfer->bits_per_word != xfer->bits_per_word ||
> +				    next_xfer->cs_off || next_xfer->dtr_mode ||
> +				    next_xfer->word_delay.value ||
> +				    (next_xfer != last_xfer &&
> +				     (next_xfer->cs_change || next_xfer->delay.value))) {
> +					ret = -EOPNOTSUPP;
> +					goto out_err;
> +				}
> +				if (next_xfer == last_xfer)
> +					break;
> +				next_xfer = list_next_entry(next_xfer, transfer_list);
> +			}
> +		}

[Severity: Medium]
Does a combined QSPI read validate buswidth across phases or handle split
command and address TX transfers?

setup_gsi_xfer() sets peripheral.qspi_mode from spi_geni_qspi_mode(last),
programming a single GO TRE mode for the entire SPI_TX_RX command from
last->rx_nbits while ignoring xfer->tx_nbits and the dummy phase tx_nbits,
and the loop above does not check that tx_nbits and rx_nbits are compatible
with that single mode.

In addition, because the driver advertises SPI_TX/RX_DUAL and
SPI_TX/RX_QUAD without implementing mem_ops, spi_mem_exec_op() builds four
transfers ([CMD TX, ADDR TX, DUMMY, DATA RX]) when an address phase is
present; the lookahead above only combines one TX transfer before the dummy
and RX phases, so CMD TX is sent as a separate SPI_TX command before
[ADDR TX, DUMMY, DATA RX].

> +
>  		if ((xfer->tx_buf || xfer->rx_buf) && xfer->len) {
>  			reinit_completion(&mas->xfer_done);
>  
> @@ -1074,16 +1215,17 @@ static int spi_geni_transfer_one_message(struct spi_controller *spi,
>  				     ((xfer->tx_sg.nents || xfer->rx_sg.nents) &&
>  				      xfer->tx_sg.nents <= 1 && xfer->rx_sg.nents <= 1);
>  			if (dma_synced)
> -				spi_geni_dma_sync(spi, xfer, true);
> +				spi_geni_dma_sync(spi, xfer, last_xfer, true);
>  
> -			ret = spi_geni_transfer_one(spi, spi_slv, xfer);
> +			ret = spi_geni_transfer_one(spi, spi_slv, xfer,
> +						    last_xfer == xfer ? NULL : last_xfer);
>  			if (ret < 0) {
>  				dev_err(mas->dev, "Transfer failed: %d\n", ret);
>  				goto out_err;
>  			}
>  			started = true;
>  
> -			ret = spi_geni_wait_for_xfer(spi, xfer);
> +			ret = spi_geni_wait_for_xfer(spi, xfer, last_xfer);
>  			if (ret)
>  				goto out_err;
>  
> @@ -1093,7 +1235,7 @@ static int spi_geni_transfer_one_message(struct spi_controller *spi,
>  				goto out_err;
>  			}
>  			if (dma_synced) {
> -				spi_geni_dma_sync(spi, xfer, false);
> +				spi_geni_dma_sync(spi, xfer, last_xfer, false);
>  				dma_synced = false;
>  			}

[Severity: Medium]
Should started be reset to false once a transfer completes?

When an earlier transfer in a multi-transfer message finishes normally and
a later transfer fails validation or setup before being submitted to
hardware (such as the combined-phase check above or the checks in
setup_gsi_xfer()), started is still true at out_err.  That causes
spi_geni_handle_err() to run on an idle controller, terminating and
restarting the GPI DMA channels (or issuing SE cancel/abort commands that
time out when no transfer is active).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-qspi_qup_upstream-v2-0-cd69894107c8@oss.qualcomm.com?part=6

      reply	other threads:[~2026-11-24 12:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 12:15 [PATCH v2 0/6] spi: qcom-geni: Add QSPI support over GPI DMA Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 1/6] spi: spi-geni-qcom: Add transfer_one_message() support Jyothi Kumar Seerapu
2026-11-24 12:30   ` sashiko-bot
2026-11-24 12:15 ` [PATCH v2 2/6] dt-bindings: dma: qcom-gpi: Add QSPI protocol identifier Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 3/6] dt-bindings: spi: qcom,spi-geni-qcom: Document QSPI support Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 4/6] soc: qcom: geni-se: Define the QSPI firmware protocol Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 5/6] dmaengine: qcom: gpi: Add QSPI protocol support Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 6/6] spi: spi-geni-qcom: Add QSPI support over GPI DMA Jyothi Kumar Seerapu
2026-11-24 12:41   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-231162@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=jyothi.seerapu@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox