Make q_dev_state a little more readable and maintainable by using named initializers. Also convert QLA8XXX_DEV_* macros into an enum and remove qla83xx_dev_state_to_string(), which is a duplicate of qdev_state(). Signed-off-by: Gleb Chesnokov <Chesnokov.G@xxxxxxxxxx> --- drivers/scsi/qla2xxx/qla_gbl.h | 2 +- drivers/scsi/qla2xxx/qla_init.c | 28 ++------------------------ drivers/scsi/qla2xxx/qla_nx.c | 35 ++++++++++++++------------------- drivers/scsi/qla2xxx/qla_nx.h | 20 +++++++++++-------- drivers/scsi/qla2xxx/qla_nx2.c | 9 +++------ 5 files changed, 33 insertions(+), 61 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h index 8d8503a28479..7e93ab9104fd 100644 --- a/drivers/scsi/qla2xxx/qla_gbl.h +++ b/drivers/scsi/qla2xxx/qla_gbl.h @@ -890,7 +890,7 @@ extern void qla82xx_chip_reset_cleanup(scsi_qla_host_t *); extern int qla81xx_set_led_config(scsi_qla_host_t *, uint16_t *); extern int qla81xx_get_led_config(scsi_qla_host_t *, uint16_t *); extern int qla82xx_mbx_beacon_ctl(scsi_qla_host_t *, int); -extern char *qdev_state(uint32_t); +extern const char *qdev_state(uint32_t); extern void qla82xx_clear_pending_mbx(scsi_qla_host_t *); extern int qla82xx_read_temperature(scsi_qla_host_t *); extern int qla8044_read_temperature(scsi_qla_host_t *); diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c index 1fe4966fc2f6..b07ebfb02ea9 100644 --- a/drivers/scsi/qla2xxx/qla_init.c +++ b/drivers/scsi/qla2xxx/qla_init.c @@ -6773,29 +6773,6 @@ __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) return rval; } -static const char * -qla83xx_dev_state_to_string(uint32_t dev_state) -{ - switch (dev_state) { - case QLA8XXX_DEV_COLD: - return "COLD/RE-INIT"; - case QLA8XXX_DEV_INITIALIZING: - return "INITIALIZING"; - case QLA8XXX_DEV_READY: - return "READY"; - case QLA8XXX_DEV_NEED_RESET: - return "NEED RESET"; - case QLA8XXX_DEV_NEED_QUIESCENT: - return "NEED QUIESCENT"; - case QLA8XXX_DEV_FAILED: - return "FAILED"; - case QLA8XXX_DEV_QUIESCENT: - return "QUIESCENT"; - default: - return "Unknown"; - } -} - /* Assumes idc-lock always held on entry */ void qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) @@ -6849,9 +6826,8 @@ qla83xx_initiating_reset(scsi_qla_host_t *vha) ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); } else { - const char *state = qla83xx_dev_state_to_string(dev_state); - - ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); + ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", + qdev_state(dev_state)); /* SV: XXX: Is timeout required here? */ /* Wait for IDC state change READY -> NEED_RESET */ diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c index 11aad97dfca8..6dfb70edb9a6 100644 --- a/drivers/scsi/qla2xxx/qla_nx.c +++ b/drivers/scsi/qla2xxx/qla_nx.c @@ -335,20 +335,20 @@ static unsigned qla82xx_crb_hub_agt[64] = { }; /* Device states */ -static char *q_dev_state[] = { - "Unknown", - "Cold", - "Initializing", - "Ready", - "Need Reset", - "Need Quiescent", - "Failed", - "Quiescent", +static const char *const q_dev_state[] = { + [QLA8XXX_DEV_UNKNOWN] = "Unknown", + [QLA8XXX_DEV_COLD] = "Cold/Re-init", + [QLA8XXX_DEV_INITIALIZING] = "Initializing", + [QLA8XXX_DEV_READY] = "Ready", + [QLA8XXX_DEV_NEED_RESET] = "Need Reset", + [QLA8XXX_DEV_NEED_QUIESCENT] = "Need Quiescent", + [QLA8XXX_DEV_FAILED] = "Failed", + [QLA8XXX_DEV_QUIESCENT] = "Quiescent", }; -char *qdev_state(uint32_t dev_state) +const char *qdev_state(uint32_t dev_state) { - return q_dev_state[dev_state]; + return (dev_state < MAX_STATES) ? q_dev_state[dev_state] : "Unknown"; } /* @@ -3061,8 +3061,7 @@ qla82xx_need_reset_handler(scsi_qla_host_t *vha) ql_log(ql_log_info, vha, 0x00b6, "Device state is 0x%x = %s.\n", - dev_state, - dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown"); + dev_state, qdev_state(dev_state)); /* Force to DEV_COLD unless someone else is starting a reset */ if (dev_state != QLA8XXX_DEV_INITIALIZING && @@ -3185,8 +3184,7 @@ qla82xx_device_state_handler(scsi_qla_host_t *vha) old_dev_state = dev_state; ql_log(ql_log_info, vha, 0x009b, "Device state is 0x%x = %s.\n", - dev_state, - dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown"); + dev_state, qdev_state(dev_state)); /* wait for 30 seconds for device to go ready */ dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ); @@ -3207,9 +3205,7 @@ qla82xx_device_state_handler(scsi_qla_host_t *vha) if (loopcount < 5) { ql_log(ql_log_info, vha, 0x009d, "Device state is 0x%x = %s.\n", - dev_state, - dev_state < MAX_STATES ? qdev_state(dev_state) : - "Unknown"); + dev_state, qdev_state(dev_state)); } switch (dev_state) { @@ -3439,8 +3435,7 @@ qla82xx_set_reset_owner(scsi_qla_host_t *vha) } else ql_log(ql_log_info, vha, 0xb031, "Device state is 0x%x = %s.\n", - dev_state, - dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown"); + dev_state, qdev_state(dev_state)); } /* diff --git a/drivers/scsi/qla2xxx/qla_nx.h b/drivers/scsi/qla2xxx/qla_nx.h index 8567eaf1bddd..6dc80c8ddf79 100644 --- a/drivers/scsi/qla2xxx/qla_nx.h +++ b/drivers/scsi/qla2xxx/qla_nx.h @@ -540,14 +540,18 @@ #define QLA82XX_CRB_DRV_IDC_VERSION (QLA82XX_CAM_RAM(0x174)) /* Every driver should use these Device State */ -#define QLA8XXX_DEV_COLD 1 -#define QLA8XXX_DEV_INITIALIZING 2 -#define QLA8XXX_DEV_READY 3 -#define QLA8XXX_DEV_NEED_RESET 4 -#define QLA8XXX_DEV_NEED_QUIESCENT 5 -#define QLA8XXX_DEV_FAILED 6 -#define QLA8XXX_DEV_QUIESCENT 7 -#define MAX_STATES 8 /* Increment if new state added */ +enum { + QLA8XXX_DEV_UNKNOWN, + QLA8XXX_DEV_COLD, + QLA8XXX_DEV_INITIALIZING, + QLA8XXX_DEV_READY, + QLA8XXX_DEV_NEED_RESET, + QLA8XXX_DEV_NEED_QUIESCENT, + QLA8XXX_DEV_FAILED, + QLA8XXX_DEV_QUIESCENT, + MAX_STATES, /* Increment if new state added */ +}; + #define QLA8XXX_BAD_VALUE 0xbad0bad0 #define QLA82XX_IDC_VERSION 1 diff --git a/drivers/scsi/qla2xxx/qla_nx2.c b/drivers/scsi/qla2xxx/qla_nx2.c index 5ceecc9642fc..41ff6fbdb933 100644 --- a/drivers/scsi/qla2xxx/qla_nx2.c +++ b/drivers/scsi/qla2xxx/qla_nx2.c @@ -1938,8 +1938,7 @@ qla8044_device_state_handler(struct scsi_qla_host *vha) dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX); ql_dbg(ql_dbg_p3p, vha, 0xb0ce, "Device state is 0x%x = %s\n", - dev_state, dev_state < MAX_STATES ? - qdev_state(dev_state) : "Unknown"); + dev_state, qdev_state(dev_state)); /* wait for 30 seconds for device to go ready */ dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ); @@ -1952,8 +1951,7 @@ qla8044_device_state_handler(struct scsi_qla_host *vha) ql_log(ql_log_warn, vha, 0xb0cf, "%s: Device Init Failed 0x%x = %s\n", QLA2XXX_DRIVER_NAME, dev_state, - dev_state < MAX_STATES ? - qdev_state(dev_state) : "Unknown"); + qdev_state(dev_state)); qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX, QLA8XXX_DEV_FAILED); @@ -1963,8 +1961,7 @@ qla8044_device_state_handler(struct scsi_qla_host *vha) dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX); ql_log(ql_log_info, vha, 0xb0d0, "Device state is 0x%x = %s\n", - dev_state, dev_state < MAX_STATES ? - qdev_state(dev_state) : "Unknown"); + dev_state, qdev_state(dev_state)); /* NOTE: Make sure idc unlocked upon exit of switch statement */ switch (dev_state) { -- 2.35.1