mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] i2c: cgbc: Fetch the status of a write transfer
@ 2026-11-23 12:33 Markus Haberlander via B4 Relay
  2026-11-26 10:19 ` Thomas Richard (congatec GmbH)
  0 siblings, 1 reply; 7+ messages in thread
From: Markus Haberlander via B4 Relay @ 2026-11-23 12:33 UTC (permalink / raw)
  To: Thomas Richard, Andi Shyti
  Cc: Lee Jones, mfd, linux-i2c, linux-kernel, stable, Markus Haberlander

From: Markus Haberlander <markus.haberlander@rosenberger.com>

A write transfer sends the I2C command to the board controller and
returns without reading the controller's I2C status, while a read polls
the status until the controller is no longer busy. The status of a write
is therefore never fetched:

- the write reports success before the bus transfer has finished, and
  an error such as a NAK is only reported by the next transfer;
- the controller keeps the status of the last write pending. On a
  conga-PA7 (BIOS PA70R026, board controller CGBCP032), a board reset
  with a write status pending does not power the board up again: after
  a reboot that follows a write on the general purpose bus, the board
  stays off until it is power cycled.

Read the status after a write as well, as the read path does: poll until
the controller is no longer busy, return the error it reports, and treat
any state other than idle as an error.

Tested on a conga-PA7 with v6.18.64 and "i2c: cgbc: Propagate hardware
errors when polling read status": without this patch, a write to an
absent address returns success, the next read fails, and a reboot after
a write does not come back. With it, the write itself fails, the next
transfer succeeds, and 14 reboots, each right after an acknowledged or a
NAKed write, all came back.

The patch and this changelog were drafted with the help of Claude
Opus 5.5 and reviewed and tested by me.

Fixes: 6894f640b8f3 ("i2c: Congatec Board Controller i2c bus driver")
Cc: stable@vger.kernel.org
Signed-off-by: Markus Haberlander <markus.haberlander@rosenberger.com>
---
Hi Thomas, hi all,

this is my first patch for this driver, so please bear with me if
something is not done the usual way.

We use the conga-PA7 in a product, with the mainline cgbc drivers. While
bringing it up, we found that the board does not power up again after a
reboot that follows an I2C write on the general purpose bus. The patch
below describes the cause and fixes it.

While preparing it, I saw your series "Congatec Board Controller: Add
storage devices support" v6:
https://lore.kernel.org/r/20261117-cgbc-i2c-storage-devices-support-v6-0-bb070ad3e9aa@bootlin.com
Its patch 2/10 ("i2c: cgbc: Propagate hardware errors when polling read
status") fixes the read side of the same function, and this patch is the
write side of it. As Lee wants to take the series as a whole, I based it
on top of 2/10 rather than send something that conflicts with it.

Whatever suits you best is fine with me: carrying it in a v7 right after
2/10, or me resending it once your series is applied. Right after 2/10,
it backports to stable together with 2/10, as both carry Cc: stable.
After 5/10, it would no longer build on stable kernels without
"i2c->read_maxtime_us", so I would send the backport myself.

Thanks for having a look!
---
 drivers/i2c/busses/i2c-cgbc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
index dfdb9ffc6..2361591a1 100644
--- a/drivers/i2c/busses/i2c-cgbc.c
+++ b/drivers/i2c/busses/i2c-cgbc.c
@@ -254,6 +254,22 @@ static int cgbc_i2c_xfer_msg(struct i2c_adapter *adap)
 		ret = cgbc_command(cgbc, &cmd, cmd_len, NULL, 0, NULL);
 		if (ret)
 			goto err;
+
+		ret = read_poll_timeout(cgbc_i2c_get_status, status,
+					status != CGBC_I2C_STAT_BUSY, 0,
+					2 * algo_data->read_maxtime_us, false, adap);
+		if (ret)
+			goto err;
+
+		if (status < 0) {
+			ret = status;
+			goto err;
+		}
+
+		if (status != CGBC_I2C_STAT_IDL) {
+			ret = -EIO;
+			goto err;
+		}
 	} else if (i2c->state == CGBC_I2C_STATE_READ) {
 		xfer.write = 0;
 		xfer.read = len;

---
base-commit: 1cb7268b6638c411fc32f373e965eb8ba9e9b2b4
change-id: 20261123-cgbc-i2c-write-status-20f457e75879
prerequisite-patch-id: 4e27d38e51d4920d74478abe76d4ae0a2440d33e

Best regards,
--  
Markus Haberlander <markus.haberlander@rosenberger.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: cgbc: Fetch the status of a write transfer
  2026-11-23 12:33 [PATCH] i2c: cgbc: Fetch the status of a write transfer Markus Haberlander via B4 Relay
@ 2026-11-26 10:19 ` Thomas Richard (congatec GmbH)
  2026-11-26 13:14   ` Andi Shyti
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-11-26 10:19 UTC (permalink / raw)
  To: Thomas Richard, Andi Shyti, Lee Jones
  Cc: mfd, linux-i2c, linux-kernel, stable, Markus Haberlander

> A write transfer sends the I2C command to the board controller and
> returns without reading the controller's I2C status, while a read polls
> the status until the controller is no longer busy. The status of a write
> is therefore never fetched:
> 
> - the write reports success before the bus transfer has finished, and
>   an error such as a NAK is only reported by the next transfer;
> - the controller keeps the status of the last write pending. On a
>   conga-PA7 (BIOS PA70R026, board controller CGBCP032), a board reset
>   with a write status pending does not power the board up again: after
>   a reboot that follows a write on the general purpose bus, the board
>   stays off until it is power cycled.
> 
> Read the status after a write as well, as the read path does: poll until
> the controller is no longer busy, return the error it reports, and treat
> any state other than idle as an error.
> 
> Tested on a conga-PA7 with v6.18.64 and "i2c: cgbc: Propagate hardware
> errors when polling read status": without this patch, a write to an
> absent address returns success, the next read fails, and a reboot after
> a write does not come back. With it, the write itself fails, the next
> transfer succeeds, and 14 reboots, each right after an acknowledged or a
> NAKed write, all came back.
> 
> The patch and this changelog were drafted with the help of Claude
> Opus 5.5 and reviewed and tested by me.
> 
> Fixes: 6894f640b8f3 ("i2c: Congatec Board Controller i2c bus driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Markus Haberlander <markus.haberlander@rosenberger.com>
>
> diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
> index dfdb9ffc6447..2361591a1e31 100644
> --- a/drivers/i2c/busses/i2c-cgbc.c
> +++ b/drivers/i2c/busses/i2c-cgbc.c
> @@ -254,6 +254,22 @@ static int cgbc_i2c_xfer_msg(struct i2c_adapter *adap)
>  		ret = cgbc_command(cgbc, &cmd, cmd_len, NULL, 0, NULL);
>  		if (ret)
>  			goto err;
> +
> +		ret = read_poll_timeout(cgbc_i2c_get_status, status,
> +					status != CGBC_I2C_STAT_BUSY, 0,
> +					2 * algo_data->read_maxtime_us, false, adap);
> +		if (ret)
> +			goto err;
> +
> +		if (status < 0) {
> +			ret = status;
> +			goto err;
> +		}
> +
> +		if (status != CGBC_I2C_STAT_IDL) {
> +			ret = -EIO;
> +			goto err;
> +		}
>  	} else if (i2c->state == CGBC_I2C_STATE_READ) {
>  		xfer.write = 0;
>  		xfer.read = len;

I was able to reproduce the issue on conga-SA7 (and also the reboot crash).

$ i2ctransfer -y 11 w1@0x40 0x00	 <- non-existing device
$ i2ctransfer -y 11 w1@0x50 0x00 r1@0x50 <- read EEPROM
Error: Sending messages failed: Input/output error
$ i2ctransfer -y 11 w1@0x50 0x00 r1@0x50 <- read EEPROM
0x01

And with your patch:

$ i2ctransfer -y 11 w1@0x40 0x00	 <- non-existing device
Error: Sending messages failed: Input/output error
$ i2ctransfer -y 11 w1@0x50 0x00 r1@0x50 <- read EEPROM
0x01

Reviewed-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
Tested-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>

Yes it conflicts (compile issue) with the series [1]. The possibilies are:
- I pick this patch in my series and send a v7.
- [1] is applied, an immutable branch is created, you rebase your patch on
  top of it, and patch is applied in I2C tree.
- [1] is applied, you rebase on top of mfd-next, and your patch is applied
  in MFD tree.

Andi, Lee, what do you prefer?

[1] https://lore.kernel.org/all/20261117-cgbc-i2c-storage-devices-support-v6-0-bb070ad3e9aa@bootlin.com/

-- 
Best Regards,
Thomas Richard


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: cgbc: Fetch the status of a write transfer
  2026-11-26 10:19 ` Thomas Richard (congatec GmbH)
@ 2026-11-26 13:14   ` Andi Shyti
  2026-11-26 17:49     ` Andi Shyti
  2026-11-26 20:18     ` Thomas Richard
  0 siblings, 2 replies; 7+ messages in thread
From: Andi Shyti @ 2026-11-26 13:14 UTC (permalink / raw)
  To: Thomas Richard (congatec GmbH)
  Cc: Lee Jones, mfd, linux-i2c, linux-kernel, stable, Markus Haberlander

Hi Thomas and Markus,

> > diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
> > index dfdb9ffc6447..2361591a1e31 100644
> > --- a/drivers/i2c/busses/i2c-cgbc.c
> > +++ b/drivers/i2c/busses/i2c-cgbc.c
> > @@ -254,6 +254,22 @@ static int cgbc_i2c_xfer_msg(struct i2c_adapter *adap)
> >  		ret = cgbc_command(cgbc, &cmd, cmd_len, NULL, 0, NULL);
> >  		if (ret)
> >  			goto err;
> > +
> > +		ret = read_poll_timeout(cgbc_i2c_get_status, status,
> > +					status != CGBC_I2C_STAT_BUSY, 0,
> > +					2 * algo_data->read_maxtime_us, false, adap);

would it make sense use USEC_PER_SEC here to preserve the
existing one-second timeout between write chunks?

> > +		if (ret)
> > +			goto err;
> > +
> > +		if (status < 0) {
> > +			ret = status;
> > +			goto err;
> > +		}
> > +
> > +		if (status != CGBC_I2C_STAT_IDL) {
> > +			ret = -EIO;
> > +			goto err;
> > +		}
> >  	} else if (i2c->state == CGBC_I2C_STATE_READ) {
> >  		xfer.write = 0;
> >  		xfer.read = len;
> 
> I was able to reproduce the issue on conga-SA7 (and also the reboot crash).
> 
> $ i2ctransfer -y 11 w1@0x40 0x00	 <- non-existing device
> $ i2ctransfer -y 11 w1@0x50 0x00 r1@0x50 <- read EEPROM
> Error: Sending messages failed: Input/output error
> $ i2ctransfer -y 11 w1@0x50 0x00 r1@0x50 <- read EEPROM
> 0x01
> 
> And with your patch:
> 
> $ i2ctransfer -y 11 w1@0x40 0x00	 <- non-existing device
> Error: Sending messages failed: Input/output error
> $ i2ctransfer -y 11 w1@0x50 0x00 r1@0x50 <- read EEPROM
> 0x01
> 
> Reviewed-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
> Tested-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
> 
> Yes it conflicts (compile issue) with the series [1]. The possibilies are:
> - I pick this patch in my series and send a v7.
> - [1] is applied, an immutable branch is created, you rebase your patch on
>   top of it, and patch is applied in I2C tree.
> - [1] is applied, you rebase on top of mfd-next, and your patch is applied
>   in MFD tree.
> 
> Andi, Lee, what do you prefer?

Let's wait your patches to get in first and then Markus can
rebase on top of them.

I will now prioritize your series.

Thanks,
Andi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: cgbc: Fetch the status of a write transfer
  2026-11-26 13:14   ` Andi Shyti
@ 2026-11-26 17:49     ` Andi Shyti
  2026-11-26 18:04       ` Thomas Richard
  2026-11-26 20:18     ` Thomas Richard
  1 sibling, 1 reply; 7+ messages in thread
From: Andi Shyti @ 2026-11-26 17:49 UTC (permalink / raw)
  To: Thomas Richard (congatec GmbH)
  Cc: Lee Jones, mfd, linux-i2c, linux-kernel, stable, Markus Haberlander

Hi Thomas,

...

> > Yes it conflicts (compile issue) with the series [1]. The possibilies are:
> > - I pick this patch in my series and send a v7.
> > - [1] is applied, an immutable branch is created, you rebase your patch on
> >   top of it, and patch is applied in I2C tree.
> > - [1] is applied, you rebase on top of mfd-next, and your patch is applied
> >   in MFD tree.
> > 
> > Andi, Lee, what do you prefer?
> 
> Let's wait your patches to get in first and then Markus can
> rebase on top of them.

as you are going to resend your series, would you be so kind to
include this, as well?

Thanks,
Andi

> I will now prioritize your series.
> 
> Thanks,
> Andi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: cgbc: Fetch the status of a write transfer
  2026-11-26 17:49     ` Andi Shyti
@ 2026-11-26 18:04       ` Thomas Richard
  2026-11-26 18:28         ` Lee Jones
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Richard @ 2026-11-26 18:04 UTC (permalink / raw)
  To: Andi Shyti
  Cc: Lee Jones, mfd, linux-i2c, linux-kernel, stable, Markus Haberlander

On 11/26/26 6:49 PM, Andi Shyti wrote:
> Hi Thomas,
> 
> ...
> 
>>> Yes it conflicts (compile issue) with the series [1]. The possibilies are:
>>> - I pick this patch in my series and send a v7.
>>> - [1] is applied, an immutable branch is created, you rebase your patch on
>>>   top of it, and patch is applied in I2C tree.
>>> - [1] is applied, you rebase on top of mfd-next, and your patch is applied
>>>   in MFD tree.
>>>
>>> Andi, Lee, what do you prefer?
>>
>> Let's wait your patches to get in first and then Markus can
>> rebase on top of them.
> 
> as you are going to resend your series, would you be so kind to
> include this, as well?
Yes no problem. Thanks for the review!

Best Regards,
Thomas

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: cgbc: Fetch the status of a write transfer
  2026-11-26 18:04       ` Thomas Richard
@ 2026-11-26 18:28         ` Lee Jones
  0 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-26 18:28 UTC (permalink / raw)
  To: Thomas Richard
  Cc: Andi Shyti, mfd, linux-i2c, linux-kernel, stable, Markus Haberlander

On Thu, 26 Nov 2026, Thomas Richard wrote:

> On 11/26/26 6:49 PM, Andi Shyti wrote:
> > Hi Thomas,
> > 
> > ...
> > 
> >>> Yes it conflicts (compile issue) with the series [1]. The possibilies are:
> >>> - I pick this patch in my series and send a v7.
> >>> - [1] is applied, an immutable branch is created, you rebase your patch on
> >>>   top of it, and patch is applied in I2C tree.
> >>> - [1] is applied, you rebase on top of mfd-next, and your patch is applied
> >>>   in MFD tree.
> >>>
> >>> Andi, Lee, what do you prefer?
> >>
> >> Let's wait your patches to get in first and then Markus can
> >> rebase on top of them.
> > 
> > as you are going to resend your series, would you be so kind to
> > include this, as well?
> Yes no problem. Thanks for the review!

No preference.  Happy with whatever.

-- 
Lee Jones

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: cgbc: Fetch the status of a write transfer
  2026-11-26 13:14   ` Andi Shyti
  2026-11-26 17:49     ` Andi Shyti
@ 2026-11-26 20:18     ` Thomas Richard
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Richard @ 2026-11-26 20:18 UTC (permalink / raw)
  To: Andi Shyti
  Cc: Lee Jones, mfd, linux-i2c, linux-kernel, stable, Markus Haberlander

On 11/26/26 2:14 PM, Andi Shyti wrote:
> Hi Thomas and Markus,
> 
>>> diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
>>> index dfdb9ffc6447..2361591a1e31 100644
>>> --- a/drivers/i2c/busses/i2c-cgbc.c
>>> +++ b/drivers/i2c/busses/i2c-cgbc.c
>>> @@ -254,6 +254,22 @@ static int cgbc_i2c_xfer_msg(struct i2c_adapter *adap)
>>>  		ret = cgbc_command(cgbc, &cmd, cmd_len, NULL, 0, NULL);
>>>  		if (ret)
>>>  			goto err;
>>> +
>>> +		ret = read_poll_timeout(cgbc_i2c_get_status, status,
>>> +					status != CGBC_I2C_STAT_BUSY, 0,
>>> +					2 * algo_data->read_maxtime_us, false, adap);
> 
> would it make sense use USEC_PER_SEC here to preserve the
> existing one-second timeout between write chunks?
read_maxtime_us was computed based on the bus frequency and the maximum
amount of data that can be read by one transfer.
CGBC_I2C_WRITE_MAX_LEN is 32 whereas CGBC_I2C_READ_MAX_LEN is 31, but
multiplied by 2 we should be safe.

If I'm not mistaken, USEC_PER_SEC is only used if master_xfer returns
-EGAIN (arbitration loss), else __i2c_transfer() directly returns so no
1s timeout. And we never return -EAGAIN.

So why should we wait 1s?

Maybe I did not get your point.

Best Regards,
Thomas

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-26 20:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 12:33 [PATCH] i2c: cgbc: Fetch the status of a write transfer Markus Haberlander via B4 Relay
2026-11-26 10:19 ` Thomas Richard (congatec GmbH)
2026-11-26 13:14   ` Andi Shyti
2026-11-26 17:49     ` Andi Shyti
2026-11-26 18:04       ` Thomas Richard
2026-11-26 18:28         ` Lee Jones
2026-11-26 20:18     ` Thomas Richard

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®