occ: fsi and hwmon: Fixes for polling un-initialized OCC
Subsystems (2)
Eddie James
maintainercover occ: fsi and hwmon: Fixes for polling un-initialized OCC
In the event that the OCC is not initialized when the driver sends a poll command, the driver may receive an invalid response. This isn't an error condition unless there is no valid response before the timeout expires. So change the starting sequence number and check for the un-initialized OCC state before returning the response in order to detect this condition and continue waiting if necessary.
Eddie James (4):
fsi: occ: Don't accept response from un-initialized OCC
fsi: occ: Log error for checksum failure
hwmon: (occ) Start sequence number at one
hwmon: (occ) Print response status in first poll error message
drivers/fsi/fsi-occ.c | 11 ++++++++--- drivers/hwmon/occ/common.c | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
2.27.0
Eddie James
maintainerPATCH 1/4 fsi: occ: Don't accept response from un-initialized OCC
If the OCC is not initialized and responds as such, the driver should continue waiting for a valid response until the timeout expires.
--- drivers/fsi/fsi-occ.c | 1 + 1 file changed, 1 insertion(+)
drivers/fsi/fsi-occ.c +1 -0
@@ -495,6 +495,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, goto done;if (resp->return_status ==OCC_RESP_CMD_IN_PRG || + resp->return_status ==OCC_RESP_CRIT_INIT || resp->seq_no != seq_no) { rc = -ETIMEDOUT ;
Signature · 1 line
2.27.0
Re: [PATCH 1/4] fsi: occ: Don't accept response from un-initialized OCC
Quoted 6 lines · Eddie James
If the OCC is not initialized and responds as such, the driver should continue waiting for a valid response until the timeout expires.
Signed-off-by Eddie James <[email protected]>
I guess we should add this too?
Quoted 19 lines
--- drivers/fsi/fsi-occ.c | 1 + 1 file changed, 1 insertion(+)drivers/fsi/fsi-occ.c +1
-1@@ -495,6 +495,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, goto done;if (resp->return_status ==OCC_RESP_CMD_IN_PRG || + resp->return_status ==OCC_RESP_CRIT_INIT || resp->seq_no != seq_no) { rc = -ETIMEDOUT ; --2.27.0
Eddie James
maintainerPATCH 2/4 fsi: occ: Log error for checksum failure
In reply to Eddie JamesLog an error if the response checksum doesn't match the calculated checksum.
--- drivers/fsi/fsi-occ.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/fsi/fsi-occ.c +7 -3
@@ -223,7 +223,8 @@ static const struct file_operations occ_fops = { .release = occ_release, }; -static int occ_verify_checksum (struct occ_response *resp,u16 data_length) +static int occ_verify_checksum (struct occ *occ,struct occ_response *resp, +u16 data_length) {/* Fetch the two bytes after the data for the checksum. */ u16 checksum_resp =get_unaligned_be16 (&resp->data[data_length]);
@@ -238,8 +239,11 @@ static int occ_verify_checksum(struct occ_response *resp, u16 data_length)for (i =0 ; i < data_length; ++i) checksum += resp->data[i]; -if (checksum != checksum_resp) +if (checksum != checksum_resp) { +dev_err (occ->dev,"Bad checksum: %04x!=%04x\n" , checksum, + checksum_resp);return -EBADMSG ; + }return 0 ; }
@@ -533,7 +537,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, } *resp_len = resp_data_length +7 ; - rc =occ_verify_checksum (resp, resp_data_length); + rc =occ_verify_checksum (occ, resp, resp_data_length); done:mutex_unlock (&occ->occ_lock);
Signature · 1 line
2.27.0
Re: [PATCH 2/4] fsi: occ: Log error for checksum failure
Quoted 3 lines · Eddie James
Log an error if the response checksum doesn't match the calculated checksum.
Quoted 21 lines
Signed-off-by Eddie James <[email protected]>--- drivers/fsi/fsi-occ.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/fsi/fsi-occ.c +2
-1@@ -223,7 +223,8 @@ static const struct file_operations occ_fops = { .release = occ_release, }; -static int occ_verify_checksum (struct occ_response *resp,u16 data_length) +static int occ_verify_checksum (struct occ *occ,struct occ_response *resp, +u16 data_length) {/* Fetch the two bytes after the data for the checksum. */ u16 checksum_resp =get_unaligned_be16 (&resp->data[data_length]);
drivers/fsi/fsi-occ.c static int occ_verify_checksum(struct occ_response *resp, u16 data_length) · line 244
Quoted 7 lines
drivers/fsi/fsi-occ.c +3
-1@@ -238,8 +239,11 @@ static int occ_verify_checksum(struct occ_response *resp, u16 data_length)for (i =0 ; i < data_length; ++i) checksum += resp->data[i]; -if (checksum != checksum_resp) +if (checksum != checksum_resp) { +dev_err (occ->dev,"Bad checksum: %04x!=%04x\n" , checksum, + checksum_resp);
Just confirming that this is unexpected, we won't see this eg. if the system is booting or when the BMC is reset while the host is running?
Quoted 17 lines
drivers/fsi/fsi-occ.c +2
-2return -EBADMSG ; + }return 0 ; }@@ -533,7 +537,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, } *resp_len = resp_data_length +7 ; - rc =occ_verify_checksum (resp, resp_data_length); + rc =occ_verify_checksum (occ, resp, resp_data_length); done:mutex_unlock (&occ->occ_lock); --2.27.0
Eddie James
maintainerPATCH 3/4 hwmon: (occ) Start sequence number at one
In reply to Eddie JamesInitialize the sequence number at one, rather than zero, in order to prevent false matches with the zero-initialized OCC SRAM buffer before the OCC is fully initialized.
--- drivers/hwmon/occ/common.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/occ/common.c +2 -0
@@ -1150,6 +1150,8 @@ int occ_setup(struct occ *occ, const char *name) {int rc; +/* start with 1 to avoid false match with zero-initialized SRAM buffer */ + occ->seq_no =1 ;mutex_init (&occ->lock); occ->groups[0 ] = &occ->group;
Signature · 1 line
2.27.0
Re: [PATCH 3/4] hwmon: (occ) Start sequence number at one
Quoted 5 lines · Eddie James
Initialize the sequence number at one, rather than zero, in order to prevent false matches with the zero-initialized OCC SRAM buffer before the OCC is fully initialized.
Signed-off-by Eddie James <[email protected]>
For now I'll assume that the series has to be submitted together, and that this won't happen through the hwmon branch.
Guenter
Quoted 20 lines
--- drivers/hwmon/occ/common.c | 2 ++ 1 file changed, 2 insertions(+)drivers/hwmon/occ/common.c +2
-0@@ -1150,6 +1150,8 @@ int occ_setup(struct occ *occ, const char *name) {int rc; +/* start with 1 to avoid false match with zero-initialized SRAM buffer */ + occ->seq_no =1 ;mutex_init (&occ->lock); occ->groups[0 ] = &occ->group;Signature · 1 line
2.27.0
Eddie James
maintainerPATCH 4/4 hwmon: (occ) Print response status in first poll error message
In reply to Eddie JamesIn order to better debug problems starting up the driver, print the response status from the OCC in the error logged when the first poll command fails.
--- drivers/hwmon/occ/common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/occ/common.c +3 -2
@@ -1161,8 +1161,9 @@ int occ_setup(struct occ *occ, const char *name)dev_info (occ->bus_dev,"host is not ready\n" );return rc; }else if (rc <0 ) { -dev_err (occ->bus_dev,"failed to get OCC poll response: %d\n" , - rc); +dev_err (occ->bus_dev, +"failed to get OCC poll response=%02x: %d\n" , + occ->resp.return_status, rc);return rc; }
Signature · 1 line
2.27.0
Re: [PATCH 4/4] hwmon: (occ) Print response status in first poll error message
Quoted 5 lines · Eddie James
In order to better debug problems starting up the driver, print the response status from the OCC in the error logged when the first poll command fails.
Signed-off-by Eddie James <[email protected]>
Quoted 23 lines
--- drivers/hwmon/occ/common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/hwmon/occ/common.c +3
-2@@ -1161,8 +1161,9 @@ int occ_setup(struct occ *occ, const char *name)dev_info (occ->bus_dev,"host is not ready\n" );return rc; }else if (rc <0 ) { -dev_err (occ->bus_dev,"failed to get OCC poll response: %d\n" , - rc); +dev_err (occ->bus_dev, +"failed to get OCC poll response=%02x: %d\n" , + occ->resp.return_status, rc);return rc; }Signature · 1 line
2.27.0
Eddie James
maintainerQuoted 11 lines · Eddie James
In the event that the OCC is not initialized when the driver sends a poll
command, the driver may receive an invalid response. This isn't an error
condition unless there is no valid response before the timeout expires. So
change the starting sequence number and check for the un-initialized OCC
state before returning the response in order to detect this condition and
continue waiting if necessary.
Hi Joel,
Do you have any comments on the FSI side of this series?
Thanks,
Eddie
Quoted 11 lines
Eddie James (4):
fsi: occ: Don't accept response from un-initialized OCC
fsi: occ: Log error for checksum failure
hwmon: (occ) Start sequence number at one
hwmon: (occ) Print response status in first poll error messagedrivers/fsi/fsi-occ.c | 11 ++++++++--- drivers/hwmon/occ/common.c | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-)
Quoted 14 lines · Eddie James
Quoted 11 lines · Eddie James
In the event that the OCC is not initialized when the driver sends a poll
command, the driver may receive an invalid response. This isn't an error
condition unless there is no valid response before the timeout expires. So
change the starting sequence number and check for the un-initialized OCC
state before returning the response in order to detect this condition and
continue waiting if necessary.
Quoted 3 lines
Hi Joel,
Do you have any comments on the FSI side of this series?
They look fine to me. Guenter, if you want to take the series through the hwmon tree I do not anticipate any conflicts.
Cheers,
Joel