at24: Support SMBus read/write of 16-bit devices
Subsystems (2)
PATCH v6 1/1 at24: Support SMBus read/write of 16-bit devices
In reply to a message not in the archivePreviously, the at24 driver would bail out in the case of a 16-bit addressable EEPROM attached to an SMBus controller. This is because SMBus block reads and writes don't map to I2C multi-byte reads and writes when the offset portion is 2 bytes.
Instead of bailing out, this patch settles for functioning with single byte read SMBus cycles. Writes can be block or single-byte, depending on SMBus controller features.
Read access is not without some risk. Multiple SMBus cycles are required to read even one byte. If the SMBus has multiple masters and one accesses this EEPROM between the dummy address write and the subsequent current-address-read cycle(s), this driver will receive data from the wrong address.
Functionality has been tested with the following devices:
AT24CM01 attached to Intel ISCH SMBus
AT24C512 attached to Intel I801 SMBus
Read performance:
3.6 KB/s with 32-byte* access
*limited to 32-bytes by I2C_SMBUS_BLOCK_MAX.
Write performance:
248 B/s with 1-byte page (default)
3.9 KB/s with 128-byte* page (via platform data)
*limited to 31-bytes by I2C_SMBUS_BLOCK_MAX - 1.
---
v2 - Account for changes related to introduction of
i2c_smbus_read_i2c_block_data_or_emulated()
v3 - Consolidate three patches into one
- Expand comments regarding SMBus multi-master read risks.
- Rely on current-address-read for improved read performance (i.e. one dummy address write followed by multiple individual byte reads). This improves performance from 1.4 KiB/s to 3.6 KiB/s.
- Use struct at24_data's writebuf instead of kzalloc-ing
- Only limit write_max by 1-byte when accessing a 16-bit device with block writes instead of attempting to preserve a power-of-two.
- Style fixes (indentation, parentheses, unnecessary masking, etc.)
v4 - Address 16-bit safety in Kconfig
- Set "count" to zero later in at24_smbus_read_block_data()
- Fix over-80-columns issues in at24_eeprom_read()
- Fix write_max off-by-one in at24_probe()
- Check SMBus functionality needed for 16-bit device reads
- Homogenize indentation of SMBus functionality checks for SMBus write
v5 - 16-bit device read needs READ_BYTE not READ_BYTE_DATA
- Clarify write_max limiting with smbus_max
- Add X-ES copyright
v6 - Update comment associated with SMBus functionality testing for 16-bit
device read (READ_BYTE not READ_BYTE_DATA)
drivers/misc/eeprom/Kconfig | 5 +- drivers/misc/eeprom/at24.c | 132 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 122 insertions(+), 15 deletions(-)
drivers/misc/eeprom/Kconfig +4 -1
@@ -22,7 +22,10 @@ config EEPROM_AT24 If you use this with an SMBus adapter instead of an I2C adapter, full functionality is not available. Only smaller devices are - supported (24c16 and below, max 4 kByte). + supported via block reads (24c16 and below, max 4 kByte). + Larger devices that use 16-bit addresses will only work with + individual byte reads, which is very slow in general and is unsafe + in multi-master SMBus topologies. This driver can also be built as a module. If so, the module will be called at24.
drivers/misc/eeprom/at24.c +118 -14
188 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 58 lines · Aaron Sierra
Previously, the at24 driver would bail out in the case of a 16-bit addressable EEPROM attached to an SMBus controller. This is because SMBus block reads and writes don't map to I2C multi-byte reads and writes when the offset portion is 2 bytes.
Instead of bailing out, this patch settles for functioning with single byte read SMBus cycles. Writes can be block or single-byte, depending on SMBus controller features.
Read access is not without some risk. Multiple SMBus cycles are required to read even one byte. If the SMBus has multiple masters and one accesses this EEPROM between the dummy address write and the subsequent current-address-read cycle(s), this driver will receive data from the wrong address.
Functionality has been tested with the following devices:
AT24CM01 attached to Intel ISCH SMBus
AT24C512 attached to Intel I801 SMBusRead performance:
3.6 KB/s with 32-byte* access*limited to 32-bytes by
I2C_SMBUS_BLOCK_MAX.Write performance:
248 B/s with 1-byte page (default)
3.9 KB/s with 128-byte* page (via platform data)*limited to 31-bytes by
I2C_SMBUS_BLOCK_MAX- 1.Signed-off-by Nate Case <[email protected]>Signed-off-by Aaron Sierra <[email protected]>Reviewed-by Jean Delvare <[email protected]>---
v2 - Account for changes related to introduction ofi2c_smbus_read_i2c_block_data_or_emulated()v3 - Consolidate three patches into one
- Expand comments regarding SMBus multi-master read risks.
- Rely on current-address-read for improved read performance (i.e. one dummy address write followed by multiple individual byte reads). This improves performance from 1.4 KiB/s to 3.6 KiB/s.
- Use struct at24_data's writebuf instead of kzalloc-ing
- Only limitwrite_maxby 1-byte when accessing a 16-bit device with block writes instead of attempting to preserve a power-of-two.
- Style fixes (indentation, parentheses, unnecessary masking, etc.)
v4 - Address 16-bit safety inKconfig
- Set "count" to zero later inat24_smbus_read_block_data()
- Fix over-80-columns issues inat24_eeprom_read()
- Fixwrite_maxoff-by-one inat24_probe()
- Check SMBus functionality needed for 16-bit device reads
- Homogenize indentation of SMBus functionality checks for SMBus write
v5 - 16-bit device read needsREAD_BYTEnotREAD_BYTE_DATA
- Clarifywrite_maxlimiting withsmbus_max
- Add X-ES copyright
v6 - Update comment associated with SMBus functionality testing for 16-bit
device read (READ_BYTEnotREAD_BYTE_DATA)
Quoted 4 lines
drivers/misc/eeprom/Kconfig | 5 +- drivers/misc/eeprom/at24.c | 132 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 122 insertions(+), 15 deletions(-)(...)
Sweet, thanks for your patience.
Now it's up to Wolfram.
Signature · 2 lines
Jean Delvare SUSE L3 Support
Quoted 58 lines · Aaron Sierra
Previously, the at24 driver would bail out in the case of a 16-bit addressable EEPROM attached to an SMBus controller. This is because SMBus block reads and writes don't map to I2C multi-byte reads and writes when the offset portion is 2 bytes.
Instead of bailing out, this patch settles for functioning with single byte read SMBus cycles. Writes can be block or single-byte, depending on SMBus controller features.
Read access is not without some risk. Multiple SMBus cycles are required to read even one byte. If the SMBus has multiple masters and one accesses this EEPROM between the dummy address write and the subsequent current-address-read cycle(s), this driver will receive data from the wrong address.
Functionality has been tested with the following devices:
AT24CM01 attached to Intel ISCH SMBus
AT24C512 attached to Intel I801 SMBusRead performance:
3.6 KB/s with 32-byte* access*limited to 32-bytes by
I2C_SMBUS_BLOCK_MAX.Write performance:
248 B/s with 1-byte page (default)
3.9 KB/s with 128-byte* page (via platform data)*limited to 31-bytes by
I2C_SMBUS_BLOCK_MAX- 1.Signed-off-by Nate Case <[email protected]>Signed-off-by Aaron Sierra <[email protected]>Reviewed-by Jean Delvare <[email protected]>---
v2 - Account for changes related to introduction ofi2c_smbus_read_i2c_block_data_or_emulated()v3 - Consolidate three patches into one
- Expand comments regarding SMBus multi-master read risks.
- Rely on current-address-read for improved read performance (i.e. one dummy address write followed by multiple individual byte reads). This improves performance from 1.4 KiB/s to 3.6 KiB/s.
- Use struct at24_data's writebuf instead of kzalloc-ing
- Only limitwrite_maxby 1-byte when accessing a 16-bit device with block writes instead of attempting to preserve a power-of-two.
- Style fixes (indentation, parentheses, unnecessary masking, etc.)
v4 - Address 16-bit safety inKconfig
- Set "count" to zero later inat24_smbus_read_block_data()
- Fix over-80-columns issues inat24_eeprom_read()
- Fixwrite_maxoff-by-one inat24_probe()
- Check SMBus functionality needed for 16-bit device reads
- Homogenize indentation of SMBus functionality checks for SMBus write
v5 - 16-bit device read needsREAD_BYTEnotREAD_BYTE_DATA
- Clarifywrite_maxlimiting withsmbus_max
- Add X-ES copyright
v6 - Update comment associated with SMBus functionality testing for 16-bit
device read (READ_BYTEnotREAD_BYTE_DATA)
Quoted 3 lines
drivers/misc/eeprom/Kconfig | 5 +- drivers/misc/eeprom/at24.c | 132 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 122 insertions(+), 15 deletions(-)
I remember I had a lengthy discussion with Guenter Roeck about 16 bit support via smbus. I don't have the bandwidth right now to recap the discussion and check if the concerns apply to your implementation as well. Could you check this thread
https://lkml.org/lkml/2015/2/4/436
and report back if it applies to your patch as well? This would speed up the review significantly.
Thanks,
Wolfram
----- Original Message -----
Quoted 72 lines
From: "Wolfram Sang" <[email protected]>
Sent: Friday, December 11, 2015 7:19:40 AMQuoted 58 lines · Aaron Sierra
Previously, the at24 driver would bail out in the case of a 16-bit addressable EEPROM attached to an SMBus controller. This is because SMBus block reads and writes don't map to I2C multi-byte reads and writes when the offset portion is 2 bytes.
Instead of bailing out, this patch settles for functioning with single byte read SMBus cycles. Writes can be block or single-byte, depending on SMBus controller features.
Read access is not without some risk. Multiple SMBus cycles are required to read even one byte. If the SMBus has multiple masters and one accesses this EEPROM between the dummy address write and the subsequent current-address-read cycle(s), this driver will receive data from the wrong address.
Functionality has been tested with the following devices:
AT24CM01 attached to Intel ISCH SMBus
AT24C512 attached to Intel I801 SMBusRead performance:
3.6 KB/s with 32-byte* access*limited to 32-bytes by
I2C_SMBUS_BLOCK_MAX.Write performance:
248 B/s with 1-byte page (default)
3.9 KB/s with 128-byte* page (via platform data)*limited to 31-bytes by
I2C_SMBUS_BLOCK_MAX- 1.Signed-off-by Nate Case <[email protected]>Signed-off-by Aaron Sierra <[email protected]>Reviewed-by Jean Delvare <[email protected]>---
v2 - Account for changes related to introduction ofi2c_smbus_read_i2c_block_data_or_emulated()v3 - Consolidate three patches into one
- Expand comments regarding SMBus multi-master read risks.
- Rely on current-address-read for improved read performance (i.e. one dummy address write followed by multiple individual byte reads). This improves performance from 1.4 KiB/s to 3.6 KiB/s.
- Use struct at24_data's writebuf instead of kzalloc-ing
- Only limitwrite_maxby 1-byte when accessing a 16-bit device with block writes instead of attempting to preserve a power-of-two.
- Style fixes (indentation, parentheses, unnecessary masking, etc.)
v4 - Address 16-bit safety inKconfig
- Set "count" to zero later inat24_smbus_read_block_data()
- Fix over-80-columns issues inat24_eeprom_read()
- Fixwrite_maxoff-by-one inat24_probe()
- Check SMBus functionality needed for 16-bit device reads
- Homogenize indentation of SMBus functionality checks for SMBus write
v5 - 16-bit device read needsREAD_BYTEnotREAD_BYTE_DATA
- Clarifywrite_maxlimiting withsmbus_max
- Add X-ES copyright
v6 - Update comment associated with SMBus functionality testing for 16-bit
device read (READ_BYTEnotREAD_BYTE_DATA)Quoted 4 lines
drivers/misc/eeprom/Kconfig | 5 +- drivers/misc/eeprom/at24.c | 132 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 122 insertions(+), 15 deletions(-)I remember I had a lengthy discussion with Guenter Roeck about 16 bit support via smbus. I don't have the bandwidth right now to recap the discussion and check if the concerns apply to your implementation as well. Could you check this thread
Quoted 4 lines
https://lkml.org/lkml/2015/2/4/436
and report back if it applies to your patch as well? This would speed up the review significantly.
Wolfram,
The real bus-level multi-master issue is still present. However, it is documented via comments in the driver and warnings in the Kconfig.
The other (and apparently bigger) issue of a single master experiencing corruption due to simultaneous access through i2c-dev and this driver appears to have been resolved. The i2cdump, i2cget, and i2cset utilities refuse to access any device that has a driver bound to it. My attempts to cause corruption using i2cdump were met with the following message until I unregistered the at24 driver from the device:
# i2cdump 8 0x54 No size specified (using byte-data access) Error: Could not set address to 0x54: Device or resource busy
-Aaron S.
Quoted 24 lines · Aaron Sierra
----- Original Message -----
Quoted 8 lines
From: "Wolfram Sang" <[email protected]>
Sent: Friday, December 11, 2015 7:19:40 AMI remember I had a lengthy discussion with Guenter Roeck about 16 bit support via smbus. I don't have the bandwidth right now to recap the discussion and check if the concerns apply to your implementation as well. Could you check this thread
Quoted 4 lines
https://lkml.org/lkml/2015/2/4/436
and report back if it applies to your patch as well? This would speed up the review significantly.
The real bus-level multi-master issue is still present. However, it is documented via comments in the driver and warnings in the
Kconfig.The other (and apparently bigger) issue of a single master experiencing corruption due to simultaneous access through i2c-dev and this driver appears to have been resolved. The i2cdump, i2cget, and i2cset utilities refuse to access any device that has a driver bound to it. My attempts to cause corruption using i2cdump were met with the following message until I unregistered the at24 driver from the device:
Quoted 3 lines
# i2cdump 8 0x54 No size specified (using byte-data access) Error: Could not set address to 0x54: Device or resource busy
You could always bypass the security check and force the access with option -f. But then there are plenty of ways to corrupt any device that way, regardless of the driver (or even without any driver bound to the device, if you run multiple i2c-dev-based user-space tools in parallel.) So I'd say this is not relevant.
Signature · 2 lines
Jean Delvare SUSE L3 Support