From: Abdurrahman Hussain <abdurrahman@nexthop.ai>
To: Michal Simek <michal.simek@amd.com>,
Andi Shyti <andi.shyti@kernel.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Raviteja Narayanam <raviteja.narayanam@xilinx.com>,
Wolfram Sang <wsa@kernel.org>,
Manikanta Guntupalli <manikanta.guntupalli@amd.com>
Cc: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>,
linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org,
Abdurrahman Hussain <abdurrahman@nexthop.ai>,
stable@vger.kernel.org
Subject: [PATCH v7 2/3] i2c: xiic: defer RX_FULL until all trailing bytes are in FIFO
Date: Thu, 24 Sep 2026 17:10:36 -0700 [thread overview]
Message-ID: <20260924-i2c-xiic-v7-2-df7e752332ef@nexthop.ai> (raw)
In-Reply-To: <20260924-i2c-xiic-v7-0-df7e752332ef@nexthop.ai>
For the normal path of xiic_smbus_block_read_setup() -- the trailing
bytes all fit in one Rx FIFO fill -- RFD was programmed two below the
byte count, which fires the RX_FULL interrupt while the last byte is
still in flight. xiic_read_rx() then lands in its bytes_rem == 1 branch
and sets NACK on a byte still on the wire, truncating the read.
Without PEC this is harmless: the truncated byte is the dummy one the
caller never looks at. With PEC enabled it is the PEC byte itself, and
i2c_smbus_check_pec() fails the transfer with -EBADMSG.
Raise the threshold by one so RX_FULL fires only once every remaining
byte is already buffered. That routes the drain through
xiic_read_rx()'s bytes_rem == 0 path, which reads everything out and
emits the stop cleanly. The only change for the non-PEC case is that
the controller waits one extra byte-time before servicing the
interrupt.
rfd_set stays inside the 4 bits of XIIC_RFD_REG_OFFSET: this branch is
only reached when rxmsg_len + pec_len <= IIC_RX_FIFO_DEPTH, so the
value is at most IIC_RX_FIFO_DEPTH - 1.
Fixes: e4c1ff772e1a ("i2c: xiic: Add smbus_block_read functionality")
Cc: stable@vger.kernel.org
Acked-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
---
drivers/i2c/busses/i2c-xiic.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 0777de45bdf4..5cd737c7608f 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -569,11 +569,11 @@ static void xiic_smbus_block_read_setup(struct xiic_i2c *i2c)
i2c->smbus_actual_len = 1 + rxmsg_len + pec_len;
} else {
/*
- * All trailing bytes fit in the Rx FIFO. The widened
- * condition above guarantees rxmsg_len + pec_len >= 2,
- * so this cannot underflow.
+ * All trailing bytes fit in the Rx FIFO. Defer RX_FULL
+ * until every one of them is buffered, so the drain
+ * takes xiic_read_rx()'s bytes_rem == 0 path.
*/
- rfd_set = rxmsg_len + pec_len - 2;
+ rfd_set = rxmsg_len + pec_len - 1;
i2c->rx_msg->len = rxmsg_len + 1 + pec_len;
}
xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set);
--
2.54.0
next prev parent reply other threads:[~2026-09-25 0:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 0:10 [PATCH v7 0/3] i2c: xiic: fix SMBus block read and PEC support Abdurrahman Hussain
2026-09-25 0:10 ` [PATCH v7 1/3] i2c: xiic: preserve PEC byte length in SMBus block read setup Abdurrahman Hussain
2026-09-25 0:10 ` Abdurrahman Hussain [this message]
2026-09-25 0:10 ` [PATCH v7 3/3] i2c: xiic: don't clobber msg->len to signal block-read completion Abdurrahman Hussain
2026-09-27 11:40 ` [SPAM] [PATCH v7 0/3] i2c: xiic: fix SMBus block read and PEC support Andi Shyti
2026-09-27 18:48 ` Abdurrahman Hussain
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=20260924-i2c-xiic-v7-2-df7e752332ef@nexthop.ai \
--to=abdurrahman@nexthop.ai \
--cc=andi.shyti@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manikanta.guntupalli@amd.com \
--cc=michal.simek@amd.com \
--cc=raviteja.narayanam@xilinx.com \
--cc=shubhrajyoti.datta@amd.com \
--cc=stable@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=wsa@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