Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge patch series "NCR5380: Bug fixes and other improvements"

Finn Thain <fthain@linux-m68k.org> says:

This series begins with some work on the mac_scsi driver to improve
compatibility with SCSI2SD v5 devices. Better error handling is needed
there because the PDMA hardware does not tolerate the write latency
spikes which SD cards can produce.

A bug is fixed in the 5380 core driver so that scatter/gather can be
enabled in mac_scsi.

Several patches at the end of this series improve robustness and
correctness in the core driver.

This series has been tested on a variety of mac_scsi hosts. A variety
of SCSI targets was also tested, including Quantum HDD, Fujitsu HDD,
Iomega FDD, Ricoh CD-RW, Matsushita CD-ROM, SCSI2SD and BlueSCSI.

Link: https://lore.kernel.org/r/cover.1723001788.git.fthain@linux-m68k.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

+217 -212
+116 -117
drivers/scsi/NCR5380.c
··· 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) ··· 198 199 * Polls the chip in a reasonably efficient manner waiting for an 199 200 * event to occur. After a short quick poll we begin to yield the CPU 200 201 * (if possible). In irq contexts the time-out is arbitrarily limited. 201 - * Callers may hold locks as long as they are held in irq mode. 202 202 * 203 203 * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT. 204 204 */ ··· 1226 1228 return ret; 1227 1229 } 1228 1230 1229 - /* 1230 - * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance, 1231 - * unsigned char *phase, int *count, unsigned char **data) 1231 + /** 1232 + * NCR5380_transfer_pio() - transfers data in given phase using polled I/O 1233 + * @instance: instance of driver 1234 + * @phase: pointer to what phase is expected 1235 + * @count: pointer to number of bytes to transfer 1236 + * @data: pointer to data pointer 1237 + * @can_sleep: 1 or 0 when sleeping is permitted or not, respectively 1232 1238 * 1233 - * Purpose : transfers data in given phase using polled I/O 1234 - * 1235 - * Inputs : instance - instance of driver, *phase - pointer to 1236 - * what phase is expected, *count - pointer to number of 1237 - * bytes to transfer, **data - pointer to data pointer, 1238 - * can_sleep - 1 or 0 when sleeping is permitted or not, respectively. 1239 - * 1240 - * Returns : -1 when different phase is entered without transferring 1241 - * maximum number of bytes, 0 if all bytes are transferred or exit 1242 - * is in same phase. 1243 - * 1244 - * Also, *phase, *count, *data are modified in place. 1245 - * 1246 - * XXX Note : handling for bus free may be useful. 1239 + * Returns: void. *phase, *count, *data are modified in place. 1247 1240 */ 1248 1241 1249 1242 /* ··· 1243 1254 * counts, we will always do a pseudo DMA or DMA transfer. 1244 1255 */ 1245 1256 1246 - static int NCR5380_transfer_pio(struct Scsi_Host *instance, 1247 - unsigned char *phase, int *count, 1248 - unsigned char **data, unsigned int can_sleep) 1257 + static void NCR5380_transfer_pio(struct Scsi_Host *instance, 1258 + unsigned char *phase, int *count, 1259 + unsigned char **data, unsigned int can_sleep) 1249 1260 { 1250 1261 struct NCR5380_hostdata *hostdata = shost_priv(instance); 1251 1262 unsigned char p = *phase, tmp; ··· 1266 1277 * valid 1267 1278 */ 1268 1279 1269 - if (NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, 1270 - HZ * can_sleep) < 0) 1280 + if (NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ | SR_BSY, 1281 + SR_REQ | SR_BSY, HZ * can_sleep) < 0) 1271 1282 break; 1272 1283 1273 1284 dsprintk(NDEBUG_HANDSHAKE, instance, "REQ asserted\n"); ··· 1318 1329 1319 1330 dsprintk(NDEBUG_HANDSHAKE, instance, "REQ negated, handshake complete\n"); 1320 1331 1321 - /* 1322 - * We have several special cases to consider during REQ/ACK handshaking : 1323 - * 1. We were in MSGOUT phase, and we are on the last byte of the 1324 - * message. ATN must be dropped as ACK is dropped. 1325 - * 1326 - * 2. We are in a MSGIN phase, and we are on the last byte of the 1327 - * message. We must exit with ACK asserted, so that the calling 1328 - * code may raise ATN before dropping ACK to reject the message. 1329 - * 1330 - * 3. ACK and ATN are clear and the target may proceed as normal. 1331 - */ 1332 + /* 1333 + * We have several special cases to consider during REQ/ACK 1334 + * handshaking: 1335 + * 1336 + * 1. We were in MSGOUT phase, and we are on the last byte of 1337 + * the message. ATN must be dropped as ACK is dropped. 1338 + * 1339 + * 2. We are in MSGIN phase, and we are on the last byte of the 1340 + * message. We must exit with ACK asserted, so that the calling 1341 + * code may raise ATN before dropping ACK to reject the message. 1342 + * 1343 + * 3. ACK and ATN are clear & the target may proceed as normal. 1344 + */ 1332 1345 if (!(p == PHASE_MSGIN && c == 1)) { 1333 1346 if (p == PHASE_MSGOUT && c > 1) 1334 1347 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); ··· 1352 1361 *phase = tmp & PHASE_MASK; 1353 1362 else 1354 1363 *phase = PHASE_UNKNOWN; 1355 - 1356 - if (!c || (*phase == p)) 1357 - return 0; 1358 - else 1359 - return -1; 1360 1364 } 1361 1365 1362 1366 /** ··· 1471 1485 unsigned char **data) 1472 1486 { 1473 1487 struct NCR5380_hostdata *hostdata = shost_priv(instance); 1488 + struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(hostdata->connected); 1474 1489 int c = *count; 1475 1490 unsigned char p = *phase; 1476 1491 unsigned char *d = *data; ··· 1483 1496 return -1; 1484 1497 } 1485 1498 1486 - NCR5380_to_ncmd(hostdata->connected)->phase = p; 1499 + ncmd->phase = p; 1487 1500 1488 1501 if (p & SR_IO) { 1489 1502 if (hostdata->read_overruns) ··· 1561 1574 /* The result is zero iff pseudo DMA send/receive was completed. */ 1562 1575 hostdata->dma_len = c; 1563 1576 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] we 1574 - * could test Last Byte Sent to assure transfer (I imagine this is precisely 1575 - * why this signal was added to the newer chips) but on the older 538[01] 1576 - * this signal does not exist. The workaround for this lack is a watchdog; 1577 - * we bail out of the wait-loop after a modest amount of wait-time if 1578 - * the usual exit conditions are not met. Not a terribly clean or 1579 - * correct solution :-% 1580 - * 1581 - * DMA receive is equally tricky due to a nasty characteristic of the NCR5380. 1582 - * If the chip is in DMA receive mode, it will respond to a target's 1583 - * REQ by latching the SCSI data into the INPUT DATA register and asserting 1584 - * ACK, even if it has _already_ been notified by the DMA controller that 1585 - * the current DMA transfer has completed! If the NCR5380 is then taken 1586 - * out of DMA mode, this already-acknowledged byte is lost. This is 1587 - * not a problem for "one DMA transfer per READ command", because 1588 - * the situation will never arise... either all of the data is DMA'ed 1589 - * properly, or the target switches to MESSAGE IN phase to signal a 1590 - * disconnection (either operation bringing the DMA to a clean halt). 1591 - * However, in order to handle scatter-receive, we must work around the 1592 - * problem. The chosen fix is to DMA fewer bytes, then check for the 1593 - * condition before taking the NCR5380 out of DMA mode. One or two extra 1594 - * bytes are transferred via PIO as necessary to fill out the original 1595 - * request. 1596 - */ 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] 1587 + * we could test Last Byte Sent to assure transfer (I imagine this is 1588 + * precisely why this signal was added to the newer chips) but on the 1589 + * older 538[01] this signal does not exist. The workaround for this 1590 + * lack is a watchdog; we bail out of the wait-loop after a modest 1591 + * amount of wait-time if the usual exit conditions are not met. 1592 + * Not a terribly clean or correct solution :-% 1593 + * 1594 + * DMA receive is equally tricky due to a nasty characteristic of the 1595 + * NCR5380. If the chip is in DMA receive mode, it will respond to a 1596 + * target's REQ by latching the SCSI data into the INPUT DATA register 1597 + * and asserting ACK, even if it has _already_ been notified by the 1598 + * DMA controller that the current DMA transfer has completed! If the 1599 + * NCR5380 is then taken out of DMA mode, this already-acknowledged 1600 + * byte is lost. 1601 + * 1602 + * This is not a problem for "one DMA transfer per READ 1603 + * command", because the situation will never arise... either all of 1604 + * the data is DMA'ed properly, or the target switches to MESSAGE IN 1605 + * phase to signal a disconnection (either operation bringing the DMA 1606 + * to a clean halt). However, in order to handle scatter-receive, we 1607 + * must work around the problem. The chosen fix is to DMA fewer bytes, 1608 + * then check for the condition before taking the NCR5380 out of DMA 1609 + * mode. One or two extra bytes are transferred via PIO as necessary 1610 + * to fill out the original request. 1611 + */ 1597 1612 1598 - if (hostdata->flags & FLAG_DMA_FIXUP) { 1599 - if (p & SR_IO) { 1600 - /* 1601 - * The workaround was to transfer fewer bytes than we 1602 - * intended to with the pseudo-DMA read function, wait for 1603 - * the chip to latch the last byte, read it, and then disable 1604 - * pseudo-DMA mode. 1605 - * 1606 - * After REQ is asserted, the NCR5380 asserts DRQ and ACK. 1607 - * REQ is deasserted when ACK is asserted, and not reasserted 1608 - * until ACK goes false. Since the NCR5380 won't lower ACK 1609 - * until DACK is asserted, which won't happen unless we twiddle 1610 - * the DMA port or we take the NCR5380 out of DMA mode, we 1611 - * can guarantee that we won't handshake another extra 1612 - * byte. 1613 - */ 1614 - 1615 - if (NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG, 1616 - BASR_DRQ, BASR_DRQ, 0) < 0) { 1617 - result = -1; 1618 - shost_printk(KERN_ERR, instance, "PDMA read: DRQ timeout\n"); 1613 + if ((hostdata->flags & FLAG_DMA_FIXUP) && 1614 + (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) { 1615 + /* 1616 + * The workaround was to transfer fewer bytes than we 1617 + * intended to with the pseudo-DMA receive function, wait for 1618 + * the chip to latch the last byte, read it, and then disable 1619 + * DMA mode. 1620 + * 1621 + * After REQ is asserted, the NCR5380 asserts DRQ and ACK. 1622 + * REQ is deasserted when ACK is asserted, and not reasserted 1623 + * until ACK goes false. Since the NCR5380 won't lower ACK 1624 + * until DACK is asserted, which won't happen unless we twiddle 1625 + * the DMA port or we take the NCR5380 out of DMA mode, we 1626 + * can guarantee that we won't handshake another extra 1627 + * byte. 1628 + * 1629 + * If sending, wait for the last byte to be sent. If REQ is 1630 + * being asserted for the byte we're interested, we'll ACK it 1631 + * and it will go false. 1632 + */ 1633 + if (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG, 1634 + BASR_DRQ, BASR_DRQ, 0)) { 1635 + if ((p & SR_IO) && 1636 + (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) { 1637 + if (!NCR5380_poll_politely(hostdata, STATUS_REG, 1638 + SR_REQ, 0, 0)) { 1639 + d[c] = NCR5380_read(INPUT_DATA_REG); 1640 + --ncmd->this_residual; 1641 + } else { 1642 + result = -1; 1643 + scmd_printk(KERN_ERR, hostdata->connected, 1644 + "PDMA fixup: !REQ timeout\n"); 1645 + } 1619 1646 } 1620 - if (NCR5380_poll_politely(hostdata, STATUS_REG, 1621 - SR_REQ, 0, 0) < 0) { 1622 - result = -1; 1623 - shost_printk(KERN_ERR, instance, "PDMA read: !REQ timeout\n"); 1624 - } 1625 - d[*count - 1] = NCR5380_read(INPUT_DATA_REG); 1626 - } else { 1627 - /* 1628 - * Wait for the last byte to be sent. If REQ is being asserted for 1629 - * the byte we're interested, we'll ACK it and it will go false. 1630 - */ 1631 - if (NCR5380_poll_politely2(hostdata, 1632 - BUS_AND_STATUS_REG, BASR_DRQ, BASR_DRQ, 1633 - BUS_AND_STATUS_REG, BASR_PHASE_MATCH, 0, 0) < 0) { 1634 - result = -1; 1635 - shost_printk(KERN_ERR, instance, "PDMA write: DRQ and phase timeout\n"); 1636 - } 1647 + } else if (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH) { 1648 + result = -1; 1649 + scmd_printk(KERN_ERR, hostdata->connected, 1650 + "PDMA fixup: DRQ timeout\n"); 1637 1651 } 1638 1652 } 1639 1653 ··· 1654 1666 * Side effects : SCSI things happen, the disconnected queue will be 1655 1667 * modified if a command disconnects, *instance->connected will 1656 1668 * change. 1657 - * 1658 - * XXX Note : we need to watch for bus free or a reset condition here 1659 - * to recover from an unexpected bus free condition. 1660 1669 */ 1661 1670 1662 1671 static void NCR5380_information_transfer(struct Scsi_Host *instance) ··· 1792 1807 return; 1793 1808 case PHASE_MSGIN: 1794 1809 len = 1; 1810 + tmp = 0xff; 1795 1811 data = &tmp; 1796 1812 NCR5380_transfer_pio(instance, &phase, &len, &data, 0); 1797 - ncmd->message = tmp; 1813 + if (tmp == 0xff) 1814 + break; 1798 1815 1799 1816 switch (tmp) { 1800 1817 case ABORT: ··· 1983 1996 break; 1984 1997 case PHASE_STATIN: 1985 1998 len = 1; 1999 + tmp = ncmd->status; 1986 2000 data = &tmp; 1987 2001 NCR5380_transfer_pio(instance, &phase, &len, &data, 0); 1988 2002 ncmd->status = tmp; ··· 1993 2005 NCR5380_dprint(NDEBUG_ANY, instance); 1994 2006 } /* switch(phase) */ 1995 2007 } else { 2008 + int err; 2009 + 1996 2010 spin_unlock_irq(&hostdata->lock); 1997 - NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, HZ); 2011 + err = NCR5380_poll_politely(hostdata, STATUS_REG, 2012 + SR_REQ, SR_REQ, HZ); 1998 2013 spin_lock_irq(&hostdata->lock); 2014 + 2015 + if (err < 0 && hostdata->connected && 2016 + !(NCR5380_read(STATUS_REG) & SR_BSY)) { 2017 + scmd_printk(KERN_ERR, hostdata->connected, 2018 + "BSY signal lost\n"); 2019 + do_reset(instance); 2020 + bus_reset_cleanup(instance); 2021 + } 1999 2022 } 2000 2023 } 2001 2024 }
+10 -10
drivers/scsi/NCR5380.h
··· 3 3 * NCR 5380 defines 4 4 * 5 5 * Copyright 1993, Drew Eckhardt 6 - * Visionary Computing 7 - * (Unix consulting and custom programming) 8 - * drew@colorado.edu 9 - * +1 (303) 666-5836 6 + * Visionary Computing 7 + * (Unix consulting and custom programming) 8 + * drew@colorado.edu 9 + * +1 (303) 666-5836 10 10 * 11 11 * For more information, please consult 12 12 * ··· 78 78 #define ICR_DIFF_ENABLE 0x20 /* wo Set to enable diff. drivers */ 79 79 #define ICR_ASSERT_ACK 0x10 /* rw ini Set to assert ACK */ 80 80 #define ICR_ASSERT_BSY 0x08 /* rw Set to assert BSY */ 81 - #define ICR_ASSERT_SEL 0x04 /* rw Set to assert SEL */ 81 + #define ICR_ASSERT_SEL 0x04 /* rw Set to assert SEL */ 82 82 #define ICR_ASSERT_ATN 0x02 /* rw Set to assert ATN */ 83 83 #define ICR_ASSERT_DATA 0x01 /* rw SCSI_DATA_REG is asserted */ 84 84 ··· 135 135 #define BASR_IRQ 0x10 /* ro mirror of IRQ pin */ 136 136 #define BASR_PHASE_MATCH 0x08 /* ro Set when MSG CD IO match TCR */ 137 137 #define BASR_BUSY_ERROR 0x04 /* ro Unexpected change to inactive state */ 138 - #define BASR_ATN 0x02 /* ro BUS status */ 138 + #define BASR_ATN 0x02 /* ro BUS status */ 139 139 #define BASR_ACK 0x01 /* ro BUS status */ 140 140 141 141 /* Write any value to this register to start a DMA send */ ··· 170 170 #define CSR_BASE CSR_53C80_INTR 171 171 172 172 /* Note : PHASE_* macros are based on the values of the STATUS register */ 173 - #define PHASE_MASK (SR_MSG | SR_CD | SR_IO) 173 + #define PHASE_MASK (SR_MSG | SR_CD | SR_IO) 174 174 175 175 #define PHASE_DATAOUT 0 176 176 #define PHASE_DATAIN SR_IO ··· 231 231 int this_residual; 232 232 struct scatterlist *buffer; 233 233 int status; 234 - int message; 235 234 int phase; 236 235 struct list_head list; 237 236 }; ··· 285 286 static void NCR5380_reselect(struct Scsi_Host *instance); 286 287 static bool NCR5380_select(struct Scsi_Host *, struct scsi_cmnd *); 287 288 static int NCR5380_transfer_dma(struct Scsi_Host *instance, unsigned char *phase, int *count, unsigned char **data); 288 - static int NCR5380_transfer_pio(struct Scsi_Host *instance, unsigned char *phase, int *count, unsigned char **data, 289 - unsigned int can_sleep); 289 + static void NCR5380_transfer_pio(struct Scsi_Host *instance, 290 + unsigned char *phase, int *count, 291 + unsigned char **data, unsigned int can_sleep); 290 292 static int NCR5380_poll_politely2(struct NCR5380_hostdata *, 291 293 unsigned int, u8, u8, 292 294 unsigned int, u8, u8, unsigned long);
+90 -84
drivers/scsi/mac_scsi.c
··· 102 102 * Linux SCSI drivers lack knowledge of the timing behaviour of SCSI targets 103 103 * so bus errors are unavoidable. 104 104 * 105 - * If a MOVE.B instruction faults, we assume that zero bytes were transferred 106 - * and simply retry. That assumption probably depends on target behaviour but 107 - * seems to hold up okay. The NOP provides synchronization: without it the 108 - * fault can sometimes occur after the program counter has moved past the 109 - * offending instruction. Post-increment addressing can't be used. 105 + * If a MOVE.B instruction faults during a receive operation, we assume the 106 + * target sent nothing and try again. That assumption probably depends on 107 + * target firmware but it seems to hold up okay. If a fault happens during a 108 + * send operation, the target may or may not have seen /ACK and got the byte. 109 + * It's uncertain so the whole SCSI command gets retried. 110 + * 111 + * The NOP is needed for synchronization because the fault address in the 112 + * exception stack frame may or may not be the instruction that actually 113 + * caused the bus error. Post-increment addressing can't be used. 110 114 */ 111 115 112 116 #define MOVE_BYTE(operands) \ ··· 212 208 ".previous \n" \ 213 209 : "+a" (addr), "+r" (n), "+r" (result) : "a" (io)) 214 210 215 - #define MAC_PDMA_DELAY 32 216 - 217 211 static inline int mac_pdma_recv(void __iomem *io, unsigned char *start, int n) 218 212 { 219 213 unsigned char *addr = start; ··· 247 245 if (n >= 1) { 248 246 MOVE_BYTE("%0@,%3@"); 249 247 if (result) 250 - goto out; 248 + return -1; 251 249 } 252 250 if (n >= 1 && ((unsigned long)addr & 1)) { 253 251 MOVE_BYTE("%0@,%3@"); 254 252 if (result) 255 - goto out; 253 + return -2; 256 254 } 257 255 while (n >= 32) 258 256 MOVE_16_WORDS("%0@+,%3@"); 259 257 while (n >= 2) 260 258 MOVE_WORD("%0@+,%3@"); 261 259 if (result) 262 - return start - addr; /* Negated to indicate uncertain length */ 260 + return start - addr - 1; /* Negated to indicate uncertain length */ 263 261 if (n == 1) 264 262 MOVE_BYTE("%0@,%3@"); 265 - out: 266 263 return addr - start; 267 264 } 268 265 ··· 275 274 out_be32(hostdata->io + (CTRL_REG << 4), value); 276 275 } 277 276 277 + static inline int macscsi_wait_for_drq(struct NCR5380_hostdata *hostdata) 278 + { 279 + unsigned int n = 1; /* effectively multiplies NCR5380_REG_POLL_TIME */ 280 + unsigned char basr; 281 + 282 + again: 283 + basr = NCR5380_read(BUS_AND_STATUS_REG); 284 + 285 + if (!(basr & BASR_PHASE_MATCH)) 286 + return 1; 287 + 288 + if (basr & BASR_IRQ) 289 + return -1; 290 + 291 + if (basr & BASR_DRQ) 292 + return 0; 293 + 294 + if (n-- == 0) { 295 + NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host); 296 + dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host, 297 + "%s: DRQ timeout\n", __func__); 298 + return -1; 299 + } 300 + 301 + NCR5380_poll_politely2(hostdata, 302 + BUS_AND_STATUS_REG, BASR_DRQ, BASR_DRQ, 303 + BUS_AND_STATUS_REG, BASR_PHASE_MATCH, 0, 0); 304 + goto again; 305 + } 306 + 278 307 static inline int macscsi_pread(struct NCR5380_hostdata *hostdata, 279 308 unsigned char *dst, int len) 280 309 { 281 310 u8 __iomem *s = hostdata->pdma_io + (INPUT_DATA_REG << 4); 282 311 unsigned char *d = dst; 283 - int result = 0; 284 312 285 313 hostdata->pdma_residual = len; 286 314 287 - while (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG, 288 - BASR_DRQ | BASR_PHASE_MATCH, 289 - BASR_DRQ | BASR_PHASE_MATCH, 0)) { 290 - int bytes; 315 + while (macscsi_wait_for_drq(hostdata) == 0) { 316 + int bytes, chunk_bytes; 291 317 292 318 if (macintosh_config->ident == MAC_MODEL_IIFX) 293 319 write_ctrl_reg(hostdata, CTRL_HANDSHAKE_MODE | 294 320 CTRL_INTERRUPTS_ENABLE); 295 321 296 - bytes = mac_pdma_recv(s, d, min(hostdata->pdma_residual, 512)); 322 + chunk_bytes = min(hostdata->pdma_residual, 512); 323 + bytes = mac_pdma_recv(s, d, chunk_bytes); 324 + 325 + if (macintosh_config->ident == MAC_MODEL_IIFX) 326 + write_ctrl_reg(hostdata, CTRL_INTERRUPTS_ENABLE); 297 327 298 328 if (bytes > 0) { 299 329 d += bytes; ··· 332 300 } 333 301 334 302 if (hostdata->pdma_residual == 0) 335 - goto out; 303 + break; 336 304 337 - if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ, 338 - BUS_AND_STATUS_REG, BASR_ACK, 339 - BASR_ACK, 0) < 0) 340 - scmd_printk(KERN_DEBUG, hostdata->connected, 341 - "%s: !REQ and !ACK\n", __func__); 342 - if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) 343 - goto out; 344 - 345 - if (bytes == 0) 346 - udelay(MAC_PDMA_DELAY); 347 - 348 - if (bytes >= 0) 305 + if (bytes > 0) 349 306 continue; 350 307 351 - dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host, 352 - "%s: bus error (%d/%d)\n", __func__, d - dst, len); 353 308 NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host); 354 - result = -1; 355 - goto out; 309 + dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host, 310 + "%s: bus error [%d/%d] (%d/%d)\n", 311 + __func__, d - dst, len, bytes, chunk_bytes); 312 + 313 + if (bytes == 0) 314 + continue; 315 + 316 + if (macscsi_wait_for_drq(hostdata) <= 0) 317 + set_host_byte(hostdata->connected, DID_ERROR); 318 + break; 356 319 } 357 320 358 - scmd_printk(KERN_ERR, hostdata->connected, 359 - "%s: phase mismatch or !DRQ\n", __func__); 360 - NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host); 361 - result = -1; 362 - out: 363 - if (macintosh_config->ident == MAC_MODEL_IIFX) 364 - write_ctrl_reg(hostdata, CTRL_INTERRUPTS_ENABLE); 365 - return result; 321 + return 0; 366 322 } 367 323 368 324 static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata, ··· 358 338 { 359 339 unsigned char *s = src; 360 340 u8 __iomem *d = hostdata->pdma_io + (OUTPUT_DATA_REG << 4); 361 - int result = 0; 362 341 363 342 hostdata->pdma_residual = len; 364 343 365 - while (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG, 366 - BASR_DRQ | BASR_PHASE_MATCH, 367 - BASR_DRQ | BASR_PHASE_MATCH, 0)) { 368 - int bytes; 344 + while (macscsi_wait_for_drq(hostdata) == 0) { 345 + int bytes, chunk_bytes; 369 346 370 347 if (macintosh_config->ident == MAC_MODEL_IIFX) 371 348 write_ctrl_reg(hostdata, CTRL_HANDSHAKE_MODE | 372 349 CTRL_INTERRUPTS_ENABLE); 373 350 374 - bytes = mac_pdma_send(s, d, min(hostdata->pdma_residual, 512)); 351 + chunk_bytes = min(hostdata->pdma_residual, 512); 352 + bytes = mac_pdma_send(s, d, chunk_bytes); 353 + 354 + if (macintosh_config->ident == MAC_MODEL_IIFX) 355 + write_ctrl_reg(hostdata, CTRL_INTERRUPTS_ENABLE); 375 356 376 357 if (bytes > 0) { 377 358 s += bytes; 378 359 hostdata->pdma_residual -= bytes; 379 360 } 380 361 381 - if (hostdata->pdma_residual == 0) { 382 - if (NCR5380_poll_politely(hostdata, TARGET_COMMAND_REG, 383 - TCR_LAST_BYTE_SENT, 384 - TCR_LAST_BYTE_SENT, 385 - 0) < 0) { 386 - scmd_printk(KERN_ERR, hostdata->connected, 387 - "%s: Last Byte Sent timeout\n", __func__); 388 - result = -1; 389 - } 390 - goto out; 391 - } 362 + if (hostdata->pdma_residual == 0) 363 + break; 392 364 393 - if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ, 394 - BUS_AND_STATUS_REG, BASR_ACK, 395 - BASR_ACK, 0) < 0) 396 - scmd_printk(KERN_DEBUG, hostdata->connected, 397 - "%s: !REQ and !ACK\n", __func__); 398 - if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) 399 - goto out; 400 - 401 - if (bytes == 0) 402 - udelay(MAC_PDMA_DELAY); 403 - 404 - if (bytes >= 0) 365 + if (bytes > 0) 405 366 continue; 406 367 407 - dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host, 408 - "%s: bus error (%d/%d)\n", __func__, s - src, len); 409 368 NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host); 410 - result = -1; 411 - goto out; 369 + dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host, 370 + "%s: bus error [%d/%d] (%d/%d)\n", 371 + __func__, s - src, len, bytes, chunk_bytes); 372 + 373 + if (bytes == 0) 374 + continue; 375 + 376 + if (macscsi_wait_for_drq(hostdata) <= 0) 377 + set_host_byte(hostdata->connected, DID_ERROR); 378 + break; 412 379 } 413 380 414 - scmd_printk(KERN_ERR, hostdata->connected, 415 - "%s: phase mismatch or !DRQ\n", __func__); 416 - NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host); 417 - result = -1; 418 - out: 419 - if (macintosh_config->ident == MAC_MODEL_IIFX) 420 - write_ctrl_reg(hostdata, CTRL_INTERRUPTS_ENABLE); 421 - return result; 381 + return 0; 422 382 } 423 383 424 384 static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata, ··· 432 432 .eh_host_reset_handler = macscsi_host_reset, 433 433 .can_queue = 16, 434 434 .this_id = 7, 435 - .sg_tablesize = 1, 435 + .sg_tablesize = SG_ALL, 436 436 .cmd_per_lun = 2, 437 437 .dma_boundary = PAGE_SIZE - 1, 438 438 .cmd_size = sizeof(struct NCR5380_cmd), ··· 470 470 if (setup_hostid >= 0) 471 471 mac_scsi_template.this_id = setup_hostid & 7; 472 472 473 + if (macintosh_config->ident == MAC_MODEL_IIFX) 474 + mac_scsi_template.sg_tablesize = 1; 475 + 473 476 instance = scsi_host_alloc(&mac_scsi_template, 474 477 sizeof(struct NCR5380_hostdata)); 475 478 if (!instance) ··· 493 490 host_flags |= FLAG_NO_PSEUDO_DMA; 494 491 495 492 host_flags |= setup_toshiba_delay > 0 ? FLAG_TOSHIBA_DELAY : 0; 493 + 494 + if (instance->sg_tablesize > 1) 495 + host_flags |= FLAG_DMA_FIXUP; 496 496 497 497 error = NCR5380_init(instance, host_flags | FLAG_LATE_DMA_SETUP); 498 498 if (error)
+1 -1
drivers/scsi/sun3_scsi.c
··· 304 304 sun3_udc_write(UDC_INT_ENABLE, UDC_CSR); 305 305 #endif 306 306 307 - return count; 307 + return count; 308 308 309 309 } 310 310