Re: [PATCH v3 43/77] ncr5380: Standardize reselection handling

2015-12-21 Thread Hannes Reinecke

On 12/22/2015 02:18 AM, Finn Thain wrote:

Bring the two NCR5380_reselect() implementations into agreement.

Replace infinite loops in atari_NCR5380.c with timeouts, as per NCR5380.c.

Remove 'abort' flag in NCR5380.c as per atari_NCR5380.c -- if reselection
fails, there may be no MESSAGE IN phase so don't attempt data transfer.

During selection, don't interfere with the chip registers after a
reselection interrupt intervenes.

Clean up some trivial issues with code style, comments and printk.

Signed-off-by: Finn Thain 

---
  drivers/scsi/NCR5380.c   |  115 
+++
  drivers/scsi/atari_NCR5380.c |   50 ++
  2 files changed, 93 insertions(+), 72 deletions(-)


Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
--
Dr. Hannes Reinecke   zSeries & Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 43/77] ncr5380: Standardize reselection handling

2015-12-21 Thread Finn Thain
Bring the two NCR5380_reselect() implementations into agreement.

Replace infinite loops in atari_NCR5380.c with timeouts, as per NCR5380.c.

Remove 'abort' flag in NCR5380.c as per atari_NCR5380.c -- if reselection
fails, there may be no MESSAGE IN phase so don't attempt data transfer.

During selection, don't interfere with the chip registers after a
reselection interrupt intervenes.

Clean up some trivial issues with code style, comments and printk.

Signed-off-by: Finn Thain 

---
 drivers/scsi/NCR5380.c   |  115 +++
 drivers/scsi/atari_NCR5380.c |   50 ++
 2 files changed, 93 insertions(+), 72 deletions(-)

Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2015-12-22 12:16:34.0 +1100
+++ linux/drivers/scsi/NCR5380.c2015-12-22 12:16:35.0 +1100
@@ -1182,6 +1182,10 @@ static int NCR5380_select(struct Scsi_Ho
else
udelay(2);
 
+   /* NCR5380_reselect() clears MODE_REG after a reselection interrupt */
+   if (!(NCR5380_read(MODE_REG) & MR_ARBITRATE))
+   return -1;
+
dprintk(NDEBUG_ARBITRATION, "scsi%d : won arbitration\n", 
instance->host_no);
 
/* 
@@ -1953,12 +1957,14 @@ static void NCR5380_information_transfer
cmd->scsi_done(cmd);
}
 
-   NCR5380_write(SELECT_ENABLE_REG, 
hostdata->id_mask);
/* 
 * Restore phase bits to 0 so an 
interrupted selection, 
 * arbitration can resume.
 */
NCR5380_write(TARGET_COMMAND_REG, 0);
+
+   /* Enable reselect interrupts */
+   NCR5380_write(SELECT_ENABLE_REG, 
hostdata->id_mask);
return;
case MESSAGE_REJECT:
/* Accept message by clearing ACK */
@@ -2144,7 +2150,6 @@ static void NCR5380_reselect(struct Scsi
unsigned char msg[3];
unsigned char *data;
struct scsi_cmnd *tmp = NULL, *prev;
-   int abort = 0;
 
/*
 * Disable arbitration, etc. since the host adapter obviously
@@ -2154,7 +2159,7 @@ static void NCR5380_reselect(struct Scsi
NCR5380_write(MODE_REG, MR_BASE);
 
target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & 
~(hostdata->id_mask);
-   dprintk(NDEBUG_SELECTION, "scsi%d : reselect\n", instance->host_no);
+   dprintk(NDEBUG_RESELECTION, "scsi%d : reselect\n", instance->host_no);
 
/* 
 * At this point, we have detected that our SCSI ID is on the bus,
@@ -2166,77 +2171,85 @@ static void NCR5380_reselect(struct Scsi
 */
 
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
-
-   /* FIXME: timeout too long, must fail to workqueue */   
-   if(NCR5380_poll_politely(instance, STATUS_REG, SR_SEL, 0, 2*HZ)<0)
-   abort = 1;
-   
+   if (NCR5380_poll_politely(instance,
+ STATUS_REG, SR_SEL, 0, 2 * HZ) < 0) {
+   NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
+   return;
+   }
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
 
/*
 * Wait for target to go into MSGIN.
-* FIXME: timeout needed and fail to work queeu
 */
 
if (NCR5380_poll_politely(instance,
- STATUS_REG, SR_REQ, SR_REQ, 2 * HZ) < 0)
-   abort = 1;
+ STATUS_REG, SR_REQ, SR_REQ, 2 * HZ) < 0) {
+   do_abort(instance);
+   return;
+   }
 
len = 1;
data = msg;
phase = PHASE_MSGIN;
NCR5380_transfer_pio(instance, , , );
 
+   if (len) {
+   do_abort(instance);
+   return;
+   }
+
if (!(msg[0] & 0x80)) {
-   printk(KERN_ERR "scsi%d : expecting IDENTIFY message, got ", 
instance->host_no);
+   shost_printk(KERN_ERR, instance, "expecting IDENTIFY message, 
got ");
spi_print_msg(msg);
-   abort = 1;
-   } else {
-   /* Accept message by clearing ACK */
-   NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
-   lun = (msg[0] & 0x07);
-
-   /* 
-* We need to add code for SCSI-II to track which devices have
-* I_T_L_Q nexuses established, and which have simple I_T_L
-* nexuses so we can chose to do additional data transfer.
-*/
+   printk("\n");
+   do_abort(instance);
+

[PATCH v3 43/77] ncr5380: Standardize reselection handling

2015-12-21 Thread Finn Thain
Bring the two NCR5380_reselect() implementations into agreement.

Replace infinite loops in atari_NCR5380.c with timeouts, as per NCR5380.c.

Remove 'abort' flag in NCR5380.c as per atari_NCR5380.c -- if reselection
fails, there may be no MESSAGE IN phase so don't attempt data transfer.

During selection, don't interfere with the chip registers after a
reselection interrupt intervenes.

Clean up some trivial issues with code style, comments and printk.

Signed-off-by: Finn Thain 

---
 drivers/scsi/NCR5380.c   |  115 +++
 drivers/scsi/atari_NCR5380.c |   50 ++
 2 files changed, 93 insertions(+), 72 deletions(-)

Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2015-12-22 12:16:34.0 +1100
+++ linux/drivers/scsi/NCR5380.c2015-12-22 12:16:35.0 +1100
@@ -1182,6 +1182,10 @@ static int NCR5380_select(struct Scsi_Ho
else
udelay(2);
 
+   /* NCR5380_reselect() clears MODE_REG after a reselection interrupt */
+   if (!(NCR5380_read(MODE_REG) & MR_ARBITRATE))
+   return -1;
+
dprintk(NDEBUG_ARBITRATION, "scsi%d : won arbitration\n", 
instance->host_no);
 
/* 
@@ -1953,12 +1957,14 @@ static void NCR5380_information_transfer
cmd->scsi_done(cmd);
}
 
-   NCR5380_write(SELECT_ENABLE_REG, 
hostdata->id_mask);
/* 
 * Restore phase bits to 0 so an 
interrupted selection, 
 * arbitration can resume.
 */
NCR5380_write(TARGET_COMMAND_REG, 0);
+
+   /* Enable reselect interrupts */
+   NCR5380_write(SELECT_ENABLE_REG, 
hostdata->id_mask);
return;
case MESSAGE_REJECT:
/* Accept message by clearing ACK */
@@ -2144,7 +2150,6 @@ static void NCR5380_reselect(struct Scsi
unsigned char msg[3];
unsigned char *data;
struct scsi_cmnd *tmp = NULL, *prev;
-   int abort = 0;
 
/*
 * Disable arbitration, etc. since the host adapter obviously
@@ -2154,7 +2159,7 @@ static void NCR5380_reselect(struct Scsi
NCR5380_write(MODE_REG, MR_BASE);
 
target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & 
~(hostdata->id_mask);
-   dprintk(NDEBUG_SELECTION, "scsi%d : reselect\n", instance->host_no);
+   dprintk(NDEBUG_RESELECTION, "scsi%d : reselect\n", instance->host_no);
 
/* 
 * At this point, we have detected that our SCSI ID is on the bus,
@@ -2166,77 +2171,85 @@ static void NCR5380_reselect(struct Scsi
 */
 
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
-
-   /* FIXME: timeout too long, must fail to workqueue */   
-   if(NCR5380_poll_politely(instance, STATUS_REG, SR_SEL, 0, 2*HZ)<0)
-   abort = 1;
-   
+   if (NCR5380_poll_politely(instance,
+ STATUS_REG, SR_SEL, 0, 2 * HZ) < 0) {
+   NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
+   return;
+   }
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
 
/*
 * Wait for target to go into MSGIN.
-* FIXME: timeout needed and fail to work queeu
 */
 
if (NCR5380_poll_politely(instance,
- STATUS_REG, SR_REQ, SR_REQ, 2 * HZ) < 0)
-   abort = 1;
+ STATUS_REG, SR_REQ, SR_REQ, 2 * HZ) < 0) {
+   do_abort(instance);
+   return;
+   }
 
len = 1;
data = msg;
phase = PHASE_MSGIN;
NCR5380_transfer_pio(instance, , , );
 
+   if (len) {
+   do_abort(instance);
+   return;
+   }
+
if (!(msg[0] & 0x80)) {
-   printk(KERN_ERR "scsi%d : expecting IDENTIFY message, got ", 
instance->host_no);
+   shost_printk(KERN_ERR, instance, "expecting IDENTIFY message, 
got ");
spi_print_msg(msg);
-   abort = 1;
-   } else {
-   /* Accept message by clearing ACK */
-   NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
-   lun = (msg[0] & 0x07);
-
-   /* 
-* We need to add code for SCSI-II to track which devices have
-* I_T_L_Q nexuses established, and which have simple I_T_L
-* nexuses so we can chose to do additional data transfer.
-*/
+   printk("\n");
+   

Re: [PATCH v3 43/77] ncr5380: Standardize reselection handling

2015-12-21 Thread Hannes Reinecke

On 12/22/2015 02:18 AM, Finn Thain wrote:

Bring the two NCR5380_reselect() implementations into agreement.

Replace infinite loops in atari_NCR5380.c with timeouts, as per NCR5380.c.

Remove 'abort' flag in NCR5380.c as per atari_NCR5380.c -- if reselection
fails, there may be no MESSAGE IN phase so don't attempt data transfer.

During selection, don't interfere with the chip registers after a
reselection interrupt intervenes.

Clean up some trivial issues with code style, comments and printk.

Signed-off-by: Finn Thain 

---
  drivers/scsi/NCR5380.c   |  115 
+++
  drivers/scsi/atari_NCR5380.c |   50 ++
  2 files changed, 93 insertions(+), 72 deletions(-)


Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
--
Dr. Hannes Reinecke   zSeries & Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/