[PATCH 3/5] scsi/esp_scsi: Clean up control flow and dead code

2017-08-03 Thread Finn Thain
This patch improves readability. There are no functional changes.

Since this touches on a questionable ESP_INTR_DC conditional, add some
commentary to help others who may (as I did) find themselves chasing an
"Invalid Command" error after the device flags this condition.

This cleanup also eliminates a warning from "make W=1":
drivers/scsi/esp_scsi.c: In function 'esp_finish_select':
drivers/scsi/esp_scsi.c:1233:5: warning: variable 'orig_select_state' set but 
not used [-Wunused-but-set-variable]
  u8 orig_select_state;

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/scsi/esp_scsi.c | 40 ++--
 drivers/scsi/esp_scsi.h |  1 -
 2 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 71cb05b1c3eb..93fef2b3d357 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -597,14 +597,12 @@ static int esp_alloc_lun_tag(struct esp_cmd_entry *ent,
 
lp->non_tagged_cmd = ent;
return 0;
-   } else {
-   /* Tagged command, see if blocked by a
-* non-tagged one.
-*/
-   if (lp->non_tagged_cmd || lp->hold)
-   return -EBUSY;
}
 
+   /* Tagged command. Check that it isn't blocked by a non-tagged one. */
+   if (lp->non_tagged_cmd || lp->hold)
+   return -EBUSY;
+
BUG_ON(lp->tagged_cmds[ent->orig_tag[1]]);
 
lp->tagged_cmds[ent->orig_tag[1]] = ent;
@@ -1210,12 +1208,6 @@ static int esp_reconnect(struct esp *esp)
 
esp->active_cmd = ent;
 
-   if (ent->flags & ESP_CMD_FLAG_ABORT) {
-   esp->msg_out[0] = ABORT_TASK_SET;
-   esp->msg_out_len = 1;
-   scsi_esp_cmd(esp, ESP_CMD_SATN);
-   }
-
esp_event(esp, ESP_EVENT_CHECK_PHASE);
esp_restore_pointers(esp, ent);
esp->flags |= ESP_FLAG_QUICKIRQ_CHECK;
@@ -1230,9 +1222,6 @@ static int esp_finish_select(struct esp *esp)
 {
struct esp_cmd_entry *ent;
struct scsi_cmnd *cmd;
-   u8 orig_select_state;
-
-   orig_select_state = esp->select_state;
 
/* No longer selecting.  */
esp->select_state = ESP_SELECT_NONE;
@@ -1745,7 +1734,6 @@ static int esp_process_event(struct esp *esp)
return 0;
}
goto again;
-   break;
 
case ESP_EVENT_DATA_IN:
write = 1;
@@ -1956,12 +1944,14 @@ static int esp_process_event(struct esp *esp)
} else {
if (esp->msg_out_len > 1)
esp->ops->dma_invalidate(esp);
-   }
 
-   if (!(esp->ireg & ESP_INTR_DC)) {
-   if (esp->rev != FASHME)
+   /* XXX if the chip went into disconnected mode,
+* we can't run the phase state machine anyway.
+*/
+   if (!(esp->ireg & ESP_INTR_DC))
scsi_esp_cmd(esp, ESP_CMD_NULL);
}
+
esp_event(esp, ESP_EVENT_CHECK_PHASE);
goto again;
case ESP_EVENT_MSGIN:
@@ -2022,7 +2012,6 @@ static int esp_process_event(struct esp *esp)
}
esp_schedule_reset(esp);
return 0;
-   break;
 
case ESP_EVENT_RESET:
scsi_esp_cmd(esp, ESP_CMD_RS);
@@ -2033,7 +2022,6 @@ static int esp_process_event(struct esp *esp)
 "Unexpected event %x, resetting\n", esp->event);
esp_schedule_reset(esp);
return 0;
-   break;
}
return 1;
 }
@@ -2170,14 +2158,14 @@ static void __esp_interrupt(struct esp *esp)
 
esp_schedule_reset(esp);
} else {
-   if (!(esp->ireg & ESP_INTR_RSEL)) {
-   /* Some combination of FDONE, BSERV, DC.  */
-   if (esp->select_state != ESP_SELECT_NONE)
-   intr_done = esp_finish_select(esp);
-   } else if (esp->ireg & ESP_INTR_RSEL) {
+   if (esp->ireg & ESP_INTR_RSEL) {
if (esp->active_cmd)
(void) esp_finish_select(esp);
intr_done = esp_reconnect(esp);
+   } else {
+   /* Some combination of FDONE, BSERV, DC. */
+   if (esp->select_state != ESP_SELECT_NONE)
+   intr_done = esp_finish_select(esp);
}
}
while (!intr_done)
diff --git a/drivers/scsi/esp_scsi.h b/drivers/scsi/esp_scsi.h
index 84dcbe4a6268..7e8932ae91f8 100644
--- a/drivers/scsi/esp_scsi.h
+++ b/drivers/scsi/esp_scsi.h
@@ -281,7 +281,6 @@ struct esp_cmd_entry {
 
u8  

[PATCH 3/5] scsi/esp_scsi: Clean up control flow and dead code

2017-08-03 Thread Finn Thain
This patch improves readability. There are no functional changes.

Since this touches on a questionable ESP_INTR_DC conditional, add some
commentary to help others who may (as I did) find themselves chasing an
"Invalid Command" error after the device flags this condition.

This cleanup also eliminates a warning from "make W=1":
drivers/scsi/esp_scsi.c: In function 'esp_finish_select':
drivers/scsi/esp_scsi.c:1233:5: warning: variable 'orig_select_state' set but 
not used [-Wunused-but-set-variable]
  u8 orig_select_state;

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/scsi/esp_scsi.c | 40 ++--
 drivers/scsi/esp_scsi.h |  1 -
 2 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 71cb05b1c3eb..93fef2b3d357 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -597,14 +597,12 @@ static int esp_alloc_lun_tag(struct esp_cmd_entry *ent,
 
lp->non_tagged_cmd = ent;
return 0;
-   } else {
-   /* Tagged command, see if blocked by a
-* non-tagged one.
-*/
-   if (lp->non_tagged_cmd || lp->hold)
-   return -EBUSY;
}
 
+   /* Tagged command. Check that it isn't blocked by a non-tagged one. */
+   if (lp->non_tagged_cmd || lp->hold)
+   return -EBUSY;
+
BUG_ON(lp->tagged_cmds[ent->orig_tag[1]]);
 
lp->tagged_cmds[ent->orig_tag[1]] = ent;
@@ -1210,12 +1208,6 @@ static int esp_reconnect(struct esp *esp)
 
esp->active_cmd = ent;
 
-   if (ent->flags & ESP_CMD_FLAG_ABORT) {
-   esp->msg_out[0] = ABORT_TASK_SET;
-   esp->msg_out_len = 1;
-   scsi_esp_cmd(esp, ESP_CMD_SATN);
-   }
-
esp_event(esp, ESP_EVENT_CHECK_PHASE);
esp_restore_pointers(esp, ent);
esp->flags |= ESP_FLAG_QUICKIRQ_CHECK;
@@ -1230,9 +1222,6 @@ static int esp_finish_select(struct esp *esp)
 {
struct esp_cmd_entry *ent;
struct scsi_cmnd *cmd;
-   u8 orig_select_state;
-
-   orig_select_state = esp->select_state;
 
/* No longer selecting.  */
esp->select_state = ESP_SELECT_NONE;
@@ -1745,7 +1734,6 @@ static int esp_process_event(struct esp *esp)
return 0;
}
goto again;
-   break;
 
case ESP_EVENT_DATA_IN:
write = 1;
@@ -1956,12 +1944,14 @@ static int esp_process_event(struct esp *esp)
} else {
if (esp->msg_out_len > 1)
esp->ops->dma_invalidate(esp);
-   }
 
-   if (!(esp->ireg & ESP_INTR_DC)) {
-   if (esp->rev != FASHME)
+   /* XXX if the chip went into disconnected mode,
+* we can't run the phase state machine anyway.
+*/
+   if (!(esp->ireg & ESP_INTR_DC))
scsi_esp_cmd(esp, ESP_CMD_NULL);
}
+
esp_event(esp, ESP_EVENT_CHECK_PHASE);
goto again;
case ESP_EVENT_MSGIN:
@@ -2022,7 +2012,6 @@ static int esp_process_event(struct esp *esp)
}
esp_schedule_reset(esp);
return 0;
-   break;
 
case ESP_EVENT_RESET:
scsi_esp_cmd(esp, ESP_CMD_RS);
@@ -2033,7 +2022,6 @@ static int esp_process_event(struct esp *esp)
 "Unexpected event %x, resetting\n", esp->event);
esp_schedule_reset(esp);
return 0;
-   break;
}
return 1;
 }
@@ -2170,14 +2158,14 @@ static void __esp_interrupt(struct esp *esp)
 
esp_schedule_reset(esp);
} else {
-   if (!(esp->ireg & ESP_INTR_RSEL)) {
-   /* Some combination of FDONE, BSERV, DC.  */
-   if (esp->select_state != ESP_SELECT_NONE)
-   intr_done = esp_finish_select(esp);
-   } else if (esp->ireg & ESP_INTR_RSEL) {
+   if (esp->ireg & ESP_INTR_RSEL) {
if (esp->active_cmd)
(void) esp_finish_select(esp);
intr_done = esp_reconnect(esp);
+   } else {
+   /* Some combination of FDONE, BSERV, DC. */
+   if (esp->select_state != ESP_SELECT_NONE)
+   intr_done = esp_finish_select(esp);
}
}
while (!intr_done)
diff --git a/drivers/scsi/esp_scsi.h b/drivers/scsi/esp_scsi.h
index 84dcbe4a6268..7e8932ae91f8 100644
--- a/drivers/scsi/esp_scsi.h
+++ b/drivers/scsi/esp_scsi.h
@@ -281,7 +281,6 @@ struct esp_cmd_entry {
 
u8  flags;
 #define ESP_CMD_FLAG_WRITE 0x01 /*