@@ -157,7 +157,6 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
157157 }
158158
159159 ncmd -> status = 0 ;
160- ncmd -> message = 0 ;
161160}
162161
163162static inline void advance_sg_buffer (struct NCR5380_cmd * ncmd )
@@ -199,7 +198,6 @@ static inline void set_resid_from_SCp(struct scsi_cmnd *cmd)
199198 * Polls the chip in a reasonably efficient manner waiting for an
200199 * event to occur. After a short quick poll we begin to yield the CPU
201200 * (if possible). In irq contexts the time-out is arbitrarily limited.
202- * Callers may hold locks as long as they are held in irq mode.
203201 *
204202 * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT.
205203 */
@@ -1228,24 +1226,15 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
12281226 return ret ;
12291227}
12301228
1231- /*
1232- * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance,
1233- * unsigned char *phase, int *count, unsigned char **data)
1234- *
1235- * Purpose : transfers data in given phase using polled I/O
1236- *
1237- * Inputs : instance - instance of driver, *phase - pointer to
1238- * what phase is expected, *count - pointer to number of
1239- * bytes to transfer, **data - pointer to data pointer,
1240- * can_sleep - 1 or 0 when sleeping is permitted or not, respectively.
1241- *
1242- * Returns : -1 when different phase is entered without transferring
1243- * maximum number of bytes, 0 if all bytes are transferred or exit
1244- * is in same phase.
1245- *
1246- * Also, *phase, *count, *data are modified in place.
1229+ /**
1230+ * NCR5380_transfer_pio() - transfers data in given phase using polled I/O
1231+ * @instance: instance of driver
1232+ * @phase: pointer to what phase is expected
1233+ * @count: pointer to number of bytes to transfer
1234+ * @data: pointer to data pointer
1235+ * @can_sleep: 1 or 0 when sleeping is permitted or not, respectively
12471236 *
1248- * XXX Note : handling for bus free may be useful .
1237+ * Returns: void. *phase, *count, *data are modified in place .
12491238 */
12501239
12511240/*
@@ -1254,9 +1243,9 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
12541243 * counts, we will always do a pseudo DMA or DMA transfer.
12551244 */
12561245
1257- static int NCR5380_transfer_pio (struct Scsi_Host * instance ,
1258- unsigned char * phase , int * count ,
1259- unsigned char * * data , unsigned int can_sleep )
1246+ static void NCR5380_transfer_pio (struct Scsi_Host * instance ,
1247+ unsigned char * phase , int * count ,
1248+ unsigned char * * data , unsigned int can_sleep )
12601249{
12611250 struct NCR5380_hostdata * hostdata = shost_priv (instance );
12621251 unsigned char p = * phase , tmp ;
@@ -1277,8 +1266,8 @@ static int NCR5380_transfer_pio(struct Scsi_Host *instance,
12771266 * valid
12781267 */
12791268
1280- if (NCR5380_poll_politely (hostdata , STATUS_REG , SR_REQ , SR_REQ ,
1281- HZ * can_sleep ) < 0 )
1269+ if (NCR5380_poll_politely (hostdata , STATUS_REG , SR_REQ | SR_BSY ,
1270+ SR_REQ | SR_BSY , HZ * can_sleep ) < 0 )
12821271 break ;
12831272
12841273 dsprintk (NDEBUG_HANDSHAKE , instance , "REQ asserted\n" );
@@ -1329,17 +1318,19 @@ static int NCR5380_transfer_pio(struct Scsi_Host *instance,
13291318
13301319 dsprintk (NDEBUG_HANDSHAKE , instance , "REQ negated, handshake complete\n" );
13311320
1332- /*
1333- * We have several special cases to consider during REQ/ACK handshaking :
1334- * 1. We were in MSGOUT phase, and we are on the last byte of the
1335- * message. ATN must be dropped as ACK is dropped.
1336- *
1337- * 2. We are in a MSGIN phase, and we are on the last byte of the
1338- * message. We must exit with ACK asserted, so that the calling
1339- * code may raise ATN before dropping ACK to reject the message.
1340- *
1341- * 3. ACK and ATN are clear and the target may proceed as normal.
1342- */
1321+ /*
1322+ * We have several special cases to consider during REQ/ACK
1323+ * handshaking:
1324+ *
1325+ * 1. We were in MSGOUT phase, and we are on the last byte of
1326+ * the message. ATN must be dropped as ACK is dropped.
1327+ *
1328+ * 2. We are in MSGIN phase, and we are on the last byte of the
1329+ * message. We must exit with ACK asserted, so that the calling
1330+ * code may raise ATN before dropping ACK to reject the message.
1331+ *
1332+ * 3. ACK and ATN are clear & the target may proceed as normal.
1333+ */
13431334 if (!(p == PHASE_MSGIN && c == 1 )) {
13441335 if (p == PHASE_MSGOUT && c > 1 )
13451336 NCR5380_write (INITIATOR_COMMAND_REG , ICR_BASE | ICR_ASSERT_ATN );
@@ -1361,11 +1352,6 @@ static int NCR5380_transfer_pio(struct Scsi_Host *instance,
13611352 * phase = tmp & PHASE_MASK ;
13621353 else
13631354 * phase = PHASE_UNKNOWN ;
1364-
1365- if (!c || (* phase == p ))
1366- return 0 ;
1367- else
1368- return -1 ;
13691355}
13701356
13711357/**
@@ -1485,6 +1471,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
14851471 unsigned char * * data )
14861472{
14871473 struct NCR5380_hostdata * hostdata = shost_priv (instance );
1474+ struct NCR5380_cmd * ncmd = NCR5380_to_ncmd (hostdata -> connected );
14881475 int c = * count ;
14891476 unsigned char p = * phase ;
14901477 unsigned char * d = * data ;
@@ -1496,7 +1483,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
14961483 return -1 ;
14971484 }
14981485
1499- NCR5380_to_ncmd ( hostdata -> connected ) -> phase = p ;
1486+ ncmd -> phase = p ;
15001487
15011488 if (p & SR_IO ) {
15021489 if (hostdata -> read_overruns )
@@ -1574,79 +1561,80 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
15741561 /* The result is zero iff pseudo DMA send/receive was completed. */
15751562 hostdata -> dma_len = c ;
15761563
1577- /*
1578- * A note regarding the DMA errata workarounds for early NMOS silicon.
1579- *
1580- * For DMA sends, we want to wait until the last byte has been
1581- * transferred out over the bus before we turn off DMA mode. Alas, there
1582- * seems to be no terribly good way of doing this on a 5380 under all
1583- * conditions. For non-scatter-gather operations, we can wait until REQ
1584- * and ACK both go false, or until a phase mismatch occurs. Gather-sends
1585- * are nastier, since the device will be expecting more data than we
1586- * are prepared to send it, and REQ will remain asserted. On a 53C8[01] we
1587- * could test Last Byte Sent to assure transfer (I imagine this is precisely
1588- * why this signal was added to the newer chips) but on the older 538[01]
1589- * this signal does not exist. The workaround for this lack is a watchdog;
1590- * we bail out of the wait-loop after a modest amount of wait-time if
1591- * the usual exit conditions are not met. Not a terribly clean or
1592- * correct solution :-%
1593- *
1594- * DMA receive is equally tricky due to a nasty characteristic of the NCR5380.
1595- * If the chip is in DMA receive mode, it will respond to a target's
1596- * REQ by latching the SCSI data into the INPUT DATA register and asserting
1597- * ACK, even if it has _already_ been notified by the DMA controller that
1598- * the current DMA transfer has completed! If the NCR5380 is then taken
1599- * out of DMA mode, this already-acknowledged byte is lost. This is
1600- * not a problem for "one DMA transfer per READ command", because
1601- * the situation will never arise... either all of the data is DMA'ed
1602- * properly, or the target switches to MESSAGE IN phase to signal a
1603- * disconnection (either operation bringing the DMA to a clean halt).
1604- * However, in order to handle scatter-receive, we must work around the
1605- * problem. The chosen fix is to DMA fewer bytes, then check for the
1606- * condition before taking the NCR5380 out of DMA mode. One or two extra
1607- * bytes are transferred via PIO as necessary to fill out the original
1608- * request.
1609- */
1610-
1611- if (hostdata -> flags & FLAG_DMA_FIXUP ) {
1612- if (p & SR_IO ) {
1613- /*
1614- * The workaround was to transfer fewer bytes than we
1615- * intended to with the pseudo-DMA read function, wait for
1616- * the chip to latch the last byte, read it, and then disable
1617- * pseudo-DMA mode.
1618- *
1619- * After REQ is asserted, the NCR5380 asserts DRQ and ACK.
1620- * REQ is deasserted when ACK is asserted, and not reasserted
1621- * until ACK goes false. Since the NCR5380 won't lower ACK
1622- * until DACK is asserted, which won't happen unless we twiddle
1623- * the DMA port or we take the NCR5380 out of DMA mode, we
1624- * can guarantee that we won't handshake another extra
1625- * byte.
1626- */
1564+ /*
1565+ * A note regarding the DMA errata workarounds for early NMOS silicon.
1566+ *
1567+ * For DMA sends, we want to wait until the last byte has been
1568+ * transferred out over the bus before we turn off DMA mode. Alas, there
1569+ * seems to be no terribly good way of doing this on a 5380 under all
1570+ * conditions. For non-scatter-gather operations, we can wait until REQ
1571+ * and ACK both go false, or until a phase mismatch occurs. Gather-sends
1572+ * are nastier, since the device will be expecting more data than we
1573+ * are prepared to send it, and REQ will remain asserted. On a 53C8[01]
1574+ * we could test Last Byte Sent to assure transfer (I imagine this is
1575+ * precisely why this signal was added to the newer chips) but on the
1576+ * older 538[01] this signal does not exist. The workaround for this
1577+ * lack is a watchdog; we bail out of the wait-loop after a modest
1578+ * amount of wait-time if the usual exit conditions are not met.
1579+ * Not a terribly clean or correct solution :-%
1580+ *
1581+ * DMA receive is equally tricky due to a nasty characteristic of the
1582+ * NCR5380. If the chip is in DMA receive mode, it will respond to a
1583+ * target's REQ by latching the SCSI data into the INPUT DATA register
1584+ * and asserting ACK, even if it has _already_ been notified by the
1585+ * DMA controller that the current DMA transfer has completed! If the
1586+ * NCR5380 is then taken out of DMA mode, this already-acknowledged
1587+ * byte is lost.
1588+ *
1589+ * This is not a problem for "one DMA transfer per READ
1590+ * command", because the situation will never arise... either all of
1591+ * the data is DMA'ed properly, or the target switches to MESSAGE IN
1592+ * phase to signal a disconnection (either operation bringing the DMA
1593+ * to a clean halt). However, in order to handle scatter-receive, we
1594+ * must work around the problem. The chosen fix is to DMA fewer bytes,
1595+ * then check for the condition before taking the NCR5380 out of DMA
1596+ * mode. One or two extra bytes are transferred via PIO as necessary
1597+ * to fill out the original request.
1598+ */
16271599
1628- if (NCR5380_poll_politely (hostdata , BUS_AND_STATUS_REG ,
1629- BASR_DRQ , BASR_DRQ , 0 ) < 0 ) {
1630- result = -1 ;
1631- shost_printk (KERN_ERR , instance , "PDMA read: DRQ timeout\n" );
1632- }
1633- if (NCR5380_poll_politely (hostdata , STATUS_REG ,
1634- SR_REQ , 0 , 0 ) < 0 ) {
1635- result = -1 ;
1636- shost_printk (KERN_ERR , instance , "PDMA read: !REQ timeout\n" );
1637- }
1638- d [* count - 1 ] = NCR5380_read (INPUT_DATA_REG );
1639- } else {
1640- /*
1641- * Wait for the last byte to be sent. If REQ is being asserted for
1642- * the byte we're interested, we'll ACK it and it will go false.
1643- */
1644- if (NCR5380_poll_politely2 (hostdata ,
1645- BUS_AND_STATUS_REG , BASR_DRQ , BASR_DRQ ,
1646- BUS_AND_STATUS_REG , BASR_PHASE_MATCH , 0 , 0 ) < 0 ) {
1647- result = -1 ;
1648- shost_printk (KERN_ERR , instance , "PDMA write: DRQ and phase timeout\n" );
1600+ if ((hostdata -> flags & FLAG_DMA_FIXUP ) &&
1601+ (NCR5380_read (BUS_AND_STATUS_REG ) & BASR_PHASE_MATCH )) {
1602+ /*
1603+ * The workaround was to transfer fewer bytes than we
1604+ * intended to with the pseudo-DMA receive function, wait for
1605+ * the chip to latch the last byte, read it, and then disable
1606+ * DMA mode.
1607+ *
1608+ * After REQ is asserted, the NCR5380 asserts DRQ and ACK.
1609+ * REQ is deasserted when ACK is asserted, and not reasserted
1610+ * until ACK goes false. Since the NCR5380 won't lower ACK
1611+ * until DACK is asserted, which won't happen unless we twiddle
1612+ * the DMA port or we take the NCR5380 out of DMA mode, we
1613+ * can guarantee that we won't handshake another extra
1614+ * byte.
1615+ *
1616+ * If sending, wait for the last byte to be sent. If REQ is
1617+ * being asserted for the byte we're interested, we'll ACK it
1618+ * and it will go false.
1619+ */
1620+ if (!NCR5380_poll_politely (hostdata , BUS_AND_STATUS_REG ,
1621+ BASR_DRQ , BASR_DRQ , 0 )) {
1622+ if ((p & SR_IO ) &&
1623+ (NCR5380_read (BUS_AND_STATUS_REG ) & BASR_PHASE_MATCH )) {
1624+ if (!NCR5380_poll_politely (hostdata , STATUS_REG ,
1625+ SR_REQ , 0 , 0 )) {
1626+ d [c ] = NCR5380_read (INPUT_DATA_REG );
1627+ -- ncmd -> this_residual ;
1628+ } else {
1629+ result = -1 ;
1630+ scmd_printk (KERN_ERR , hostdata -> connected ,
1631+ "PDMA fixup: !REQ timeout\n" );
1632+ }
16491633 }
1634+ } else if (NCR5380_read (BUS_AND_STATUS_REG ) & BASR_PHASE_MATCH ) {
1635+ result = -1 ;
1636+ scmd_printk (KERN_ERR , hostdata -> connected ,
1637+ "PDMA fixup: DRQ timeout\n" );
16501638 }
16511639 }
16521640
@@ -1666,9 +1654,6 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
16661654 * Side effects : SCSI things happen, the disconnected queue will be
16671655 * modified if a command disconnects, *instance->connected will
16681656 * change.
1669- *
1670- * XXX Note : we need to watch for bus free or a reset condition here
1671- * to recover from an unexpected bus free condition.
16721657 */
16731658
16741659static void NCR5380_information_transfer (struct Scsi_Host * instance )
@@ -1807,9 +1792,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
18071792 return ;
18081793 case PHASE_MSGIN :
18091794 len = 1 ;
1795+ tmp = 0xff ;
18101796 data = & tmp ;
18111797 NCR5380_transfer_pio (instance , & phase , & len , & data , 0 );
1812- ncmd -> message = tmp ;
1798+ if (tmp == 0xff )
1799+ break ;
18131800
18141801 switch (tmp ) {
18151802 case ABORT :
@@ -1996,6 +1983,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
19961983 break ;
19971984 case PHASE_STATIN :
19981985 len = 1 ;
1986+ tmp = ncmd -> status ;
19991987 data = & tmp ;
20001988 NCR5380_transfer_pio (instance , & phase , & len , & data , 0 );
20011989 ncmd -> status = tmp ;
@@ -2005,9 +1993,20 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
20051993 NCR5380_dprint (NDEBUG_ANY , instance );
20061994 } /* switch(phase) */
20071995 } else {
1996+ int err ;
1997+
20081998 spin_unlock_irq (& hostdata -> lock );
2009- NCR5380_poll_politely (hostdata , STATUS_REG , SR_REQ , SR_REQ , HZ );
1999+ err = NCR5380_poll_politely (hostdata , STATUS_REG ,
2000+ SR_REQ , SR_REQ , HZ );
20102001 spin_lock_irq (& hostdata -> lock );
2002+
2003+ if (err < 0 && hostdata -> connected &&
2004+ !(NCR5380_read (STATUS_REG ) & SR_BSY )) {
2005+ scmd_printk (KERN_ERR , hostdata -> connected ,
2006+ "BSY signal lost\n" );
2007+ do_reset (instance );
2008+ bus_reset_cleanup (instance );
2009+ }
20112010 }
20122011 }
20132012}
0 commit comments