Home | History | Annotate | Line # | Download | only in scsipi
atapi_wdc.c revision 1.4
      1  1.4  bouyer /*	$NetBSD: atapi_wdc.c,v 1.4 1998/10/13 09:34:01 bouyer Exp $	*/
      2  1.2  bouyer 
      3  1.2  bouyer /*
      4  1.2  bouyer  * Copyright (c) 1998 Manuel Bouyer.
      5  1.2  bouyer  *
      6  1.2  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.2  bouyer  * modification, are permitted provided that the following conditions
      8  1.2  bouyer  * are met:
      9  1.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.2  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     15  1.2  bouyer  *    must display the following acknowledgement:
     16  1.2  bouyer  *	This product includes software developed by the University of
     17  1.2  bouyer  *	California, Berkeley and its contributors.
     18  1.2  bouyer  * 4. Neither the name of the University nor the names of its contributors
     19  1.2  bouyer  *    may be used to endorse or promote products derived from this software
     20  1.2  bouyer  *    without specific prior written permission.
     21  1.2  bouyer  *
     22  1.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.2  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.2  bouyer  * SUCH DAMAGE.
     33  1.2  bouyer  *
     34  1.2  bouyer  */
     35  1.2  bouyer 
     36  1.2  bouyer #define WDCDEBUG
     37  1.2  bouyer 
     38  1.2  bouyer #include <sys/param.h>
     39  1.2  bouyer #include <sys/systm.h>
     40  1.2  bouyer #include <sys/kernel.h>
     41  1.2  bouyer #include <sys/file.h>
     42  1.2  bouyer #include <sys/stat.h>
     43  1.2  bouyer #include <sys/buf.h>
     44  1.2  bouyer #include <sys/malloc.h>
     45  1.2  bouyer #include <sys/device.h>
     46  1.2  bouyer #include <sys/syslog.h>
     47  1.2  bouyer #include <sys/proc.h>
     48  1.2  bouyer 
     49  1.2  bouyer #include <vm/vm.h>
     50  1.2  bouyer 
     51  1.2  bouyer #include <machine/intr.h>
     52  1.2  bouyer #include <machine/bus.h>
     53  1.2  bouyer 
     54  1.2  bouyer #ifndef __BUS_SPACE_HAS_STREAM_METHODS
     55  1.2  bouyer #define    bus_space_write_multi_stream_2    bus_space_write_multi_2
     56  1.2  bouyer #define    bus_space_write_multi_stream_4    bus_space_write_multi_4
     57  1.2  bouyer #define    bus_space_read_multi_stream_2    bus_space_read_multi_2
     58  1.2  bouyer #define    bus_space_read_multi_stream_4    bus_space_read_multi_4
     59  1.2  bouyer #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
     60  1.2  bouyer 
     61  1.2  bouyer #include <dev/ata/atareg.h>
     62  1.2  bouyer #include <dev/ata/atavar.h>
     63  1.2  bouyer #include <dev/ic/wdcreg.h>
     64  1.2  bouyer #include <dev/ic/wdcvar.h>
     65  1.2  bouyer #include <dev/scsipi/scsipi_all.h>
     66  1.2  bouyer #include <dev/scsipi/scsipiconf.h>
     67  1.2  bouyer #include <dev/scsipi/atapiconf.h>
     68  1.2  bouyer 
     69  1.2  bouyer #define DEBUG_INTR   0x01
     70  1.2  bouyer #define DEBUG_XFERS  0x02
     71  1.2  bouyer #define DEBUG_STATUS 0x04
     72  1.2  bouyer #define DEBUG_FUNCS  0x08
     73  1.2  bouyer #define DEBUG_PROBE  0x10
     74  1.2  bouyer #ifdef WDCDEBUG
     75  1.3  bouyer int wdcdebug_atapi_mask = 0;
     76  1.2  bouyer #define WDCDEBUG_PRINT(args, level) \
     77  1.2  bouyer 	if (wdcdebug_atapi_mask & (level)) \
     78  1.2  bouyer 		printf args
     79  1.2  bouyer #else
     80  1.2  bouyer #define WDCDEBUG_PRINT(args, level)
     81  1.2  bouyer #endif
     82  1.2  bouyer 
     83  1.2  bouyer #define ATAPI_DELAY 10	/* 10 ms, this is used only before sending a cmd */
     84  1.2  bouyer 
     85  1.2  bouyer void  wdc_atapi_minphys  __P((struct buf *bp));
     86  1.2  bouyer void  wdc_atapi_start	__P((struct channel_softc *,struct wdc_xfer *));
     87  1.2  bouyer int   wdc_atapi_intr	 __P((struct channel_softc *, struct wdc_xfer *));
     88  1.2  bouyer int   wdc_atapi_ctrl	 __P((struct channel_softc *, struct wdc_xfer *));
     89  1.2  bouyer void  wdc_atapi_done	 __P((struct channel_softc *, struct wdc_xfer *));
     90  1.2  bouyer void  wdc_atapi_reset	 __P((struct channel_softc *, struct wdc_xfer *));
     91  1.2  bouyer int   wdc_atapi_send_cmd __P((struct scsipi_xfer *sc_xfer));
     92  1.2  bouyer 
     93  1.2  bouyer #define MAX_SIZE MAXPHYS
     94  1.2  bouyer 
     95  1.2  bouyer static struct scsipi_adapter wdc_switch  = {
     96  1.2  bouyer 	wdc_atapi_send_cmd,
     97  1.2  bouyer 	wdc_atapi_minphys,
     98  1.2  bouyer 	NULL,                   /* scsipi_ioctl */
     99  1.2  bouyer };
    100  1.2  bouyer 
    101  1.2  bouyer void
    102  1.2  bouyer wdc_atapibus_attach(chp)
    103  1.2  bouyer 	struct channel_softc *chp;
    104  1.2  bouyer {
    105  1.2  bouyer 	struct wdc_softc *wdc = chp->wdc;
    106  1.2  bouyer 	int channel = chp->channel;
    107  1.2  bouyer 	struct ata_atapi_attach aa_link;
    108  1.2  bouyer 
    109  1.2  bouyer 	memset(&aa_link, 0, sizeof(struct ata_atapi_attach));
    110  1.2  bouyer 	aa_link.aa_type = T_ATAPI;
    111  1.2  bouyer 	aa_link.aa_channel = channel;
    112  1.2  bouyer 	aa_link.aa_openings = 1;
    113  1.2  bouyer 	aa_link.aa_drv_data = chp->ch_drive; /* pass the whole array */
    114  1.2  bouyer 	aa_link.aa_bus_private = &wdc_switch;
    115  1.2  bouyer 	(void)config_found(&wdc->sc_dev, (void *)&aa_link, atapi_print);
    116  1.2  bouyer }
    117  1.2  bouyer 
    118  1.2  bouyer void
    119  1.2  bouyer wdc_atapi_minphys (struct buf *bp)
    120  1.2  bouyer {
    121  1.2  bouyer 	if(bp->b_bcount > MAX_SIZE)
    122  1.2  bouyer 		bp->b_bcount = MAX_SIZE;
    123  1.2  bouyer 	minphys(bp);
    124  1.2  bouyer }
    125  1.2  bouyer 
    126  1.2  bouyer int
    127  1.2  bouyer wdc_atapi_get_params(ab_link, drive, flags, id)
    128  1.2  bouyer 	struct scsipi_link *ab_link;
    129  1.2  bouyer 	u_int8_t drive;
    130  1.2  bouyer 	int flags;
    131  1.2  bouyer 	struct ataparams *id;
    132  1.2  bouyer {
    133  1.2  bouyer 	struct wdc_softc *wdc = (void*)ab_link->adapter_softc;
    134  1.2  bouyer 	struct channel_softc *chp =
    135  1.2  bouyer 	    &wdc->channels[ab_link->scsipi_atapi.channel];
    136  1.2  bouyer 	struct wdc_command wdc_c;
    137  1.2  bouyer 
    138  1.2  bouyer 	/* if no ATAPI device detected at wdc attach time, skip */
    139  1.2  bouyer 	/*
    140  1.2  bouyer 	 * XXX this will break scsireprobe if this is of any interest for
    141  1.2  bouyer 	 * ATAPI devices one day.
    142  1.2  bouyer 	 */
    143  1.2  bouyer 	if ((chp->ch_drive[drive].drive_flags & DRIVE_ATAPI) == 0) {
    144  1.2  bouyer 		WDCDEBUG_PRINT(("wdc_atapi_get_params: drive %d not present\n",
    145  1.2  bouyer 		    drive), DEBUG_PROBE);
    146  1.2  bouyer 		return -1;
    147  1.2  bouyer 	}
    148  1.2  bouyer 	memset(&wdc_c, 0, sizeof(struct wdc_command));
    149  1.2  bouyer 	wdc_c.r_command = ATAPI_SOFT_RESET;
    150  1.2  bouyer 	wdc_c.r_st_bmask = 0;
    151  1.2  bouyer 	wdc_c.r_st_pmask = 0;
    152  1.2  bouyer 	wdc_c.flags = AT_POLL;
    153  1.2  bouyer 	wdc_c.timeout = WDC_RESET_WAIT;
    154  1.2  bouyer 	if (wdc_exec_command(&chp->ch_drive[drive], &wdc_c) != WDC_COMPLETE) {
    155  1.2  bouyer 		printf("wdc_atapi_get_params: ATAPI_SOFT_RESET failed for"
    156  1.2  bouyer 		    " drive %s:%d:%d: driver failed\n",
    157  1.2  bouyer 		    chp->wdc->sc_dev.dv_xname, chp->channel, drive);
    158  1.2  bouyer 		panic("wdc_atapi_get_params");
    159  1.2  bouyer 	}
    160  1.2  bouyer 	if (wdc_c.flags & (AT_ERROR | AT_TIMEOU | AT_DF)) {
    161  1.2  bouyer 		WDCDEBUG_PRINT(("wdc_atapi_get_params: ATAPI_SOFT_RESET "
    162  1.2  bouyer 		    "failed for drive %s:%d:%d: error 0x%x\n",
    163  1.2  bouyer 		    chp->wdc->sc_dev.dv_xname, chp->channel, drive,
    164  1.2  bouyer 		    wdc_c.r_error), DEBUG_PROBE);
    165  1.2  bouyer 		return -1;
    166  1.2  bouyer 	}
    167  1.2  bouyer 	chp->ch_drive[drive].state = 0;
    168  1.2  bouyer 
    169  1.2  bouyer 	bus_space_read_1(chp->cmd_iot, chp->cmd_ioh, wd_status);
    170  1.2  bouyer 
    171  1.2  bouyer 	/* Some ATAPI devices need a bit more time after software reset. */
    172  1.2  bouyer 	delay(5000);
    173  1.2  bouyer 	if (ata_get_params(&chp->ch_drive[drive], AT_POLL, id) != 0) {
    174  1.2  bouyer 		WDCDEBUG_PRINT(("wdc_atapi_get_params: ATAPI_IDENTIFY_DEVICE "
    175  1.2  bouyer 		    "failed for drive %s:%d:%d: error 0x%x\n",
    176  1.2  bouyer 		    chp->wdc->sc_dev.dv_xname, chp->channel, drive,
    177  1.2  bouyer 		    wdc_c.r_error), DEBUG_PROBE);
    178  1.2  bouyer 		return -1;
    179  1.2  bouyer 	}
    180  1.2  bouyer 	return COMPLETE;
    181  1.2  bouyer }
    182  1.2  bouyer 
    183  1.2  bouyer int
    184  1.2  bouyer wdc_atapi_send_cmd(sc_xfer)
    185  1.2  bouyer 	struct scsipi_xfer *sc_xfer;
    186  1.2  bouyer {
    187  1.2  bouyer 	struct scsipi_link *sc_link = sc_xfer->sc_link;
    188  1.2  bouyer 	struct wdc_softc *wdc = (void*)sc_link->adapter_softc;
    189  1.2  bouyer 	struct wdc_xfer *xfer;
    190  1.2  bouyer 	struct ata_drive_datas *drvp;
    191  1.2  bouyer 	int flags = sc_xfer->flags;
    192  1.2  bouyer 	int channel = sc_xfer->sc_link->scsipi_atapi.channel;
    193  1.2  bouyer 	int drive = sc_xfer->sc_link->scsipi_atapi.drive;
    194  1.2  bouyer 	int s, ret;
    195  1.2  bouyer 
    196  1.4  bouyer 	WDCDEBUG_PRINT(("wdc_atapi_send_cmd\n"), DEBUG_XFERS);
    197  1.2  bouyer 
    198  1.2  bouyer 	xfer = wdc_get_xfer(flags & SCSI_NOSLEEP ? WDC_NOSLEEP : WDC_CANSLEEP);
    199  1.2  bouyer 	if (xfer == NULL) {
    200  1.2  bouyer 		return TRY_AGAIN_LATER;
    201  1.2  bouyer 	}
    202  1.2  bouyer 	if (sc_xfer->flags & SCSI_POLL)
    203  1.2  bouyer 		xfer->c_flags |= C_POLL;
    204  1.2  bouyer 	drvp = &wdc->channels[channel].ch_drive[drive];
    205  1.2  bouyer 	if ((drvp->drive_flags & (DRIVE_DMA | DRIVE_UDMA)) &&
    206  1.2  bouyer 	    sc_xfer->datalen > 0)
    207  1.2  bouyer 		xfer->c_flags |= C_DMA;
    208  1.2  bouyer 	xfer->drive = drive;
    209  1.2  bouyer 	xfer->c_flags |= C_ATAPI;
    210  1.2  bouyer 	xfer->cmd = sc_xfer;
    211  1.2  bouyer 	xfer->databuf = sc_xfer->data;
    212  1.2  bouyer 	xfer->c_bcount = sc_xfer->datalen;
    213  1.2  bouyer 	xfer->c_start = wdc_atapi_start;
    214  1.2  bouyer 	xfer->c_intr = wdc_atapi_intr;
    215  1.2  bouyer 	s = splbio();
    216  1.2  bouyer 	wdc_exec_xfer(&wdc->channels[channel], xfer);
    217  1.2  bouyer #ifdef DIAGNOSTIC
    218  1.2  bouyer 	if ((sc_xfer->flags & SCSI_POLL) != 0 &&
    219  1.2  bouyer 	    (sc_xfer->flags & ITSDONE) == 0)
    220  1.2  bouyer 		panic("wdc_atapi_send_cmd: polled command not done");
    221  1.2  bouyer #endif
    222  1.2  bouyer 	ret = (sc_xfer->flags & ITSDONE) ? COMPLETE : SUCCESSFULLY_QUEUED;
    223  1.2  bouyer 	splx(s);
    224  1.2  bouyer 	return ret;
    225  1.2  bouyer }
    226  1.2  bouyer 
    227  1.2  bouyer void
    228  1.2  bouyer wdc_atapi_start(chp, xfer)
    229  1.2  bouyer 	struct channel_softc *chp;
    230  1.2  bouyer 	struct wdc_xfer *xfer;
    231  1.2  bouyer {
    232  1.2  bouyer 	struct scsipi_xfer *sc_xfer = xfer->cmd;
    233  1.2  bouyer 	struct ata_drive_datas *drvp = &chp->ch_drive[xfer->drive];
    234  1.2  bouyer 
    235  1.2  bouyer 	WDCDEBUG_PRINT(("wdc_atapi_start, scsi flags 0x%x \n",sc_xfer->flags),
    236  1.4  bouyer 	    DEBUG_XFERS);
    237  1.2  bouyer 	/* Do control operations specially. */
    238  1.2  bouyer 	if (drvp->state < READY) {
    239  1.2  bouyer 		if (drvp->state != PIOMODE) {
    240  1.2  bouyer 			printf("%s:%d:%d: bad state %d in wdc_atapi_start\n",
    241  1.2  bouyer 			    chp->wdc->sc_dev.dv_xname, chp->channel,
    242  1.2  bouyer 			    xfer->drive, drvp->state);
    243  1.2  bouyer 			panic("wdc_atapi_start: bad state");
    244  1.2  bouyer 		}
    245  1.2  bouyer 		wdc_atapi_ctrl(chp, xfer);
    246  1.2  bouyer 		return;
    247  1.2  bouyer 	}
    248  1.2  bouyer 	bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_sdh,
    249  1.2  bouyer 	    WDSD_IBM | (xfer->drive << 4));
    250  1.2  bouyer 	if (wait_for_unbusy(chp, ATAPI_DELAY) < 0) {
    251  1.2  bouyer 		printf("wdc_atapi_start: not ready, st = %02x\n",
    252  1.2  bouyer 		    chp->ch_status);
    253  1.3  bouyer 		sc_xfer->error = XS_TIMEOUT;
    254  1.2  bouyer 		wdc_atapi_reset(chp, xfer);
    255  1.2  bouyer 		return;
    256  1.2  bouyer 	}
    257  1.2  bouyer 
    258  1.2  bouyer 	/*
    259  1.2  bouyer 	 * Even with WDCS_ERR, the device should accept a command packet
    260  1.2  bouyer 	 * Limit length to what can be stuffed into the cylinder register
    261  1.2  bouyer 	 * (16 bits).  Some CD-ROMs seem to interpret '0' as 65536,
    262  1.2  bouyer 	 * but not all devices do that and it's not obvious from the
    263  1.2  bouyer 	 * ATAPI spec that that behaviour should be expected.  If more
    264  1.2  bouyer 	 * data is necessary, multiple data transfer phases will be done.
    265  1.2  bouyer 	 */
    266  1.2  bouyer 	wdccommand(chp, xfer->drive, ATAPI_PKT_CMD,
    267  1.2  bouyer 	    sc_xfer->datalen <= 0xffff ? sc_xfer->datalen : 0xffff,
    268  1.2  bouyer 	    0, 0, 0,
    269  1.2  bouyer 	    (xfer->c_flags & C_DMA) ? ATAPI_PKT_CMD_FTRE_DMA : 0);
    270  1.2  bouyer 
    271  1.2  bouyer 	/*
    272  1.2  bouyer 	 * If there is no interrupt for CMD input, busy-wait for it (done in
    273  1.2  bouyer 	 * the interrupt routine. If it is a polled command, call the interrupt
    274  1.2  bouyer 	 * routine until command is done.
    275  1.2  bouyer 	 */
    276  1.2  bouyer 	if ((sc_xfer->sc_link->scsipi_atapi.cap  & 0x0300) != ACAP_DRQ_INTR ||
    277  1.2  bouyer 	    sc_xfer->flags & SCSI_POLL) {
    278  1.2  bouyer 		/* Wait for at last 400ns for status bit to be valid */
    279  1.2  bouyer 		delay(1);
    280  1.2  bouyer 		if (wdc_atapi_intr(chp, xfer) == 0) {
    281  1.3  bouyer 			sc_xfer->error = XS_TIMEOUT;
    282  1.2  bouyer 			wdc_atapi_reset(chp, xfer);
    283  1.2  bouyer 			return;
    284  1.2  bouyer 		}
    285  1.2  bouyer 	}
    286  1.2  bouyer 	if (sc_xfer->flags & SCSI_POLL) {
    287  1.2  bouyer 		while ((sc_xfer->flags & ITSDONE) == 0) {
    288  1.2  bouyer 			/* Wait for at last 400ns for status bit to be valid */
    289  1.2  bouyer 			delay(1);
    290  1.2  bouyer 			if (wdc_atapi_intr(chp, xfer) == 0) {
    291  1.2  bouyer 				sc_xfer->error = XS_SELTIMEOUT;
    292  1.2  bouyer 				    /* do we know more ? */
    293  1.2  bouyer 				wdc_atapi_done(chp, xfer);
    294  1.2  bouyer 				return;
    295  1.2  bouyer 			}
    296  1.2  bouyer 		}
    297  1.2  bouyer 	}
    298  1.2  bouyer }
    299  1.2  bouyer 
    300  1.2  bouyer int
    301  1.2  bouyer wdc_atapi_intr(chp, xfer)
    302  1.2  bouyer 	struct channel_softc *chp;
    303  1.2  bouyer 	struct wdc_xfer *xfer;
    304  1.2  bouyer {
    305  1.2  bouyer 	struct scsipi_xfer *sc_xfer = xfer->cmd;
    306  1.2  bouyer 	struct ata_drive_datas *drvp = &chp->ch_drive[xfer->drive];
    307  1.2  bouyer 	int len, phase, i, retries=0;
    308  1.2  bouyer 	int ire, dma_err = 0;
    309  1.2  bouyer 	int dma_flags = 0;
    310  1.2  bouyer 
    311  1.2  bouyer 	WDCDEBUG_PRINT(("wdc_atapi_intr\n"), DEBUG_INTR);
    312  1.2  bouyer 
    313  1.2  bouyer 	/* Is it not a transfer, but a control operation? */
    314  1.2  bouyer 	if (drvp->state < READY) {
    315  1.2  bouyer 		printf("%s:%d:%d: bad state %d in wdc_atapi_intr\n",
    316  1.2  bouyer 		    chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,
    317  1.2  bouyer 		    drvp->state);
    318  1.2  bouyer 		panic("wdc_atapi_intr: bad state\n");
    319  1.2  bouyer 	}
    320  1.2  bouyer 	/* Ack interrupt done in wait_for_unbusy */
    321  1.2  bouyer 	bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_sdh,
    322  1.2  bouyer 	    WDSD_IBM | (xfer->drive << 4));
    323  1.2  bouyer 	if (wait_for_unbusy(chp, sc_xfer->timeout) != 0) {
    324  1.2  bouyer 		printf("%s:%d:%d: device timeout, c_bcount=%d, c_skip%d\n",
    325  1.2  bouyer 		    chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,
    326  1.2  bouyer 		    xfer->c_bcount, xfer->c_skip);
    327  1.3  bouyer 		sc_xfer->error = XS_TIMEOUT;
    328  1.2  bouyer 		wdc_atapi_reset(chp, xfer);
    329  1.2  bouyer 		return 1;
    330  1.2  bouyer 	}
    331  1.2  bouyer 	/* Error here only if the command is aborted */
    332  1.2  bouyer 	if ((chp->ch_status & WDCS_ERR) != 0 &&
    333  1.2  bouyer 	    (chp->ch_error & WDCE_ABRT) != 0) {
    334  1.2  bouyer 		sc_xfer->error = XS_SENSE;
    335  1.2  bouyer 		sc_xfer->sense.atapi_sense = chp->ch_error;
    336  1.2  bouyer 		WDCDEBUG_PRINT(("wdc_atapi_intr: wdc_atapi_done(), "
    337  1.2  bouyer 		    "sense 0x%x\n", sc_xfer->sense.atapi_sense), DEBUG_INTR);
    338  1.2  bouyer 		wdc_atapi_done(chp, xfer);
    339  1.2  bouyer 		return 1;
    340  1.2  bouyer 	}
    341  1.2  bouyer 
    342  1.2  bouyer 	if (xfer->c_flags & C_DMA) {
    343  1.2  bouyer 		dma_flags = (sc_xfer->flags & SCSI_DATA_IN) ?
    344  1.2  bouyer 		    WDC_DMA_READ : 0;
    345  1.2  bouyer 		dma_flags |= sc_xfer->flags & SCSI_POLL ? WDC_DMA_POLL : 0;
    346  1.2  bouyer 	}
    347  1.2  bouyer again:
    348  1.2  bouyer 	len = bus_space_read_1(chp->cmd_iot, chp->cmd_ioh, wd_cyl_lo) +
    349  1.2  bouyer 	    256 * bus_space_read_1(chp->cmd_iot, chp->cmd_ioh, wd_cyl_hi);
    350  1.2  bouyer 	ire = bus_space_read_1(chp->cmd_iot, chp->cmd_ioh, wd_ireason);
    351  1.2  bouyer 	phase = (ire & (WDCI_CMD | WDCI_IN)) | (chp->ch_status & WDCS_DRQ);
    352  1.2  bouyer 	WDCDEBUG_PRINT(("wdc_atapi_intr: c_bcount %d len %d st 0x%x err 0x%x "
    353  1.2  bouyer 	    "ire 0x%x :", xfer->c_bcount,
    354  1.2  bouyer 	    len, chp->ch_status, chp->ch_error, ire), DEBUG_INTR);
    355  1.2  bouyer 
    356  1.2  bouyer 	switch (phase) {
    357  1.2  bouyer 	case PHASE_CMDOUT:
    358  1.2  bouyer 		WDCDEBUG_PRINT(("PHASE_CMDOUT\n"), DEBUG_INTR);
    359  1.2  bouyer 		/* Init the DMA channel if necessary */
    360  1.2  bouyer 		if (xfer->c_flags & C_DMA) {
    361  1.2  bouyer 			if ((*chp->wdc->dma_init)(chp->wdc->dma_arg,
    362  1.2  bouyer 			    chp->channel, xfer->drive,
    363  1.2  bouyer 			    xfer->databuf, sc_xfer->datalen, dma_flags) != 0) {
    364  1.2  bouyer 				sc_xfer->error = XS_DRIVER_STUFFUP;
    365  1.2  bouyer 				break;
    366  1.2  bouyer 			}
    367  1.2  bouyer 		}
    368  1.2  bouyer 		/* send packet command */
    369  1.2  bouyer 		/* Commands are 12 or 16 bytes long. It's 32-bit aligned */
    370  1.2  bouyer 		if ((chp->wdc->cap & WDC_CAPABILITY_ATAPI_NOSTREAM)) {
    371  1.2  bouyer 			if (drvp->drive_flags & DRIVE_CAP32) {
    372  1.2  bouyer 				bus_space_write_multi_4(chp->data32iot,
    373  1.2  bouyer 				    chp->data32ioh, 0,
    374  1.2  bouyer 				    (u_int32_t *)sc_xfer->cmd,
    375  1.2  bouyer 				    sc_xfer->cmdlen >> 2);
    376  1.2  bouyer 			} else {
    377  1.2  bouyer 				bus_space_write_multi_2(chp->cmd_iot,
    378  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    379  1.2  bouyer 				    (u_int16_t *)sc_xfer->cmd,
    380  1.2  bouyer 				    sc_xfer->cmdlen >> 1);
    381  1.2  bouyer 			}
    382  1.2  bouyer 		} else {
    383  1.2  bouyer 			if (drvp->drive_flags & DRIVE_CAP32) {
    384  1.2  bouyer 				bus_space_write_multi_stream_4(chp->data32iot,
    385  1.2  bouyer 				    chp->data32ioh, 0,
    386  1.2  bouyer 				    (u_int32_t *)sc_xfer->cmd,
    387  1.2  bouyer 				    sc_xfer->cmdlen >> 2);
    388  1.2  bouyer 			} else {
    389  1.2  bouyer 				bus_space_write_multi_stream_2(chp->cmd_iot,
    390  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    391  1.2  bouyer 				    (u_int16_t *)sc_xfer->cmd,
    392  1.2  bouyer 				    sc_xfer->cmdlen >> 1);
    393  1.2  bouyer 			}
    394  1.2  bouyer 		}
    395  1.2  bouyer 		/* Start the DMA channel if necessary */
    396  1.2  bouyer 		if (xfer->c_flags & C_DMA) {
    397  1.2  bouyer 			(*chp->wdc->dma_start)(chp->wdc->dma_arg,
    398  1.2  bouyer 			    chp->channel, xfer->drive, dma_flags);
    399  1.2  bouyer 		}
    400  1.2  bouyer 
    401  1.2  bouyer 		if ((sc_xfer->flags & SCSI_POLL) == 0) {
    402  1.2  bouyer 			chp->ch_flags |= WDCF_IRQ_WAIT;
    403  1.2  bouyer 			timeout(wdctimeout, chp, sc_xfer->timeout * hz / 1000);
    404  1.2  bouyer 		}
    405  1.2  bouyer 		return 1;
    406  1.2  bouyer 
    407  1.2  bouyer 	 case PHASE_DATAOUT:
    408  1.2  bouyer 		/* write data */
    409  1.2  bouyer 		WDCDEBUG_PRINT(("PHASE_DATAOUT\n"), DEBUG_INTR);
    410  1.2  bouyer 		if ((sc_xfer->flags & SCSI_DATA_OUT) == 0 ||
    411  1.2  bouyer 		    (xfer->c_flags & C_DMA) != 0) {
    412  1.2  bouyer 			printf("wdc_atapi_intr: bad data phase DATAOUT");
    413  1.2  bouyer 			if (xfer->c_flags & C_DMA) {
    414  1.2  bouyer 				printf(", falling back to PIO\n");
    415  1.2  bouyer 				drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);
    416  1.2  bouyer 			}
    417  1.3  bouyer 			sc_xfer->error = XS_TIMEOUT;
    418  1.2  bouyer 			wdc_atapi_reset(chp, xfer);
    419  1.2  bouyer 			return 1;
    420  1.2  bouyer 		}
    421  1.2  bouyer 		if (xfer->c_bcount < len) {
    422  1.2  bouyer 			printf("wdc_atapi_intr: warning: write only "
    423  1.2  bouyer 			    "%d of %d requested bytes\n", xfer->c_bcount, len);
    424  1.2  bouyer 			if ((chp->wdc->cap & WDC_CAPABILITY_ATAPI_NOSTREAM)) {
    425  1.2  bouyer 				bus_space_write_multi_2(chp->cmd_iot,
    426  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    427  1.2  bouyer 				    xfer->databuf + xfer->c_skip,
    428  1.2  bouyer 				    xfer->c_bcount >> 1);
    429  1.2  bouyer 			} else {
    430  1.2  bouyer 				bus_space_write_multi_stream_2(chp->cmd_iot,
    431  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    432  1.2  bouyer 				    xfer->databuf + xfer->c_skip,
    433  1.2  bouyer 				    xfer->c_bcount >> 1);
    434  1.2  bouyer 			}
    435  1.2  bouyer 			for (i = xfer->c_bcount; i < len; i += 2)
    436  1.2  bouyer 				bus_space_write_2(chp->cmd_iot, chp->cmd_ioh,
    437  1.2  bouyer 				    wd_data, 0);
    438  1.2  bouyer 			xfer->c_skip += xfer->c_bcount;
    439  1.2  bouyer 			xfer->c_bcount = 0;
    440  1.2  bouyer 		} else {
    441  1.2  bouyer 			if (drvp->drive_flags & DRIVE_CAP32) {
    442  1.2  bouyer 			    if ((chp->wdc->cap & WDC_CAPABILITY_ATAPI_NOSTREAM))
    443  1.2  bouyer 				bus_space_write_multi_4(chp->data32iot,
    444  1.2  bouyer 				    chp->data32ioh, 0,
    445  1.2  bouyer 				    xfer->databuf + xfer->c_skip, len >> 2);
    446  1.2  bouyer 			    else
    447  1.2  bouyer 				bus_space_write_multi_stream_4(chp->cmd_iot,
    448  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    449  1.2  bouyer 				    xfer->databuf + xfer->c_skip, len >> 2);
    450  1.2  bouyer 
    451  1.2  bouyer 			    xfer->c_skip += len & 0xfffffffc;
    452  1.2  bouyer 			    xfer->c_bcount -= len & 0xfffffffc;
    453  1.2  bouyer 			    len = len & 0x03;
    454  1.2  bouyer 			}
    455  1.2  bouyer 			if (len > 0) {
    456  1.2  bouyer 			    if ((chp->wdc->cap & WDC_CAPABILITY_ATAPI_NOSTREAM))
    457  1.2  bouyer 				bus_space_write_multi_2(chp->cmd_iot,
    458  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    459  1.2  bouyer 				    xfer->databuf + xfer->c_skip, len >> 1);
    460  1.2  bouyer 			    else
    461  1.2  bouyer 				bus_space_write_multi_stream_2(chp->cmd_iot,
    462  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    463  1.2  bouyer 				    xfer->databuf + xfer->c_skip, len >> 1);
    464  1.2  bouyer 			    xfer->c_skip += len;
    465  1.2  bouyer 			    xfer->c_bcount -= len;
    466  1.2  bouyer 			}
    467  1.2  bouyer 		}
    468  1.2  bouyer 		if ((sc_xfer->flags & SCSI_POLL) == 0) {
    469  1.2  bouyer 			chp->ch_flags |= WDCF_IRQ_WAIT;
    470  1.2  bouyer 			timeout(wdctimeout, chp, sc_xfer->timeout * hz / 1000);
    471  1.2  bouyer 		}
    472  1.2  bouyer 		return 1;
    473  1.2  bouyer 
    474  1.2  bouyer 	case PHASE_DATAIN:
    475  1.2  bouyer 		/* Read data */
    476  1.2  bouyer 		WDCDEBUG_PRINT(("PHASE_DATAIN\n"), DEBUG_INTR);
    477  1.2  bouyer 		if ((sc_xfer->flags & SCSI_DATA_IN) == 0 ||
    478  1.2  bouyer 		    (xfer->c_flags & C_DMA) != 0) {
    479  1.2  bouyer 			printf("wdc_atapi_intr: bad data phase DATAIN");
    480  1.2  bouyer 			if (xfer->c_flags & C_DMA) {
    481  1.2  bouyer 				printf(", falling back to PIO\n");
    482  1.2  bouyer 				drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);
    483  1.2  bouyer 			}
    484  1.3  bouyer 			sc_xfer->error = XS_TIMEOUT;
    485  1.2  bouyer 			wdc_atapi_reset(chp, xfer);
    486  1.2  bouyer 			return 1;
    487  1.2  bouyer 		}
    488  1.2  bouyer 		if (xfer->c_bcount < len) {
    489  1.2  bouyer 			printf("wdc_atapi_intr: warning: reading only "
    490  1.2  bouyer 			    "%d of %d bytes\n", xfer->c_bcount, len);
    491  1.2  bouyer 			if ((chp->wdc->cap & WDC_CAPABILITY_ATAPI_NOSTREAM)) {
    492  1.2  bouyer 			    bus_space_read_multi_2(chp->cmd_iot,
    493  1.2  bouyer 			    chp->cmd_ioh, wd_data,
    494  1.2  bouyer 			    xfer->databuf + xfer->c_skip, xfer->c_bcount >> 1);
    495  1.2  bouyer 			} else {
    496  1.2  bouyer 			    bus_space_read_multi_stream_2(chp->cmd_iot,
    497  1.2  bouyer 			    chp->cmd_ioh, wd_data,
    498  1.2  bouyer 			    xfer->databuf + xfer->c_skip, xfer->c_bcount >> 1);
    499  1.2  bouyer 			}
    500  1.2  bouyer 			wdcbit_bucket(chp, len - xfer->c_bcount);
    501  1.2  bouyer 			xfer->c_skip += xfer->c_bcount;
    502  1.2  bouyer 			xfer->c_bcount = 0;
    503  1.2  bouyer 		} else {
    504  1.2  bouyer 			if (drvp->drive_flags & DRIVE_CAP32) {
    505  1.2  bouyer 			    if ((chp->wdc->cap & WDC_CAPABILITY_ATAPI_NOSTREAM))
    506  1.2  bouyer 				bus_space_read_multi_4(chp->data32iot,
    507  1.2  bouyer 				    chp->data32ioh, 0,
    508  1.2  bouyer 				    xfer->databuf + xfer->c_skip, len >> 2);
    509  1.2  bouyer 			    else
    510  1.2  bouyer 				bus_space_read_multi_stream_4(chp->cmd_iot,
    511  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    512  1.2  bouyer 				    xfer->databuf + xfer->c_skip, len >> 2);
    513  1.2  bouyer 
    514  1.2  bouyer 			    xfer->c_skip += len & 0xfffffffc;
    515  1.2  bouyer 			    xfer->c_bcount -= len & 0xfffffffc;
    516  1.2  bouyer 			    len = len & 0x03;
    517  1.2  bouyer 			}
    518  1.2  bouyer 			if (len > 0) {
    519  1.2  bouyer 			    if ((chp->wdc->cap & WDC_CAPABILITY_ATAPI_NOSTREAM))
    520  1.2  bouyer 				bus_space_read_multi_2(chp->cmd_iot,
    521  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    522  1.2  bouyer 				    xfer->databuf + xfer->c_skip, len >> 1);
    523  1.2  bouyer 			    else
    524  1.2  bouyer 				bus_space_read_multi_stream_2(chp->cmd_iot,
    525  1.2  bouyer 				    chp->cmd_ioh, wd_data,
    526  1.2  bouyer 				    xfer->databuf + xfer->c_skip, len >> 1);
    527  1.2  bouyer 			    xfer->c_skip += len;
    528  1.2  bouyer 			    xfer->c_bcount -=len;
    529  1.2  bouyer 			}
    530  1.2  bouyer 		}
    531  1.2  bouyer 		if ((sc_xfer->flags & SCSI_POLL) == 0) {
    532  1.2  bouyer 			chp->ch_flags |= WDCF_IRQ_WAIT;
    533  1.2  bouyer 			timeout(wdctimeout, chp, sc_xfer->timeout * hz / 1000);
    534  1.2  bouyer 		}
    535  1.2  bouyer 		return 1;
    536  1.2  bouyer 
    537  1.2  bouyer 	case PHASE_ABORTED:
    538  1.2  bouyer 	case PHASE_COMPLETED:
    539  1.2  bouyer 		WDCDEBUG_PRINT(("PHASE_COMPLETED\n"), DEBUG_INTR);
    540  1.2  bouyer 		/* turn off DMA channel */
    541  1.2  bouyer 		if (xfer->c_flags & C_DMA) {
    542  1.2  bouyer 			dma_err = (*chp->wdc->dma_finish)(chp->wdc->dma_arg,
    543  1.2  bouyer 			    chp->channel, xfer->drive, dma_flags);
    544  1.2  bouyer 			xfer->c_bcount -= sc_xfer->datalen;
    545  1.2  bouyer 		}
    546  1.2  bouyer 
    547  1.2  bouyer 		if (chp->ch_status & WDCS_ERR) {
    548  1.2  bouyer 			sc_xfer->error = XS_SENSE;
    549  1.2  bouyer 			sc_xfer->sense.atapi_sense = chp->ch_error;
    550  1.2  bouyer 		} else if (dma_err < 0) {
    551  1.2  bouyer 			sc_xfer->error = XS_DRIVER_STUFFUP;
    552  1.2  bouyer 		}
    553  1.2  bouyer #ifdef DIAGNOSTIC
    554  1.2  bouyer 		if (xfer->c_bcount != 0) {
    555  1.2  bouyer 			printf("wdc_atapi_intr warning: bcount value "
    556  1.2  bouyer 			    "is %d after io\n", xfer->c_bcount);
    557  1.2  bouyer 		}
    558  1.2  bouyer #endif
    559  1.2  bouyer 		break;
    560  1.2  bouyer 
    561  1.2  bouyer 	default:
    562  1.2  bouyer 		if (++retries<500) {
    563  1.2  bouyer 			DELAY(100);
    564  1.2  bouyer 			chp->ch_status = bus_space_read_1(chp->cmd_iot,
    565  1.2  bouyer 			    chp->cmd_ioh, wd_status);
    566  1.2  bouyer 			chp->ch_error = bus_space_read_1(chp->cmd_iot,
    567  1.2  bouyer 			    chp->cmd_ioh, wd_error);
    568  1.2  bouyer 			goto again;
    569  1.2  bouyer 		}
    570  1.2  bouyer 		printf("wdc_atapi_intr: unknown phase 0x%x\n", phase);
    571  1.2  bouyer 		if (chp->ch_status & WDCS_ERR) {
    572  1.2  bouyer 			sc_xfer->error = XS_SENSE;
    573  1.2  bouyer 			sc_xfer->sense.atapi_sense = chp->ch_error;
    574  1.2  bouyer 		} else {
    575  1.2  bouyer 			sc_xfer->error = XS_DRIVER_STUFFUP;
    576  1.2  bouyer 		}
    577  1.2  bouyer 	}
    578  1.2  bouyer 	WDCDEBUG_PRINT(("wdc_atapi_intr: wdc_atapi_done() (end), error 0x%x "
    579  1.2  bouyer 	    "sense 0x%x\n", sc_xfer->error, sc_xfer->sense.atapi_sense),
    580  1.2  bouyer 	    DEBUG_INTR);
    581  1.2  bouyer 	wdc_atapi_done(chp, xfer);
    582  1.2  bouyer 	return (1);
    583  1.2  bouyer }
    584  1.2  bouyer 
    585  1.2  bouyer int
    586  1.2  bouyer wdc_atapi_ctrl(chp, xfer)
    587  1.2  bouyer 	struct channel_softc *chp;
    588  1.2  bouyer 	struct wdc_xfer *xfer;
    589  1.2  bouyer {
    590  1.2  bouyer 	struct scsipi_xfer *sc_xfer = xfer->cmd;
    591  1.2  bouyer 	struct ata_drive_datas *drvp = &chp->ch_drive[xfer->drive];
    592  1.2  bouyer 	char *errstring = NULL;
    593  1.2  bouyer 
    594  1.2  bouyer 	/* Ack interrupt done in wait_for_unbusy */
    595  1.2  bouyer again:
    596  1.4  bouyer 	WDCDEBUG_PRINT(("wdc_atapi_ctrl state %d\n", drvp->state),
    597  1.4  bouyer 	    DEBUG_INTR | DEBUG_FUNCS);
    598  1.2  bouyer 	bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_sdh,
    599  1.2  bouyer 	    WDSD_IBM | (xfer->drive << 4));
    600  1.2  bouyer 	switch (drvp->state) {
    601  1.2  bouyer 	case PIOMODE:
    602  1.2  bouyer 		/* Don't try to set mode if controller can't be adjusted */
    603  1.2  bouyer 		if ((chp->wdc->cap & WDC_CAPABILITY_MODE) == 0)
    604  1.2  bouyer 			goto ready;
    605  1.2  bouyer 		wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
    606  1.2  bouyer 		    0x08 | drvp->PIO_mode, WDSF_SET_MODE);
    607  1.2  bouyer 		drvp->state = PIOMODE_WAIT;
    608  1.2  bouyer 		break;
    609  1.2  bouyer 	case PIOMODE_WAIT:
    610  1.2  bouyer 		errstring = "piomode";
    611  1.2  bouyer 		if (wait_for_unbusy(chp, ATAPI_DELAY))
    612  1.2  bouyer 			goto timeout;
    613  1.2  bouyer 		if (chp->ch_status & WDCS_ERR)
    614  1.2  bouyer 			goto error;
    615  1.2  bouyer 	/* fall through */
    616  1.2  bouyer 
    617  1.2  bouyer 	case DMAMODE:
    618  1.2  bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    619  1.2  bouyer 			wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
    620  1.2  bouyer 			    0x40 | drvp->UDMA_mode, WDSF_SET_MODE);
    621  1.2  bouyer 		} else if (drvp->drive_flags & DRIVE_DMA) {
    622  1.2  bouyer 			wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
    623  1.2  bouyer 			    0x20 | drvp->DMA_mode, WDSF_SET_MODE);
    624  1.2  bouyer 		} else {
    625  1.2  bouyer 			goto ready;
    626  1.2  bouyer 		}
    627  1.2  bouyer 		drvp->state = DMAMODE_WAIT;
    628  1.2  bouyer 		break;
    629  1.2  bouyer 	case DMAMODE_WAIT:
    630  1.2  bouyer 		errstring = "dmamode";
    631  1.2  bouyer 		if (wait_for_unbusy(chp, ATAPI_DELAY))
    632  1.2  bouyer 			goto timeout;
    633  1.2  bouyer 		if (chp->ch_status & WDCS_ERR)
    634  1.2  bouyer 			goto error;
    635  1.2  bouyer 	/* fall through */
    636  1.2  bouyer 
    637  1.2  bouyer 	case READY:
    638  1.2  bouyer 	ready:
    639  1.2  bouyer 		drvp->state = READY;
    640  1.2  bouyer 		xfer->c_intr = wdc_atapi_intr;
    641  1.2  bouyer 		wdc_atapi_start(chp, xfer);
    642  1.2  bouyer 		return 1;
    643  1.2  bouyer 	}
    644  1.2  bouyer 	if ((sc_xfer->flags & SCSI_POLL) == 0) {
    645  1.2  bouyer 		chp->ch_flags |= WDCF_IRQ_WAIT;
    646  1.2  bouyer 		xfer->c_intr = wdc_atapi_ctrl;
    647  1.2  bouyer 		timeout(wdctimeout, chp, sc_xfer->timeout * hz / 1000);
    648  1.2  bouyer 	} else {
    649  1.2  bouyer 		goto again;
    650  1.2  bouyer 	}
    651  1.2  bouyer 	return 1;
    652  1.2  bouyer 
    653  1.2  bouyer timeout:
    654  1.2  bouyer 	if ((xfer->c_flags & C_TIMEOU) == 0 ) {
    655  1.2  bouyer 		return 0; /* IRQ was not for us */
    656  1.2  bouyer 	}
    657  1.2  bouyer 	printf("%s:%d:%d: %s timed out\n",
    658  1.2  bouyer 	    chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive, errstring);
    659  1.3  bouyer 	sc_xfer->error = XS_TIMEOUT;
    660  1.2  bouyer 	wdc_atapi_reset(chp, xfer);
    661  1.2  bouyer 	return 1;
    662  1.2  bouyer error:
    663  1.2  bouyer 	printf("%s:%d:%d: %s ",
    664  1.2  bouyer 	    chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,
    665  1.2  bouyer 	    errstring);
    666  1.3  bouyer 	printf("error (0x%x)\n", chp->ch_error);
    667  1.2  bouyer 	sc_xfer->error = XS_SENSE;
    668  1.2  bouyer 	sc_xfer->sense.atapi_sense = chp->ch_error;
    669  1.3  bouyer 	wdc_atapi_reset(chp, xfer);
    670  1.2  bouyer 	return 1;
    671  1.2  bouyer }
    672  1.2  bouyer 
    673  1.2  bouyer void
    674  1.2  bouyer wdc_atapi_done(chp, xfer)
    675  1.2  bouyer 	struct channel_softc *chp;
    676  1.2  bouyer 	struct wdc_xfer *xfer;
    677  1.2  bouyer {
    678  1.2  bouyer 	struct scsipi_xfer *sc_xfer = xfer->cmd;
    679  1.2  bouyer 	struct wdc_softc *wdc = chp->wdc;
    680  1.2  bouyer 	int need_done =  xfer->c_flags & C_NEEDDONE;
    681  1.2  bouyer 
    682  1.2  bouyer 	WDCDEBUG_PRINT(("wdc_atapi_done: flags 0x%x\n", (u_int)xfer->c_flags),
    683  1.4  bouyer 	    DEBUG_XFERS);
    684  1.2  bouyer 	sc_xfer->resid = xfer->c_bcount;
    685  1.2  bouyer 	/* remove this command from xfer queue */
    686  1.2  bouyer 	xfer->c_skip = 0;
    687  1.2  bouyer 	wdc_free_xfer(chp, xfer);
    688  1.2  bouyer 	sc_xfer->flags |= ITSDONE;
    689  1.2  bouyer 	if (need_done) {
    690  1.4  bouyer 		WDCDEBUG_PRINT(("wdc_atapi_done: scsipi_done\n"), DEBUG_XFERS);
    691  1.2  bouyer 		scsipi_done(sc_xfer);
    692  1.2  bouyer 	}
    693  1.2  bouyer 	WDCDEBUG_PRINT(("wdcstart from wdc_atapi_done, flags 0x%x\n",
    694  1.4  bouyer 	    chp->ch_flags), DEBUG_XFERS);
    695  1.2  bouyer 	wdcstart(wdc, chp->channel);
    696  1.2  bouyer }
    697  1.2  bouyer 
    698  1.2  bouyer void
    699  1.2  bouyer wdc_atapi_reset(chp, xfer)
    700  1.2  bouyer 	struct channel_softc *chp;
    701  1.2  bouyer 	struct wdc_xfer *xfer;
    702  1.2  bouyer {
    703  1.2  bouyer 	struct ata_drive_datas *drvp = &chp->ch_drive[xfer->drive];
    704  1.2  bouyer 	struct scsipi_xfer *sc_xfer = xfer->cmd;
    705  1.2  bouyer 
    706  1.2  bouyer 	wdccommandshort(chp, xfer->drive, ATAPI_SOFT_RESET);
    707  1.2  bouyer 	drvp->state = 0;
    708  1.2  bouyer 	if (wait_for_unbusy(chp, WDC_RESET_WAIT) != 0) {
    709  1.2  bouyer 		printf("%s:%d:%d: reset failed\n",
    710  1.2  bouyer 		    chp->wdc->sc_dev.dv_xname, chp->channel,
    711  1.2  bouyer 		    xfer->drive);
    712  1.2  bouyer 		sc_xfer->error = XS_SELTIMEOUT;
    713  1.2  bouyer 		wdc_atapi_done(chp, xfer);
    714  1.2  bouyer 		return;
    715  1.2  bouyer 	}
    716  1.2  bouyer 	wdc_atapi_done(chp, xfer);
    717  1.2  bouyer 	return;
    718  1.2  bouyer }
    719