mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Menzel <pmenzel@molgen.mpg.de>
To: Mark Brown <broonie@kernel.org>,
	linux-spi@vger.kernel.org, Lixu Zhang <lixu.zhang@intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Paul Menzel <pmenzel@molgen.mpg.de>,
	Hans de Goede <hansg@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] spi: ljca: Do not wait for an ack after every write chunk
Date: Wed, 25 Nov 2026 14:49:38 +0100	[thread overview]
Message-ID: <20261125134941.309622-1-pmenzel@molgen.mpg.de> (raw)

The LJCA adapter in the Dell XPS 9315 (8086:0b63) is a USB Full Speed
device with 64-byte bulk endpoints, so ljca_spi_transfer() splits each
SPI transfer into chunks of 58 bytes, and ljca_transfer() waits for the
adapter’s ack after each of them. On the Full Speed bus, every such
round trip takes about 0.3 ms.

This is most visible when mei_vsc boots the Intel Visual Sensing
Controller (IVSC): it downloads about 1.7 MB of firmware with write-only
SPI transfers, which takes about 12 seconds. Tracing `modprobe mei_vsc`
with the function_graph tracer:

    SPI device statistics:   1730864 bytes in 3407 transfers
    ljca_send():             30085 calls, median 279 us, 11.1 s in total
      usb_bulk_msg() (OUT):  median 133 us, 4.6 s in total
      waiting for the ack:   median 146 us, 6.5 s in total

Only request an ack for the last chunk of a write, and send the others
with ljca_transfer_noack(). Bulk messages arrive in order, so the
transfer still completes only after the adapter has handled all chunks.
A write chunk then takes 112 us (median) instead of 279 us. Reads and
full-duplex transfers are unchanged, as each of their chunks returns
data.

On the Dell XPS 9315, with Debian’s 7.3.5 kernel and only spi-ljca.ko
rebuilt with this change, `modprobe mei_vsc` (mei_vsc blacklisted, so
that the IVSC is in its reset state), two boots each:

    without this change:  12.28 s, 12.08 s
    with this change:      7.56 s,  7.34 s

Both cases transfer the same 1730864 bytes in 3407 transfers, the IVSC
boots, the IPU6 finds the sensor, and libcamera captures frames.

Sending several of the 64-byte messages in one bulk transfer was slower
(8.4 to 8.6 s for 8 messages), as the adapter seems to NAK the next
packet while it still forwards the previous chunk over SPI.
---

Notes:
    The analysis (function_graph traces, the A/B boots), the patch and this
    commit message were drafted with claude-opus-5-5 (Claude Code), asked to
    speed up the IVSC firmware download, see
    Documentation/process/generated-content.rst.
    
    Only one LJCA firmware was tested, the one in the Dell XPS 9315 (BIOS
    1.26.0). It honours the missing ack request for SPI writes. If other
    LJCA firmware versions still acked such messages, the late acks would
    complete the wait for the final chunk early. Lixu, Sakari, can you
    confirm the behaviour for the other adapter firmware versions?
    
    The hardware test used the v7.3.4 spi-ljca.c, which equals the one in
    origin/master 4dce97c6c2655 and linux-next 3dd8c790a7b70, with
    the same condition; this exact commit is compile-tested (W=1) only.

 drivers/spi/spi-ljca.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/spi/spi-ljca.c b/drivers/spi/spi-ljca.c
index b1babd43adda1..37050d0b01bde 100644
--- a/drivers/spi/spi-ljca.c
+++ b/drivers/spi/spi-ljca.c
@@ -100,6 +100,17 @@ static int ljca_spi_read_write(struct ljca_spi_dev *ljca_spi, const u8 *w_data,
 		memcpy(w_packet->data, w_data, len);
 	}
 
+	/*
+	 * Each acked chunk is a USB round trip of about 0.3 ms on the Full
+	 * Speed adapter. Request an ack only for the last chunk of a write;
+	 * the bulk messages arrive in order, so the transfer still ends only
+	 * after the adapter has handled all chunks.
+	 */
+	if (cmd == LJCA_SPI_WRITE && !complete)
+		return ljca_transfer_noack(ljca_spi->ljca, cmd, (u8 *)w_packet,
+					   struct_size(w_packet, data,
+						       w_packet->len));
+
 	ret = ljca_transfer(ljca_spi->ljca, cmd, (u8 *)w_packet,
 			    struct_size(w_packet, data, w_packet->len),
 			    (u8 *)r_packet, LJCA_SPI_BUF_SIZE);
-- 
2.54.0


                 reply	other threads:[~2026-11-25 13:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125134941.309622-1-pmenzel@molgen.mpg.de \
    --to=pmenzel@molgen.mpg.de \
    --cc=broonie@kernel.org \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lixu.zhang@intel.com \
    --cc=sakari.ailus@linux.intel.com \
    /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

all inboxes | Powered by JetHome®