From: "Michael Walle" <mwalle@kernel.org>
To: "Carlos Song" <carlos.song@oss.nxp.com>,
"Dong Aisheng" <aisheng.dong@nxp.com>,
"Andi Shyti" <andi.shyti@kernel.org>,
"Frank Li" <Frank.Li@nxp.com>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>
Cc: "Carlos Song" <carlos.song@nxp.com>,
"Wolfram Sang" <wsa+renesas@sang-engineering.com>,
<linux-i2c@vger.kernel.org>, <imx@lists.linux.dev>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] i2c: imx-lpi2c: fix SMBus block read with PEC
Date: Thu, 05 Nov 2026 09:41:00 +0100 [thread overview]
Message-ID: <DMN55MF5SLDY.21QNY4T1VJ4IQ@kernel.org> (raw)
In-Reply-To: <e0094b33-f73d-43f5-bd07-19bc0e88aaa5@oss.nxp.com>
[-- Attachment #1: Type: text/plain, Size: 2631 bytes --]
Hi Carlos,
On Thu Nov 5, 2026 at 9:29 AM CET, Carlos Song wrote:
>
>
>> If PEC is enabled, the I2C core sets msgs->len to 2 instead of 1. The
>> length calculation for the second receive command assumes it's always
>> 1. This will lead to a short read and eventually a timeout because the
>> PEC byte is never received.
>>
>> Take msgs->len into account when calculating the remaining bytes.
>>
>> This was tested on a board which uses an IPMI SSIF BMC.
>>
>> Fixes: efdc383d1cc2 ("i2c: imx-lpi2c: fix SMBus block read NACK after byte count")
>> Signed-off-by: Michael Walle <mwalle@kernel.org>
>> ---
>> drivers/i2c/busses/i2c-imx-lpi2c.c | 10 +++++++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
>> index 7302464c371a..f57e800ac3b5 100644
>> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
>> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
>> @@ -563,7 +563,7 @@ static unsigned int lpi2c_SMBus_block_read_length_byte(struct lpi2c_imx_struct *
>> static int lpi2c_imx_read_init(struct lpi2c_imx_struct *lpi2c_imx,
>> struct i2c_msg *msgs)
>> {
>> - unsigned int temp, val, block_len;
>> + unsigned int temp, val, block_len, remaining;
>> int ret;
>>
>> lpi2c_imx->rx_buf = msgs->buf;
>> @@ -612,9 +612,13 @@ static int lpi2c_imx_read_init(struct lpi2c_imx_struct *lpi2c_imx,
>> * keep MTDR non-empty and ensuring continuous ACKs. Only update command register
>> * here. All block bytes will be read out at IRQ handler or lpi2c_imx_read_atomic()
>> * function.
>> + *
>> + * msgs->len is 1 - or if PEC enabled msgs->len is 2. Two bytes
>> + * have already been requested.
>> */
>> - if (block_len > 1)
>> - writel((RECV_DATA << 8) | (block_len - 2), lpi2c_imx->base + LPI2C_MTDR);
>> + remaining = msgs->len + block_len - 2;
>> + if (remaining)
>> + writel((RECV_DATA << 8) | (remaining - 1), lpi2c_imx->base + LPI2C_MTDR);
>
> Hi Michael,
>
> Just to confirm my understanding:
>
> For SMBus block read with PEC enabled, the PEC (CRC-8) byte is appended
> at the end of the transfer. In that case the I2C core sets msgs->len to
> 2 instead of 1.
>
> The previous code still calculated the remaining receive count assuming
> msgs->len == 1, which means the PEC byte was not included in the total
> number of bytes requested from the controller.
>
> As a result, the last PEC byte was never read out, leading to a short
> read and eventually a timeout.
>
> Is that the issue this patch is fixing?
Yes exactly.
-michael
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 297 bytes --]
prev parent reply other threads:[~2026-11-05 8:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 12:10 [PATCH 1/2] i2c: imx-lpi2c: fix SMBus block read with PEC Michael Walle
2026-11-04 12:10 ` [PATCH 2/2] i2c: imx-lpi2c: don't treat a NACK in SMBus block read as an error Michael Walle
2026-11-05 8:33 ` Carlos Song
2026-11-05 8:29 ` [PATCH 1/2] i2c: imx-lpi2c: fix SMBus block read with PEC Carlos Song
2026-11-05 8:41 ` Michael Walle [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=DMN55MF5SLDY.21QNY4T1VJ4IQ@kernel.org \
--to=mwalle@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=aisheng.dong@nxp.com \
--cc=andi.shyti@kernel.org \
--cc=carlos.song@nxp.com \
--cc=carlos.song@oss.nxp.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=wsa+renesas@sang-engineering.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.