Skip to contentSkip to conversation

spi: ljca: Do not wait for an ack after every write chunk

PATCH Superseded Paul Menzel 2 participants 2 messages Nov 25 – Nov 26

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: ljca: Do not wait for an ack after every write chunk

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(+)
drivers/spi/spi-ljca.c +11 -0
index b1babd43adda1..37050d0b01bde 100644
@@ -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);
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 30 lines

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
Quoted 7 lines

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.
---

You've not provided a Signed-off-by for this so I can't do anything with it, please see Documentation/process/submitting-patches.rst for details on what this is and why it's important.

Signature · 1 line
Mark Brown <[email protected]>