scsi: ufs: Improve static type checking for the host controller state
authorBart Van Assche <bvanassche@acm.org>
Thu, 22 Jul 2021 03:34:29 +0000 (20:34 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 3 Aug 2021 01:43:58 +0000 (21:43 -0400)
Assign a name to the enumeration type for UFS host controller states and
remove the default clause from switch statements on this enumeration type
to make the compiler warn about unhandled enumeration labels.

Link: https://lore.kernel.org/r/20210722033439.26550-9-bvanassche@acm.org
Cc: Can Guo <cang@codeaurora.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/ufs/ufshcd.c
drivers/scsi/ufs/ufshcd.h

index 8e3873e00bc4144854f13509e06d40a0b53039ca..3ef2a2dda700c26400e147814adece1f8cc3c37b 100644 (file)
@@ -128,15 +128,6 @@ enum {
        UFSHCD_CAN_QUEUE        = 32,
 };
 
-/* UFSHCD states */
-enum {
-       UFSHCD_STATE_RESET,
-       UFSHCD_STATE_ERROR,
-       UFSHCD_STATE_OPERATIONAL,
-       UFSHCD_STATE_EH_SCHEDULED_FATAL,
-       UFSHCD_STATE_EH_SCHEDULED_NON_FATAL,
-};
-
 /* UFSHCD error handling flags */
 enum {
        UFSHCD_EH_IN_PROGRESS = (1 << 0),
@@ -2737,12 +2728,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
                set_host_byte(cmd, DID_ERROR);
                cmd->scsi_done(cmd);
                goto out;
-       default:
-               dev_WARN_ONCE(hba->dev, 1, "%s: invalid state %d\n",
-                               __func__, hba->ufshcd_state);
-               set_host_byte(cmd, DID_BAD_TARGET);
-               cmd->scsi_done(cmd);
-               goto out;
        }
 
        hba->req_abort_count = 0;
index 139e43c6f77689bd04827413646ac61d64e2485a..334b49cb00b3a6d799ff6657572a17793d0bbee0 100644 (file)
@@ -476,6 +476,27 @@ struct ufs_stats {
        struct ufs_event_hist event[UFS_EVT_CNT];
 };
 
+/**
+ * enum ufshcd_state - UFS host controller state
+ * @UFSHCD_STATE_RESET: Link is not operational. Postpone SCSI command
+ *     processing.
+ * @UFSHCD_STATE_OPERATIONAL: The host controller is operational and can process
+ *     SCSI commands.
+ * @UFSHCD_STATE_EH_SCHEDULED_NON_FATAL: The error handler has been scheduled.
+ *     SCSI commands may be submitted to the controller.
+ * @UFSHCD_STATE_EH_SCHEDULED_FATAL: The error handler has been scheduled. Fail
+ *     newly submitted SCSI commands with error code DID_BAD_TARGET.
+ * @UFSHCD_STATE_ERROR: An unrecoverable error occurred, e.g. link recovery
+ *     failed. Fail all SCSI commands with error code DID_ERROR.
+ */
+enum ufshcd_state {
+       UFSHCD_STATE_RESET,
+       UFSHCD_STATE_OPERATIONAL,
+       UFSHCD_STATE_EH_SCHEDULED_NON_FATAL,
+       UFSHCD_STATE_EH_SCHEDULED_FATAL,
+       UFSHCD_STATE_ERROR,
+};
+
 enum ufshcd_quirks {
        /* Interrupt aggregation support is broken */
        UFSHCD_QUIRK_BROKEN_INTR_AGGR                   = 1 << 0,
@@ -712,7 +733,7 @@ struct ufs_hba_monitor {
  * @tmf_tag_set: TMF tag set.
  * @tmf_queue: Used to allocate TMF tags.
  * @pwr_done: completion for power mode change
- * @ufshcd_state: UFSHCD states
+ * @ufshcd_state: UFSHCD state
  * @eh_flags: Error handling flags
  * @intr_mask: Interrupt Mask Bits
  * @ee_ctrl_mask: Exception event control mask
@@ -810,7 +831,7 @@ struct ufs_hba {
        struct mutex uic_cmd_mutex;
        struct completion *uic_async_done;
 
-       u32 ufshcd_state;
+       enum ufshcd_state ufshcd_state;
        u32 eh_flags;
        u32 intr_mask;
        u16 ee_ctrl_mask; /* Exception event mask */