Skip to contentSkip to conversation

i2c: cadence: Support PEC for SMBus block read

PATCH Applied Lars-Peter Clausen 4 participants 8 messages Jul 17, 2022 – Jul 24, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: cadence: Support PEC for SMBus block read

SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the I2C bus.

SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes.

The combination of PEC and block read is currently not supported by the Cadence I2C driver.
* When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes.
* The I2C core smbus emulation layer relies on the driver updating the i2c_msg len field with the number of received bytes. The updated length is used when checking the PEC.

Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial len value of the i2c_msg. When PEC is enabled this will be 2, when it is disabled it will be 1.

Once a read transfer is done also increment the len field by the amount of received data bytes.

This change has been tested with a UCM90320 PMBus power monitor, which requires block reads to access certain data fields, but also has PEC enabled by default.

Fixes df8eb5691c48 ("i2c: Add driver for Cadence I2C controller")
---
 drivers/i2c/busses/i2c-cadence.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-cadence.c +9 -1
index 630cfa4ddd46..33f5588a50c0 100644
@@ -573,8 +573,13 @@ static void cdns_i2c_mrecv(struct cdns_i2c *id)
 	ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
 	ctrl_reg |= CDNS_I2C_CR_RW | CDNS_I2C_CR_CLR_FIFO;
 
+	/*
+	 * Receive up to I2C_SMBUS_BLOCK_MAX data bytes, plus one message length
+	 * byte, plus one checksum byte if PEC is enabled. p_msg->len will be 2 if
+	 * PEC is enabled, otherwise 1.
+	 */
 	if (id->p_msg->flags & I2C_M_RECV_LEN)
-		id->recv_count = I2C_SMBUS_BLOCK_MAX + 1;
+		id->recv_count = I2C_SMBUS_BLOCK_MAX + id->p_msg->len;
 
 	id->curr_recv_count = id->recv_count;
 
@@ -789,6 +794,9 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
 	if (id->err_status & CDNS_I2C_IXR_ARB_LOST)
 		return -EAGAIN;
 
+	if (msg->flags & I2C_M_RECV_LEN)
+		msg->len += min_t(unsigned int, msg->buf[0], I2C_SMBUS_BLOCK_MAX);
+
 	return 0;
 }
 
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 20 lines · Lars-Peter Clausen

SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the I2C bus.

SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes.

The combination of PEC and block read is currently not supported by the Cadence I2C driver.
* When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes.
* The I2C core smbus emulation layer relies on the driver updating the i2c_msg len field with the number of received bytes. The updated length is used when checking the PEC.

Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial len value of the i2c_msg. When PEC is enabled this will be 2, when it is disabled it will be 1.

Quoted 8 lines

Once a read transfer is done also increment the len field by the amount of received data bytes.

This change has been tested with a UCM90320 PMBus power monitor, which requires block reads to access certain data fields, but also has PEC enabled by default.

Fixes df8eb5691c48 ("i2c: Add driver for Cadence I2C controller")

Subject is saying that you adding support for PEC and here you are saying that it is fixing initial commit.

If this is adding new support I think Fixes tag shouldn't be here.

If it is fixing issue subject should be updated and this Fixes tag kept here.

The rest looks good to me.

Shubhrajyoti: Can you please test?

Thanks,
Michal

#2 lore raw

[AMD Official Use Only - General]

Quoted 45 lines

-----Original Message-----
From: Simek, Michal <[email protected]>
Sent: Monday, July 18, 2022 2:56 PM
To: Lars-Peter Clausen <[email protected]>; Wolfram Sang <[email protected]>; Datta, Shubhrajyoti <[email protected]>
Cc: [email protected]; git <[email protected]>
Subject: Re: [PATCH] i2c: cadence: Support PEC for SMBus block read

Quoted 3 lines · Lars-Peter Clausen

SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the

I2C bus.

Quoted 17 lines

SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes.

The combination of PEC and block read is currently not supported by the Cadence I2C driver.
* When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes.
* The I2C core smbus emulation layer relies on the driver updating the i2c_msg len field with the number of received bytes. The updated length is used when checking the PEC.

Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial len value of the i2c_msg. When PEC is enabled this will be 2, when it is disabled it will be 1.

Quoted 4 lines

Once a read transfer is done also increment the len field by the amount of received data bytes.

This change has been tested with a UCM90320 PMBus power monitor,

which

Quoted 4 lines

requires block reads to access certain data fields, but also has PEC enabled by default.

Fixes df8eb5691c48 ("i2c: Add driver for Cadence I2C controller")

Subject is saying that you adding support for PEC and here you are saying that it is fixing initial commit.

Quoted 7 lines

If this is adding new support I think Fixes tag shouldn't be here.

If it is fixing issue subject should be updated and this Fixes tag kept here.

The rest looks good to me.

Shubhrajyoti: Can you please test?

I have tested the reads and write smbus without packet error check.

Quoted 3 lines

Thanks,
Michal

maintainer
#3 lore raw
Quoted 51 lines · Shubhrajyoti

[AMD Official Use Only - General]

Quoted 47 lines

-----Original Message-----
From: Simek, Michal <[email protected]>
Sent: Monday, July 18, 2022 2:56 PM
To: Lars-Peter Clausen <[email protected]>; Wolfram Sang <[email protected]>; Datta, Shubhrajyoti <[email protected]>
Cc: [email protected]; git <[email protected]>
Subject: Re: [PATCH] i2c: cadence: Support PEC for SMBus block read

Quoted 3 lines · Lars-Peter Clausen

SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the

I2C bus.

Quoted 17 lines

SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes.

The combination of PEC and block read is currently not supported by the Cadence I2C driver.
* When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes.
* The I2C core smbus emulation layer relies on the driver updating the i2c_msg len field with the number of received bytes. The updated length is used when checking the PEC.

Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial len value of the i2c_msg. When PEC is enabled this will be 2, when it is disabled it will be 1.

Quoted 4 lines

Once a read transfer is done also increment the len field by the amount of received data bytes.

This change has been tested with a UCM90320 PMBus power monitor,

which

Quoted 4 lines

requires block reads to access certain data fields, but also has PEC enabled by default.

Fixes df8eb5691c48 ("i2c: Add driver for Cadence I2C controller")

Subject is saying that you adding support for PEC and here you are saying that it is fixing initial commit.

If this is adding new support I think Fixes tag shouldn't be here.

Quoted 7 lines
Quoted 5 lines

If it is fixing issue subject should be updated and this Fixes tag kept here.

The rest looks good to me.

Shubhrajyoti: Can you please test?

I have tested the reads and write smbus without packet error check.

Can you please switch it to formal Tested-by: tag?

M

#4 lore raw

[AMD Official Use Only - General]

Quoted 65 lines

-----Original Message-----
From: Simek, Michal <[email protected]>
Sent: Monday, July 18, 2022 6:25 PM
To: Datta, Shubhrajyoti <[email protected]>; Lars-Peter Clausen <[email protected]>; Wolfram Sang <[email protected]>
Cc: [email protected]; git <[email protected]>
Subject: Re: [PATCH] i2c: cadence: Support PEC for SMBus block read

Quoted 54 lines · Shubhrajyoti

[AMD Official Use Only - General]

Quoted 50 lines

-----Original Message-----
From: Simek, Michal <[email protected]>
Sent: Monday, July 18, 2022 2:56 PM
To: Lars-Peter Clausen <[email protected]>; Wolfram Sang <[email protected]>; Datta, Shubhrajyoti <[email protected]>
Cc: [email protected]; git <[email protected]>
Subject: Re: [PATCH] i2c: cadence: Support PEC for SMBus block read

Quoted 4 lines · Lars-Peter Clausen

SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the

I2C bus.

Quoted 17 lines

SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes.

The combination of PEC and block read is currently not supported by the Cadence I2C driver.
* When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes.
* The I2C core smbus emulation layer relies on the driver updating the i2c_msg len field with the number of received bytes. The updated length is used when checking the PEC.

Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial len value of the i2c_msg. When PEC is enabled this will be 2, when it is disabled it will be 1.

Quoted 4 lines

Once a read transfer is done also increment the len field by the amount of received data bytes.

This change has been tested with a UCM90320 PMBus power monitor,

which

Quoted 4 lines

requires block reads to access certain data fields, but also has PEC enabled by default.

Fixes df8eb5691c48 ("i2c: Add driver for Cadence I2C controller")

Subject is saying that you adding support for PEC and here you are saying that it is fixing initial commit.

If this is adding new support I think Fixes tag shouldn't be here.

If it is fixing issue subject should be updated and this Fixes tag kept here.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

The rest looks good to me.

Shubhrajyoti: Can you please test?

I have tested the reads and write smbus without packet error check.

Can you please switch it to formal Tested-by: tag?

Quoted 2 lines

M

#6 lore raw
In reply to Michal Simek
Quoted 30 lines · Michal Simek
Quoted 27 lines · Lars-Peter Clausen

SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the I2C bus.

SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes.

The combination of PEC and block read is currently not supported by the Cadence I2C driver.
  * When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes.
  * The I2C core smbus emulation layer relies on the driver updating the i2c_msg len field with the number of received bytes. The updated length is used when checking the PEC.

Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial len value of the i2c_msg. When PEC is enabled this will be 2, when it is disabled it will be 1.

Once a read transfer is done also increment the len field by the amount of received data bytes.

This change has been tested with a UCM90320 PMBus power monitor, which requires block reads to access certain data fields, but also has PEC enabled by default.

Quoted 7 lines
Quoted 1 line
Fixes df8eb5691c48 ("i2c: Add driver for Cadence I2C controller")

Subject is saying that you adding support for PEC and here you are saying that it is fixing initial commit.

If this is adding new support I think Fixes tag shouldn't be here.

If it is fixing issue subject should be updated and this Fixes tag kept here.

I added it because I was afraid Wolfram would ask where is the fixes tag.

This change arguably somewhere between new feature and fix. The driver reports that it supports SMBus block read, but it does not work under the case that PEC is enabled. You can argue that it is a new feature because it never worked, but you can also argue it is a fix because the current implementation is broken. I'm fine either way with or without Fixes tag. I'll let Wolfram make the decision what he prefers.

Applied
#7 lore raw
In reply to Lars-Peter Clausen
Quoted 23 lines · Lars-Peter Clausen

SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the I2C bus.

SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes.

The combination of PEC and block read is currently not supported by the Cadence I2C driver.
* When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes.
* The I2C core smbus emulation layer relies on the driver updating the i2c_msg len field with the number of received bytes. The updated length is used when checking the PEC.

Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial len value of the i2c_msg. When PEC is enabled this will be 2, when it is disabled it will be 1.

Once a read transfer is done also increment the len field by the amount of received data bytes.

Quoted 6 lines

This change has been tested with a UCM90320 PMBus power monitor, which requires block reads to access certain data fields, but also has PEC enabled by default.

Fixes df8eb5691c48 ("i2c: Add driver for Cadence I2C controller")

Applied to for-next with the Fixes tag, thanks!