[PATCH v2 8/9] i3c: mipi-i3c-hci: Improve AST2700 PIO TX queue utilization
From: Billy Tsai
Date: Tue Nov 10 2026 - 22:20:34 EST
The PIO TX path only pushes data once STAT_TX_THLD reports that
tx_thresh_size words are free, with the threshold set to half the TX
FIFO. The FIFO is therefore never filled beyond half from a single
wait, which under-utilizes the queue, and sending buffers larger than
the threshold makes software race against the hardware draining the
FIFO, resulting in an unstable flow.
The AST2700 vendor block exposes the TX FIFO read and write pointers,
which give the exact number of free entries. When HCI_QUIRK_VENDOR_TX_AVAIL
is set, size each burst from those pointers, using CIRC_SPACE() to
derive the free-entry count, so the FIFO can be used up to its full
depth. Other controllers keep the existing threshold-based flow.
Signed-off-by: Billy Tsai <billy_tsai@xxxxxxxxxxxxxx>
---
drivers/i3c/master/mipi-i3c-hci/aspeed.c | 11 +++++++++++
drivers/i3c/master/mipi-i3c-hci/aspeed.h | 6 ++++++
drivers/i3c/master/mipi-i3c-hci/core.c | 3 ++-
drivers/i3c/master/mipi-i3c-hci/pio.c | 25 +++++++++++++++++++++----
4 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/drivers/i3c/master/mipi-i3c-hci/aspeed.c b/drivers/i3c/master/mipi-i3c-hci/aspeed.c
index 4a73e0180a10..8f2a00a940f7 100644
--- a/drivers/i3c/master/mipi-i3c-hci/aspeed.c
+++ b/drivers/i3c/master/mipi-i3c-hci/aspeed.c
@@ -7,6 +7,7 @@
*/
#include <linux/bitfield.h>
+#include <linux/circ_buf.h>
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/i3c/master.h>
@@ -156,6 +157,16 @@ void aspeed_i3c_ibi_grow_threshold(struct i3c_hci *hci, unsigned int ibi_max_len
FIELD_PREP(ASPEED_I3C_IBI_TERMINATE_LEN, ibi_max_len));
}
+/* Free TX FIFO entries derived from the vendor FIFO read/write pointers */
+unsigned int aspeed_i3c_avail_tx_entries(struct i3c_hci *hci)
+{
+ u32 ptr = aspeed_i3c_read(hci, ASPEED_I3C_QUEUE_PTR0);
+ unsigned int w = FIELD_GET(ASPEED_I3C_QUEUE_PTR0_TX_W, ptr);
+ unsigned int r = FIELD_GET(ASPEED_I3C_QUEUE_PTR0_TX_R, ptr);
+
+ return CIRC_SPACE(w, r, ASPEED_I3C_TX_QUEUE_ENTRIES);
+}
+
static void aspeed_i3c_phy_write(struct i3c_hci *hci, u32 reg, u32 val)
{
writel(val, to_aspeed_vendor_data(hci)->phy_regs + reg);
diff --git a/drivers/i3c/master/mipi-i3c-hci/aspeed.h b/drivers/i3c/master/mipi-i3c-hci/aspeed.h
index 7aecce04bba7..e80a0dff0dc9 100644
--- a/drivers/i3c/master/mipi-i3c-hci/aspeed.h
+++ b/drivers/i3c/master/mipi-i3c-hci/aspeed.h
@@ -38,6 +38,7 @@ u32 aspeed_i3c_read(struct i3c_hci *hci, u32 reg);
void aspeed_i3c_write(struct i3c_hci *hci, u32 reg, u32 val);
int aspeed_i3c_phy_init(struct i3c_hci *hci);
void aspeed_i3c_ibi_grow_threshold(struct i3c_hci *hci, unsigned int ibi_max_len);
+unsigned int aspeed_i3c_avail_tx_entries(struct i3c_hci *hci);
#define ASPEED_I3C_CTRL 0x00
#define ASPEED_I3C_CTRL_CLOCK_STALL_EN BIT(14)
@@ -54,6 +55,11 @@ void aspeed_i3c_ibi_grow_threshold(struct i3c_hci *hci, unsigned int ibi_max_len
#define ASPEED_I3C_DAA_INDEX2 0x18
#define ASPEED_I3C_DAA_INDEX3 0x1c
+#define ASPEED_I3C_QUEUE_PTR0 0xd8
+#define ASPEED_I3C_QUEUE_PTR0_TX_R GENMASK(24, 20)
+#define ASPEED_I3C_QUEUE_PTR0_TX_W GENMASK(16, 12)
+#define ASPEED_I3C_TX_QUEUE_ENTRIES 32
+
#define ASPEED_I3C_INTR_STATUS 0xe0
#define ASPEED_I3C_INTR_STATUS_ENABLE 0xe4
#define ASPEED_I3C_INTR_SIGNAL_ENABLE 0xe8
diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index 31fab1fe614c..5e7af7717da7 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -1415,7 +1415,8 @@ static const __maybe_unused struct of_device_id i3c_hci_of_match[] = {
HCI_QUIRK_VENDOR_INTR_SUMMARY |
HCI_QUIRK_VENDOR_RESOURCES |
HCI_QUIRK_VENDOR_DAA_INDEX |
- HCI_QUIRK_IBI_PAYLOAD_THLD) },
+ HCI_QUIRK_IBI_PAYLOAD_THLD |
+ HCI_QUIRK_VENDOR_TX_AVAIL) },
{},
};
MODULE_DEVICE_TABLE(of, i3c_hci_of_match);
diff --git a/drivers/i3c/master/mipi-i3c-hci/pio.c b/drivers/i3c/master/mipi-i3c-hci/pio.c
index a95ef7fc351c..b58edff234ea 100644
--- a/drivers/i3c/master/mipi-i3c-hci/pio.c
+++ b/drivers/i3c/master/mipi-i3c-hci/pio.c
@@ -14,6 +14,7 @@
#include "hci.h"
#include "cmd.h"
#include "ibi.h"
+#include "aspeed.h"
/*
* PIO Access Area
@@ -397,11 +398,23 @@ static bool hci_pio_do_tx(struct i3c_hci *hci, struct hci_pio_data *pio)
p += (xfer->data_len - xfer->data_left) / 4;
while (xfer->data_left >= 4) {
- /* bail out if FIFO free space is below set threshold */
- if (!(pio_reg_read(INTR_STATUS) & STAT_TX_THLD))
+ unsigned int avail = pio->tx_thresh_size;
+
+ if (hci->quirks & HCI_QUIRK_VENDOR_TX_AVAIL) {
+ /*
+ * The vendor FIFO pointers give the exact free space,
+ * allowing better TX FIFO utilization than the
+ * threshold status.
+ */
+ avail = aspeed_i3c_avail_tx_entries(hci);
+ if (!avail)
+ return false;
+ } else if (!(pio_reg_read(INTR_STATUS) & STAT_TX_THLD)) {
+ /* bail out if FIFO free space is below set threshold */
return false;
+ }
/* we can fill up to that TX threshold */
- nr_words = min(xfer->data_left / 4, pio->tx_thresh_size);
+ nr_words = min(xfer->data_left / 4, avail);
/* push data into the FIFO */
xfer->data_left -= nr_words * 4;
dev_dbg(&hci->master.dev, "now %d left %d",
@@ -418,8 +431,12 @@ static bool hci_pio_do_tx(struct i3c_hci *hci, struct hci_pio_data *pio)
* also get some bytes past the actual buffer but no one
* should care as they won't be sent out.
*/
- if (!(pio_reg_read(INTR_STATUS) & STAT_TX_THLD))
+ if (hci->quirks & HCI_QUIRK_VENDOR_TX_AVAIL) {
+ if (!aspeed_i3c_avail_tx_entries(hci))
+ return false;
+ } else if (!(pio_reg_read(INTR_STATUS) & STAT_TX_THLD)) {
return false;
+ }
dev_dbg(&hci->master.dev, "trailing %d", xfer->data_left);
pio_reg_write(XFER_DATA_PORT, *p);
xfer->data_left = 0;
--
2.34.1