Skip to contentSkip to conversation

fix functionality constant for read_byte_pec

PATCH New Hideki IWAMOTO 3 participants 7 messages Sep 24, 2005 – Sep 28, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix functionality constant for read_byte_pec

Implementing read_byte_pec using read_byte_data is impossible.

SMBus read byte with PEC:
S Addr Rd [A] [Data] A [PEC] NA P

SMBus read byte data:
S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

Index: i2c/kernel/i2c.h
=================================RCS file: /home/cvs/i2c/kernel/i2c.h,v retrieving revision 1.95

kernel/i2c.h +3 -2
diff -u -r1.95 i2c.h
@@ -397,6 +397,7 @@
 #define I2C_FUNC_10BIT_ADDR		0x00000002
 #define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
 #define I2C_FUNC_SMBUS_HWPEC_CALC	0x00000008 /* SMBus 2.0 */
+#define I2C_FUNC_SMBUS_READ_BYTE_PEC	0x00000400 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_PROC_CALL_PEC	0x00002000 /* SMBus 2.0 */
@@ -435,12 +436,12 @@
                                        I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC)
 #define I2C_FUNC_SMBUS_WORD_DATA_PEC  (I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
                                        I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC)
+#define I2C_FUNC_SMBUS_BYTE_PEC (I2C_FUNC_SMBUS_READ_BYTE_PEC | \
+                                 I2C_FUNC_SMBUS_WRITE_BYTE_PEC)
 
-#define I2C_FUNC_SMBUS_READ_BYTE_PEC		I2C_FUNC_SMBUS_READ_BYTE_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_PEC		I2C_FUNC_SMBUS_WRITE_BYTE_DATA
 #define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC	I2C_FUNC_SMBUS_READ_WORD_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC	I2C_FUNC_SMBUS_WRITE_WORD_DATA
-#define I2C_FUNC_SMBUS_BYTE_PEC			I2C_FUNC_SMBUS_BYTE_DATA
 #define I2C_FUNC_SMBUS_BYTE_DATA_PEC		I2C_FUNC_SMBUS_WORD_DATA
 
 #define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \

Index: lm_sensors2/kernel/include/i2c-dev.h =================================RCS file: /home/cvs/lm_sensors2/kernel/include/i2c-dev.h,v retrieving revision 1.7

kernel/include/i2c-dev.h +3 -2
diff -u -r1.7 i2c-dev.h
@@ -55,6 +55,7 @@
 #define I2C_FUNC_10BIT_ADDR		0x00000002
 #define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
 #define I2C_FUNC_SMBUS_HWPEC_CALC	0x00000008 /* SMBus 2.0 */
+#define I2C_FUNC_SMBUS_READ_BYTE_PEC	0x00000400 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_PROC_CALL_PEC	0x00002000 /* SMBus 2.0 */
@@ -93,12 +94,12 @@
                                       I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
 #define I2C_FUNC_SMBUS_WORD_DATA_PEC  I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
                                       I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
+#define I2C_FUNC_SMBUS_BYTE_PEC I2C_FUNC_SMBUS_READ_BYTE_PEC | \
+                                I2C_FUNC_SMBUS_WRITE_BYTE_PEC
 
-#define I2C_FUNC_SMBUS_READ_BYTE_PEC		I2C_FUNC_SMBUS_READ_BYTE_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_PEC		I2C_FUNC_SMBUS_WRITE_BYTE_DATA
 #define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC	I2C_FUNC_SMBUS_READ_WORD_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC	I2C_FUNC_SMBUS_WRITE_WORD_DATA
-#define I2C_FUNC_SMBUS_BYTE_PEC			I2C_FUNC_SMBUS_BYTE_DATA
 #define I2C_FUNC_SMBUS_BYTE_DATA_PEC		I2C_FUNC_SMBUS_WORD_DATA
 
 #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \

----
Hideki IWAMOTO [email protected]

#1 lore raw

PATCH 1/1 fix functionality constant for read_byte_pec

Konbanwa Hideki,

Quoted 7 lines

Implementing read_byte_pec using read_byte_data is impossible.

SMBus read byte with PEC:
S Addr Rd [A] [Data] A [PEC] NA P

SMBus read byte data:
S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

You're right once again... Impressive how our code is broken, and nobody ever noticed before.

Quoted 19 lines

Index: i2c/kernel/i2c.h
=================================> RCS file: /home/cvs/i2c/kernel/i2c.h,v retrieving revision 1.95
diff -u -r1.95 i2c.h

kernel/i2c.h +2 -0
@@ -397,6 +397,7 @@
 #define I2C_FUNC_10BIT_ADDR		0x00000002
 #define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
 #define I2C_FUNC_SMBUS_HWPEC_CALC	0x00000008 /* SMBus 2.0 */
+#define I2C_FUNC_SMBUS_READ_BYTE_PEC	0x00000400 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_PROC_CALL_PEC	0x00002000 /* SMBus 2.0 */
@@ -435,12 +436,12 @@
                                        I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC)
 #define I2C_FUNC_SMBUS_WORD_DATA_PEC  (I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
                                        I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC)
+#define I2C_FUNC_SMBUS_BYTE_PEC (I2C_FUNC_SMBUS_READ_BYTE_PEC | \

kernel/i2c.h line 447

Quoted 10 lines
kernel/i2c.h +1 -2
+                                 I2C_FUNC_SMBUS_WRITE_BYTE_PEC)
 
-#define I2C_FUNC_SMBUS_READ_BYTE_PEC		I2C_FUNC_SMBUS_READ_BYTE_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_PEC		I2C_FUNC_SMBUS_WRITE_BYTE_DATA
 #define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC	I2C_FUNC_SMBUS_READ_WORD_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC	I2C_FUNC_SMBUS_WRITE_WORD_DATA
-#define I2C_FUNC_SMBUS_BYTE_PEC			I2C_FUNC_SMBUS_BYTE_DATA
 #define I2C_FUNC_SMBUS_BYTE_DATA_PEC		I2C_FUNC_SMBUS_WORD_DATA
 
 #define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \

Everyone:

This bug report (and the other ones Hideki sent before) made me look at the PEC-related code more carefully. I had never actually looked at it before. I don't much like the way it was implemented, it is awfully complex, which must explain why it has so many bugs, and why PEC is almost unused while the feature was implemented more than 3 years ago.

I think this is the right time to analyze the situation, and rework the whole PEC implementation to make it better. I think I understand that the current implementation was made with in a "do as much as we can on every hardware combination" perspective. While this was a noble intention, I don't think this was the right thing to do. Given that PEC is optional in almost all cases (the only exception being ARP), I would prefer a much simpler, more robust and less buggy implementation.

Let me summarize what I understood from the current implementation:

(1) Bus drivers are supposed to explicitely list all SMBus transactions they are able to do with PEC, in addition to all transactions they can do without PEC (using the "functionality" bitfield). Clients can check for PEC support on individual transactions.

(2) Clients can explicitely ask for PEC on every transaction.

(3) Clients can declare themselves PEC-capable, letting bus drivers use the PEC-version of each transaction without explicitely requesting it.

(4) For non-SMBus I2C adapters, PEC is implemented in software by i2c-core.

(5) For SMBus adapters, PEC can be implemented in hardware. If it is not, i2c-core attempts to do as much as possible, using the fact that some non-PEC transactions can be used to emulate some PEC transactions. This results in a partial PEC support on these adapters, and tricky code (my opinion at least).

Additionally, my reading of the SMBus 2.0 specification is that:

(6) PEC is always optional, except for ARP. This means that a client should never ask explicitely for a PEC transaction. Instead, it should declare itself PEC-capable, ask for a standard transaction and let the bus driver decide whether or not to use PEC depending on its own capabilities.

Finally, my knowledge of the various hardware SMBus chips (masters and slaves) suggests that:

(7) SMBus slaves will support PEC on all transactions they use, or none.

(8) SMBus masters will support PEC an all transactions they support, or none. Not sure it actually matters though.

My conclusions are:

(6) implies that (1) is not needed for SMBus masters. Clients do not need to be aware of PEC support for individual transactions. It's actually questionable whether they need to know about the bus PEC capabilities at all (except for ARP, maybe.) They certainly don't need to know whether PEC support is hardware or software.

(5) is what makes (1) needed in the current implementation, but I do not this it is worth the additional code and complexity. Software PEC support on non-PEC SMBus masters is partial by construction, and has proven to be broken.

(6) implies that (2) is not wanted. Clients ask for a normal transaction, PEC or not is the master's decision.

(6) and (7) imply that (3) is wanted. That's what I2C_CLIENT_PEC is for.

(4) looks sane to me. We can add PEC support to any transaction in I2C emulation mode, it's only a matter of writing the code.

Which leads me to the point that we should consider dropping (1), (2) and (5). This would make the i2c-core smaller and faster, more readable and less buggy as a consequence, for almost no functionality loss if any. I wouldn't expect SMBus slaves which can do PEC connected to SMBus masters which cannot. If it happens, this means that the designer did not think PEC was required, so we are most certainly fine without it.

The good thing here is that PEC is not used right now. Just consider the number of bugs Hideki reported these last few days, anyone actually using PEC would have reported at least one of them. So nobody tried to use it, or they all gave up quickly (understandably). I searched the kernel source and couldn't find any real use case, neither in 2.4 nor 2.6, except for smbus-arp in lm_sensors CVS. In user-space, the only user seems to be i2cdump. This means that we can probably change the way PEC works without affecting anyone. Let's just hope that such a cleanup would invite people to use PEC in chip drivers, and implement it in bus drivers where hardware can do it, once it is properly implemented.

Hideki:

You seem to have read the code in great details. Can you comment on it? Does the PEC implementation look OK to you? How does my simplification proposal sound to you? Do you have a immediate need for PEC support yourself?

Arigato,

Signature · 1 line
Jean Delvare
#2 lore raw

PATCH 1/1 fix functionality constant for read_byte_pec

In reply to Hideki IWAMOTO

On Sun, 25 Sep 2005 23:32:39 +0200, Jean Delvare wrote...

Quoted 2 lines

Does the PEC implementation look OK to you? How does my simplification proposal sound to you?

Since I have never used a PEC-capable slave device,
I can understand only in respect of the maintainability of source. I agree with your opinion.

Quoted 1 line

Do you have a immediate need for PEC support yourself?

No.

----
Hideki IWAMOTO [email protected]

#3 lore raw

PATCH 1/1 fix functionality constant for read_byte_pec

In reply to Hideki IWAMOTO

Konbanwa Hideki, hi all,

Quoted 56 lines

Implementing read_byte_pec using read_byte_data is impossible.

SMBus read byte with PEC:
S Addr Rd [A] [Data] A [PEC] NA P

SMBus read byte data:
S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

Index: i2c/kernel/i2c.h
=================================> RCS file: /home/cvs/i2c/kernel/i2c.h,v retrieving revision 1.95
diff -u -r1.95 i2c.h

kernel/i2c.h +3 -2
@@ -397,6 +397,7 @@
 #define I2C_FUNC_10BIT_ADDR		0x00000002
 #define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
 #define I2C_FUNC_SMBUS_HWPEC_CALC	0x00000008 /* SMBus 2.0 */
+#define I2C_FUNC_SMBUS_READ_BYTE_PEC	0x00000400 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_PROC_CALL_PEC	0x00002000 /* SMBus 2.0 */
@@ -435,12 +436,12 @@
                                        I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC)
 #define I2C_FUNC_SMBUS_WORD_DATA_PEC  (I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
                                        I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC)
+#define I2C_FUNC_SMBUS_BYTE_PEC (I2C_FUNC_SMBUS_READ_BYTE_PEC | \
+                                 I2C_FUNC_SMBUS_WRITE_BYTE_PEC)
 
-#define I2C_FUNC_SMBUS_READ_BYTE_PEC		I2C_FUNC_SMBUS_READ_BYTE_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_PEC		I2C_FUNC_SMBUS_WRITE_BYTE_DATA
 #define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC	I2C_FUNC_SMBUS_READ_WORD_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC	I2C_FUNC_SMBUS_WRITE_WORD_DATA
-#define I2C_FUNC_SMBUS_BYTE_PEC			I2C_FUNC_SMBUS_BYTE_DATA
 #define I2C_FUNC_SMBUS_BYTE_DATA_PEC		I2C_FUNC_SMBUS_WORD_DATA
 
 #define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \

Index: lm_sensors2/kernel/include/i2c-dev.h
=================================> RCS file: /home/cvs/lm_sensors2/kernel/include/i2c-dev.h,v retrieving revision 1.7
diff -u -r1.7 i2c-dev.h

kernel/include/i2c-dev.h +2 -0
@@ -55,6 +55,7 @@
 #define I2C_FUNC_10BIT_ADDR		0x00000002
 #define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
 #define I2C_FUNC_SMBUS_HWPEC_CALC	0x00000008 /* SMBus 2.0 */
+#define I2C_FUNC_SMBUS_READ_BYTE_PEC	0x00000400 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
 #define I2C_FUNC_SMBUS_PROC_CALL_PEC	0x00002000 /* SMBus 2.0 */
@@ -93,12 +94,12 @@
                                       I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
 #define I2C_FUNC_SMBUS_WORD_DATA_PEC  I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
                                       I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
+#define I2C_FUNC_SMBUS_BYTE_PEC I2C_FUNC_SMBUS_READ_BYTE_PEC | \

kernel/include/i2c-dev.h line 105

Quoted 10 lines
kernel/include/i2c-dev.h +1 -2
+                                I2C_FUNC_SMBUS_WRITE_BYTE_PEC
 
-#define I2C_FUNC_SMBUS_READ_BYTE_PEC		I2C_FUNC_SMBUS_READ_BYTE_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_PEC		I2C_FUNC_SMBUS_WRITE_BYTE_DATA
 #define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC	I2C_FUNC_SMBUS_READ_WORD_DATA
 #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC	I2C_FUNC_SMBUS_WRITE_WORD_DATA
-#define I2C_FUNC_SMBUS_BYTE_PEC			I2C_FUNC_SMBUS_BYTE_DATA
 #define I2C_FUNC_SMBUS_BYTE_DATA_PEC		I2C_FUNC_SMBUS_WORD_DATA
 
 #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \

As a consequence of the opinion I exposed yesterday, I would like to propose a different fix: I think we should simply drop all I2C_FUNC_SMBUS_*_PEC constants. i2c clients are not supposed to check whether an adapter can do PEC on a specific SMBus transaction. Instead, they should declare themselves PEC-capable (flags |= I2C_CLIENT_PEC) and ask for the regular (non-PEC) transaction, leaving it to the bus driver to do PEC or not.

Attached are three patches doing that: one for i2c CVS, one for lm_sensors2 CVS and one for linux-2.6. Note that the latter should be applied after the i2c-i801 patch I posted on this list earlier today.

In details, here's what these patches do:

i2c-func-pec-i2c-CVS.diff:
* i2c-algo-bit.c: No need to explicitely declare the ability to do Block Process Call and Block Read with PEC.
* i2c.h: Drop I2C_FUNC_SMBUS_*_PEC constants.

i2c-func-pec-lm_sensors2-CVS.diff:
* i2c-i801.c: Rely on I2C_CLIENT_PEC to detect the PEC support in core. No need to explicitely declare the ability to do Block Read/Write with PEC.
* smbus-arp.c: Use a different way to detect SW PEC capabilities. It's probably not a definitive fix, but that will do for now.
* i2c-dev.h: Drop I2C_FUNC_SMBUS_*_PEC constants.
* i2cdump.c: Do not check explictely for individual PEC transactions support. Check for global PEC support instead. It's not reliable at this point (which is why I made it a warning rather than an error) so the fix isn't definitive either.

i2c-func-pec-linux-2.6.diff:
* i2c.h: Drop I2C_FUNC_SMBUS_*_PEC constants.
* i2c-i801.c: Rely on I2C_CLIENT_PEC to detect the PEC support in core. No need to explicitely declare the ability to do Block Read/Write with PEC.

Are there objections to this approach? If not, I'll just apply these patches.

Note that the bug Hideki found here (read_byte_pec cannot be emulated with read_byte_data) seems to be a proof that the design of the current PEC implementation is broken. This implementation (or at least the software PEC part) was relying on the fact that one transaction "size" (really more a transaction type) would always lead to another, unique "size" when adding PEC. Now we see that this isn't true anymore for size = byte: the new size is byte_data for writes, and something different (no #define yet) for reads. This means that we will need to rewrite a part of the code if we want to support SW PEC on byte reads. I'll work on this. My idea is that we shouldn't be considering PEC transactions as new or reused "sizes", but as an independant flag. I'll see what code changes are needed to do this.

Arigato/thanks,

Signature · 335 lines
Jean Delvare
-------------- next part --------------
Index: kernel/i2c-algo-bit.c
=================================RCS file: /home/cvs/i2c/kernel/i2c-algo-bit.c,v
retrieving revision 1.53
diff -u -r1.53 i2c-algo-bit.c
--- kernel/i2c-algo-bit.c	30 Apr 2005 19:53:50 -0000	1.53
+++ kernel/i2c-algo-bit.c	26 Sep 2005 20:55:47 -0000
@@ -534,9 +534,7 @@
 	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
 	       I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING |
 	       I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
-	       I2C_FUNC_SMBUS_READ_BLOCK_DATA |
-	       I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC |
-	       I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC;
+	       I2C_FUNC_SMBUS_READ_BLOCK_DATA;
 }
 
 
Index: kernel/i2c.h
=================================RCS file: /home/cvs/i2c/kernel/i2c.h,v
retrieving revision 1.96
diff -u -r1.96 i2c.h
--- kernel/i2c.h	24 Sep 2005 09:38:17 -0000	1.96
+++ kernel/i2c.h	26 Sep 2005 20:55:48 -0000
@@ -397,10 +397,6 @@
 #define I2C_FUNC_10BIT_ADDR		0x00000002
 #define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
 #define I2C_FUNC_SMBUS_HWPEC_CALC	0x00000008 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
-#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
-#define I2C_FUNC_SMBUS_PROC_CALL_PEC	0x00002000 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL	0x00008000 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_QUICK		0x00010000 
 #define I2C_FUNC_SMBUS_READ_BYTE	0x00020000 
@@ -416,8 +412,6 @@
 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK	0x08000000 /* w/ 1-byte reg. addr. */
 #define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2	 0x10000000 /* I2C-like block xfer  */
 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
-#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC  0x40000000 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
 
 #define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \
                              I2C_FUNC_SMBUS_WRITE_BYTE)
@@ -431,17 +425,6 @@
                                   I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)
 #define I2C_FUNC_SMBUS_I2C_BLOCK_2 (I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
                                     I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2)
-#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC (I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
-                                       I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC)
-#define I2C_FUNC_SMBUS_WORD_DATA_PEC  (I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
-                                       I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC)
-
-#define I2C_FUNC_SMBUS_READ_BYTE_PEC		I2C_FUNC_SMBUS_READ_BYTE_DATA
-#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC		I2C_FUNC_SMBUS_WRITE_BYTE_DATA
-#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC	I2C_FUNC_SMBUS_READ_WORD_DATA
-#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC	I2C_FUNC_SMBUS_WRITE_WORD_DATA
-#define I2C_FUNC_SMBUS_BYTE_PEC			I2C_FUNC_SMBUS_BYTE_DATA
-#define I2C_FUNC_SMBUS_BYTE_DATA_PEC		I2C_FUNC_SMBUS_WORD_DATA
 
 #define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \
                              I2C_FUNC_SMBUS_BYTE | \
@@ -449,7 +432,6 @@
                              I2C_FUNC_SMBUS_WORD_DATA | \
                              I2C_FUNC_SMBUS_PROC_CALL | \
                              I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
-                             I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
                              I2C_FUNC_SMBUS_I2C_BLOCK)
 
 /* 
-------------- next part --------------
Index: kernel/busses/i2c-i801.c
=================================RCS file: /home/cvs/lm_sensors2/kernel/busses/i2c-i801.c,v
retrieving revision 1.48
diff -u -r1.48 i2c-i801.c
--- kernel/busses/i2c-i801.c	26 Jun 2005 08:48:04 -0000	1.48
+++ kernel/busses/i2c-i801.c	26 Sep 2005 20:58:08 -0000
@@ -91,7 +91,7 @@
 #define PCI_DEVICE_ID_INTEL_ICH7_17	0x27da
 #endif
 
-#ifdef I2C_FUNC_SMBUS_BLOCK_DATA_PEC
+#ifdef I2C_CLIENT_PEC
 #define HAVE_PEC
 #endif
 
@@ -594,8 +594,7 @@
 	    I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
 	    I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
 #ifdef HAVE_PEC
-	     | (isich4 ? I2C_FUNC_SMBUS_BLOCK_DATA_PEC |
-	                 I2C_FUNC_SMBUS_HWPEC_CALC
+	     | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC
 	               : 0)
 #endif
 #if 0
Index: kernel/chips/smbus-arp.c
=================================RCS file: /home/cvs/lm_sensors2/kernel/chips/smbus-arp.c,v
retrieving revision 1.14
diff -u -r1.14 smbus-arp.c
--- kernel/chips/smbus-arp.c	23 Jan 2005 18:02:43 -0000	1.14
+++ kernel/chips/smbus-arp.c	26 Sep 2005 20:58:08 -0000
@@ -184,8 +184,7 @@
 	/* must support block data w/ HW PEC or SW PEC */
 	if ((!i2c_check_functionality(adapter,
 	        I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_HWPEC_CALC)) &&
-	    (!i2c_check_functionality(adapter,
-	        I2C_FUNC_SMBUS_BLOCK_DATA_PEC)))
+	    (!i2c_check_functionality(adapter, I2C_FUNC_I2C)))
 		return(0);
 
 	if (!(data = kmalloc(sizeof(struct arp_data), GFP_KERNEL))) {
Index: kernel/include/i2c-dev.h
=================================RCS file: /home/cvs/lm_sensors2/kernel/include/i2c-dev.h,v
retrieving revision 1.9
diff -u -r1.9 i2c-dev.h
--- kernel/include/i2c-dev.h	26 Sep 2005 17:35:48 -0000	1.9
+++ kernel/include/i2c-dev.h	26 Sep 2005 20:58:08 -0000
@@ -55,10 +55,6 @@
 #define I2C_FUNC_10BIT_ADDR		0x00000002
 #define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
 #define I2C_FUNC_SMBUS_HWPEC_CALC	0x00000008 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
-#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
-#define I2C_FUNC_SMBUS_PROC_CALL_PEC	0x00002000 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL	0x00008000 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_QUICK		0x00010000 
 #define I2C_FUNC_SMBUS_READ_BYTE	0x00020000 
@@ -74,8 +70,6 @@
 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK	0x08000000 /* w/ 1-byte reg. addr. */
 #define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2	 0x10000000 /* I2C-like block xfer  */
 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
-#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC  0x40000000 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
 
 #define I2C_FUNC_SMBUS_BYTE I2C_FUNC_SMBUS_READ_BYTE | \
                             I2C_FUNC_SMBUS_WRITE_BYTE
@@ -89,17 +83,6 @@
                                   I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
 #define I2C_FUNC_SMBUS_I2C_BLOCK_2 I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
                                    I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2
-#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
-                                      I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
-#define I2C_FUNC_SMBUS_WORD_DATA_PEC  I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
-                                      I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
-
-#define I2C_FUNC_SMBUS_READ_BYTE_PEC		I2C_FUNC_SMBUS_READ_BYTE_DATA
-#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC		I2C_FUNC_SMBUS_WRITE_BYTE_DATA
-#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC	I2C_FUNC_SMBUS_READ_WORD_DATA
-#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC	I2C_FUNC_SMBUS_WRITE_WORD_DATA
-#define I2C_FUNC_SMBUS_BYTE_PEC			I2C_FUNC_SMBUS_BYTE_DATA
-#define I2C_FUNC_SMBUS_BYTE_DATA_PEC		I2C_FUNC_SMBUS_WORD_DATA
 
 #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \
                             I2C_FUNC_SMBUS_BYTE | \
@@ -107,7 +90,6 @@
                             I2C_FUNC_SMBUS_WORD_DATA | \
                             I2C_FUNC_SMBUS_PROC_CALL | \
                             I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
-                            I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
                             I2C_FUNC_SMBUS_I2C_BLOCK
 
 /* 
Index: prog/dump/i2cdump.c
=================================RCS file: /home/cvs/lm_sensors2/prog/dump/i2cdump.c,v
retrieving revision 1.35
diff -u -r1.35 i2cdump.c
--- prog/dump/i2cdump.c	25 Sep 2005 18:57:42 -0000	1.35
+++ prog/dump/i2cdump.c	26 Sep 2005 20:58:08 -0000
@@ -183,74 +183,35 @@
 
 	switch(size) {
 	case I2C_SMBUS_BYTE:
-		if (pec) {
-			if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_PEC)) {
-				fprintf(stderr, "Error: Adapter for i2c bus "
-				        "%d does not have read w/ PEC "
-				        "capability\n", i2cbus);
-				exit(1);
-			}
-		} else {
-			if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE)) {
-				fprintf(stderr, "Error: Adapter for i2c bus "
-				        "%d does not have read capability\n",
-				        i2cbus);
-				exit(1);
-			}
+		if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE)) {
+			fprintf(stderr, "Error: Adapter for i2c bus %d does "
+				"not have read capability\n", i2cbus);
+			exit(1);
 		}
 		break;
 
 	case I2C_SMBUS_BYTE_DATA:
-		if (pec) {
-			if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC)) {
-				fprintf(stderr, "Error: Adapter for i2c bus "
-				        "%d does not have byte read w/ PEC "
-				        "capability\n", i2cbus);
-				exit(1);
-			}
-		} else {
-			if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
-				fprintf(stderr, "Error: Adapter for i2c bus "
-				        "%d does not have byte read "
-				        "capability\n", i2cbus);
-				exit(1);
-			}
+		if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
+			fprintf(stderr, "Error: Adapter for i2c bus %d does "
+				"not have byte read capability\n", i2cbus);
+			exit(1);
 		}
 		break;
 
 	case I2C_SMBUS_WORD_DATA:
-		if (pec) {
-			if (!(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA_PEC)) {
-				fprintf(stderr, "Error: Adapter for i2c bus "
-				        "%d does not have word read w/ PEC "
-					"capability\n", i2cbus);
-				exit(1);
-			}
-		} else {
-			if (!(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) {
-				fprintf(stderr, "Error: Adapter for i2c bus "
-				        "%d does not have word read "
-				        "capability\n", i2cbus);
-				exit(1);
-			}
+		if (!(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) {
+			fprintf(stderr, "Error: Adapter for i2c bus %d does "
+				"not have word read capability\n", i2cbus);
+			exit(1);
 		}
 		break;
 
 	case I2C_SMBUS_BLOCK_DATA:
-		if (pec) {
-			if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC)) {
-				fprintf(stderr, "Error: Adapter for i2c bus "
-				        "%d does not have smbus block read "
-					"w/ PEC capability\n", i2cbus);
-				exit(1);
-			}
-		} else {
-			if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
-				fprintf(stderr, "Error: Adapter for i2c bus "
-				        "%d does not have smbus block read "
-				        "capability\n", i2cbus);
-				exit(1);
-			}
+		if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
+			fprintf(stderr, "Error: Adapter for i2c bus %d does "
+				"not have smbus block read capability\n",
+				i2cbus);
+			exit(1);
 		}
 		break;
 
@@ -278,6 +239,10 @@
 			        strerror(errno));
 			exit(1);
 		}
+		if (!(funcs & (I2C_FUNC_SMBUS_HWPEC_CALC | I2C_FUNC_I2C))) {
+			fprintf(stderr, "Warning: Adapter for i2c bus %d does "
+			        "not seem to actually support PEC\n", i2cbus);
+		}
 	}
 
 	if (!yes) {
-------------- next part --------------
--- linux-2.6.14-rc2.orig/include/linux/i2c.h	2005-09-26 19:26:40.000000000 +0200
+++ linux-2.6.14-rc2/include/linux/i2c.h	2005-09-26 19:43:23.000000000 +0200
@@ -391,10 +391,6 @@
 #define I2C_FUNC_10BIT_ADDR		0x00000002
 #define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
 #define I2C_FUNC_SMBUS_HWPEC_CALC	0x00000008 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
-#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
-#define I2C_FUNC_SMBUS_PROC_CALL_PEC	0x00002000 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL	0x00008000 /* SMBus 2.0 */
 #define I2C_FUNC_SMBUS_QUICK		0x00010000 
 #define I2C_FUNC_SMBUS_READ_BYTE	0x00020000 
@@ -410,8 +406,6 @@
 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK	0x08000000 /* w/ 1-byte reg. addr. */
 #define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2	 0x10000000 /* I2C-like block xfer  */
 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
-#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC  0x40000000 /* SMBus 2.0 */
-#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
 
 #define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \
                              I2C_FUNC_SMBUS_WRITE_BYTE)
@@ -425,17 +419,6 @@
                                   I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)
 #define I2C_FUNC_SMBUS_I2C_BLOCK_2 (I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
                                     I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2)
-#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC (I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
-                                       I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC)
-#define I2C_FUNC_SMBUS_WORD_DATA_PEC  (I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
-                                       I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC)
-
-#define I2C_FUNC_SMBUS_READ_BYTE_PEC		I2C_FUNC_SMBUS_READ_BYTE_DATA
-#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC		I2C_FUNC_SMBUS_WRITE_BYTE_DATA
-#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC	I2C_FUNC_SMBUS_READ_WORD_DATA
-#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC	I2C_FUNC_SMBUS_WRITE_WORD_DATA
-#define I2C_FUNC_SMBUS_BYTE_PEC			I2C_FUNC_SMBUS_BYTE_DATA
-#define I2C_FUNC_SMBUS_BYTE_DATA_PEC		I2C_FUNC_SMBUS_WORD_DATA
 
 #define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \
                              I2C_FUNC_SMBUS_BYTE | \
@@ -443,7 +426,6 @@
                              I2C_FUNC_SMBUS_WORD_DATA | \
                              I2C_FUNC_SMBUS_PROC_CALL | \
                              I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
-                             I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
                              I2C_FUNC_SMBUS_I2C_BLOCK)
 
 /* 
--- linux-2.6.14-rc2.orig/drivers/i2c/busses/i2c-i801.c	2005-09-26 19:36:34.000000000 +0200
+++ linux-2.6.14-rc2/drivers/i2c/busses/i2c-i801.c	2005-09-26 19:47:48.000000000 +0200
@@ -513,8 +513,7 @@
 	return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
 	    I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
 	    I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
-	     | (isich4 ? I2C_FUNC_SMBUS_BLOCK_DATA_PEC |
-	                 I2C_FUNC_SMBUS_HWPEC_CALC
+	     | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC
 	               : 0)
 	    ;
 }
#4 lore raw

PATCH 1/1 fix functionality constant for read_byte_pec

In reply to Hideki IWAMOTO

Hi Jean:

Quoted 5 lines · Jean Delvare

This bug report (and the other ones Hideki sent before) made me look at the PEC-related code more carefully. I had never actually looked at it before. I don't much like the way it was implemented, it is awfully complex, which must explain why it has so many bugs, and why PEC is almost unused while the feature was implemented more than 3 years ago.

If there was a need, it would get fixed. Actually, it's a wonder that it wasn't ripped out of 2.6.x by the bloat police. ;)

Quoted 2 lines

I think this is the right time to analyze the situation, and rework the whole PEC implementation to make it better. I think I understand that

I question whether it's the "right time" if there are no in-kernel users. OTOH, I won't try to talk you out of working on it.

Quoted 18 lines

the current implementation was made with in a "do as much as we can on every hardware combination" perspective. While this was a noble intention, I don't think this was the right thing to do. Given that PEC is optional in almost all cases (the only exception being ARP), I would prefer a much simpler, more robust and less buggy implementation.

Let me summarize what I understood from the current implementation:

(1) Bus drivers are supposed to explicitely list all SMBus transactions they are able to do with PEC, in addition to all transactions they can do without PEC (using the "functionality" bitfield). Clients can check for PEC support on individual transactions.

(2) Clients can explicitely ask for PEC on every transaction.

(3) Clients can declare themselves PEC-capable, letting bus drivers use the PEC-version of each transaction without explicitely requesting it.

Quoted 8 lines

(4) For non-SMBus I2C adapters, PEC is implemented in software by i2c-core.

(5) For SMBus adapters, PEC can be implemented in hardware. If it is not, i2c-core attempts to do as much as possible, using the fact that some non-PEC transactions can be used to emulate some PEC transactions. This results in a partial PEC support on these adapters, and tricky code (my opinion at least).

Looks right to me.

Quoted 7 lines

Additionally, my reading of the SMBus 2.0 specification is that:

(6) PEC is always optional, except for ARP. This means that a client should never ask explicitely for a PEC transaction. Instead, it should declare itself PEC-capable, ask for a standard transaction and let the bus driver decide whether or not to use PEC depending on its own capabilities.

I can't think of a reason this won't work.

Quoted 7 lines

Finally, my knowledge of the various hardware SMBus chips (masters and slaves) suggests that:

(7) SMBus slaves will support PEC on all transactions they use, or none.

(8) SMBus masters will support PEC an all transactions they support, or none. Not sure it actually matters though.

Yes that's probably true of the hardware at least. The drivers are a different story though. I'd rather have the option (as a bus driver author) to *not* implement a bus xfer that I can't test and/or don't need. If I want just one PEC xfer, now I have to implement all of them?

That said, I'm busy attacking the "can't test" problem anyway, so it should be moot. Stay tuned...

Quoted 7 lines

My conclusions are:

(6) implies that (1) is not needed for SMBus masters. Clients do not need to be aware of PEC support for individual transactions. It's actually questionable whether they need to know about the bus PEC capabilities at all (except for ARP, maybe.) They certainly don't need to know whether PEC support is hardware or software.

If you're planning to kill all the individual PEC func flags, I guess that's OK. If you're going to make PEC support all-or-nothing for bus drivers, then you can just have a single PEC-capable flag for them. (That will solve the smbus-arp.c problem in your patch in a later msg.)

Quoted 7 lines

(5) is what makes (1) needed in the current implementation, but I do not this it is worth the additional code and complexity. Software PEC support on non-PEC SMBus masters is partial by construction, and has proven to be broken.

(6) implies that (2) is not wanted. Clients ask for a normal transaction, PEC or not is the master's decision.

Again: keep a single PEC-capable flag though.

Quoted 11 lines

(6) and (7) imply that (3) is wanted. That's what I2C_CLIENT_PEC is for.

(4) looks sane to me. We can add PEC support to any transaction in I2C emulation mode, it's only a matter of writing the code.

Which leads me to the point that we should consider dropping (1), (2) and (5). This would make the i2c-core smaller and faster, more readable and less buggy as a consequence, for almost no functionality loss if any. I wouldn't expect SMBus slaves which can do PEC connected to SMBus masters which cannot. If it happens, this means that the designer did not think PEC was required, so we are most certainly fine without it.

Agreed.

Quoted 11 lines

The good thing here is that PEC is not used right now. Just consider the number of bugs Hideki reported these last few days, anyone actually using PEC would have reported at least one of them. So nobody tried to use it, or they all gave up quickly (understandably). I searched the kernel source and couldn't find any real use case, neither in 2.4 nor 2.6, except for smbus-arp in lm_sensors CVS. In user-space, the only user seems to be i2cdump. This means that we can probably change the way PEC works without affecting anyone. Let's just hope that such a cleanup would invite people to use PEC in chip drivers, and implement it in bus drivers where hardware can do it, once it is properly implemented.

I still think you've reversed the cause & effect: if it *was* in common use, it would *be* in better shape. But I guess we'll see... maybe "If you build it, they will come."

BTW: I wouldn't object if you instead decided to just rip it all out. My bloat police badge should arrive any day now.

Regards,

Signature · 2 lines
Mark M. Hoffman
[email protected]
#5 lore raw

PATCH 1/1 fix functionality constant for read_byte_pec

In reply to Hideki IWAMOTO

Hi Mark,

Thanks for reviewing my proposal :)

Quoted 8 lines · Mark M. Hoffman
Quoted 5 lines

This bug report (and the other ones Hideki sent before) made me look at the PEC-related code more carefully. I had never actually looked at it before. I don't much like the way it was implemented, it is awfully complex, which must explain why it has so many bugs, and why PEC is almost unused while the feature was implemented more than 3 years ago.

If there was a need, it would get fixed. Actually, it's a wonder that it wasn't ripped out of 2.6.x by the bloat police. ;)

My guess is that they did not understand what the code was doing so they didn't dare removing it ;) The PEC code is currently heavily anchored into the core i2c functions. The bloat police focusses on removing unused functions and useless function exports, the PEC stuff just doesn't fit within these criteria.

Quoted 5 lines
Quoted 2 lines

I think this is the right time to analyze the situation, and rework the whole PEC implementation to make it better. I think I understand that

I question whether it's the "right time" if there are no in-kernel users. OTOH, I won't try to talk you out of working on it.

Let me reformulate then. As there are no in-kernel users yet, I think this is the right time to remove the current (partly broken) PEC implementation before anyone starts using it. And while we are (or at least I am) at it, let's see if we can come up with a better implementation. I plan to have the lm90 driver use PEC for at least the ADM1032, so this will be the first user of the new PEC implementation.

Quoted 9 lines
Quoted 4 lines

(7) SMBus slaves will support PEC on all transactions they use, or none.

(8) SMBus masters will support PEC an all transactions they support, or none. Not sure it actually matters though.

Yes that's probably true of the hardware at least. The drivers are a different story though. I'd rather have the option (as a bus driver author) to *not* implement a bus xfer that I can't test and/or don't need. If I want just one PEC xfer, now I have to implement all of them?

No, you don't, which is why I commented on (8) probably not mattering after all. In my planned model, clients (that is, chip driver implentations) declare themselves globally PEC-capable, then start a transaction. The bus driver *may* check for I2C_CLIENT_PEC and *may* use the PEC version of the requested transaction if it implements it. This is all optional and the choice is made on individual transaction types. A given bus driver may implement byte data writes with PEC and not byte data reads with PEC, for example (purely hypothetical case). A client which declared itself PEC capable when attaching to that bus will get byte data writes with PEC when asking for byte data writes, and byte data reads without PEC when asking for byte data reads. The client isn't supposed to care or even know whether the bus does support any particular transaction with PEC.

Quoted 10 lines
Quoted 5 lines

(6) implies that (1) is not needed for SMBus masters. Clients do not need to be aware of PEC support for individual transactions. It's actually questionable whether they need to know about the bus PEC capabilities at all (except for ARP, maybe.) They certainly don't need to know whether PEC support is hardware or software.

If you're planning to kill all the individual PEC func flags, I guess that's OK. If you're going to make PEC support all-or-nothing for bus drivers, then you can just have a single PEC-capable flag for them. (That will solve the smbus-arp.c problem in your patch in a later msg.)

I'm not sure a global flag is even needed. Apart from arp-smbus, I can't think of any other case where a client will make a decision on that flag. As I see it, arp-smbus was a proof-of-concept, it's not supposed to stay as is if we ever implement ARP. ARP is a part of the SMBus specification itself and should be included in i2c-core (or i2c-core-arp if we want to keep it separated) rather than a regular chip driver.

Do you happen to know how ARP is physically implemented on systems where it exists? Unfortunately I have no system with ARP (or I guess I'd see something at address 0x61). My guess is that the ARP is no separate chip on the bus but is integrated into the host itself. If this is true, then it would probably be more logical to have bus drivers that are ARP capable register themselves to i2c-core-arp which would contain the common code, rather than blindly probing for something at 0x61 on every bus. But I need to take a longer look at arp-smbus and the ARP section in the SMBus 2.0 specification before I say more on this.

Additional notes of interest:

* I'm not even sure we need the current arp-smbus driver to check for PEC capabilities. Although the SMBus 2.0 specification says PEC is mandatory for ARP, it's obviously for reliability reasons, and I don't think anything bad would happen if a non-PEC ARP-capable system was ever created, as long as no I/O error happen.

* Even if the above were wrong, I doubt we'll ever see a device at address 0x61 other than for ARP, so the address restriction alone is probably enough for detection.

* We can play it safe and leave I2C_FUNC_SMBUS_HWPEC_CALC in place at least for the moment. My planned implementation of PEC would drop software PEC support for non-I2C SMBus masters, leaving only three
possibilities: I2C masters using software PEC, SMBus masters using hardware PEC, and SMBus masters without PEC. I2C_FUNC_I2C would imply software PEC, I2C_FUNC_SMBUS_HWPEC_CALC would imply hardware PEC, so PEC support would be (I2C_FUNC_I2C | I2C_FUNC_SMBUS_HWPEC_CALC) != 0.

* I still think that a single PEC flag is rather error prone, because I2C_FUNC_SMBUS_HWPEC_CALC means that at least one transfer supports PEC, that might not the ones ARP needs, for example (just like I2C protolo mangling has a single FUNC flag covering 4 capabilities, not all of which may be implented in any bus driver). In contrast, software PEC will always be complete (I see no reason it can't be.)

Quoted 1 line

Again: keep a single PEC-capable flag though.

I will, in that I won't drop the one which exists for now - but I would welcome a concrete example where this would be needed.

Quoted 3 lines

I still think you've reversed the cause & effect: if it *was* in common use, it would *be* in better shape. But I guess we'll see... maybe "If you build it, they will come."

We'll see how it evolves, but my impression as a newbie client driver writer (remember when I wrote the lm90 driver 2 years ago) was that adding PEC support to my driver would be rather complicated. This is the reason why I didn't even bother trying. It should actually not be harder than setting flags |= I2C_CLIENT_PEC. Likewise, implementing PEC support in bus drivers for SMBus masters which support it in hardware should be trivial. In most cases, it should just be a matter of checking for client->flags and enabling the right bit in the right register before starting the transaction. You should not have to bloat your code with dozens of arbitrary defines or protect yourself against software PEC which could have already happened before you get your hands on the data (like i2c-amd8111 currently does).

Looks like there aren't that many hardware PEC capable SMBus hosts at the moment. AMD 8111, nVidia nForce2/3/4, Intel ICH4 and above, and that's it? Even the latest VIA south bridges do not seem to support it.

Quoted 2 lines

BTW: I wouldn't object if you instead decided to just rip it all out. My bloat police badge should arrive any day now.

My postal system must have been faster, I have mine for a few days already :)

--
Jean Delvare

#6 lore raw

PATCH 1/1 fix functionality constant for read_byte_pec

In reply to Hideki IWAMOTO

Hi Jean:

Quoted 7 lines
Quoted 3 lines · Jean Delvare
Quoted 2 lines

I think this is the right time to analyze the situation, and rework the whole PEC implementation to make it better. I think I understand that

Quoted 2 lines · Mark M. Hoffman

I question whether it's the "right time" if there are no in-kernel users. OTOH, I won't try to talk you out of working on it.

Quoted 6 lines · Jean Delvare

Let me reformulate then. As there are no in-kernel users yet, I think this is the right time to remove the current (partly broken) PEC implementation before anyone starts using it. And while we are (or at least I am) at it, let's see if we can come up with a better implementation. I plan to have the lm90 driver use PEC for at least the ADM1032, so this will be the first user of the new PEC implementation.

I didn't realize you had plans to use it - cool.

Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

(7) SMBus slaves will support PEC on all transactions they use, or none.

(8) SMBus masters will support PEC an all transactions they support, or none. Not sure it actually matters though.

Yes that's probably true of the hardware at least. The drivers are a different story though. I'd rather have the option (as a bus driver author) to *not* implement a bus xfer that I can't test and/or don't need. If I want just one PEC xfer, now I have to implement all of them?

Quoted 13 lines

No, you don't, which is why I commented on (8) probably not mattering after all. In my planned model, clients (that is, chip driver implentations) declare themselves globally PEC-capable, then start a transaction. The bus driver *may* check for I2C_CLIENT_PEC and *may* use the PEC version of the requested transaction if it implements it. This is all optional and the choice is made on individual transaction types. A given bus driver may implement byte data writes with PEC and not byte data reads with PEC, for example (purely hypothetical case). A client which declared itself PEC capable when attaching to that bus will get byte data writes with PEC when asking for byte data writes, and byte data reads without PEC when asking for byte data reads. The client isn't supposed to care or even know whether the bus does support any particular transaction with PEC.

OK, I get it now (duh).

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

(6) implies that (1) is not needed for SMBus masters. Clients do not need to be aware of PEC support for individual transactions. It's actually questionable whether they need to know about the bus PEC capabilities at all (except for ARP, maybe.) They certainly don't need to know whether PEC support is hardware or software.

If you're planning to kill all the individual PEC func flags, I guess that's OK. If you're going to make PEC support all-or-nothing for bus drivers, then you can just have a single PEC-capable flag for them. (That will solve the smbus-arp.c problem in your patch in a later msg.)

Quoted 7 lines

I'm not sure a global flag is even needed. Apart from arp-smbus, I can't think of any other case where a client will make a decision on that flag. As I see it, arp-smbus was a proof-of-concept, it's not supposed to stay as is if we ever implement ARP. ARP is a part of the SMBus specification itself and should be included in i2c-core (or i2c-core-arp if we want to keep it separated) rather than a regular chip driver.

I looked at this some time ago just out of curiosity. There's no doubt that real SMBus/ARP support would need some help from i2c-core. Clients would need to register as ARP-capable. The client would also have to tell i2c-core what its 128-bit UDID is. Then, whenever i2c-core decides to (re)enumerate the bus, it must have a way to let the client know if/when the address has changed.

It helps, by the way, to forget whatever you may know about ethernet ARP while you're looking at this.

Quoted 5 lines

Do you happen to know how ARP is physically implemented on systems where it exists? Unfortunately I have no system with ARP (or I guess I'd see something at address 0x61). My guess is that the ARP is no separate chip on the bus but is integrated into the host itself. If this is true, then it would probably be more logical to have bus drivers that are ARP

Every ARP-capable device listens on address 0x61. Most of the ARP commands only require the slave(s) to ACK - so if there are 2 or more slaves, they will all "answer" at once and there's no problem with that. OTOH, a cmd like Get UDID will start off with all slaves answering, but they will drop out one by one (because of normal I2C bus arbitration rules) until one of them has spoken its own UDID. When the master issues Get UDID again, any slave that has already answered completely must now stay quiet. And so the host continues issuing Get UDID until no one answers.

Quoted 2 lines

capable register themselves to i2c-core-arp which would contain the common code, rather than blindly probing for something at 0x61 on every

That was more or less my vision also. But note: I thought SMBus/ARP support would ultimately require no changes to existing bus drivers (assuming they were PEC capable, anyway). But i2c-core-arp would need some way to guarantee that the bus driver performs the PEC xfers. Or as you mentioned, let the bus driver tell the core that it is ARP capable.

Quoted 2 lines

bus. But I need to take a longer look at arp-smbus and the ARP section in the SMBus 2.0 specification before I say more on this.

Yes anyway, it's good to keep this all in mind as you're reworking PEC support.

Quoted 7 lines

Additional notes of interest:

* I'm not even sure we need the current arp-smbus driver to check for PEC capabilities. Although the SMBus 2.0 specification says PEC is mandatory for ARP, it's obviously for reliability reasons, and I don't think anything bad would happen if a non-PEC ARP-capable system was ever created, as long as no I/O error happen.

I couldn't care less about the arp-smbus demo driver in CVS. If you replaced the contents of that file with the entire works of Shakespeare (in a comment, so it still compiled) I don't think anyone would notice.

Quoted 12 lines

* Even if the above were wrong, I doubt we'll ever see a device at address 0x61 other than for ARP, so the address restriction alone is probably enough for detection.

* We can play it safe and leave I2C_FUNC_SMBUS_HWPEC_CALC in place at least for the moment. My planned implementation of PEC would drop software PEC support for non-I2C SMBus masters, leaving only three
possibilities: I2C masters using software PEC, SMBus masters using hardware PEC, and SMBus masters without PEC. I2C_FUNC_I2C would imply software PEC, I2C_FUNC_SMBUS_HWPEC_CALC would imply hardware PEC, so PEC support would be (I2C_FUNC_I2C | I2C_FUNC_SMBUS_HWPEC_CALC) != 0.

Quoted 6 lines

* I still think that a single PEC flag is rather error prone, because I2C_FUNC_SMBUS_HWPEC_CALC means that at least one transfer supports PEC, that might not the ones ARP needs, for example (just like I2C protolo mangling has a single FUNC flag covering 4 capabilities, not all of which may be implented in any bus driver). In contrast, software PEC will always be complete (I see no reason it can't be.)

True.

Quoted 4 lines
Quoted 1 line

Again: keep a single PEC-capable flag though.

I will, in that I won't drop the one which exists for now - but I would welcome a concrete example where this would be needed.

As I mentioned... *if* SMBus/ARP support were to be completely transparent to the bus driver, you would need this... else if you add a flag that marks a bus driver as ARP capable, that's just as good.

Regards,

Signature · 2 lines
Mark M. Hoffman
[email protected]