Skip to contentSkip to conversation

i2c: ismt: Separate I2C block read from SMBus block read

PATCH Applied Pontus Andersson 3 participants 6 messages Oct 2, 2017 – Oct 9, 2017 1 message not in the archive

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

PATCH 1/1 i2c: ismt: Separate I2C block read from SMBus block read

Commit b6c159a9cb69 ("i2c: ismt: Don't duplicate the receive length for block reads") broke I2C block reads. It aimed to fix normal SMBus block read, but changed the correct behavior of I2C block read in the process.

According to Documentation/i2c/smbus-protocol, one vital difference between normal SMBus block read and I2C block read is that there is no byte count prefixed in the data sent on the wire:

SMBus Block Read: i2c_smbus_read_block_data()
S Addr Wr [A] Comm [A]
S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

I2C Block Read: i2c_smbus_read_i2c_block_data()
S Addr Wr [A] Comm [A]
S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

Therefore the two transaction types need to be processed differently in the driver by copying of the dma_buffer as done previously for the I2C_SMBUS_I2C_BLOCK_DATA case.

Fixes b6c159a9cb69 ("i2c: ismt: Don't duplicate the receive length for block reads")
---
 drivers/i2c/busses/i2c-ismt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-ismt.c +4 -1
index 22ffcb73c185..b51adffa4841 100644
@@ -340,12 +340,15 @@ static int ismt_process_desc(const struct ismt_desc *desc,
 			data->word = dma_buffer[0] | (dma_buffer[1] << 8);
 			break;
 		case I2C_SMBUS_BLOCK_DATA:
-		case I2C_SMBUS_I2C_BLOCK_DATA:
 			if (desc->rxbytes != dma_buffer[0] + 1)
 				return -EMSGSIZE;
 
 			memcpy(data->block, dma_buffer, desc->rxbytes);
 			break;
+		case I2C_SMBUS_I2C_BLOCK_DATA:
+			memcpy(&data->block[1], dma_buffer, desc->rxbytes);
+			data->block[0] = desc->rxbytes;
+			break;
 		}
 		return 0;
 	}
Signature · 1 line
2.14.1
Applied
#1 lore raw
Quoted 16 lines · Pontus Andersson

Commit b6c159a9cb69 ("i2c: ismt: Don't duplicate the receive length for block reads") broke I2C block reads. It aimed to fix normal SMBus block read, but changed the correct behavior of I2C block read in the process.

According to Documentation/i2c/smbus-protocol, one vital difference between normal SMBus block read and I2C block read is that there is no byte count prefixed in the data sent on the wire:

SMBus Block Read: i2c_smbus_read_block_data()
S Addr Wr [A] Comm [A]
S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

I2C Block Read: i2c_smbus_read_i2c_block_data()
S Addr Wr [A] Comm [A]
S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

Quoted 7 lines

Therefore the two transaction types need to be processed differently in the driver by copying of the dma_buffer as done previously for the I2C_SMBUS_I2C_BLOCK_DATA case.

Fixes b6c159a9cb69 ("i2c: ismt: Don't duplicate the receive length for block reads")

Applied to for-current, thanks!

Might have been good to CC the patch author of the problematic commit, too.

#2 lore raw
Quoted 21 lines · Wolfram Sang
Quoted 20 lines · Pontus Andersson

Commit b6c159a9cb69 ("i2c: ismt: Don't duplicate the receive length for block reads") broke I2C block reads. It aimed to fix normal SMBus block read, but changed the correct behavior of I2C block read in the process.

According to Documentation/i2c/smbus-protocol, one vital difference between normal SMBus block read and I2C block read is that there is no byte count prefixed in the data sent on the wire:

SMBus Block Read: i2c_smbus_read_block_data()
S Addr Wr [A] Comm [A]
S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

I2C Block Read: i2c_smbus_read_i2c_block_data()
S Addr Wr [A] Comm [A]
S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

Therefore the two transaction types need to be processed differently in the driver by copying of the dma_buffer as done previously for the I2C_SMBUS_I2C_BLOCK_DATA case.

Quoted 5 lines
Quoted 3 lines
Fixes b6c159a9cb69 ("i2c: ismt: Don't duplicate the receive length for block reads")

Applied to for-current, thanks!

Thank you! Is it safe to asume it will be backported to 4.4 stable branch and upwards as the problematic commit did (once in mainline)?

Quoted 2 lines

Might have been good to CC the patch author of the problematic commit, too.

Yes, of course! Stephen is CC now at least (kept the commit message quoted at his convenience).

#3 lore raw
Quoted 28 lines · Pontus Andersson
Quoted 21 lines · Wolfram Sang
Quoted 20 lines · Pontus Andersson

Commit b6c159a9cb69 ("i2c: ismt: Don't duplicate the receive length for block reads") broke I2C block reads. It aimed to fix normal SMBus block read, but changed the correct behavior of I2C block read in the process.

According to Documentation/i2c/smbus-protocol, one vital difference between normal SMBus block read and I2C block read is that there is no byte count prefixed in the data sent on the wire:

SMBus Block Read: i2c_smbus_read_block_data()
S Addr Wr [A] Comm [A]
S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

I2C Block Read: i2c_smbus_read_i2c_block_data()
S Addr Wr [A] Comm [A]
S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

Therefore the two transaction types need to be processed differently in the driver by copying of the dma_buffer as done previously for the I2C_SMBUS_I2C_BLOCK_DATA case.

Quoted 5 lines
Quoted 3 lines
Fixes b6c159a9cb69 ("i2c: ismt: Don't duplicate the receive length for block reads")

Applied to for-current, thanks!

Quoted 8 lines

Thank you! Is it safe to asume it will be backported to 4.4 stable branch and upwards as the problematic commit did (once in mainline)?

Quoted 2 lines

Might have been good to CC the patch author of the problematic commit, too.

Yes, of course! Stephen is CC now at least (kept the commit message quoted at his convenience).

Doh. Looks like our regression test gave a false pass on the I2C access case. I'd guess it's probably doing a series of byte reads instead of a block read and missing the I2C_SMBUS_I2C_BLOCK_DATA case entirely.

Unfortunately I can't find the board that was modded with more I2C devices on the ismt bus to verify this right now. I'll check with Dan on Monday to see if he knows where that board is stashed.

Apologies for moving the bug instead of fixing it, and FWIW I'll have an update Monday.

#4 lore raw
In reply to Pontus Andersson
Quoted 3 lines

Thank you! Is it safe to asume it will be backported to 4.4 stable branch and upwards as the problematic commit did (once in mainline)?

Yes, it has a Fixes: and a stable tag. That should do.

Quoted 5 lines
Quoted 2 lines

Might have been good to CC the patch author of the problematic commit, too.

Yes, of course! Stephen is CC now at least (kept the commit message quoted at his convenience).

So, I'll wait for his tests and then send it to Linus ASAP. I think it should be in rc5.

A message that is not in the archive (sent off-list or not yet received): [email protected]

Tested-by
#6 lore raw
Quoted 2 lines

So, I'll wait for his tests and then send it to Linus ASAP. I think it should be in rc5.

I've been able to confirm the regression my patch introduced, and the fix from Pontus.

Doing a block read of the SPD EEPROM with my patch everything is shifted by a byte:

[root@localhost ~]# i2cdump -y 0 0x50 i

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 13 0b 02 04 21 02 01 03 11 01 08 0a 00 fe 00 69    ????!???????.?.i
10: 78 69 30 69 11 18 81 20 08 3c 3c 00 f0 83 05 80    xi0i??? ?<<.????
20: 00 00 00 00 00 00 00 00 85 00 00 00 00 00 00 00    ........?.......
30: 00 00 00 00 00 00 00 00 00 00 00 0f 01 23 00 00    ...........??#..
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
70: 00 00 00 00 80 2c 00 00 00 00 00 00 00 a6 dc 39    ....?,.......??9
80: 4b 53 46 35 31 32 37 32 41 5a 2d 31 47 36 45 31    KSF51272AZ-1G6E1

90: 20 45 31 80 2c 00 00 00 00 00 00 00 00 00 00 00 E1?,...........
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ................
b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 92 ...............?

With the patch from Pontus the I2C block read works as expected:

[root@localhost ~]# i2cdump -y 0 0x50 i

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 92 13 0b 02 04 21 02 01 03 11 01 08 0a 00 fe 00    ?????!???????.?.
10: 69 78 69 30 69 11 18 81 20 08 3c 3c 00 f0 83 05    ixi0i??? ?<<.???
20: 80 00 00 00 00 00 00 00 00 85 00 00 00 00 00 00    ?........?......
30: 00 00 00 00 00 00 00 00 00 00 00 00 0f 01 23 00    ............??#.
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
70: 00 00 00 00 00 80 2c 00 00 00 00 00 00 00 a6 dc    .....?,.......??
80: 39 4b 53 46 35 31 32 37 32 41 5a 2d 31 47 36 45    9KSF51272AZ-1G6E
90: 31 20 45 31 80 2c 00 00 00 00 00 00 00 00 00 00    1 E1?,..........
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

The ipmi_ssif driver still works with this patch, so no issues for SMBus block reads.