Skip to contentSkip to conversation

fsi and hwmon (occ): Prevent occasional checksum failures

PATCH Superseded Eddie James 3 participants 6 messages Mar 21, 2022 – Apr 26, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eddie James

author maintainer
#0 lore raw

cover fsi and hwmon (occ): Prevent occasional checksum failures

Due to the OCC communication design with a shared SRAM area, checkum errors are expected due to corrupted buffer from OCC communications with other system components. Therefore, use a unique errno for checksum failures and retry the command twice in that case.

Eddie James (2):
fsi: occ: Fix checksum failure mode
hwmon (occ): Retry for checksum failure

 drivers/fsi/fsi-occ.c      |  7 +++++--
 drivers/hwmon/occ/p9_sbe.c | 28 ++++++++++++++++++----------
 2 files changed, 23 insertions(+), 12 deletions(-)
Signature · 1 line
2.27.0
author maintainer
#1 lore raw

PATCH 1/2 fsi: occ: Fix checksum failure mode

Change the checksum errno to something different than the errno used for a bad SBE message. In addition, don't set the user's response length to the data length in this case, since it's not SBE FFDC.

---
 drivers/fsi/fsi-occ.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/fsi/fsi-occ.c +5 -2
index c9cc75fbdfb9..3d04e8baecbb 100644
@@ -246,7 +246,7 @@ static int occ_verify_checksum(struct occ *occ, struct occ_response *resp,
 	if (checksum != checksum_resp) {
 		dev_err(occ->dev, "Bad checksum: %04x!=%04x\n", checksum,
 			checksum_resp);
-		return -EBADMSG;
+		return -EBADE;
 	}
 
 	return 0;
@@ -575,8 +575,11 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len,
 	dev_dbg(dev, "resp_status=%02x resp_data_len=%d\n",
 		resp->return_status, resp_data_length);
 
-	occ->client_response_size = resp_data_length + 7;
 	rc = occ_verify_checksum(occ, resp, resp_data_length);
+	if (rc)
+		goto done;
+
+	occ->client_response_size = resp_data_length + 7;
 
  done:
 	*resp_len = occ->client_response_size;
Signature · 1 line
2.27.0
author maintainer
#2 lore raw

PATCH 2/2 hwmon (occ): Retry for checksum failure

In reply to Eddie James

Due to the OCC communication design with a shared SRAM area, checkum errors are expected due to corrupted buffer from OCC communications with other system components. Therefore, retry the command twice in the event of a checksum failure.

---
 drivers/hwmon/occ/p9_sbe.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/hwmon/occ/p9_sbe.c +18 -10
index 49b13cc01073..7f4c3f979c54 100644
@@ -84,17 +84,25 @@ static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len)
 	struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
 	size_t resp_len = sizeof(*resp);
 	int rc;
-
-	rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
-	if (rc < 0) {
-		if (resp_len) {
-			if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
-				sysfs_notify(&occ->bus_dev->kobj, NULL,
-					     bin_attr_ffdc.attr.name);
+	int tries = 0;
+
+	do {
+		rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
+		if (rc < 0) {
+			if (resp_len) {
+				if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
+					sysfs_notify(&occ->bus_dev->kobj, NULL,
+						     bin_attr_ffdc.attr.name);
+
+				return rc;
+			} else if (rc != -EBADE) {
+				return rc;
+			}
+			/* retry twice for checksum failures */
+		} else {
+			break;
 		}
-
-		return rc;
-	}
+	} while (++tries < 3);
 
 	switch (resp->return_status) {
 	case OCC_RESP_CMD_IN_PRG:
Signature · 1 line
2.27.0
maintainer Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] hwmon (occ): Retry for checksum failure

Quoted 6 lines · Eddie James

Due to the OCC communication design with a shared SRAM area, checkum errors are expected due to corrupted buffer from OCC communications with other system components. Therefore, retry the command twice in the event of a checksum failure.

I assume this will be applied together with patch 1 of the series.

Guenter

Quoted 44 lines
---
 drivers/hwmon/occ/p9_sbe.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/hwmon/occ/p9_sbe.c +18 -10
index 49b13cc01073..7f4c3f979c54 100644
@@ -84,17 +84,25 @@ static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len)
 	struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
 	size_t resp_len = sizeof(*resp);
 	int rc;
-
-	rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
-	if (rc < 0) {
-		if (resp_len) {
-			if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
-				sysfs_notify(&occ->bus_dev->kobj, NULL,
-					     bin_attr_ffdc.attr.name);
+	int tries = 0;
+
+	do {
+		rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
+		if (rc < 0) {
+			if (resp_len) {
+				if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
+					sysfs_notify(&occ->bus_dev->kobj, NULL,
+						     bin_attr_ffdc.attr.name);
+
+				return rc;
+			} else if (rc != -EBADE) {
+				return rc;
+			}
+			/* retry twice for checksum failures */
+		} else {
+			break;
 		}
-
-		return rc;
-	}
+	} while (++tries < 3);
 
 	switch (resp->return_status) {
 	case OCC_RESP_CMD_IN_PRG:
#4 lore raw

RE: [PATCH 2/2] hwmon (occ): Retry for checksum failure

From: Guenter Roeck

Quoted 30 lines

Sent: 24 April 2022 18:18

Quoted 6 lines · Eddie James

Due to the OCC communication design with a shared SRAM area, checkum errors are expected due to corrupted buffer from OCC communications with other system components. Therefore, retry the command twice in the event of a checksum failure.

I assume this will be applied together with patch 1 of the series.

Guenter

Quoted 14 lines
---
 drivers/hwmon/occ/p9_sbe.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/hwmon/occ/p9_sbe.c +0 -2
index 49b13cc01073..7f4c3f979c54 100644
@@ -84,17 +84,25 @@ static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len)
 	struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
 	size_t resp_len = sizeof(*resp);
 	int rc;
-
-	rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
Quoted 8 lines

drivers/hwmon/occ/p9_sbe.c static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) · line 89

Quoted 8 lines
drivers/hwmon/occ/p9_sbe.c +3 -5
-	if (rc < 0) {
-		if (resp_len) {
-			if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
-				sysfs_notify(&occ->bus_dev->kobj, NULL,
-					     bin_attr_ffdc.attr.name);
+	int tries = 0;
+
+	do {

Why not use a for() loop?

Quoted 11 lines

drivers/hwmon/occ/p9_sbe.c static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) · line 100

Quoted 11 lines
drivers/hwmon/occ/p9_sbe.c +11 -0
+		rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
+		if (rc < 0) {
+			if (resp_len) {
+				if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
+					sysfs_notify(&occ->bus_dev->kobj, NULL,
+						     bin_attr_ffdc.attr.name);
+
+				return rc;
+			} else if (rc != -EBADE) {
+				return rc;
+			}

No need for else after return.

Quoted 3 lines

drivers/hwmon/occ/p9_sbe.c static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) · line 103

Quoted 3 lines
drivers/hwmon/occ/p9_sbe.c +3 -0
+			/* retry twice for checksum failures */
+		} else {
+			break;

I'd break on the success path after testing (rc >= 0). Saves a level of indent.

Quoted 8 lines

drivers/hwmon/occ/p9_sbe.c static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) · line 108

Quoted 8 lines
drivers/hwmon/occ/p9_sbe.c +1 -3
 		}
-
-		return rc;
-	}
+	} while (++tries < 3);
 
 	switch (resp->return_status) {
 	case OCC_RESP_CMD_IN_PRG:

Probably end up with something like:

	for (tries = 0; tries < 3; tries++) {
		rc = ...;
		if (rc >= 0)
			break;
		if (resp_len) {
			...
			return rc;
		}
		if (rc != -EBADE)
			return rc;
	}

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

author maintainer
#5 lore raw

Re: [PATCH 2/2] hwmon (occ): Retry for checksum failure

Quoted 68 lines · David Laight

From: Guenter Roeck

Quoted 29 lines

Sent: 24 April 2022 18:18

Quoted 6 lines · Eddie James

Due to the OCC communication design with a shared SRAM area, checkum errors are expected due to corrupted buffer from OCC communications with other system components. Therefore, retry the command twice in the event of a checksum failure.

I assume this will be applied together with patch 1 of the series.

Guenter

Quoted 14 lines
---
  drivers/hwmon/occ/p9_sbe.c | 28 ++++++++++++++++++----------
  1 file changed, 18 insertions(+), 10 deletions(-)
drivers/hwmon/occ/p9_sbe.c +0 -2
index 49b13cc01073..7f4c3f979c54 100644
@@ -84,17 +84,25 @@ static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len)
  	struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
  	size_t resp_len = sizeof(*resp);
  	int rc;
-
-	rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
Quoted 8 lines

drivers/hwmon/occ/p9_sbe.c static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) · line 89

Quoted 8 lines
drivers/hwmon/occ/p9_sbe.c +3 -5
-	if (rc < 0) {
-		if (resp_len) {
-			if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
-				sysfs_notify(&occ->bus_dev->kobj, NULL,
-					     bin_attr_ffdc.attr.name);
+	int tries = 0;
+
+	do {

Why not use a for() loop?

Quoted 11 lines

drivers/hwmon/occ/p9_sbe.c static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) · line 100

Quoted 11 lines
drivers/hwmon/occ/p9_sbe.c +11 -0
+		rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
+		if (rc < 0) {
+			if (resp_len) {
+				if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
+					sysfs_notify(&occ->bus_dev->kobj, NULL,
+						     bin_attr_ffdc.attr.name);
+
+				return rc;
+			} else if (rc != -EBADE) {
+				return rc;
+			}

No need for else after return.

Quoted 3 lines

drivers/hwmon/occ/p9_sbe.c static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) · line 103

Quoted 3 lines
drivers/hwmon/occ/p9_sbe.c +3 -0
+			/* retry twice for checksum failures */
+		} else {
+			break;

I'd break on the success path after testing (rc >= 0). Saves a level of indent.

Quoted 8 lines

drivers/hwmon/occ/p9_sbe.c static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) · line 108

Quoted 8 lines
drivers/hwmon/occ/p9_sbe.c +1 -3
  		}
-
-		return rc;
-	}
+	} while (++tries < 3);
 
  	switch (resp->return_status) {
  	case OCC_RESP_CMD_IN_PRG:

Probably end up with something like:

Quoted 13 lines
	for (tries = 0; tries < 3; tries++) {
		rc = ...;
		if (rc >= 0)
			break;
		if (resp_len) {
			...
			return rc;
		}
		if (rc != -EBADE)
			return rc;
	}

	David

Thanks David, Ack.

Quoted 5 lines

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)