Annotation of src/sys/dev/scsipi/atapi_wdc.c, Revision 1.86
1.86 ! thorpej 1: /* $NetBSD: atapi_wdc.c,v 1.85 2004/08/13 03:12:59 thorpej Exp $ */
1.2 bouyer 2:
3: /*
1.47 bouyer 4: * Copyright (c) 1998, 2001 Manuel Bouyer.
1.2 bouyer 5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: * 3. All advertising materials mentioning features or use of this software
15: * must display the following acknowledgement:
1.51 bouyer 16: * This product includes software developed by Manuel Bouyer.
1.58 bouyer 17: * 4. The name of the author may not be used to endorse or promote products
18: * derived from this software without specific prior written permission.
1.2 bouyer 19: *
1.35 bouyer 20: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.2 bouyer 30: */
1.44 lukem 31:
32: #include <sys/cdefs.h>
1.86 ! thorpej 33: __KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.85 2004/08/13 03:12:59 thorpej Exp $");
1.2 bouyer 34:
1.86 ! thorpej 35: #ifndef ATADEBUG
! 36: #define ATADEBUG
! 37: #endif /* ATADEBUG */
1.2 bouyer 38:
39: #include <sys/param.h>
40: #include <sys/systm.h>
41: #include <sys/kernel.h>
42: #include <sys/file.h>
43: #include <sys/stat.h>
44: #include <sys/buf.h>
45: #include <sys/malloc.h>
46: #include <sys/device.h>
47: #include <sys/syslog.h>
48: #include <sys/proc.h>
1.39 mycroft 49: #include <sys/dvdio.h>
1.2 bouyer 50:
51: #include <machine/intr.h>
52: #include <machine/bus.h>
53:
54: #ifndef __BUS_SPACE_HAS_STREAM_METHODS
1.65 thorpej 55: #define bus_space_write_multi_stream_2 bus_space_write_multi_2
56: #define bus_space_write_multi_stream_4 bus_space_write_multi_4
57: #define bus_space_read_multi_stream_2 bus_space_read_multi_2
58: #define bus_space_read_multi_stream_4 bus_space_read_multi_4
1.2 bouyer 59: #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
60:
61: #include <dev/ata/atareg.h>
62: #include <dev/ata/atavar.h>
63: #include <dev/ic/wdcreg.h>
64: #include <dev/ic/wdcvar.h>
65:
1.40 bouyer 66: #include <dev/scsipi/scsi_all.h> /* for SCSI status */
67:
1.2 bouyer 68: #define DEBUG_INTR 0x01
69: #define DEBUG_XFERS 0x02
70: #define DEBUG_STATUS 0x04
71: #define DEBUG_FUNCS 0x08
72: #define DEBUG_PROBE 0x10
1.86 ! thorpej 73: #ifdef ATADEBUG
1.3 bouyer 74: int wdcdebug_atapi_mask = 0;
1.86 ! thorpej 75: #define ATADEBUG_PRINT(args, level) \
1.2 bouyer 76: if (wdcdebug_atapi_mask & (level)) \
77: printf args
78: #else
1.86 ! thorpej 79: #define ATADEBUG_PRINT(args, level)
1.2 bouyer 80: #endif
81:
82: #define ATAPI_DELAY 10 /* 10 ms, this is used only before sending a cmd */
1.59 bouyer 83: #define ATAPI_MODE_DELAY 1000 /* 1s, timeout for SET_FEATYRE cmds */
1.65 thorpej 84:
85: static int wdc_atapi_get_params(struct scsipi_channel *, int,
86: struct ataparams *);
87: static void wdc_atapi_probe_device(struct atapibus_softc *, int);
88: static void wdc_atapi_minphys (struct buf *bp);
1.66 thorpej 89: static void wdc_atapi_start(struct wdc_channel *,struct ata_xfer *);
90: static int wdc_atapi_intr(struct wdc_channel *, struct ata_xfer *, int);
1.71 bouyer 91: static void wdc_atapi_kill_xfer(struct wdc_channel *,
92: struct ata_xfer *, int);
1.65 thorpej 93: static void wdc_atapi_phase_complete(struct ata_xfer *);
1.66 thorpej 94: static void wdc_atapi_done(struct wdc_channel *, struct ata_xfer *);
95: static void wdc_atapi_reset(struct wdc_channel *, struct ata_xfer *);
1.65 thorpej 96: static void wdc_atapi_scsipi_request(struct scsipi_channel *,
97: scsipi_adapter_req_t, void *);
98: static void wdc_atapi_kill_pending(struct scsipi_periph *);
99: static void wdc_atapi_polldsc(void *arg);
1.2 bouyer 100:
101: #define MAX_SIZE MAXPHYS
102:
1.65 thorpej 103: static const struct scsipi_bustype wdc_atapi_bustype = {
1.40 bouyer 104: SCSIPI_BUSTYPE_ATAPI,
105: atapi_scsipi_cmd,
106: atapi_interpret_sense,
107: atapi_print_addr,
108: wdc_atapi_kill_pending,
109: };
110:
1.2 bouyer 111: void
1.65 thorpej 112: wdc_atapibus_attach(struct atabus_softc *ata_sc)
1.2 bouyer 113: {
1.66 thorpej 114: struct wdc_channel *chp = ata_sc->sc_chan;
1.67 thorpej 115: struct wdc_softc *wdc = chp->ch_wdc;
1.40 bouyer 116: struct scsipi_adapter *adapt = &wdc->sc_atapi_adapter._generic;
117: struct scsipi_channel *chan = &chp->ch_atapi_channel;
1.2 bouyer 118:
1.9 thorpej 119: /*
1.40 bouyer 120: * Fill in the scsipi_adapter.
1.9 thorpej 121: */
1.40 bouyer 122: adapt->adapt_dev = &wdc->sc_dev;
123: adapt->adapt_nchannels = wdc->nchannels;
124: adapt->adapt_request = wdc_atapi_scsipi_request;
125: adapt->adapt_minphys = wdc_atapi_minphys;
1.42 bjh21 126: if (wdc->cap & WDC_CAPABILITY_NOIRQ)
127: adapt->adapt_flags |= SCSIPI_ADAPT_POLL_ONLY;
1.40 bouyer 128: wdc->sc_atapi_adapter.atapi_probe_device = wdc_atapi_probe_device;
129:
130: /*
131: * Fill in the scsipi_channel.
132: */
133: memset(chan, 0, sizeof(*chan));
134: chan->chan_adapter = adapt;
135: chan->chan_bustype = &wdc_atapi_bustype;
1.67 thorpej 136: chan->chan_channel = chp->ch_channel;
1.40 bouyer 137: chan->chan_flags = SCSIPI_CHAN_OPENINGS;
138: chan->chan_openings = 1;
139: chan->chan_max_periph = 1;
140: chan->chan_ntargets = 2;
141: chan->chan_nluns = 1;
142:
1.59 bouyer 143: chp->atapibus = config_found(&ata_sc->sc_dev, chan, atapiprint);
1.2 bouyer 144: }
145:
1.65 thorpej 146: static void
147: wdc_atapi_minphys(struct buf *bp)
1.2 bouyer 148: {
1.40 bouyer 149:
150: if (bp->b_bcount > MAX_SIZE)
1.2 bouyer 151: bp->b_bcount = MAX_SIZE;
152: minphys(bp);
153: }
154:
1.28 enami 155: /*
1.40 bouyer 156: * Kill off all pending xfers for a periph.
1.28 enami 157: *
158: * Must be called at splbio().
159: */
1.65 thorpej 160: static void
161: wdc_atapi_kill_pending(struct scsipi_periph *periph)
1.28 enami 162: {
1.40 bouyer 163: struct wdc_softc *wdc =
164: (void *)periph->periph_channel->chan_adapter->adapt_dev;
1.66 thorpej 165: struct wdc_channel *chp =
1.40 bouyer 166: wdc->channels[periph->periph_channel->chan_channel];
1.28 enami 167:
1.82 thorpej 168: ata_kill_pending(&chp->ch_drive[periph->periph_target]);
1.28 enami 169: }
170:
1.65 thorpej 171: static void
1.71 bouyer 172: wdc_atapi_kill_xfer(struct wdc_channel *chp, struct ata_xfer *xfer, int reason)
1.28 enami 173: {
1.63 thorpej 174: struct scsipi_xfer *sc_xfer = xfer->c_cmd;
1.28 enami 175:
176: /* remove this command from xfer queue */
1.71 bouyer 177: switch (reason) {
178: case KILL_GONE:
179: sc_xfer->error = XS_DRIVER_STUFFUP;
180: break;
181: case KILL_RESET:
182: sc_xfer->error = XS_RESET;
183: break;
184: default:
185: printf("wdc_ata_bio_kill_xfer: unknown reason %d\n",
186: reason);
187: panic("wdc_ata_bio_kill_xfer");
188: }
1.81 thorpej 189: ata_free_xfer(chp, xfer);
1.73 bouyer 190: scsipi_done(sc_xfer);
1.28 enami 191: }
192:
1.65 thorpej 193: static int
194: wdc_atapi_get_params(struct scsipi_channel *chan, int drive,
195: struct ataparams *id)
1.2 bouyer 196: {
1.40 bouyer 197: struct wdc_softc *wdc = (void *)chan->chan_adapter->adapt_dev;
1.66 thorpej 198: struct wdc_channel *chp = wdc->channels[chan->chan_channel];
1.78 thorpej 199: struct ata_command ata_c;
1.2 bouyer 200:
201: /* if no ATAPI device detected at wdc attach time, skip */
202: if ((chp->ch_drive[drive].drive_flags & DRIVE_ATAPI) == 0) {
1.86 ! thorpej 203: ATADEBUG_PRINT(("wdc_atapi_get_params: drive %d not present\n",
1.2 bouyer 204: drive), DEBUG_PROBE);
205: return -1;
206: }
1.59 bouyer 207:
1.78 thorpej 208: memset(&ata_c, 0, sizeof(struct ata_command));
209: ata_c.r_command = ATAPI_SOFT_RESET;
210: ata_c.r_st_bmask = 0;
211: ata_c.r_st_pmask = 0;
212: ata_c.flags = AT_WAIT | AT_POLL;
213: ata_c.timeout = WDC_RESET_WAIT;
1.79 thorpej 214: if (wdc_exec_command(&chp->ch_drive[drive], &ata_c) != ATACMD_COMPLETE) {
1.59 bouyer 215: printf("wdc_atapi_get_params: ATAPI_SOFT_RESET failed for"
216: " drive %s:%d:%d: driver failed\n",
1.67 thorpej 217: wdc->sc_dev.dv_xname, chp->ch_channel, drive);
1.59 bouyer 218: panic("wdc_atapi_get_params");
219: }
1.78 thorpej 220: if (ata_c.flags & (AT_ERROR | AT_TIMEOU | AT_DF)) {
1.86 ! thorpej 221: ATADEBUG_PRINT(("wdc_atapi_get_params: ATAPI_SOFT_RESET "
1.59 bouyer 222: "failed for drive %s:%d:%d: error 0x%x\n",
1.67 thorpej 223: wdc->sc_dev.dv_xname, chp->ch_channel, drive,
1.78 thorpej 224: ata_c.r_error), DEBUG_PROBE);
1.2 bouyer 225: return -1;
226: }
1.59 bouyer 227: chp->ch_drive[drive].state = 0;
1.2 bouyer 228:
1.62 fvdl 229: bus_space_read_1(chp->cmd_iot, chp->cmd_iohs[wd_status], 0);
1.59 bouyer 230:
1.2 bouyer 231: /* Some ATAPI devices need a bit more time after software reset. */
232: delay(5000);
1.57 mycroft 233: if (ata_get_params(&chp->ch_drive[drive], AT_WAIT, id) != 0) {
1.86 ! thorpej 234: ATADEBUG_PRINT(("wdc_atapi_get_params: ATAPI_IDENTIFY_DEVICE "
1.2 bouyer 235: "failed for drive %s:%d:%d: error 0x%x\n",
1.67 thorpej 236: wdc->sc_dev.dv_xname, chp->ch_channel, drive,
1.78 thorpej 237: ata_c.r_error), DEBUG_PROBE);
1.2 bouyer 238: return -1;
239: }
1.40 bouyer 240: return 0;
1.2 bouyer 241: }
242:
1.65 thorpej 243: static void
244: wdc_atapi_probe_device(struct atapibus_softc *sc, int target)
1.33 bouyer 245: {
1.40 bouyer 246: struct scsipi_channel *chan = sc->sc_channel;
247: struct scsipi_periph *periph;
1.33 bouyer 248: struct ataparams ids;
249: struct ataparams *id = &ids;
1.46 bouyer 250: struct wdc_softc *wdc = (void *)chan->chan_adapter->adapt_dev;
1.66 thorpej 251: struct wdc_channel *chp = wdc->channels[chan->chan_channel];
1.46 bouyer 252: struct ata_drive_datas *drvp = &chp->ch_drive[target];
1.40 bouyer 253: struct scsipibus_attach_args sa;
1.33 bouyer 254: char serial_number[21], model[41], firmware_revision[9];
255:
1.40 bouyer 256: /* skip if already attached */
257: if (scsipi_lookup_periph(chan, target, 0) != NULL)
1.33 bouyer 258: return;
1.40 bouyer 259:
1.57 mycroft 260: if (wdc_atapi_get_params(chan, target, id) == 0) {
1.33 bouyer 261: #ifdef ATAPI_DEBUG_PROBE
262: printf("%s drive %d: cmdsz 0x%x drqtype 0x%x\n",
1.40 bouyer 263: sc->sc_dev.dv_xname, target,
1.33 bouyer 264: id->atap_config & ATAPI_CFG_CMD_MASK,
265: id->atap_config & ATAPI_CFG_DRQ_MASK);
266: #endif
1.40 bouyer 267: periph = scsipi_alloc_periph(M_NOWAIT);
268: if (periph == NULL) {
269: printf("%s: unable to allocate periph for drive %d\n",
270: sc->sc_dev.dv_xname, target);
271: return;
1.33 bouyer 272: }
1.40 bouyer 273: periph->periph_dev = NULL;
274: periph->periph_channel = chan;
275: periph->periph_switch = &atapi_probe_periphsw;
276: periph->periph_target = target;
277: periph->periph_lun = 0;
1.56 mycroft 278: periph->periph_quirks = PQUIRK_ONLYBIG;
1.40 bouyer 279:
280: #ifdef SCSIPI_DEBUG
281: if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_ATAPI &&
282: SCSIPI_DEBUG_TARGET == target)
283: periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS;
284: #endif
285: periph->periph_type = ATAPI_CFG_TYPE(id->atap_config);
286: if (id->atap_config & ATAPI_CFG_REMOV)
287: periph->periph_flags |= PERIPH_REMOVABLE;
1.45 bouyer 288: if (periph->periph_type == T_SEQUENTIAL)
289: drvp->drive_flags |= DRIVE_ATAPIST;
1.40 bouyer 290:
291: sa.sa_periph = periph;
292: sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
293: sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
294: T_REMOV : T_FIXED;
1.33 bouyer 295: scsipi_strvis(model, 40, id->atap_model, 40);
1.40 bouyer 296: scsipi_strvis(serial_number, 20, id->atap_serial, 20);
1.33 bouyer 297: scsipi_strvis(firmware_revision, 8, id->atap_revision, 8);
298: sa.sa_inqbuf.vendor = model;
299: sa.sa_inqbuf.product = serial_number;
300: sa.sa_inqbuf.revision = firmware_revision;
1.40 bouyer 301:
302: /*
303: * Determine the operating mode capabilities of the device.
304: */
305: if ((id->atap_config & ATAPI_CFG_CMD_MASK) == ATAPI_CFG_CMD_16)
306: periph->periph_cap |= PERIPH_CAP_CMD16;
307: /* XXX This is gross. */
308: periph->periph_cap |= (id->atap_config & ATAPI_CFG_DRQ_MASK);
309:
310: drvp->drv_softc = atapi_probe_device(sc, target, periph, &sa);
311:
312: if (drvp->drv_softc)
1.80 thorpej 313: ata_probe_caps(drvp);
1.60 bouyer 314: else
315: drvp->drive_flags &= ~DRIVE_ATAPI;
1.69 bouyer 316: } else {
317: drvp->drive_flags &= ~DRIVE_ATAPI;
1.33 bouyer 318: }
319: }
320:
1.65 thorpej 321: static void
322: wdc_atapi_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
323: void *arg)
1.40 bouyer 324: {
325: struct scsipi_adapter *adapt = chan->chan_adapter;
326: struct scsipi_periph *periph;
1.2 bouyer 327: struct scsipi_xfer *sc_xfer;
1.40 bouyer 328: struct wdc_softc *wdc = (void *)adapt->adapt_dev;
1.63 thorpej 329: struct ata_xfer *xfer;
1.40 bouyer 330: int channel = chan->chan_channel;
331: int drive, s;
332:
333: switch (req) {
334: case ADAPTER_REQ_RUN_XFER:
335: sc_xfer = arg;
336: periph = sc_xfer->xs_periph;
337: drive = periph->periph_target;
338:
1.86 ! thorpej 339: ATADEBUG_PRINT(("wdc_atapi_scsipi_request %s:%d:%d\n",
1.40 bouyer 340: wdc->sc_dev.dv_xname, channel, drive), DEBUG_XFERS);
341: if ((wdc->sc_dev.dv_flags & DVF_ACTIVE) == 0) {
342: sc_xfer->error = XS_DRIVER_STUFFUP;
343: scsipi_done(sc_xfer);
344: return;
345: }
346:
1.81 thorpej 347: xfer = ata_get_xfer(ATAXF_NOSLEEP);
1.40 bouyer 348: if (xfer == NULL) {
349: sc_xfer->error = XS_RESOURCE_SHORTAGE;
350: scsipi_done(sc_xfer);
351: return;
352: }
353:
354: if (sc_xfer->xs_control & XS_CTL_POLL)
355: xfer->c_flags |= C_POLL;
1.59 bouyer 356: if ((wdc->channels[channel]->ch_drive[drive].drive_flags &
357: (DRIVE_DMA | DRIVE_UDMA)) && sc_xfer->datalen > 0)
358: xfer->c_flags |= C_DMA;
1.63 thorpej 359: xfer->c_drive = drive;
1.40 bouyer 360: xfer->c_flags |= C_ATAPI;
361: if (sc_xfer->cmd->opcode == GPCMD_REPORT_KEY ||
362: sc_xfer->cmd->opcode == GPCMD_SEND_KEY ||
363: sc_xfer->cmd->opcode == GPCMD_READ_DVD_STRUCTURE) {
364: /*
365: * DVD authentication commands must always be done in
366: * PIO mode.
367: */
1.59 bouyer 368: xfer->c_flags &= ~C_DMA;
1.40 bouyer 369: }
1.52 bouyer 370: /*
371: * DMA can't deal with transfers which are not a multiple of
372: * 2 bytes. It's a bug to request such transfers for ATAPI
373: * but as the request can come from userland, we have to
374: * protect against it.
1.53 bouyer 375: * Also some devices seems to not handle DMA xfers of less than
376: * 4 bytes.
1.52 bouyer 377: */
1.53 bouyer 378: if (sc_xfer->datalen < 4 || (sc_xfer->datalen & 0x01))
1.59 bouyer 379: xfer->c_flags &= ~C_DMA;
1.52 bouyer 380:
1.63 thorpej 381: xfer->c_cmd = sc_xfer;
382: xfer->c_databuf = sc_xfer->data;
1.40 bouyer 383: xfer->c_bcount = sc_xfer->datalen;
384: xfer->c_start = wdc_atapi_start;
385: xfer->c_intr = wdc_atapi_intr;
386: xfer->c_kill_xfer = wdc_atapi_kill_xfer;
1.45 bouyer 387: xfer->c_dscpoll = 0;
1.40 bouyer 388: s = splbio();
1.83 thorpej 389: ata_exec_xfer(wdc->channels[channel], xfer);
1.2 bouyer 390: #ifdef DIAGNOSTIC
1.40 bouyer 391: if ((sc_xfer->xs_control & XS_CTL_POLL) != 0 &&
392: (sc_xfer->xs_status & XS_STS_DONE) == 0)
393: panic("wdc_atapi_scsipi_request: polled command "
394: "not done");
1.2 bouyer 395: #endif
1.40 bouyer 396: splx(s);
397: return;
398:
399: default:
400: /* Not supported, nothing to do. */
1.41 lukem 401: ;
1.40 bouyer 402: }
1.2 bouyer 403: }
404:
1.65 thorpej 405: static void
1.66 thorpej 406: wdc_atapi_start(struct wdc_channel *chp, struct ata_xfer *xfer)
1.2 bouyer 407: {
1.67 thorpej 408: struct wdc_softc *wdc = chp->ch_wdc;
1.63 thorpej 409: struct scsipi_xfer *sc_xfer = xfer->c_cmd;
410: struct ata_drive_datas *drvp = &chp->ch_drive[xfer->c_drive];
1.59 bouyer 411: int wait_flags = (sc_xfer->xs_control & XS_CTL_POLL) ? AT_POLL : 0;
412: char *errstring;
1.2 bouyer 413:
1.86 ! thorpej 414: ATADEBUG_PRINT(("wdc_atapi_start %s:%d:%d, scsi flags 0x%x \n",
1.67 thorpej 415: wdc->sc_dev.dv_xname, chp->ch_channel, drvp->drive,
1.27 thorpej 416: sc_xfer->xs_control), DEBUG_XFERS);
1.59 bouyer 417: if ((xfer->c_flags & C_DMA) && (drvp->n_xfers <= NXFER))
418: drvp->n_xfers++;
419: /* Do control operations specially. */
420: if (__predict_false(drvp->state < READY)) {
421: /* If it's not a polled command, we need the kenrel thread */
422: if ((sc_xfer->xs_control & XS_CTL_POLL) == 0 &&
423: (chp->ch_flags & WDCF_TH_RUN) == 0) {
1.61 bouyer 424: chp->ch_queue->queue_freeze++;
1.68 thorpej 425: wakeup(&chp->ch_thread);
1.59 bouyer 426: return;
427: }
428: /*
429: * disable interrupts, all commands here should be quick
430: * enouth to be able to poll, and we don't go here that often
431: */
432: bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
433: WDCTL_4BIT | WDCTL_IDS);
1.85 thorpej 434: if (wdc->select)
1.67 thorpej 435: wdc->select(chp, xfer->c_drive);
1.62 fvdl 436: bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
1.63 thorpej 437: WDSD_IBM | (xfer->c_drive << 4));
1.59 bouyer 438: /* Don't try to set mode if controller can't be adjusted */
1.85 thorpej 439: if (wdc->set_modes == NULL)
1.59 bouyer 440: goto ready;
441: /* Also don't try if the drive didn't report its mode */
442: if ((drvp->drive_flags & DRIVE_MODE) == 0)
443: goto ready;
444: errstring = "unbusy";
1.64 thorpej 445: if (wdc_wait_for_unbusy(chp, ATAPI_DELAY, wait_flags))
1.59 bouyer 446: goto timeout;
447: wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
448: 0x08 | drvp->PIO_mode, WDSF_SET_MODE);
449: errstring = "piomode";
1.64 thorpej 450: if (wdc_wait_for_unbusy(chp, ATAPI_MODE_DELAY, wait_flags))
1.59 bouyer 451: goto timeout;
452: if (chp->ch_status & WDCS_ERR) {
453: if (chp->ch_error == WDCE_ABRT) {
454: /*
1.76 mycroft 455: * Some ATAPI drives reject PIO settings.
456: * Fall back to PIO mode 3 since that's the
457: * minimum for ATAPI.
1.59 bouyer 458: */
1.76 mycroft 459: printf("%s:%d:%d: PIO mode %d rejected, "
460: "falling back to PIO mode 3\n",
1.67 thorpej 461: wdc->sc_dev.dv_xname,
1.76 mycroft 462: chp->ch_channel, xfer->c_drive,
463: drvp->PIO_mode);
464: if (drvp->PIO_mode > 3)
465: drvp->PIO_mode = 3;
466: } else
467: goto error;
1.59 bouyer 468: }
469: if (drvp->drive_flags & DRIVE_UDMA) {
470: wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
471: 0x40 | drvp->UDMA_mode, WDSF_SET_MODE);
472: } else if (drvp->drive_flags & DRIVE_DMA) {
473: wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
474: 0x20 | drvp->DMA_mode, WDSF_SET_MODE);
475: } else {
476: goto ready;
477: }
478: errstring = "dmamode";
1.64 thorpej 479: if (wdc_wait_for_unbusy(chp, ATAPI_MODE_DELAY, wait_flags))
1.59 bouyer 480: goto timeout;
1.76 mycroft 481: if (chp->ch_status & WDCS_ERR) {
482: if (chp->ch_error == WDCE_ABRT) {
483: if (drvp->drive_flags & DRIVE_UDMA)
484: goto error;
485: else {
486: /*
487: * The drive rejected our DMA setting.
488: * Fall back to mode 1.
489: */
490: printf("%s:%d:%d: DMA mode %d rejected, "
491: "falling back to DMA mode 0\n",
492: wdc->sc_dev.dv_xname,
493: chp->ch_channel, xfer->c_drive,
494: drvp->DMA_mode);
495: if (drvp->DMA_mode > 0)
496: drvp->DMA_mode = 0;
497: }
498: } else
499: goto error;
500: }
1.59 bouyer 501: ready:
502: drvp->state = READY;
503: bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
504: WDCTL_4BIT);
1.70 bouyer 505: delay(10); /* some drives need a little delay here */
1.30 bouyer 506: }
1.24 bouyer 507: /* start timeout machinery */
1.27 thorpej 508: if ((sc_xfer->xs_control & XS_CTL_POLL) == 0)
1.50 bouyer 509: callout_reset(&chp->ch_callout, mstohz(sc_xfer->timeout),
1.32 thorpej 510: wdctimeout, chp);
1.59 bouyer 511:
1.85 thorpej 512: if (wdc->select)
1.67 thorpej 513: wdc->select(chp, xfer->c_drive);
1.62 fvdl 514: bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
1.63 thorpej 515: WDSD_IBM | (xfer->c_drive << 4));
1.64 thorpej 516: switch (wdc_wait_for_unbusy(chp, ATAPI_DELAY, wait_flags) < 0) {
1.59 bouyer 517: case WDCWAIT_OK:
518: break;
519: case WDCWAIT_TOUT:
1.2 bouyer 520: printf("wdc_atapi_start: not ready, st = %02x\n",
521: chp->ch_status);
1.3 bouyer 522: sc_xfer->error = XS_TIMEOUT;
1.2 bouyer 523: wdc_atapi_reset(chp, xfer);
524: return;
1.59 bouyer 525: case WDCWAIT_THR:
526: return;
1.2 bouyer 527: }
528:
529: /*
530: * Even with WDCS_ERR, the device should accept a command packet
531: * Limit length to what can be stuffed into the cylinder register
532: * (16 bits). Some CD-ROMs seem to interpret '0' as 65536,
533: * but not all devices do that and it's not obvious from the
534: * ATAPI spec that that behaviour should be expected. If more
535: * data is necessary, multiple data transfer phases will be done.
536: */
1.5 bouyer 537:
1.63 thorpej 538: wdccommand(chp, xfer->c_drive, ATAPI_PKT_CMD,
1.29 bouyer 539: xfer->c_bcount <= 0xffff ? xfer->c_bcount : 0xffff,
1.2 bouyer 540: 0, 0, 0,
541: (xfer->c_flags & C_DMA) ? ATAPI_PKT_CMD_FTRE_DMA : 0);
542:
543: /*
544: * If there is no interrupt for CMD input, busy-wait for it (done in
545: * the interrupt routine. If it is a polled command, call the interrupt
546: * routine until command is done.
547: */
1.40 bouyer 548: if ((sc_xfer->xs_periph->periph_cap & ATAPI_CFG_DRQ_MASK) !=
1.27 thorpej 549: ATAPI_CFG_IRQ_DRQ || (sc_xfer->xs_control & XS_CTL_POLL)) {
1.2 bouyer 550: /* Wait for at last 400ns for status bit to be valid */
1.20 bouyer 551: DELAY(1);
552: wdc_atapi_intr(chp, xfer, 0);
1.21 bouyer 553: } else {
554: chp->ch_flags |= WDCF_IRQ_WAIT;
1.2 bouyer 555: }
1.27 thorpej 556: if (sc_xfer->xs_control & XS_CTL_POLL) {
1.73 bouyer 557: if (chp->ch_flags & WDCF_DMA_WAIT) {
558: wdc_dmawait(chp, xfer, sc_xfer->timeout);
559: chp->ch_flags &= ~WDCF_DMA_WAIT;
560: }
1.27 thorpej 561: while ((sc_xfer->xs_status & XS_STS_DONE) == 0) {
1.2 bouyer 562: /* Wait for at last 400ns for status bit to be valid */
1.20 bouyer 563: DELAY(1);
564: wdc_atapi_intr(chp, xfer, 0);
1.2 bouyer 565: }
566: }
1.59 bouyer 567: return;
568: timeout:
569: printf("%s:%d:%d: %s timed out\n",
1.67 thorpej 570: wdc->sc_dev.dv_xname, chp->ch_channel, xfer->c_drive,
571: errstring);
1.59 bouyer 572: sc_xfer->error = XS_TIMEOUT;
573: bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr, WDCTL_4BIT);
1.70 bouyer 574: delay(10); /* some drives need a little delay here */
1.59 bouyer 575: wdc_atapi_reset(chp, xfer);
576: return;
577: error:
578: printf("%s:%d:%d: %s ",
1.67 thorpej 579: wdc->sc_dev.dv_xname, chp->ch_channel, xfer->c_drive,
1.59 bouyer 580: errstring);
581: printf("error (0x%x)\n", chp->ch_error);
582: sc_xfer->error = XS_SHORTSENSE;
583: sc_xfer->sense.atapi_sense = chp->ch_error;
584: bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr, WDCTL_4BIT);
1.70 bouyer 585: delay(10); /* some drives need a little delay here */
1.59 bouyer 586: wdc_atapi_reset(chp, xfer);
587: return;
1.2 bouyer 588: }
589:
1.65 thorpej 590: static int
1.66 thorpej 591: wdc_atapi_intr(struct wdc_channel *chp, struct ata_xfer *xfer, int irq)
1.2 bouyer 592: {
1.67 thorpej 593: struct wdc_softc *wdc = chp->ch_wdc;
1.63 thorpej 594: struct scsipi_xfer *sc_xfer = xfer->c_cmd;
595: struct ata_drive_datas *drvp = &chp->ch_drive[xfer->c_drive];
1.2 bouyer 596: int len, phase, i, retries=0;
1.33 bouyer 597: int ire;
1.2 bouyer 598: int dma_flags = 0;
1.8 bouyer 599: void *cmd;
1.2 bouyer 600:
1.86 ! thorpej 601: ATADEBUG_PRINT(("wdc_atapi_intr %s:%d:%d\n",
1.67 thorpej 602: wdc->sc_dev.dv_xname, chp->ch_channel, drvp->drive),
603: DEBUG_INTR);
1.2 bouyer 604:
605: /* Is it not a transfer, but a control operation? */
606: if (drvp->state < READY) {
607: printf("%s:%d:%d: bad state %d in wdc_atapi_intr\n",
1.67 thorpej 608: wdc->sc_dev.dv_xname, chp->ch_channel, xfer->c_drive,
1.2 bouyer 609: drvp->state);
1.55 provos 610: panic("wdc_atapi_intr: bad state");
1.2 bouyer 611: }
1.24 bouyer 612: /*
613: * If we missed an interrupt in a PIO transfer, reset and restart.
614: * Don't try to continue transfer, we may have missed cycles.
615: */
616: if ((xfer->c_flags & (C_TIMEOU | C_DMA)) == C_TIMEOU) {
617: sc_xfer->error = XS_TIMEOUT;
618: wdc_atapi_reset(chp, xfer);
1.25 bouyer 619: return 1;
1.24 bouyer 620: }
621:
1.64 thorpej 622: /* Ack interrupt done in wdc_wait_for_unbusy */
1.85 thorpej 623: if (wdc->select)
1.67 thorpej 624: wdc->select(chp, xfer->c_drive);
1.62 fvdl 625: bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
1.63 thorpej 626: WDSD_IBM | (xfer->c_drive << 4));
1.64 thorpej 627: if (wdc_wait_for_unbusy(chp,
1.59 bouyer 628: (irq == 0) ? sc_xfer->timeout : 0, AT_POLL) == WDCWAIT_TOUT) {
1.20 bouyer 629: if (irq && (xfer->c_flags & C_TIMEOU) == 0)
1.19 bouyer 630: return 0; /* IRQ was not for us */
1.16 bouyer 631: printf("%s:%d:%d: device timeout, c_bcount=%d, c_skip=%d\n",
1.67 thorpej 632: wdc->sc_dev.dv_xname, chp->ch_channel, xfer->c_drive,
1.2 bouyer 633: xfer->c_bcount, xfer->c_skip);
1.33 bouyer 634: if (xfer->c_flags & C_DMA) {
1.59 bouyer 635: ata_dmaerr(drvp,
636: (xfer->c_flags & C_POLL) ? AT_POLL : 0);
1.33 bouyer 637: }
1.3 bouyer 638: sc_xfer->error = XS_TIMEOUT;
1.2 bouyer 639: wdc_atapi_reset(chp, xfer);
640: return 1;
641: }
1.85 thorpej 642: if (wdc->irqack)
1.67 thorpej 643: wdc->irqack(chp);
1.36 bouyer 644:
1.48 bouyer 645: /*
646: * If we missed an IRQ and were using DMA, flag it as a DMA error
647: * and reset device.
648: */
1.33 bouyer 649: if ((xfer->c_flags & C_TIMEOU) && (xfer->c_flags & C_DMA)) {
1.59 bouyer 650: ata_dmaerr(drvp, (xfer->c_flags & C_POLL) ? AT_POLL : 0);
1.48 bouyer 651: sc_xfer->error = XS_RESET;
652: wdc_atapi_reset(chp, xfer);
653: return (1);
1.33 bouyer 654: }
1.8 bouyer 655: /*
656: * if the request sense command was aborted, report the short sense
657: * previously recorded, else continue normal processing
658: */
659:
1.33 bouyer 660: if (xfer->c_flags & C_DMA)
1.40 bouyer 661: dma_flags = (sc_xfer->xs_control & XS_CTL_DATA_IN)
662: ? WDC_DMA_READ : 0;
1.2 bouyer 663: again:
1.62 fvdl 664: len = bus_space_read_1(chp->cmd_iot, chp->cmd_iohs[wd_cyl_lo], 0) +
665: 256 * bus_space_read_1(chp->cmd_iot, chp->cmd_iohs[wd_cyl_hi], 0);
666: ire = bus_space_read_1(chp->cmd_iot, chp->cmd_iohs[wd_ireason], 0);
1.2 bouyer 667: phase = (ire & (WDCI_CMD | WDCI_IN)) | (chp->ch_status & WDCS_DRQ);
1.86 ! thorpej 668: ATADEBUG_PRINT(("wdc_atapi_intr: c_bcount %d len %d st 0x%x err 0x%x "
1.2 bouyer 669: "ire 0x%x :", xfer->c_bcount,
670: len, chp->ch_status, chp->ch_error, ire), DEBUG_INTR);
671:
672: switch (phase) {
673: case PHASE_CMDOUT:
1.57 mycroft 674: cmd = sc_xfer->cmd;
1.86 ! thorpej 675: ATADEBUG_PRINT(("PHASE_CMDOUT\n"), DEBUG_INTR);
1.2 bouyer 676: /* Init the DMA channel if necessary */
677: if (xfer->c_flags & C_DMA) {
1.67 thorpej 678: if ((*wdc->dma_init)(wdc->dma_arg,
679: chp->ch_channel, xfer->c_drive,
1.63 thorpej 680: xfer->c_databuf, xfer->c_bcount, dma_flags) != 0) {
1.2 bouyer 681: sc_xfer->error = XS_DRIVER_STUFFUP;
682: break;
683: }
684: }
1.75 mycroft 685:
1.2 bouyer 686: /* send packet command */
687: /* Commands are 12 or 16 bytes long. It's 32-bit aligned */
1.77 mycroft 688: wdc->dataout_pio(chp, drvp->drive_flags, cmd, sc_xfer->cmdlen);
1.75 mycroft 689:
1.2 bouyer 690: /* Start the DMA channel if necessary */
691: if (xfer->c_flags & C_DMA) {
1.67 thorpej 692: (*wdc->dma_start)(wdc->dma_arg,
693: chp->ch_channel, xfer->c_drive);
1.33 bouyer 694: chp->ch_flags |= WDCF_DMA_WAIT;
1.2 bouyer 695: }
696:
1.27 thorpej 697: if ((sc_xfer->xs_control & XS_CTL_POLL) == 0) {
1.2 bouyer 698: chp->ch_flags |= WDCF_IRQ_WAIT;
699: }
700: return 1;
701:
702: case PHASE_DATAOUT:
703: /* write data */
1.86 ! thorpej 704: ATADEBUG_PRINT(("PHASE_DATAOUT\n"), DEBUG_INTR);
1.27 thorpej 705: if ((sc_xfer->xs_control & XS_CTL_DATA_OUT) == 0 ||
1.2 bouyer 706: (xfer->c_flags & C_DMA) != 0) {
1.15 bouyer 707: printf("wdc_atapi_intr: bad data phase DATAOUT\n");
1.2 bouyer 708: if (xfer->c_flags & C_DMA) {
1.59 bouyer 709: ata_dmaerr(drvp,
710: (xfer->c_flags & C_POLL) ? AT_POLL : 0);
1.2 bouyer 711: }
1.3 bouyer 712: sc_xfer->error = XS_TIMEOUT;
1.2 bouyer 713: wdc_atapi_reset(chp, xfer);
714: return 1;
715: }
716: if (xfer->c_bcount < len) {
717: printf("wdc_atapi_intr: warning: write only "
718: "%d of %d requested bytes\n", xfer->c_bcount, len);
1.77 mycroft 719: wdc->dataout_pio(chp, drvp->drive_flags,
1.75 mycroft 720: (char *)xfer->c_databuf + xfer->c_skip,
721: xfer->c_bcount);
1.2 bouyer 722: for (i = xfer->c_bcount; i < len; i += 2)
1.62 fvdl 723: bus_space_write_2(chp->cmd_iot,
724: chp->cmd_iohs[wd_data], 0, 0);
1.2 bouyer 725: xfer->c_skip += xfer->c_bcount;
726: xfer->c_bcount = 0;
727: } else {
1.77 mycroft 728: wdc->dataout_pio(chp, drvp->drive_flags,
1.75 mycroft 729: (char *)xfer->c_databuf + xfer->c_skip, len);
730: xfer->c_skip += len;
731: xfer->c_bcount -= len;
1.2 bouyer 732: }
1.27 thorpej 733: if ((sc_xfer->xs_control & XS_CTL_POLL) == 0) {
1.2 bouyer 734: chp->ch_flags |= WDCF_IRQ_WAIT;
735: }
736: return 1;
737:
738: case PHASE_DATAIN:
739: /* Read data */
1.86 ! thorpej 740: ATADEBUG_PRINT(("PHASE_DATAIN\n"), DEBUG_INTR);
1.40 bouyer 741: if ((sc_xfer->xs_control & XS_CTL_DATA_IN) == 0 ||
1.2 bouyer 742: (xfer->c_flags & C_DMA) != 0) {
1.15 bouyer 743: printf("wdc_atapi_intr: bad data phase DATAIN\n");
1.2 bouyer 744: if (xfer->c_flags & C_DMA) {
1.59 bouyer 745: ata_dmaerr(drvp,
746: (xfer->c_flags & C_POLL) ? AT_POLL : 0);
1.2 bouyer 747: }
1.3 bouyer 748: sc_xfer->error = XS_TIMEOUT;
1.2 bouyer 749: wdc_atapi_reset(chp, xfer);
750: return 1;
751: }
752: if (xfer->c_bcount < len) {
753: printf("wdc_atapi_intr: warning: reading only "
754: "%d of %d bytes\n", xfer->c_bcount, len);
1.77 mycroft 755: wdc->datain_pio(chp, drvp->drive_flags,
1.75 mycroft 756: (char *)xfer->c_databuf + xfer->c_skip,
757: xfer->c_bcount);
1.2 bouyer 758: wdcbit_bucket(chp, len - xfer->c_bcount);
759: xfer->c_skip += xfer->c_bcount;
760: xfer->c_bcount = 0;
761: } else {
1.77 mycroft 762: wdc->datain_pio(chp, drvp->drive_flags,
1.75 mycroft 763: (char *)xfer->c_databuf + xfer->c_skip, len);
764: xfer->c_skip += len;
765: xfer->c_bcount -=len;
1.2 bouyer 766: }
1.27 thorpej 767: if ((sc_xfer->xs_control & XS_CTL_POLL) == 0) {
1.2 bouyer 768: chp->ch_flags |= WDCF_IRQ_WAIT;
769: }
770: return 1;
771:
772: case PHASE_ABORTED:
773: case PHASE_COMPLETED:
1.86 ! thorpej 774: ATADEBUG_PRINT(("PHASE_COMPLETED\n"), DEBUG_INTR);
1.2 bouyer 775: if (xfer->c_flags & C_DMA) {
1.40 bouyer 776: xfer->c_bcount -= sc_xfer->datalen;
777: }
778: sc_xfer->resid = xfer->c_bcount;
1.45 bouyer 779: wdc_atapi_phase_complete(xfer);
780: return(1);
1.2 bouyer 781:
782: default:
783: if (++retries<500) {
784: DELAY(100);
785: chp->ch_status = bus_space_read_1(chp->cmd_iot,
1.62 fvdl 786: chp->cmd_iohs[wd_status], 0);
1.2 bouyer 787: chp->ch_error = bus_space_read_1(chp->cmd_iot,
1.62 fvdl 788: chp->cmd_iohs[wd_error], 0);
1.2 bouyer 789: goto again;
790: }
791: printf("wdc_atapi_intr: unknown phase 0x%x\n", phase);
792: if (chp->ch_status & WDCS_ERR) {
1.8 bouyer 793: sc_xfer->error = XS_SHORTSENSE;
1.2 bouyer 794: sc_xfer->sense.atapi_sense = chp->ch_error;
795: } else {
1.33 bouyer 796: if (xfer->c_flags & C_DMA) {
1.59 bouyer 797: ata_dmaerr(drvp,
798: (xfer->c_flags & C_POLL) ? AT_POLL : 0);
1.33 bouyer 799: }
1.16 bouyer 800: sc_xfer->error = XS_RESET;
801: wdc_atapi_reset(chp, xfer);
802: return (1);
1.2 bouyer 803: }
804: }
1.86 ! thorpej 805: ATADEBUG_PRINT(("wdc_atapi_intr: wdc_atapi_done() (end), error 0x%x "
1.2 bouyer 806: "sense 0x%x\n", sc_xfer->error, sc_xfer->sense.atapi_sense),
807: DEBUG_INTR);
808: wdc_atapi_done(chp, xfer);
809: return (1);
810: }
811:
1.65 thorpej 812: static void
813: wdc_atapi_phase_complete(struct ata_xfer *xfer)
1.45 bouyer 814: {
1.66 thorpej 815: struct wdc_channel *chp = xfer->c_chp;
1.67 thorpej 816: struct wdc_softc *wdc = chp->ch_wdc;
1.63 thorpej 817: struct scsipi_xfer *sc_xfer = xfer->c_cmd;
818: struct ata_drive_datas *drvp = &chp->ch_drive[xfer->c_drive];
1.45 bouyer 819:
820: /* wait for DSC if needed */
821: if (drvp->drive_flags & DRIVE_ATAPIST) {
1.86 ! thorpej 822: ATADEBUG_PRINT(("wdc_atapi_phase_complete(%s:%d:%d) "
1.67 thorpej 823: "polldsc %d\n", wdc->sc_dev.dv_xname, chp->ch_channel,
1.63 thorpej 824: xfer->c_drive, xfer->c_dscpoll), DEBUG_XFERS);
1.57 mycroft 825: #if 1
826: if (cold)
827: panic("wdc_atapi_phase_complete: cold");
828: #endif
1.59 bouyer 829: if (wdcwait(chp, WDCS_DSC, WDCS_DSC, 10,
830: AT_POLL) == WDCWAIT_TOUT) {
1.57 mycroft 831: /* 10ms not enough, try again in 1 tick */
832: if (xfer->c_dscpoll++ >
833: mstohz(sc_xfer->timeout)) {
1.59 bouyer 834: printf("%s:%d:%d: wait_for_dsc "
835: "failed\n",
1.67 thorpej 836: wdc->sc_dev.dv_xname,
837: chp->ch_channel, xfer->c_drive);
1.45 bouyer 838: sc_xfer->error = XS_TIMEOUT;
839: wdc_atapi_reset(chp, xfer);
1.59 bouyer 840: return;
1.57 mycroft 841: } else
1.45 bouyer 842: callout_reset(&chp->ch_callout, 1,
843: wdc_atapi_polldsc, xfer);
1.57 mycroft 844: return;
1.45 bouyer 845: }
846: }
847:
848: /*
849: * Some drive occasionally set WDCS_ERR with
850: * "ATA illegal length indication" in the error
851: * register. If we read some data the sense is valid
852: * anyway, so don't report the error.
853: */
854: if (chp->ch_status & WDCS_ERR &&
855: ((sc_xfer->xs_control & XS_CTL_REQSENSE) == 0 ||
856: sc_xfer->resid == sc_xfer->datalen)) {
857: /* save the short sense */
858: sc_xfer->error = XS_SHORTSENSE;
859: sc_xfer->sense.atapi_sense = chp->ch_error;
860: if ((sc_xfer->xs_periph->periph_quirks &
861: PQUIRK_NOSENSE) == 0) {
862: /* ask scsipi to send a REQUEST_SENSE */
863: sc_xfer->error = XS_BUSY;
864: sc_xfer->status = SCSI_CHECK;
1.67 thorpej 865: } else if (wdc->dma_status &
1.45 bouyer 866: (WDC_DMAST_NOIRQ | WDC_DMAST_ERR)) {
1.59 bouyer 867: ata_dmaerr(drvp,
868: (xfer->c_flags & C_POLL) ? AT_POLL : 0);
1.45 bouyer 869: sc_xfer->error = XS_RESET;
870: wdc_atapi_reset(chp, xfer);
871: return;
872: }
873: }
874: if (xfer->c_bcount != 0) {
1.86 ! thorpej 875: ATADEBUG_PRINT(("wdc_atapi_intr: bcount value is "
1.45 bouyer 876: "%d after io\n", xfer->c_bcount), DEBUG_XFERS);
877: }
878: #ifdef DIAGNOSTIC
879: if (xfer->c_bcount < 0) {
880: printf("wdc_atapi_intr warning: bcount value "
881: "is %d after io\n", xfer->c_bcount);
882: }
883: #endif
1.86 ! thorpej 884: ATADEBUG_PRINT(("wdc_atapi_phase_complete: wdc_atapi_done(), "
1.45 bouyer 885: "error 0x%x sense 0x%x\n", sc_xfer->error,
886: sc_xfer->sense.atapi_sense), DEBUG_INTR);
887: wdc_atapi_done(chp, xfer);
888: }
889:
1.65 thorpej 890: static void
1.66 thorpej 891: wdc_atapi_done(struct wdc_channel *chp, struct ata_xfer *xfer)
1.2 bouyer 892: {
1.67 thorpej 893: struct wdc_softc *wdc = chp->ch_wdc;
1.63 thorpej 894: struct scsipi_xfer *sc_xfer = xfer->c_cmd;
1.74 bouyer 895: int drive = xfer->c_drive;
1.2 bouyer 896:
1.86 ! thorpej 897: ATADEBUG_PRINT(("wdc_atapi_done %s:%d:%d: flags 0x%x\n",
1.67 thorpej 898: wdc->sc_dev.dv_xname, chp->ch_channel, xfer->c_drive,
1.5 bouyer 899: (u_int)xfer->c_flags), DEBUG_XFERS);
1.32 thorpej 900: callout_stop(&chp->ch_callout);
1.73 bouyer 901: /* mark controller inactive and free the command */
902: chp->ch_queue->active_xfer = NULL;
1.81 thorpej 903: ata_free_xfer(chp, xfer);
1.40 bouyer 904:
1.74 bouyer 905: if (chp->ch_drive[drive].drive_flags & DRIVE_WAITDRAIN) {
906: sc_xfer->error = XS_DRIVER_STUFFUP;
907: chp->ch_drive[drive].drive_flags &= ~DRIVE_WAITDRAIN;
908: wakeup(&chp->ch_queue->active_xfer);
909: }
910:
1.86 ! thorpej 911: ATADEBUG_PRINT(("wdc_atapi_done: scsipi_done\n"), DEBUG_XFERS);
1.25 bouyer 912: scsipi_done(sc_xfer);
1.86 ! thorpej 913: ATADEBUG_PRINT(("atastart from wdc_atapi_done, flags 0x%x\n",
1.4 bouyer 914: chp->ch_flags), DEBUG_XFERS);
1.84 thorpej 915: atastart(chp);
1.2 bouyer 916: }
917:
1.65 thorpej 918: static void
1.66 thorpej 919: wdc_atapi_reset(struct wdc_channel *chp, struct ata_xfer *xfer)
1.2 bouyer 920: {
1.67 thorpej 921: struct wdc_softc *wdc = chp->ch_wdc;
1.63 thorpej 922: struct ata_drive_datas *drvp = &chp->ch_drive[xfer->c_drive];
923: struct scsipi_xfer *sc_xfer = xfer->c_cmd;
1.2 bouyer 924:
1.63 thorpej 925: wdccommandshort(chp, xfer->c_drive, ATAPI_SOFT_RESET);
1.2 bouyer 926: drvp->state = 0;
1.64 thorpej 927: if (wdc_wait_for_unbusy(chp, WDC_RESET_WAIT, AT_POLL) != 0) {
1.2 bouyer 928: printf("%s:%d:%d: reset failed\n",
1.67 thorpej 929: wdc->sc_dev.dv_xname, chp->ch_channel,
1.63 thorpej 930: xfer->c_drive);
1.2 bouyer 931: sc_xfer->error = XS_SELTIMEOUT;
932: }
933: wdc_atapi_done(chp, xfer);
934: return;
1.45 bouyer 935: }
936:
1.59 bouyer 937: static void
1.65 thorpej 938: wdc_atapi_polldsc(void *arg)
1.45 bouyer 939: {
1.65 thorpej 940:
1.45 bouyer 941: wdc_atapi_phase_complete(arg);
1.2 bouyer 942: }
CVSweb <webmaster@jp.NetBSD.org>