Skip to contentSkip to conversation

i2c: i801: Remove i801_set_block_buffer_mode

PATCH Superseded Heiner Kallweit 2 participants 4 messages Nov 11, 2021 – Nov 18, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: i801: Remove i801_set_block_buffer_mode

If FEATURE_BLOCK_BUFFER is set I don't see how setting this bit could fail. Reading it back seems to be overly paranoid. Origin of this check seems to be 14 yrs ago when people were not completely sure which chip versions support block buffer mode.

---
 drivers/i2c/busses/i2c-i801.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/i2c/busses/i2c-i801.c +5 -12
index 4c96f1b47..608e928e9 100644
@@ -521,9 +521,11 @@ static int i801_block_transaction_by_block(struct i801_priv *priv,
 		return -EOPNOTSUPP;
 	}
 
+	/* Set block buffer mode */
+	outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
+
 	inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
 
-	/* Use 32-byte buffer to process this transaction */
 	if (read_write == I2C_SMBUS_WRITE) {
 		len = data->block[0];
 		outb_p(len, SMBHSTDAT0(priv));
@@ -750,14 +752,6 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
 	return i801_check_post(priv, status);
 }
 
-static int i801_set_block_buffer_mode(struct i801_priv *priv)
-{
-	outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
-	if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
-		return -EIO;
-	return 0;
-}
-
 /* Block transaction function */
 static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *data,
 				  char read_write, int command)
@@ -786,9 +780,8 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *
 	/* Experience has shown that the block buffer can only be used for
 	   SMBus (not I2C) block transactions, even though the datasheet
 	   doesn't mention this limitation. */
-	if ((priv->features & FEATURE_BLOCK_BUFFER)
-	 && command != I2C_SMBUS_I2C_BLOCK_DATA
-	 && i801_set_block_buffer_mode(priv) == 0)
+	if (priv->features & FEATURE_BLOCK_BUFFER &&
+	    command != I2C_SMBUS_I2C_BLOCK_DATA)
 		result = i801_block_transaction_by_block(priv, data,
 							 read_write,
 							 command);
Signature · 1 line
2.33.1
#1 lore raw

Hi Heiner,

Quoted 4 lines · Heiner Kallweit

If FEATURE_BLOCK_BUFFER is set I don't see how setting this bit could fail. Reading it back seems to be overly paranoid. Origin of this check seems to be 14 yrs ago when people were not completely sure which chip versions support block buffer mode.

Your reading of the history is correct, although "overly paranoid" might be a somewhat exaggerated statement. When you modify a driver used by millions and have been bitten by undocumented restrictions in the same area, being cautious not to cause a regression doesn't seem that bad to me.

What was wrong in that approach, I would think retrospectively, is that i801_set_block_buffer_mode() should have been made verbose on failure, so that we learned over time if any chipset actually failed to support the feature in question. Because 14 years later we in fact still don't know if the test was needed or not.

I'm fine with your change nevertheless, it should be fine, and if anything breaks then we'll fix it.

I'll test it on my system later today.

Quoted 39 lines
---
 drivers/i2c/busses/i2c-i801.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/i2c/busses/i2c-i801.c +3 -9
index 4c96f1b47..608e928e9 100644
@@ -521,9 +521,11 @@ static int i801_block_transaction_by_block(struct i801_priv *priv,
 		return -EOPNOTSUPP;
 	}
 
+	/* Set block buffer mode */
+	outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
+
 	inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
 
-	/* Use 32-byte buffer to process this transaction */
 	if (read_write == I2C_SMBUS_WRITE) {
 		len = data->block[0];
 		outb_p(len, SMBHSTDAT0(priv));
@@ -750,14 +752,6 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
 	return i801_check_post(priv, status);
 }
 
-static int i801_set_block_buffer_mode(struct i801_priv *priv)
-{
-	outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
-	if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
-		return -EIO;
-	return 0;
-}
-
 /* Block transaction function */
 static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *data,
 				  char read_write, int command)

drivers/i2c/busses/i2c-i801.c static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data * · line 783

Quoted 7 lines
drivers/i2c/busses/i2c-i801.c +1 -3
@@ -786,9 +780,8 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *
 	/* Experience has shown that the block buffer can only be used for
 	   SMBus (not I2C) block transactions, even though the datasheet
 	   doesn't mention this limitation. */
-	if ((priv->features & FEATURE_BLOCK_BUFFER)
-	 && command != I2C_SMBUS_I2C_BLOCK_DATA
-	 && i801_set_block_buffer_mode(priv) == 0)
+	if (priv->features & FEATURE_BLOCK_BUFFER &&

No, please preserve the parentheses. Mixing "&" and "&&" without parentheses is highly confusing (to me at least, but I suspect I'm not alone).

Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -0
+	    command != I2C_SMBUS_I2C_BLOCK_DATA)
 		result = i801_block_transaction_by_block(priv, data,
 							 read_write,
 							 command);
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#2 lore raw
Quoted 8 lines · Jean Delvare

Hi Heiner,

Quoted 4 lines · Heiner Kallweit

If FEATURE_BLOCK_BUFFER is set I don't see how setting this bit could fail. Reading it back seems to be overly paranoid. Origin of this check seems to be 14 yrs ago when people were not completely sure which chip versions support block buffer mode.

Quoted 5 lines

Your reading of the history is correct, although "overly paranoid" might be a somewhat exaggerated statement. When you modify a driver used by millions and have been bitten by undocumented restrictions in the same area, being cautious not to cause a regression doesn't seem that bad to me.

Indeed my statement could be read as: The guys back then didn't know what they were doing. It definitely wasn't meant this way.

Quoted 7 lines

What was wrong in that approach, I would think retrospectively, is that i801_set_block_buffer_mode() should have been made verbose on failure, so that we learned over time if any chipset actually failed to support the feature in question. Because 14 years later we in fact still don't know if the test was needed or not.

ICH4 spec mentions the block buffer mode and it's hard to imagine (even though not impossible) that single later versions dropped this feature.

Quoted 47 lines

I'm fine with your change nevertheless, it should be fine, and if anything breaks then we'll fix it.

I'll test it on my system later today.

Quoted 42 lines
---
 drivers/i2c/busses/i2c-i801.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/i2c/busses/i2c-i801.c +3 -9
index 4c96f1b47..608e928e9 100644
@@ -521,9 +521,11 @@ static int i801_block_transaction_by_block(struct i801_priv *priv,
 		return -EOPNOTSUPP;
 	}
 
+	/* Set block buffer mode */
+	outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
+
 	inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
 
-	/* Use 32-byte buffer to process this transaction */
 	if (read_write == I2C_SMBUS_WRITE) {
 		len = data->block[0];
 		outb_p(len, SMBHSTDAT0(priv));
@@ -750,14 +752,6 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
 	return i801_check_post(priv, status);
 }
 
-static int i801_set_block_buffer_mode(struct i801_priv *priv)
-{
-	outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
-	if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
-		return -EIO;
-	return 0;
-}
-
 /* Block transaction function */
 static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *data,
 				  char read_write, int command)
@@ -786,9 +780,8 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *
 	/* Experience has shown that the block buffer can only be used for
 	   SMBus (not I2C) block transactions, even though the datasheet
 	   doesn't mention this limitation. */
Quoted 9 lines

drivers/i2c/busses/i2c-i801.c static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data * · line 783

Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -3
-	if ((priv->features & FEATURE_BLOCK_BUFFER)
-	 && command != I2C_SMBUS_I2C_BLOCK_DATA
-	 && i801_set_block_buffer_mode(priv) == 0)
+	if (priv->features & FEATURE_BLOCK_BUFFER &&

No, please preserve the parentheses. Mixing "&" and "&&" without parentheses is highly confusing (to me at least, but I suspect I'm not alone).

Shall I send a v2 with an adjusted commit message and these parentheses re-added?

Quoted 6 lines
Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -0
+	    command != I2C_SMBUS_I2C_BLOCK_DATA)
 		result = i801_block_transaction_by_block(priv, data,
 							 read_write,
 							 command);
#3 lore raw
Quoted 7 lines · Heiner Kallweit
Quoted 6 lines · Jean Delvare
Quoted 4 lines · Heiner Kallweit

If FEATURE_BLOCK_BUFFER is set I don't see how setting this bit could fail. Reading it back seems to be overly paranoid. Origin of this check seems to be 14 yrs ago when people were not completely sure which chip versions support block buffer mode.

Quoted 8 lines
Quoted 5 lines

Your reading of the history is correct, although "overly paranoid" might be a somewhat exaggerated statement. When you modify a driver used by millions and have been bitten by undocumented restrictions in the same area, being cautious not to cause a regression doesn't seem that bad to me.

Indeed my statement could be read as: The guys back then didn't know what they were doing. It definitely wasn't meant this way.

That would be me ;-) well not alone but I remember participating.

And no worry, I did not take it personally, I just wanted to give some more background.

Quoted 9 lines
Quoted 5 lines

What was wrong in that approach, I would think retrospectively, is that i801_set_block_buffer_mode() should have been made verbose on failure, so that we learned over time if any chipset actually failed to support the feature in question. Because 14 years later we in fact still don't know if the test was needed or not.

ICH4 spec mentions the block buffer mode and it's hard to imagine (even though not impossible) that single later versions dropped this feature.

The history of computer hardware is paved with examples of exactly this or even more unexpected changes. I no longer take anything for granted.

Plus the ICH4 itself was probably the problem, I seem to recall none of us had any sample to test the new code on it, and freshly added features are sometimes subject to hardware errata.

But looking at it now, the most surprising really is that we thought the extra, probably unneeded check would help. It might as well be that the bit *would* be set properly but not do anything, or not what was documented. So all in all I suppose we should have just let it fail if it had too, and come up with a workaround later if actually needed. It was deliciously naive from us to believe we could anticipate *how* the hardware would fail if it did. Oh well :-)

Quoted 4 lines
Quoted 4 lines

I'm fine with your change nevertheless, it should be fine, and if anything breaks then we'll fix it.

I'll test it on my system later today.

For the record, I did, and it worked :-)

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines

(...)

drivers/i2c/busses/i2c-i801.c +0 -0
@@ -786,9 +780,8 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *
 	/* Experience has shown that the block buffer can only be used for
 	   SMBus (not I2C) block transactions, even though the datasheet
 	   doesn't mention this limitation. */
Quoted 9 lines

drivers/i2c/busses/i2c-i801.c static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data * · line 783

Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -3
-	if ((priv->features & FEATURE_BLOCK_BUFFER)
-	 && command != I2C_SMBUS_I2C_BLOCK_DATA
-	 && i801_set_block_buffer_mode(priv) == 0)
+	if (priv->features & FEATURE_BLOCK_BUFFER &&  

No, please preserve the parentheses. Mixing "&" and "&&" without parentheses is highly confusing (to me at least, but I suspect I'm not alone).

Quoted 7 lines

Shall I send a v2 with an adjusted commit message and these parentheses re-added?

Quoted 4 lines

drivers/i2c/busses/i2c-i801.c static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data * · line 787

Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -0
+	    command != I2C_SMBUS_I2C_BLOCK_DATA)
 		result = i801_block_transaction_by_block(priv, data,
 							 read_write,
 							 command);  

Yes please!

Signature · 2 lines
Jean Delvare
SUSE L3 Support