cxlflash: Properly obtain AFU version and check it
PATCH 19/29 cxlflash: Properly obtain AFU version and check it
The AFU version is stored as a non-terminated string of bytes within a 64-bit little-endian register. Use the correct MMIO accessor to read this value into a null-terminated buffer and add a check to prevent a GA1 AFU from being used with this driver as it doesn't support the GA1 interface.
Signed-off-by Matthew R. Ochs <[email protected]>
Signed-off-by Manoj N. Kumar <[email protected]>
--- drivers/scsi/cxlflash/common.h | 2 +- drivers/scsi/cxlflash/main.c | 18 ++++++++++++------ drivers/scsi/cxlflash/sislite.h | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-)
drivers/scsi/cxlflash/common.h +1 -1
@@ -180,7 +180,7 @@ struct afu {u32 cmd_couts;/* Number of command checkouts */ u32 internal_lun;/* User-desired LUN mode for this AFU */ -char version[8 ]; +char version[16 ];u64 interface_version;struct cxlflash_cfg *parent;/* Pointer back to parent cxlflash_cfg */
drivers/scsi/cxlflash/main.c +12 -6
@@ -1762,14 +1762,20 @@ static int init_afu(struct cxlflash_cfg *cfg) goto err1; } -/* don't byte reverse on reading afu_version, else the string form */ -/* will be backwards */ - reg = afu->afu_map->global.regs.afu_version; -memcpy (afu->version, ®,8 ); +/* No byte reverse on reading afu_version or string will be backwards */ + reg =readq (&afu->afu_map->global.regs.afu_version); +memcpy (afu->version, ®,sizeof (reg)); afu->interface_version =readq_be (&afu->afu_map->global.regs.interface_version); -pr_debug ("%s: afu version %s, interface version 0x%llX\n" , - __func__, afu->version, afu->interface_version); +if ((afu->interface_version +1 ) ==0 ) { +pr_err ("Back level AFU, please upgrade. AFU version %s " +"interface version 0x%llx\n" , afu->version, + afu->interface_version); + rc = -EINVAL ; + goto err1; + }else +pr_debug ("%s: afu version %s, interface version 0x%llX\n" , + __func__, afu->version, afu->interface_version); rc =start_afu (cfg);if (rc) {
drivers/scsi/cxlflash/sislite.h +1 -1
@@ -340,7 +340,7 @@ struct sisl_global_regs {#define SISL_AFUCONF_MBOX_CLR_READ 0x0010ULL__be64 afu_config;__be64 rsvd[0xf8 ]; -__be64 afu_version; +__le64 afu_version;__be64 interface_version; };
Signature · 1 line
2.1.0