@@ -157,7 +157,6 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
157
157
}
158
158
159
159
ncmd -> status = 0 ;
160
- ncmd -> message = 0 ;
161
160
}
162
161
163
162
static inline void advance_sg_buffer (struct NCR5380_cmd * ncmd )
@@ -199,7 +198,6 @@ static inline void set_resid_from_SCp(struct scsi_cmnd *cmd)
199
198
* Polls the chip in a reasonably efficient manner waiting for an
200
199
* event to occur. After a short quick poll we begin to yield the CPU
201
200
* (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.
203
201
*
204
202
* Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT.
205
203
*/
@@ -1228,24 +1226,15 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
1228
1226
return ret ;
1229
1227
}
1230
1228
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
1247
1236
*
1248
- * XXX Note : handling for bus free may be useful .
1237
+ * Returns: void. *phase, *count, *data are modified in place .
1249
1238
*/
1250
1239
1251
1240
/*
@@ -1254,9 +1243,9 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
1254
1243
* counts, we will always do a pseudo DMA or DMA transfer.
1255
1244
*/
1256
1245
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 )
1260
1249
{
1261
1250
struct NCR5380_hostdata * hostdata = shost_priv (instance );
1262
1251
unsigned char p = * phase , tmp ;
@@ -1277,8 +1266,8 @@ static int NCR5380_transfer_pio(struct Scsi_Host *instance,
1277
1266
* valid
1278
1267
*/
1279
1268
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 )
1282
1271
break ;
1283
1272
1284
1273
dsprintk (NDEBUG_HANDSHAKE , instance , "REQ asserted\n" );
@@ -1329,17 +1318,19 @@ static int NCR5380_transfer_pio(struct Scsi_Host *instance,
1329
1318
1330
1319
dsprintk (NDEBUG_HANDSHAKE , instance , "REQ negated, handshake complete\n" );
1331
1320
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
+ */
1343
1334
if (!(p == PHASE_MSGIN && c == 1 )) {
1344
1335
if (p == PHASE_MSGOUT && c > 1 )
1345
1336
NCR5380_write (INITIATOR_COMMAND_REG , ICR_BASE | ICR_ASSERT_ATN );
@@ -1361,11 +1352,6 @@ static int NCR5380_transfer_pio(struct Scsi_Host *instance,
1361
1352
* phase = tmp & PHASE_MASK ;
1362
1353
else
1363
1354
* phase = PHASE_UNKNOWN ;
1364
-
1365
- if (!c || (* phase == p ))
1366
- return 0 ;
1367
- else
1368
- return -1 ;
1369
1355
}
1370
1356
1371
1357
/**
@@ -1485,6 +1471,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1485
1471
unsigned char * * data )
1486
1472
{
1487
1473
struct NCR5380_hostdata * hostdata = shost_priv (instance );
1474
+ struct NCR5380_cmd * ncmd = NCR5380_to_ncmd (hostdata -> connected );
1488
1475
int c = * count ;
1489
1476
unsigned char p = * phase ;
1490
1477
unsigned char * d = * data ;
@@ -1496,7 +1483,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1496
1483
return -1 ;
1497
1484
}
1498
1485
1499
- NCR5380_to_ncmd ( hostdata -> connected ) -> phase = p ;
1486
+ ncmd -> phase = p ;
1500
1487
1501
1488
if (p & SR_IO ) {
1502
1489
if (hostdata -> read_overruns )
@@ -1574,79 +1561,80 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1574
1561
/* The result is zero iff pseudo DMA send/receive was completed. */
1575
1562
hostdata -> dma_len = c ;
1576
1563
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
+ */
1627
1599
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
+ }
1649
1633
}
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" );
1650
1638
}
1651
1639
}
1652
1640
@@ -1666,9 +1654,6 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1666
1654
* Side effects : SCSI things happen, the disconnected queue will be
1667
1655
* modified if a command disconnects, *instance->connected will
1668
1656
* 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.
1672
1657
*/
1673
1658
1674
1659
static void NCR5380_information_transfer (struct Scsi_Host * instance )
@@ -1807,9 +1792,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
1807
1792
return ;
1808
1793
case PHASE_MSGIN :
1809
1794
len = 1 ;
1795
+ tmp = 0xff ;
1810
1796
data = & tmp ;
1811
1797
NCR5380_transfer_pio (instance , & phase , & len , & data , 0 );
1812
- ncmd -> message = tmp ;
1798
+ if (tmp == 0xff )
1799
+ break ;
1813
1800
1814
1801
switch (tmp ) {
1815
1802
case ABORT :
@@ -1996,6 +1983,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
1996
1983
break ;
1997
1984
case PHASE_STATIN :
1998
1985
len = 1 ;
1986
+ tmp = ncmd -> status ;
1999
1987
data = & tmp ;
2000
1988
NCR5380_transfer_pio (instance , & phase , & len , & data , 0 );
2001
1989
ncmd -> status = tmp ;
@@ -2005,9 +1993,20 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2005
1993
NCR5380_dprint (NDEBUG_ANY , instance );
2006
1994
} /* switch(phase) */
2007
1995
} else {
1996
+ int err ;
1997
+
2008
1998
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 );
2010
2001
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
+ }
2011
2010
}
2012
2011
}
2013
2012
}
0 commit comments