Skip to contentSkip to conversation

i2c octeon & thunderx bug fixes

PATCH Applied Jan Glauber 3 participants 19 messages Dec 9, 2016 – Apr 21, 2017

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

cover i2c octeon & thunderx bug fixes

Hi Wolfram,

Patches #1 & #2 contain the fixes that didn't make 4.9. We've double-checked that they are working on Octeon MIPS cn71xx, so I hope there are no surprises this time.

Patch #3 is my original attempt on limiting the number of retries for the i2c device register access. As I found out we need to keep this simple, because these functions are called very early in the i2c driver and also from all types of context.

Patch #4 addresses a bug report I got. I haven't seen this myself, but apparently depending on probing method and/or hardware type ipmi_ssif can fail to detect the IPMI device. Setting the class in the adapter solves the problem and seems harmless.

Tested on MIPS Octeon CN71xx and ARM64 ThunderX on 4.9-rc8.

thanks,
Jan

-----------------------

Jan Glauber (4):
i2c: octeon: thunderx: TWSI software reset in recovery
i2c: octeon: thunderx: Remove double-check after interrupt
i2c: octeon: thunderx: Limit register access retries
i2c: octeon: thunderx: Add I2C_CLASS_HWMON

 drivers/i2c/busses/i2c-octeon-core.c     | 50 +++++---------------------------
 drivers/i2c/busses/i2c-octeon-core.h     | 21 ++++++++++----
 drivers/i2c/busses/i2c-octeon-platdrv.c  |  1 +
 drivers/i2c/busses/i2c-thunderx-pcidrv.c |  1 +
 4 files changed, 26 insertions(+), 47 deletions(-)
Signature · 1 line
2.9.0.rc0.21.g7777322
#1 lore raw

PATCH 1/4 i2c: octeon: thunderx: TWSI software reset in recovery

I've seen i2c recovery reporting long loops of:

[ 1035.887818] i2c i2c-4: SCL is stuck low, exit recovery
[ 1037.999748] i2c i2c-4: SCL is stuck low, exit recovery
[ 1040.111694] i2c i2c-4: SCL is stuck low, exit recovery

...

Add a TWSI software reset which clears the status and STA,STP,IFLG in SW_TWSI_EOP_TWSI_CTL.

With this the recovery works fine and above message is not seen.

---
 drivers/i2c/busses/i2c-octeon-core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/i2c/busses/i2c-octeon-core.c +3 -0
index 5e63b17..2b8a7bf 100644
@@ -789,6 +789,9 @@ static void octeon_i2c_prepare_recovery(struct i2c_adapter *adap)
 	struct octeon_i2c *i2c = i2c_get_adapdata(adap);
 
 	octeon_i2c_hlc_disable(i2c);
+	octeon_i2c_reg_write(i2c, SW_TWSI_EOP_TWSI_RST, 0);
+	/* wait for software reset to settle */
+	udelay(5);
 
 	/*
 	 * Bring control register to a good state regardless
Signature · 1 line
2.9.0.rc0.21.g7777322
Applied
#2 lore raw

Re: [PATCH 1/4] i2c: octeon: thunderx: TWSI software reset in recovery

Quoted 5 lines · Jan Glauber

I've seen i2c recovery reporting long loops of:

[ 1035.887818] i2c i2c-4: SCL is stuck low, exit recovery
[ 1037.999748] i2c i2c-4: SCL is stuck low, exit recovery
[ 1040.111694] i2c i2c-4: SCL is stuck low, exit recovery
Quoted 8 lines

...

Add a TWSI software reset which clears the status and STA,STP,IFLG in SW_TWSI_EOP_TWSI_CTL.

With this the recovery works fine and above message is not seen.

Applied to for-next, thanks!

#3 lore raw

PATCH 2/4 i2c: octeon: thunderx: Remove double-check after interrupt

In reply to Jan Glauber

Commit 1bb1ff3e7c74 ("i2c: octeon: Improve performance if interrupt is early") added a double-check around the wait_event_timeout() condition. The performance problem that this commit tried to work-around could not be reproduced. It also makes the wait condition more complicated then it should be. Therefore remove the double-check.

---
 drivers/i2c/busses/i2c-octeon-core.c | 43 ++----------------------------------
 1 file changed, 2 insertions(+), 41 deletions(-)
drivers/i2c/busses/i2c-octeon-core.c +2 -41
index 2b8a7bf..3d10f1a 100644
@@ -36,24 +36,6 @@ static bool octeon_i2c_test_iflg(struct octeon_i2c *i2c)
 	return (octeon_i2c_ctl_read(i2c) & TWSI_CTL_IFLG);
 }
 
-static bool octeon_i2c_test_ready(struct octeon_i2c *i2c, bool *first)
-{
-	if (octeon_i2c_test_iflg(i2c))
-		return true;
-
-	if (*first) {
-		*first = false;
-		return false;
-	}
-
-	/*
-	 * IRQ has signaled an event but IFLG hasn't changed.
-	 * Sleep and retry once.
-	 */
-	usleep_range(I2C_OCTEON_EVENT_WAIT, 2 * I2C_OCTEON_EVENT_WAIT);
-	return octeon_i2c_test_iflg(i2c);
-}
-
 /**
  * octeon_i2c_wait - wait for the IFLG to be set
  * @i2c: The struct octeon_i2c
@@ -63,7 +45,6 @@ static bool octeon_i2c_test_ready(struct octeon_i2c *i2c, bool *first)
 static int octeon_i2c_wait(struct octeon_i2c *i2c)
 {
 	long time_left;
-	bool first = true;
 
 	/*
 	 * Some chip revisions don't assert the irq in the interrupt
@@ -80,7 +61,7 @@ static int octeon_i2c_wait(struct octeon_i2c *i2c)
 	}
 
 	i2c->int_enable(i2c);
-	time_left = wait_event_timeout(i2c->queue, octeon_i2c_test_ready(i2c, &first),
+	time_left = wait_event_timeout(i2c->queue, octeon_i2c_test_iflg(i2c),
 				       i2c->adap.timeout);
 	i2c->int_disable(i2c);
 
@@ -102,25 +83,6 @@ static bool octeon_i2c_hlc_test_valid(struct octeon_i2c *i2c)
 	return (__raw_readq(i2c->twsi_base + SW_TWSI(i2c)) & SW_TWSI_V) == 0;
 }
 
-static bool octeon_i2c_hlc_test_ready(struct octeon_i2c *i2c, bool *first)
-{
-	/* check if valid bit is cleared */
-	if (octeon_i2c_hlc_test_valid(i2c))
-		return true;
-
-	if (*first) {
-		*first = false;
-		return false;
-	}
-
-	/*
-	 * IRQ has signaled an event but valid bit isn't cleared.
-	 * Sleep and retry once.
-	 */
-	usleep_range(I2C_OCTEON_EVENT_WAIT, 2 * I2C_OCTEON_EVENT_WAIT);
-	return octeon_i2c_hlc_test_valid(i2c);
-}
-
 static void octeon_i2c_hlc_int_clear(struct octeon_i2c *i2c)
 {
 	/* clear ST/TS events, listen for neither */
@@ -176,7 +138,6 @@ static void octeon_i2c_hlc_disable(struct octeon_i2c *i2c)
  */
 static int octeon_i2c_hlc_wait(struct octeon_i2c *i2c)
 {
-	bool first = true;
 	int time_left;
 
 	/*
@@ -195,7 +156,7 @@ static int octeon_i2c_hlc_wait(struct octeon_i2c *i2c)
 
 	i2c->hlc_int_enable(i2c);
 	time_left = wait_event_timeout(i2c->queue,
-				       octeon_i2c_hlc_test_ready(i2c, &first),
+				       octeon_i2c_hlc_test_valid(i2c),
 				       i2c->adap.timeout);
 	i2c->hlc_int_disable(i2c);
 	if (!time_left)
Signature · 1 line
2.9.0.rc0.21.g7777322
Applied
#4 lore raw

Re: [PATCH 2/4] i2c: octeon: thunderx: Remove double-check after interrupt

Quoted 7 lines · Jan Glauber

Commit 1bb1ff3e7c74 ("i2c: octeon: Improve performance if interrupt is early") added a double-check around the wait_event_timeout() condition. The performance problem that this commit tried to work-around could not be reproduced. It also makes the wait condition more complicated then it should be. Therefore remove the double-check.

Applied to for-next, thanks!

#5 lore raw

PATCH 3/4 i2c: octeon: thunderx: Limit register access retries

In reply to Jan Glauber

Do not infinitely retry register readq and writeq operations in order to not lock up the CPU in case the TWSI gets stuck.

Return -EIO in case of a failed data read. For all other cases just return so subsequent operations will fail and trigger the recovery.

---
 drivers/i2c/busses/i2c-octeon-core.c |  4 +++-
 drivers/i2c/busses/i2c-octeon-core.h | 21 ++++++++++++++++-----
 2 files changed, 19 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-octeon-core.c +3 -1
index 3d10f1a..1d8775799 100644
@@ -342,7 +342,9 @@ static int octeon_i2c_read(struct octeon_i2c *i2c, int target,
 		if (result)
 			return result;
 
-		data[i] = octeon_i2c_data_read(i2c);
+		data[i] = octeon_i2c_data_read(i2c, &result);
+		if (result)
+			return result;
 		if (recv_len && i == 0) {
 			if (data[i] > I2C_SMBUS_BLOCK_MAX + 1)
 				return -EPROTO;
drivers/i2c/busses/i2c-octeon-core.h +16 -5
index 87151ea..e160f83 100644
@@ -141,11 +141,14 @@ static inline void octeon_i2c_writeq_flush(u64 val, void __iomem *addr)
  */
 static inline void octeon_i2c_reg_write(struct octeon_i2c *i2c, u64 eop_reg, u8 data)
 {
+	int tries = 1000;
 	u64 tmp;
 
 	__raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI(i2c));
 	do {
 		tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
+		if (--tries < 0)
+			return;
 	} while ((tmp & SW_TWSI_V) != 0);
 }
 
@@ -163,24 +166,32 @@ static inline void octeon_i2c_reg_write(struct octeon_i2c *i2c, u64 eop_reg, u8
  *
  * The I2C core registers are accessed indirectly via the SW_TWSI CSR.
  */
-static inline u8 octeon_i2c_reg_read(struct octeon_i2c *i2c, u64 eop_reg)
+static inline int octeon_i2c_reg_read(struct octeon_i2c *i2c, u64 eop_reg,
+				      int *error)
 {
+	int tries = 1000;
 	u64 tmp;
 
 	__raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI(i2c));
 	do {
 		tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
+		if (--tries < 0) {
+			/* signal that the returned data is invalid */
+			if (error)
+				*error = -EIO;
+			return 0;
+		}
 	} while ((tmp & SW_TWSI_V) != 0);
 
 	return tmp & 0xFF;
 }
 
 #define octeon_i2c_ctl_read(i2c)					\
-	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_CTL)
-#define octeon_i2c_data_read(i2c)					\
-	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_DATA)
+	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_CTL, NULL)
+#define octeon_i2c_data_read(i2c, error)				\
+	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_DATA, error)
 #define octeon_i2c_stat_read(i2c)					\
-	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT)
+	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT, NULL)
 
 /**
  * octeon_i2c_read_int - read the TWSI_INT register
Signature · 1 line
2.9.0.rc0.21.g7777322
#6 lore raw

Re: [PATCH 3/4] i2c: octeon: thunderx: Limit register access retries

Quoted 8 lines · Jan Glauber

Do not infinitely retry register readq and writeq operations in order to not lock up the CPU in case the TWSI gets stuck.

Return -EIO in case of a failed data read. For all other cases just return so subsequent operations will fail and trigger the recovery.

I can't apply this one?

#7 lore raw

Re: [PATCH 3/4] i2c: octeon: thunderx: Limit register access retries

Quoted 4 lines · Wolfram Sang
Quoted 3 lines · Jan Glauber

Do not infinitely retry register readq and writeq operations in order to not lock up the CPU in case the TWSI gets stuck.

Quoted 8 lines
Quoted 5 lines

Return -EIO in case of a failed data read. For all other cases just return so subsequent operations will fail and trigger the recovery.

I can't apply this one?

Strange. Applies for me on top of 4.9 and also next-20161212. I can also apply if back from the mail. Is the mail messed up on your side?

#8 lore raw

Re: [PATCH 3/4] i2c: octeon: thunderx: Limit register access retries

Quoted 7 lines
Quoted 3 lines

I can't apply this one?

Strange. Applies for me on top of 4.9 and also next-20161212. I can also apply if back from the mail. Is the mail messed up on your side?

My fault, sorry for the noise. My branch missed the latest revert for 4.9. I'll apply this patch for a second pull request during the merge window.

Applied
#9 lore raw

Re: [PATCH 3/4] i2c: octeon: thunderx: Limit register access retries

In reply to Jan Glauber
Quoted 8 lines · Jan Glauber

Do not infinitely retry register readq and writeq operations in order to not lock up the CPU in case the TWSI gets stuck.

Return -EIO in case of a failed data read. For all other cases just return so subsequent operations will fail and trigger the recovery.

Applied to for-current, thanks!

#10 lore raw

PATCH 4/4 i2c: octeon: thunderx: Add I2C_CLASS_HWMON

In reply to Jan Glauber

It was reported that ipmi_ssif fails to create the
ipmi device on some systems if the adapter class is not containing I2C_CLASS_HWMON. Fix it by setting the class.

---
 drivers/i2c/busses/i2c-octeon-platdrv.c  | 1 +
 drivers/i2c/busses/i2c-thunderx-pcidrv.c | 1 +
 2 files changed, 2 insertions(+)
drivers/i2c/busses/i2c-octeon-platdrv.c +1 -0
index 917524c..809b868 100644
@@ -239,6 +239,7 @@ static int octeon_i2c_probe(struct platform_device *pdev)
 	i2c->adap = octeon_i2c_ops;
 	i2c->adap.timeout = msecs_to_jiffies(2);
 	i2c->adap.retries = 5;
+	i2c->adap.class = I2C_CLASS_HWMON;
 	i2c->adap.bus_recovery_info = &octeon_i2c_recovery_info;
 	i2c->adap.dev.parent = &pdev->dev;
 	i2c->adap.dev.of_node = node;
drivers/i2c/busses/i2c-thunderx-pcidrv.c +1 -0
index bba5b42..9e3365f 100644
@@ -205,6 +205,7 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
 
 	i2c->adap = thunderx_i2c_ops;
 	i2c->adap.retries = 5;
+	i2c->adap.class = I2C_CLASS_HWMON;
 	i2c->adap.bus_recovery_info = &octeon_i2c_recovery_info;
 	i2c->adap.dev.parent = dev;
 	i2c->adap.dev.of_node = pdev->dev.of_node;
Signature · 1 line
2.9.0.rc0.21.g7777322
#11 lore raw

Re: [PATCH 4/4] i2c: octeon: thunderx: Add I2C_CLASS_HWMON

Quoted 6 lines · Jan Glauber

It was reported that ipmi_ssif fails to create the
ipmi device on some systems if the adapter class is not containing I2C_CLASS_HWMON. Fix it by setting the class.

The intention of adapter classes is to *limit* probing to a certain class of devices. If a class is needed to *enable* probing, then something there looks wrong. From the details given, this must be solved elsewhere I'd say.

#12 lore raw

Re: [PATCH 4/4] i2c: octeon: thunderx: Add I2C_CLASS_HWMON

Quoted 5 lines · Wolfram Sang
Quoted 4 lines · Jan Glauber

It was reported that ipmi_ssif fails to create the
ipmi device on some systems if the adapter class is not containing I2C_CLASS_HWMON. Fix it by setting the class.

Quoted 7 lines
Quoted 2 lines

The intention of adapter classes is to *limit* probing to a certain class of devices. If a class is needed to *enable* probing, then something there looks wrong. From the details given, this must be solved elsewhere I'd say.

Makes sense?

#13 lore raw

Re: [PATCH 4/4] i2c: octeon: thunderx: Add I2C_CLASS_HWMON

Quoted 9 lines · Wolfram Sang
Quoted 8 lines · Wolfram Sang
Quoted 6 lines · Jan Glauber

It was reported that ipmi_ssif fails to create the
ipmi device on some systems if the adapter class is not containing I2C_CLASS_HWMON. Fix it by setting the class.

Quoted 7 lines
Quoted 4 lines

The intention of adapter classes is to *limit* probing to a certain class of devices. If a class is needed to *enable* probing, then something there looks wrong. From the details given, this must be solved elsewhere I'd say.

Makes sense?

Yes, perfectly, the patch can be dropped.

thanks,
Jan

#14 lore raw

Re: [PATCH 4/4] i2c: octeon: thunderx: Add I2C_CLASS_HWMON

In reply to Wolfram Sang
Quoted 9 lines · Wolfram Sang
Quoted 8 lines · Wolfram Sang
Quoted 6 lines · Jan Glauber

It was reported that ipmi_ssif fails to create the
ipmi device on some systems if the adapter class is not containing I2C_CLASS_HWMON. Fix it by setting the class.

Quoted 7 lines
Quoted 4 lines

The intention of adapter classes is to *limit* probing to a certain class of devices. If a class is needed to *enable* probing, then something there looks wrong. From the details given, this must be solved elsewhere I'd say.

Makes sense?

Hi Wolfram,

I've looked at this again because apparently auto-detection of BMCs (ipmi_ssif driver) is not working anymore.

Debugging it shows that ssif_probe is not called when ipmi_ssif is trying to automatically detect BMCs. Adding the i2c device manually works fine (ssif_probe called).

Setting the class value in the ThunderX i2c driver to I2C_CLASS_HWMON makes the autodection of ipmi_ssif work.

Looking for clues how to solve this (because you mentioned this might be the wrong solution) I've stumbled over this:

Documentation/i2c/writing-clients:
You simply have to define a detect callback which will attempt to identify supported devices (returning 0 for supported ones and -ENODEV for unsupported ones), a list of addresses to probe, and a device type (or class) so that only I2C buses which may have that type of device connected (and not otherwise enumerated) will be probed. For example, a driver for a hardware monitoring chip for which auto-detection is needed would set its class to I2C_CLASS_HWMON, and only I2C adapters with a class including I2C_CLASS_HWMON would be probed by this driver. Note that the absence of matching classes does not prevent the use of a device of that type on the given I2C adapter. All it prevents is auto-detection; explicit instantiation of devices is still possible.

We do want auto-detection, so either this text is wrong or setting I2C_CLASS_HWMON in our i2c adapter is correct. Am I missing something?

thanks,
Jan

#15 lore raw

Re: [PATCH 4/4] i2c: octeon: thunderx: Add I2C_CLASS_HWMON

Hi Jan,

Quoted 3 lines

We do want auto-detection, so either this text is wrong or setting I2C_CLASS_HWMON in our i2c adapter is correct. Am I missing something?

I was assuming the pci-driver could ACPI for device instantiation, and the platdrv could use DT. Then, the adapter class usage raised my eyebrow.

I just saw that the pci-driver does not have ACPI support, yet. So, the class could be used. Not sure about the platdrv case? But even then, the adapter will probe EVERY hwmon device as soon as its i2c client driver loads. Do you really want that? This may cost boot time, has unneeded traffic on the bus, etc.

Regards,

Wolfram

#16 lore raw

Re: [PATCH 4/4] i2c: octeon: thunderx: Add I2C_CLASS_HWMON

Quoted 10 lines · Wolfram Sang

Hi Jan,

Quoted 3 lines

We do want auto-detection, so either this text is wrong or setting I2C_CLASS_HWMON in our i2c adapter is correct. Am I missing something?

I was assuming the pci-driver could ACPI for device instantiation, and the platdrv could use DT. Then, the adapter class usage raised my eyebrow.

Quoted 5 lines

I just saw that the pci-driver does not have ACPI support, yet. So, the class could be used. Not sure about the platdrv case? But even then, the adapter will probe EVERY hwmon device as soon as its i2c client driver loads. Do you really want that? This may cost boot time, has unneeded traffic on the bus, etc.

What is missing in the pci-driver for ACPI support? We already use ACPI to detect the sclk setting.

The automatic probing is requested by distributions. As we have to support both ACPI and DT there I thought of letting ipmi-ssif use the smbios/dmi information that is already there and usable regardless of ACPI / DT.

For servers I don't think the probing overhead is an issue, the firmware only exposes the BMC device there. On the "embedded" systems I've not seen a BMC yet and anyone attempting do minimize boot time can disable the automatic probing.

So, if you're ok with this I'll re-phrase the commit message and re-submit the patch.

Gruß,
Jan

Quoted 4 lines

Regards,

Wolfram

#17 lore raw

Re: [PATCH 4/4] i2c: octeon: thunderx: Add I2C_CLASS_HWMON

Hi Jan,

Quoted 2 lines

What is missing in the pci-driver for ACPI support? We already use ACPI to detect the sclk setting.

I noticed this in the driver:

134 static int thunder_i2c_smbus_setup(struct octeon_i2c *i2c,
135 struct device_node *node)
136 {
137 /* TODO: ACPI support */
138 if (!acpi_disabled)
139 return -EOPNOTSUPP;
140
141 return thunder_i2c_smbus_setup_of(i2c, node);
142 }

And from a glimpse, I assumed this is the place to detect and instantiate client devices.

Quoted 2 lines

So, if you're ok with this I'll re-phrase the commit message and re-submit the patch.

I'm OK. It is basically your call. I just wanted to make sure you know what it means adding the class to a master driver.

Regards,

Wolfram

#18 lore raw

Re: [PATCH 4/4] i2c: octeon: thunderx: Add I2C_CLASS_HWMON

Quoted 17 lines · Wolfram Sang

Hi Jan,

Quoted 2 lines

What is missing in the pci-driver for ACPI support? We already use ACPI to detect the sclk setting.

I noticed this in the driver:

134 static int thunder_i2c_smbus_setup(struct octeon_i2c *i2c,
135 struct device_node *node)
136 {
137 /* TODO: ACPI support */
138 if (!acpi_disabled)
139 return -EOPNOTSUPP;
140
141 return thunder_i2c_smbus_setup_of(i2c, node);
142 }

Quoted 2 lines

And from a glimpse, I assumed this is the place to detect and instantiate client devices.

I see. This function is only setting up the optional smbus alert irq stuff.

Quoted 5 lines
Quoted 2 lines

So, if you're ok with this I'll re-phrase the commit message and re-submit the patch.

I'm OK. It is basically your call. I just wanted to make sure you know what it means adding the class to a master driver.

Understood. I think we should look at fully describing the BMC in ACPI and DT, if that is possible we could get rid of the additional probing.

As we are not there yet I'll post the patch adding the class.

thanks,
Jan

Quoted 4 lines

Regards,

Wolfram