Deleted Added
full compact
2a3
> * Copyright (c) 2005, 2008 Marius Strobl <marius@FreeBSD.org>
28c29
< /* $NetBSD: ncr53c9x.c,v 1.114 2005/02/27 00:27:02 perry Exp $ */
---
> /* $NetBSD: ncr53c9x.c,v 1.125 2007/01/09 12:53:12 itohy Exp $ */
107c108
< __FBSDID("$FreeBSD: head/sys/dev/esp/ncr53c9x.c 180692 2008-07-22 13:51:21Z marius $");
---
> __FBSDID("$FreeBSD: head/sys/dev/esp/ncr53c9x.c 182876 2008-09-08 20:20:44Z marius $");
114d114
< #include <sys/resource.h>
115a116
> #include <sys/module.h>
132c133,136
< int ncr53c9x_debug =
---
> MODULE_DEPEND(esp, cam, 1, 1, 1);
>
> #ifdef NCR53C9X_DEBUG
> static int ncr53c9x_debug =
134,135d137
< #ifdef DEBUG
< int ncr53c9x_notag = 0;
139a142,148
> static void ncr53c9x_action(struct cam_sim *sim, union ccb *ccb);
> static void ncr53c9x_async(void *cbarg, uint32_t code,
> struct cam_path *path, void *arg);
> static void ncr53c9x_callout(void *arg);
> static void ncr53c9x_clear(struct ncr53c9x_softc *sc, cam_status result);
> static void ncr53c9x_clear_target(struct ncr53c9x_softc *sc, int target,
> cam_status result);
147a157,158
> static void ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset);
> static void ncr53c9x_intr1(struct ncr53c9x_softc *sc);
151a163
> static void ncr53c9x_reset(struct ncr53c9x_softc *sc);
154d165
< static void ncr53c9x_scsi_reset(struct ncr53c9x_softc *sc);
158d168
< static void ncr53c9x_timeout(void *arg);
241c251,254
< mtx_init(&sc->sc_lock, "ncr", "ncr53c9x lock", MTX_DEF);
---
> if (NCR_LOCK_INITIALIZED(sc) == 0) {
> device_printf(sc->sc_dev, "mutex not initialized\n");
> return (ENXIO);
> }
242a256,257
> callout_init_mtx(&sc->sc_watchdog, &sc->sc_lock, 0);
>
295,296d309
< callout_init(&sc->sc_watchdog, 0);
<
337c350
< device_get_unit(sc->sc_dev), &Giant, 1, NCR_TAG_DEPTH, devq);
---
> device_get_unit(sc->sc_dev), &sc->sc_lock, 1, NCR_TAG_DEPTH, devq);
342a356,358
>
> NCR_LOCK(sc);
>
346c362
< goto fail_sim;
---
> goto fail_lock;
355a372,378
> if (xpt_register_async(AC_LOST_DEVICE, ncr53c9x_async, sim, path) !=
> CAM_REQ_CMP) {
> device_printf(sc->sc_dev, "cannot register async handler\n");
> error = EIO;
> goto fail_path;
> }
>
374c397
< goto fail_path;
---
> goto fail_async;
383c406
< callout_reset(&sc->sc_watchdog, 60*hz, ncr53c9x_watch, sc);
---
> callout_reset(&sc->sc_watchdog, 60 * hz, ncr53c9x_watch, sc);
384a408,409
> NCR_UNLOCK(sc);
>
386a412,413
> fail_async:
> xpt_register_async(0, ncr53c9x_async, sim, path);
391c418,419
< fail_sim:
---
> fail_lock:
> NCR_UNLOCK(sc);
408a437,438
> struct ncr53c9x_linfo *li, *nextli;
> int t;
411,413c441,458
< mtx_lock(&sc->sc_lock);
< ncr53c9x_init(sc, 1);
< mtx_unlock(&sc->sc_lock);
---
>
> NCR_LOCK(sc);
>
> if (sc->sc_tinfo) {
> /* Cancel all commands. */
> ncr53c9x_clear(sc, CAM_REQ_ABORTED);
>
> /* Free logical units. */
> for (t = 0; t < sc->sc_ntarg; t++) {
> for (li = LIST_FIRST(&sc->sc_tinfo[t].luns); li;
> li = nextli) {
> nextli = LIST_NEXT(li, link);
> free(li, M_DEVBUF);
> }
> }
> }
>
> xpt_register_async(0, ncr53c9x_async, sc->sc_sim, sc->sc_path);
415a461,463
>
> NCR_UNLOCK(sc);
>
423d470
< mtx_destroy(&sc->sc_lock);
436c483
< void
---
> static void
439a487,488
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
479a529,530
> if (sc->sc_id > 7)
> sc->sc_cfg3 |= NCRFASCFG3_IDBIT3;
482c533
< sc->sc_cfg2 = 0; /* NCRCFG2_HMEFE | NCRCFG2_HME32 */
---
> sc->sc_cfg2 = NCRCFG2_HMEFE | NCRCFG2_HME32;
512c563
< * Reset the SCSI bus, but not the chip.
---
> * Clear all commands.
515c566
< ncr53c9x_scsi_reset(struct ncr53c9x_softc *sc)
---
> ncr53c9x_clear(struct ncr53c9x_softc *sc, cam_status result)
516a568,569
> struct ncr53c9x_ecb *ecb;
> int r;
518c571
< (*sc->sc_glue->gl_dma_stop)(sc);
---
> NCR_LOCK_ASSERT(sc, MA_OWNED);
520,522c573,582
< NCR_MISC(("%s: resetting SCSI bus\n", device_get_nameunit(sc->sc_dev)));
< NCRCMD(sc, NCRCMD_RSTSCSI);
< DELAY(250000); /* Give the bus a fighting chance to settle */
---
> /* Cancel any active commands. */
> sc->sc_state = NCR_CLEANING;
> sc->sc_msgify = 0;
> if ((ecb = sc->sc_nexus) != NULL) {
> ecb->ccb->ccb_h.status = result;
> ncr53c9x_done(sc, ecb);
> }
> /* Cancel outstanding disconnected commands. */
> for (r = 0; r < sc->sc_ntarg; r++)
> ncr53c9x_clear_target(sc, r, result);
526c586
< * Initialize ncr53c9x state machine.
---
> * Clear all commands for a specific target.
528,529c588,590
< void
< ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset)
---
> static void
> ncr53c9x_clear_target(struct ncr53c9x_softc *sc, int target,
> cam_status result)
532a594,625
> int i;
>
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
> /* Cancel outstanding disconnected commands on each LUN. */
> LIST_FOREACH(li, &sc->sc_tinfo[target].luns, link) {
> if ((ecb = li->untagged) != NULL) {
> li->untagged = NULL;
> /*
> * XXX should we terminate a command
> * that never reached the disk?
> */
> li->busy = 0;
> ecb->ccb->ccb_h.status = result;
> ncr53c9x_done(sc, ecb);
> }
> for (i = 0; i < NCR_TAG_DEPTH; i++)
> if ((ecb = li->queued[i])) {
> li->queued[i] = NULL;
> ecb->ccb->ccb_h.status = result;
> ncr53c9x_done(sc, ecb);
> }
> li->used = 0;
> }
> }
>
> /*
> * Initialize ncr53c9x state machine.
> */
> static void
> ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset)
> {
534c627
< int i, r;
---
> int r;
535a629,630
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
547,581c642,643
< } else {
< /* Cancel any active commands. */
< sc->sc_state = NCR_CLEANING;
< sc->sc_msgify = 0;
< if ((ecb = sc->sc_nexus) != NULL) {
< ecb->ccb->ccb_h.status = CAM_CMD_TIMEOUT;
< ncr53c9x_done(sc, ecb);
< }
< /* Cancel outstanding disconnected commands on each LUN. */
< for (r = 0; r < sc->sc_ntarg; r++) {
< LIST_FOREACH(li, &sc->sc_tinfo[r].luns, link) {
< if ((ecb = li->untagged) != NULL) {
< li->untagged = NULL;
< /*
< * XXX
< *
< * Should we terminate a command
< * that never reached the disk?
< */
< li->busy = 0;
< ecb->ccb->ccb_h.status =
< CAM_CMD_TIMEOUT;
< ncr53c9x_done(sc, ecb);
< }
< for (i = 0; i < 256; i++)
< if ((ecb = li->queued[i])) {
< li->queued[i] = NULL;
< ecb->ccb->ccb_h.status =
< CAM_CMD_TIMEOUT;
< ncr53c9x_done(sc, ecb);
< }
< li->used = 0;
< }
< }
< }
---
> } else
> ncr53c9x_clear(sc, CAM_CMD_TIMEOUT);
592,593c654,662
< for (r = 0; r < sc->sc_ntarg; r++) {
< ti = &sc->sc_tinfo[r];
---
> /*
> * If we're the first time through, set the default parameters
> * for all targets. Otherwise we only clear their current transfer
> * settings so we'll renegotiate their goal settings with the next
> * command.
> */
> if (sc->sc_state == 0) {
> for (r = 0; r < sc->sc_ntarg; r++) {
> ti = &sc->sc_tinfo[r];
595,599d663
< ti->flags = ((sc->sc_minsync != 0 &&
< (sc->sc_cfflags & (1 << ((r & 7) + 8))) == 0) ?
< 0 : T_SYNCHOFF) |
< ((sc->sc_cfflags & (1 << (r & 7))) == 0 ?
< 0 : T_RSELECTOFF);
601,607c665,682
< #ifdef DEBUG
< if (ncr53c9x_notag)
< ti->flags &= ~T_TAG;
< #endif
< ti->period = sc->sc_minsync;
< ti->offset = 0;
< ti->cfg3 = 0;
---
> ti->flags = ((sc->sc_minsync != 0 &&
> (sc->sc_cfflags & (1 << ((r & 7) + 8))) == 0) ?
> 0 : T_SYNCHOFF) |
> ((sc->sc_cfflags & (1 << (r & 7))) == 0 ?
> 0 : T_RSELECTOFF);
> ti->curr.period = ti->goal.period = 0;
> ti->curr.offset = ti->goal.offset = 0;
> ti->curr.width = ti->goal.width =
> MSG_EXT_WDTR_BUS_8_BIT;
> }
> } else {
> for (r = 0; r < sc->sc_ntarg; r++) {
> ti = &sc->sc_tinfo[r];
> ti->flags &= ~(T_SDTRSENT | T_WDTRSENT);
> ti->curr.period = 0;
> ti->curr.offset = 0;
> ti->curr.width = MSG_EXT_WDTR_BUS_8_BIT;
> }
612a688,689
> /* Give the bus a fighting chance to settle. */
> DELAY(250000);
631a709,710
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
661a741,743
>
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
672,673c754
< u_char syncoff, synctp;
< u_char cfg3 = sc->sc_cfg3 | ti->cfg3;
---
> u_char cfg3, syncoff, synctp;
675,677c756,761
< if (ti->flags & T_SYNCMODE) {
< syncoff = ti->offset;
< synctp = ncr53c9x_stp2cpb(sc, ti->period);
---
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
> cfg3 = sc->sc_cfg3;
> if (ti->curr.offset != 0) {
> syncoff = ti->curr.offset;
> synctp = ncr53c9x_stp2cpb(sc, ti->curr.period);
683c767
< if (ti->period <= 50)
---
> if (ti->curr.period <= 50)
705a790,794
> if (ti->curr.width != MSG_EXT_WDTR_BUS_8_BIT) {
> if (sc->sc_rev == NCR_VARIANT_FAS366)
> cfg3 |= NCRFASCFG3_EWIDE;
> }
>
729a819,820
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
736c827
< * Schedule the timeout now, the first time we will go away
---
> * Schedule the callout now, the first time we will go away
740,741c831
< ecb->ccb->ccb_h.timeout_ch =
< timeout(ncr53c9x_timeout, ecb, mstohz(ecb->timeout));
---
> callout_reset(&ecb->ch, mstohz(ecb->timeout), ncr53c9x_callout, ecb);
749c839,840
< NCR_WRITE_REG(sc, NCR_SELID, target | NCR_BUSID_HME);
---
> NCR_WRITE_REG(sc, NCR_SELID, target | NCR_BUSID_HMEXC32 |
> NCR_BUSID_HMEENCID);
753d843
< ncr53c9x_setsync(sc, ti);
755,782c845,854
< if ((ecb->flags & ECB_SENSE) != 0) {
< /*
< * For REQUEST SENSE, we should not send an IDENTIFY or
< * otherwise mangle the target. There should be no MESSAGE IN
< * phase.
< */
< if (sc->sc_features & NCR_F_DMASELECT) {
< /* setup DMA transfer for command */
< dmasize = clen = ecb->clen;
< sc->sc_cmdlen = clen;
< sc->sc_cmdp = (caddr_t)&ecb->cmd.cmd;
<
< /* Program the SCSI counter */
< NCR_SET_COUNT(sc, dmasize);
<
< if (sc->sc_rev != NCR_VARIANT_FAS366)
< NCRCMD(sc, NCRCMD_NOP | NCRCMD_DMA);
<
< /* And get the target's attention */
< NCRCMD(sc, NCRCMD_SELNATN | NCRCMD_DMA);
< NCRDMA_SETUP(sc, &sc->sc_cmdp, &sc->sc_cmdlen, 0,
< &dmasize);
< NCRDMA_GO(sc);
< } else {
< ncr53c9x_wrfifo(sc, (u_char *)&ecb->cmd.cmd, ecb->clen);
< NCRCMD(sc, NCRCMD_SELNATN);
< }
< return;
---
> /*
> * If we are requesting sense, force a renegotiation if we are
> * currently using anything different from asynchronous at 8 bit
> * as the target might have lost our transfer negotiations.
> */
> if ((ecb->flags & ECB_SENSE) != 0 && (ti->curr.offset != 0 ||
> ti->curr.width != MSG_EXT_WDTR_BUS_8_BIT)) {
> ti->curr.period = 0;
> ti->curr.offset = 0;
> ti->curr.width = MSG_EXT_WDTR_BUS_8_BIT;
783a856
> ncr53c9x_setsync(sc, ti);
795c868,870
< if (ti->flags & T_NEGOTIATE) {
---
> if (ti->curr.period != ti->goal.period ||
> ti->curr.offset != ti->goal.offset ||
> ti->curr.width != ti->goal.width) {
822c897
<
---
> NCRDMA_SETUP(sc, &sc->sc_cmdp, &sc->sc_cmdlen, 0, &dmasize);
837d911
< NCRDMA_SETUP(sc, &sc->sc_cmdp, &sc->sc_cmdlen, 0, &dmasize);
866a941,942
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
875a952,953
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
898c976
< void
---
> static void
911,912d988
< NCR_TRACE(("[ncr53c9x_action %d]", ccb->ccb_h.func_code));
<
914d989
< mtx_lock(&sc->sc_lock);
915a991,994
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
> NCR_TRACE(("[ncr53c9x_action %d]", ccb->ccb_h.func_code));
>
918c997
< ncr53c9x_scsi_reset(sc);
---
> ncr53c9x_init(sc, 1);
920d998
< mtx_unlock(&sc->sc_lock);
925d1002
< mtx_unlock(&sc->sc_lock);
940c1017
< cpi->max_lun = 8;
---
> cpi->max_lun = 7;
953d1029
< mtx_unlock(&sc->sc_lock);
969,971c1045,1047
< spi->sync_period = ti->period;
< spi->sync_offset = ti->offset;
< spi->bus_width = ti->width;
---
> spi->sync_period = ti->curr.period;
> spi->sync_offset = ti->curr.offset;
> spi->bus_width = ti->curr.width;
980,981c1056,1062
< spi->sync_period = sc->sc_maxsync;
< spi->sync_offset = sc->sc_maxoffset;
---
> if ((ti->flags & T_SYNCHOFF) != 0) {
> spi->sync_period = 0;
> spi->sync_offset = 0;
> } else {
> spi->sync_period = sc->sc_minsync;
> spi->sync_offset = sc->sc_maxoffset;
> }
993d1073
< mtx_unlock(&sc->sc_lock);
998c1078
< printf("XPT_ABORT called\n");
---
> device_printf(sc->sc_dev, "XPT_ABORT called\n");
1000d1079
< mtx_unlock(&sc->sc_lock);
1005c1084
< printf("XPT_TERM_IO called\n");
---
> device_printf(sc->sc_dev, "XPT_TERM_IO called\n");
1007d1085
< mtx_unlock(&sc->sc_lock);
1012d1089
< printf("XPT_RESET_DEV called\n");
1017d1093
< mtx_unlock(&sc->sc_lock);
1030,1031c1106
< printf("unable to allocate ecb\n");
< mtx_unlock(&sc->sc_lock);
---
> device_printf(sc->sc_dev, "unable to allocate ecb\n");
1082,1093c1157,1159
< if (spi->bus_width != 0) {
< NCR_MISC(("%s: target %d: wide negotiation\n",
< device_get_nameunit(sc->sc_dev), target));
< if (sc->sc_rev == NCR_VARIANT_FAS366) {
< ti->flags |= T_WIDE;
< ti->width = 1;
< }
< } else {
< ti->flags &= ~T_WIDE;
< ti->width = 0;
< }
< ti->flags |= T_NEGOTIATE;
---
> NCR_MISC(("%s: target %d: wide negotiation\n",
> device_get_nameunit(sc->sc_dev), target));
> ti->goal.width = spi->bus_width;
1099,1100c1165
< ti->flags |= T_NEGOTIATE;
< ti->period = spi->sync_period;
---
> ti->goal.period = spi->sync_period;
1106,1107c1171
< ti->flags |= T_NEGOTIATE;
< ti->offset = spi->sync_offset;
---
> ti->goal.offset = spi->sync_offset;
1110d1173
< mtx_unlock(&sc->sc_lock);
1119d1181
< mtx_unlock(&sc->sc_lock);
1123,1124d1184
<
< mtx_unlock(&sc->sc_lock);
1135d1194
< NCR_TRACE(("[ncr53c9x_poll] "));
1137,1138c1196,1239
< if (NCRDMA_ISINTR(sc)) {
< ncr53c9x_intr(sc);
---
>
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
> NCR_TRACE(("[ncr53c9x_poll] "));
>
> if (NCRDMA_ISINTR(sc))
> ncr53c9x_intr1(sc);
> }
>
> /*
> * Asynchronous notification handler
> */
> static void
> ncr53c9x_async(void *cbarg, uint32_t code, struct cam_path *path, void *arg)
> {
> struct ncr53c9x_softc *sc;
> struct ncr53c9x_tinfo *ti;
> int target;
>
> sc = cam_sim_softc(cbarg);
>
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
> switch (code) {
> case AC_LOST_DEVICE:
> target = xpt_path_target_id(path);
> if (target < 0 || target >= sc->sc_ntarg)
> break;
>
> /* Cancel outstanding disconnected commands. */
> ncr53c9x_clear_target(sc, target, CAM_REQ_ABORTED);
>
> /* Set the default parameters for the target. */
> ti = &sc->sc_tinfo[target];
> /* XXX - config flags per target: low bits: no reselect; high bits: no synch */
> ti->flags = ((sc->sc_minsync != 0 &&
> (sc->sc_cfflags & (1 << ((target & 7) + 8))) == 0) ?
> 0 : T_SYNCHOFF) |
> ((sc->sc_cfflags & (1 << (target & 7))) == 0 ?
> 0 : T_RSELECTOFF);
> ti->curr.period = ti->goal.period = 0;
> ti->curr.offset = ti->goal.offset = 0;
> ti->curr.width = ti->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
> break;
1148,1150c1249,1251
< * handler so that we may call it from ncr53c9x_scsipi_request and
< * ncr53c9x_done. This may save us an unnecessary interrupt just to get
< * things going. Should only be called when state == NCR_IDLE and at bio pl.
---
> * handler so that we may call it from ncr53c9x_action and ncr53c9x_done.
> * This may save us an unnecessary interrupt just to get things going.
> * Should only be called when state == NCR_IDLE and with sc_lock held.
1159a1261,1262
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
1169,1170c1272
< for (ecb = TAILQ_FIRST(&sc->ready_list); ecb != NULL;
< ecb = TAILQ_NEXT(ecb, chain)) {
---
> TAILQ_FOREACH(ecb, &sc->ready_list, chain) {
1175c1277
< if ((ti->flags & (T_RSELECTOFF)) != 0)
---
> if ((ti->flags & (T_RSELECTOFF | T_TAG)) != T_TAG)
1177,1178d1278
< else if ((ti->flags & (T_TAG)) == 0)
< tag = 0;
1256a1357,1358
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
1299a1402,1403
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
1306c1410
< untimeout(ncr53c9x_timeout, ecb, ccb->ccb_h.timeout_ch);
---
> callout_stop(&ecb->ch);
1310c1414
< * initial XS_NOERROR, and the status code signals that we should
---
> * initial CAM_REQ_CMP, and the status code signals that we should
1316a1421
> ccb->csio.scsi_status = ecb->stat;
1321c1426,1428
< ccb->ccb_h.status = CAM_AUTOSNS_VALID;
---
> ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
> ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR |
> CAM_AUTOSNS_VALID;
1328,1329c1435,1440
< ncr53c9x_sense(sc, ecb);
< return;
---
> if ((ccb->ccb_h.flags & CAM_DIS_AUTOSENSE) ==
> 0) {
> ncr53c9x_sense(sc, ecb);
> return;
> }
> ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR;
1334,1337c1445,1448
< #if 0
< if (xs->status == SCSI_QUEUE_FULL || xs->status == XS_BUSY)
< xs->error = XS_BUSY;
< #endif
---
> if (ecb->stat == SCSI_STATUS_QUEUE_FULL)
> ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR;
> else if (ecb->stat == SCSI_STATUS_BUSY)
> ccb->ccb_h.status = CAM_SCSI_BUSY;
1344,1345c1455
< #if 0
< if (xs->error == XS_SENSE)
---
> if ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
1347c1457
< xs->sense.scsi_sense.error_code);
---
> ccb->csio.sense_data.error_code);
1349,1350c1459,1460
< printf("error=%d\n", xs->error);
< #endif
---
> printf("status SCSI=0x%x CAM=0x%x\n",
> ccb->csio.scsi_status, ccb->ccb_h.status);
1387a1498,1499
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
1410a1523
> ecb->tag[0] = ecb->tag[1] = 0;
1436a1550,1552
>
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
1451a1568,1569
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
1513a1632,1633
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
1539a1660
> NCR_LOCK_ASSERT(sc, MA_OWNED);
1653a1775,1776
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
1681c1804,1805
< printf("<dropping msg byte %x>", sc->sc_imess[sc->sc_imlen]);
---
> device_printf(sc->sc_dev, "<dropping msg byte %x>",
> sc->sc_imess[sc->sc_imlen]);
1781,1782c1905,1907
< sc->sc_flags &= ~NCR_SYNCHNEGO;
< ti->flags &= ~(T_NEGOTIATE | T_SYNCMODE);
---
> ti->flags &= ~T_SDTRSENT;
> ti->curr.period = ti->goal.period = 0;
> ti->curr.offset = ti->goal.offset = 0;
1790,1791c1915,1919
< ti->flags &= ~(T_WIDE | T_WDTRSENT);
< ti->width = 0;
---
>
> ti->flags &= ~T_WDTRSENT;
> ti->curr.width = ti->goal.width =
> MSG_EXT_WDTR_BUS_8_BIT;
> ncr53c9x_setsync(sc, ti);
1845,1847c1973,1974
< ti->period = sc->sc_imess[3];
< ti->offset = sc->sc_imess[4];
< ti->flags &= ~T_NEGOTIATE;
---
> ti->curr.period = sc->sc_imess[3];
> ti->curr.offset = sc->sc_imess[4];
1849,1850c1976,1977
< ti->offset == 0 ||
< ti->period > 124) {
---
> ti->curr.offset == 0 ||
> ti->curr.period > 124) {
1857,1859c1984
< ti->flags &= ~T_SYNCMODE;
< if ((sc->sc_flags & NCR_SYNCHNEGO) ==
< 0) {
---
> if ((ti->flags & T_SDTRSENT) == 0) {
1863c1988
< ti->offset = 0;
---
> ti->curr.offset = 0;
1868c1993
< ti->period =
---
> ti->curr.period =
1871,1873c1996,1997
< ti->period));
< if ((sc->sc_flags & NCR_SYNCHNEGO) ==
< 0) {
---
> ti->curr.period));
> if ((ti->flags & T_SDTRSENT) == 0) {
1877,1878c2001,2003
< if (ti->period < sc->sc_minsync)
< ti->period =
---
> if (ti->curr.period <
> sc->sc_minsync)
> ti->curr.period =
1880,1882c2005,2008
< if (ti->offset > 15)
< ti->offset = 15;
< ti->flags &= ~T_SYNCMODE;
---
> if (ti->curr.offset >
> sc->sc_maxoffset)
> ti->curr.offset =
> sc->sc_maxoffset;
1885,1887d2010
< } else {
< /* We are sync. */
< ti->flags |= T_SYNCMODE;
1890c2013,2015
< sc->sc_flags &= ~NCR_SYNCHNEGO;
---
> ti->flags &= ~T_SDTRSENT;
> ti->goal.period = ti->curr.period;
> ti->goal.offset = ti->curr.offset;
1895,1906c2020,2021
< #ifdef NCR53C9X_DEBUG
< device_printf(sc->sc_dev, "wide mode %d\n",
< sc->sc_imess[3]);
< #endif
< if (sc->sc_imess[3] == 1) {
< ti->cfg3 |= NCRFASCFG3_EWIDE;
< ncr53c9x_setsync(sc, ti);
< } else
< ti->width = 0;
< /*
< * Device started width negotiation.
< */
---
> NCR_MSGS(("wide mode %d ", sc->sc_imess[3]));
> ti->curr.width = sc->sc_imess[3];
1907a2023,2025
> /*
> * target initiated negotiation
> */
1909c2027,2029
< ti->flags &= ~(T_WIDE | T_WDTRSENT);
---
> ti->flags &= ~T_WDTRSENT;
> ti->goal.width = ti->curr.width;
> ncr53c9x_setsync(sc, ti);
1971c2091
< if (sc->sc_msgpriq)
---
> if (sc->sc_msgpriq) {
1972a2093,2094
> sc->sc_flags |= NCR_ATN;
> }
1994a2117,2118
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
2036,2037c2160,2161
< sc->sc_omess[3] = ti->period;
< sc->sc_omess[4] = ti->offset;
---
> sc->sc_omess[3] = ti->goal.period;
> sc->sc_omess[4] = ti->goal.offset;
2039,2042d2162
< if ((sc->sc_flags & NCR_SYNCHNEGO) == 0) {
< ti->flags |= T_SYNCMODE;
< ncr53c9x_setsync(sc, ti);
< }
2051c2171
< sc->sc_omess[3] = ti->width;
---
> sc->sc_omess[3] = ti->goal.width;
2081,2084c2201,2203
< ti->flags &= ~T_SYNCMODE;
< if ((ti->flags & T_SYNCHOFF) == 0)
< /* We can re-start sync negotiation. */
< ti->flags |= T_NEGOTIATE;
---
> ti->curr.period = 0;
> ti->curr.offset = 0;
> ti->curr.width = MSG_EXT_WDTR_BUS_8_BIT;
2141c2260
< size = min(sc->sc_omlen, sc->sc_maxxfer);
---
> size = ulmin(sc->sc_omlen, sc->sc_maxxfer);
2152a2272,2286
> void
> ncr53c9x_intr(void *arg)
> {
> struct ncr53c9x_softc *sc = arg;
>
> if (!NCRDMA_ISINTR(sc))
> return;
>
> NCR_LOCK(sc);
>
> ncr53c9x_intr1(sc);
>
> NCR_UNLOCK(sc);
> }
>
2162,2163c2296,2297
< void
< ncr53c9x_intr(void *arg)
---
> static void
> ncr53c9x_intr1(struct ncr53c9x_softc *sc)
2165d2298
< struct ncr53c9x_softc *sc = arg;
2173a2307,2308
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
2176,2179d2310
< if (!NCRDMA_ISINTR(sc))
< return;
<
< mtx_lock(&sc->sc_lock);
2209c2340
< goto out;
---
> return;
2212c2343
< /*XXX*/ printf("<expected bus reset: "
---
> /*XXX*/ device_printf(sc->sc_dev, "<expected bus reset: "
2238c2369
< goto out;
---
> return;
2254c2385
< goto out;
---
> return;
2265,2266c2396
< ncr53c9x_init(sc, 1); /* Restart everything. */
< goto out;
---
> goto reset;
2281,2282c2411
< ncr53c9x_init(sc, 1);
< goto out;
---
> goto reset;
2286c2415
< goto out;
---
> return;
2336c2465
< panic("esp: unrecoverable DMA error");
---
> goto reset;
2393,2398c2522
< if ((sc->sc_flags & NCR_SYNCHNEGO) != 0) {
< #ifdef NCR53C9X_DEBUG
< if (ecb != NULL)
< xpt_print_path(ecb->ccb->ccb_h.path);
< printf("sync nego not completed!\n");
< #endif
---
> if (ecb != NULL) {
2400,2401c2524,2539
< sc->sc_flags &= ~NCR_SYNCHNEGO;
< ti->flags &= ~(T_NEGOTIATE | T_SYNCMODE);
---
> if ((ti->flags & T_SDTRSENT) != 0) {
> xpt_print_path(ecb->ccb->ccb_h.path);
> printf("sync nego not completed!\n");
> ti->flags &= ~T_SDTRSENT;
> ti->curr.period = ti->goal.period = 0;
> ti->curr.offset = ti->goal.offset = 0;
> ncr53c9x_setsync(sc, ti);
> }
> if ((ti->flags & T_WDTRSENT) != 0) {
> xpt_print_path(ecb->ccb->ccb_h.path);
> printf("wide nego not completed!\n");
> ti->flags &= ~T_WDTRSENT;
> ti->curr.width = ti->goal.width =
> MSG_EXT_WDTR_BUS_8_BIT;
> ncr53c9x_setsync(sc, ti);
> }
2434,2435c2572
< untimeout(ncr53c9x_timeout, ecb,
< ecb->ccb->ccb_h.timeout_ch);
---
> callout_stop(&ecb->ch);
2437c2574,2578
< goto out;
---
> return;
> } else if (ecb != NULL &&
> (ecb->flags & ECB_RESET) != 0) {
> ecb->ccb->ccb_h.status = CAM_REQ_CMP;
> goto finish;
2456c2597
< goto out;
---
> return;
2464,2465c2605
< ncr53c9x_init(sc, 1);
< goto out;
---
> goto reset;
2482,2483c2622
< ncr53c9x_init(sc, 1);
< goto out;
---
> goto reset;
2500,2501c2639
< untimeout(ncr53c9x_timeout, ecb,
< ecb->ccb->ccb_h.timeout_ch);
---
> callout_stop(&ecb->ch);
2515,2516c2653
< ncr53c9x_init(sc, 1);
< goto out;
---
> goto reset;
2558,2559c2695
< ncr53c9x_init(sc, 1);
< goto out;
---
> goto reset;
2573,2574c2709
< ncr53c9x_init(sc, 1);
< goto out;
---
> goto reset;
2593c2728
< goto out;
---
> return;
2614c2749,2751
< if ((ti->flags & T_NEGOTIATE) == 0 &&
---
> if (ti->curr.period == ti->goal.period &&
> ti->curr.offset == ti->goal.offset &&
> ti->curr.width == ti->goal.width &&
2616,2617c2753,2755
< device_printf(sc->sc_dev, "step 1 & "
< "!NEG\n");
---
> device_printf(sc->sc_dev, "step 1 "
> "and no negotiation to perform "
> "or tag to send\n");
2621c2759,2760
< device_printf(sc->sc_dev, "!MSGOUT\n");
---
> device_printf(sc->sc_dev, "step 1 "
> "but not in MESSAGE_OUT_PHASE\n");
2624,2626c2763,2777
< if (ti->flags & T_WIDE) {
< ti->flags |= T_WDTRSENT;
< ncr53c9x_sched_msgout(SEND_WDTR);
---
> sc->sc_prevphase = MESSAGE_OUT_PHASE; /* XXX */
> if (ecb->flags & ECB_RESET) {
> /*
> * A DEVICE RESET was scheduled and
> * ATNS used. As SEND_DEV_RESET has
> * the highest priority, the target
> * will reset and disconnect and we
> * will end up in ncr53c9x_done w/o
> * negotiating or sending a TAG. So
> * we just break here in order to
> * avoid warnings about negotiation
> * not having completed.
> */
> ncr53c9x_sched_msgout(SEND_DEV_RESET);
> break;
2628,2637c2779,2789
< if (ti->flags & T_NEGOTIATE) {
< /* Start negotiating */
< sc->sc_flags |= NCR_SYNCHNEGO;
< if (ecb->tag[0])
< ncr53c9x_sched_msgout(
< SEND_TAG|SEND_SDTR);
< else
< ncr53c9x_sched_msgout(
< SEND_SDTR);
< } else {
---
> if (ti->curr.width != ti->goal.width) {
> ti->flags |= T_WDTRSENT | T_SDTRSENT;
> ncr53c9x_sched_msgout(SEND_WDTR |
> SEND_SDTR);
> }
> if (ti->curr.period != ti->goal.period ||
> ti->curr.offset != ti->goal.offset) {
> ti->flags |= T_SDTRSENT;
> ncr53c9x_sched_msgout(SEND_SDTR);
> }
> if (ecb->tag[0] != 0)
2640,2641d2791
< }
< sc->sc_prevphase = MESSAGE_OUT_PHASE; /* XXXX */
2662,2663c2812,2813
< printf("(%s:%d:%d): selection failed;"
< " %d left in FIFO "
---
> xpt_print_path(ecb->ccb->ccb_h.path);
> printf("selection failed; %d left in FIFO "
2665,2667d2814
< device_get_nameunit(sc->sc_dev),
< ecb->ccb->ccb_h.target_id,
< ecb->ccb->ccb_h.target_lun,
2673c2820
< goto out;
---
> return;
2682,2684c2829,2831
< sc->sc_cmdlen != 0)
< printf("(%s:%d:%d): select; "
< "%lu left in DMA buffer "
---
> sc->sc_cmdlen != 0) {
> xpt_print_path(ecb->ccb->ccb_h.path);
> printf("select; %lu left in DMA buffer "
2686,2688d2832
< device_get_nameunit(sc->sc_dev),
< ecb->ccb->ccb_h.target_id,
< ecb->ccb->ccb_h.target_lun,
2692a2837
> }
2713c2858
< goto out;
---
> return;
2817a2963,2971
> /*
> * If we have more messages to send, e.g. WDTR or SDTR
> * after we've sent a TAG, set ATN so we'll go back to
> * MESSAGE_OUT_PHASE.
> */
> if (sc->sc_msgpriq) {
> NCRCMD(sc, NCRCMD_SETATN);
> sc->sc_flags |= NCR_ATN;
> }
2844c2998
< size = min(sc->sc_dleft, sc->sc_maxxfer);
---
> size = ulmin(sc->sc_dleft, sc->sc_maxxfer);
2853c3007
< size = min(sc->sc_dleft, sc->sc_maxxfer);
---
> size = ulmin(sc->sc_dleft, sc->sc_maxxfer);
2876c3030
< goto out;
---
> return;
2894,2895d3047
< out:
< mtx_unlock(&sc->sc_lock);
2900c3052
< goto out;
---
> return;
2904c3056
< goto out;
---
> return;
2909c3061
< goto out;
---
> return;
2932d3083
< goto out;
2938a3090,3091
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
2952c3105
< * Reschedule timeout.
---
> * Reschedule callout.
2954,2955c3107,3108
< ecb->ccb->ccb_h.timeout_ch =
< timeout(ncr53c9x_timeout, ecb, mstohz(ecb->timeout));
---
> callout_reset(&ecb->ch, mstohz(ecb->timeout),
> ncr53c9x_callout, ecb);
2968c3121
< ncr53c9x_timeout(void *arg)
---
> ncr53c9x_callout(void *arg)
2973c3126
< struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[ccb->ccb_h.target_id];
---
> struct ncr53c9x_tinfo *ti;
2974a3128,3130
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
> ti = &sc->sc_tinfo[ccb->ccb_h.target_id];
2989,2990d3144
< mtx_lock(&sc->sc_lock);
<
3003,3004c3157,3158
< (ti->flags & T_SYNCMODE) != 0 &&
< (sc->sc_phase & (MSGI|CDI)) == 0) {
---
> ti->curr.offset != 0 &&
> (sc->sc_phase & (MSGI | CDI)) == 0) {
3005a3160
> ti->goal.offset = 0;
3008,3009d3162
< sc->sc_cfflags |=
< (1 << ((ccb->ccb_h.target_id & 7) + 8));
3012,3013d3164
<
< mtx_unlock(&sc->sc_lock);
3024a3176,3177
> NCR_LOCK_ASSERT(sc, MA_OWNED);
>
3028d3180
< mtx_lock(&sc->sc_lock);
3047d3198
< mtx_unlock(&sc->sc_lock);