ata_wdc.c revision 1.31 1 1.31 lukem /* $NetBSD: ata_wdc.c,v 1.31 2001/11/13 12:53:09 lukem 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.27 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.27 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.27 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.27 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.27 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.27 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.27 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.27 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.27 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.27 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.2 bouyer *
33 1.2 bouyer */
34 1.2 bouyer
35 1.2 bouyer /*-
36 1.2 bouyer * Copyright (c) 1998 The NetBSD Foundation, Inc.
37 1.2 bouyer * All rights reserved.
38 1.2 bouyer *
39 1.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
40 1.2 bouyer * by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
41 1.2 bouyer *
42 1.2 bouyer * Redistribution and use in source and binary forms, with or without
43 1.2 bouyer * modification, are permitted provided that the following conditions
44 1.2 bouyer * are met:
45 1.2 bouyer * 1. Redistributions of source code must retain the above copyright
46 1.2 bouyer * notice, this list of conditions and the following disclaimer.
47 1.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
48 1.2 bouyer * notice, this list of conditions and the following disclaimer in the
49 1.2 bouyer * documentation and/or other materials provided with the distribution.
50 1.2 bouyer * 3. All advertising materials mentioning features or use of this software
51 1.2 bouyer * must display the following acknowledgement:
52 1.2 bouyer * This product includes software developed by the NetBSD
53 1.2 bouyer * Foundation, Inc. and its contributors.
54 1.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
55 1.2 bouyer * contributors may be used to endorse or promote products derived
56 1.2 bouyer * from this software without specific prior written permission.
57 1.2 bouyer *
58 1.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
59 1.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60 1.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
61 1.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
62 1.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63 1.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
64 1.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65 1.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66 1.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67 1.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68 1.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
69 1.2 bouyer */
70 1.31 lukem
71 1.31 lukem #include <sys/cdefs.h>
72 1.31 lukem __KERNEL_RCSID(0, "$NetBSD: ata_wdc.c,v 1.31 2001/11/13 12:53:09 lukem Exp $");
73 1.2 bouyer
74 1.15 hubertf #ifndef WDCDEBUG
75 1.2 bouyer #define WDCDEBUG
76 1.15 hubertf #endif /* WDCDEBUG */
77 1.2 bouyer
78 1.2 bouyer #include <sys/param.h>
79 1.2 bouyer #include <sys/systm.h>
80 1.2 bouyer #include <sys/kernel.h>
81 1.2 bouyer #include <sys/file.h>
82 1.2 bouyer #include <sys/stat.h>
83 1.2 bouyer #include <sys/buf.h>
84 1.2 bouyer #include <sys/malloc.h>
85 1.2 bouyer #include <sys/device.h>
86 1.2 bouyer #include <sys/disklabel.h>
87 1.2 bouyer #include <sys/syslog.h>
88 1.2 bouyer #include <sys/proc.h>
89 1.2 bouyer
90 1.2 bouyer #include <machine/intr.h>
91 1.2 bouyer #include <machine/bus.h>
92 1.2 bouyer #ifndef __BUS_SPACE_HAS_STREAM_METHODS
93 1.2 bouyer #define bus_space_write_multi_stream_2 bus_space_write_multi_2
94 1.2 bouyer #define bus_space_write_multi_stream_4 bus_space_write_multi_4
95 1.2 bouyer #define bus_space_read_multi_stream_2 bus_space_read_multi_2
96 1.2 bouyer #define bus_space_read_multi_stream_4 bus_space_read_multi_4
97 1.2 bouyer #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
98 1.2 bouyer
99 1.2 bouyer #include <dev/ata/atareg.h>
100 1.2 bouyer #include <dev/ata/atavar.h>
101 1.2 bouyer #include <dev/ic/wdcreg.h>
102 1.2 bouyer #include <dev/ic/wdcvar.h>
103 1.2 bouyer #include <dev/ata/wdvar.h>
104 1.2 bouyer
105 1.2 bouyer #define DEBUG_INTR 0x01
106 1.2 bouyer #define DEBUG_XFERS 0x02
107 1.2 bouyer #define DEBUG_STATUS 0x04
108 1.2 bouyer #define DEBUG_FUNCS 0x08
109 1.2 bouyer #define DEBUG_PROBE 0x10
110 1.2 bouyer #ifdef WDCDEBUG
111 1.3 thorpej int wdcdebug_wd_mask = 0;
112 1.2 bouyer #define WDCDEBUG_PRINT(args, level) \
113 1.2 bouyer if (wdcdebug_wd_mask & (level)) \
114 1.2 bouyer printf args
115 1.2 bouyer #else
116 1.2 bouyer #define WDCDEBUG_PRINT(args, level)
117 1.2 bouyer #endif
118 1.2 bouyer
119 1.17 bouyer #define ATA_DELAY 10000 /* 10s for a drive I/O */
120 1.2 bouyer
121 1.2 bouyer void wdc_ata_bio_start __P((struct channel_softc *,struct wdc_xfer *));
122 1.20 bouyer void _wdc_ata_bio_start __P((struct channel_softc *,struct wdc_xfer *));
123 1.19 bouyer int wdc_ata_bio_intr __P((struct channel_softc *, struct wdc_xfer *, int));
124 1.22 enami void wdc_ata_bio_kill_xfer __P((struct channel_softc *,struct wdc_xfer *));
125 1.2 bouyer void wdc_ata_bio_done __P((struct channel_softc *, struct wdc_xfer *));
126 1.19 bouyer int wdc_ata_ctrl_intr __P((struct channel_softc *, struct wdc_xfer *, int));
127 1.16 bouyer int wdc_ata_err __P((struct ata_drive_datas *, struct ata_bio *));
128 1.2 bouyer #define WDC_ATA_NOERR 0x00 /* Drive doesn't report an error */
129 1.2 bouyer #define WDC_ATA_RECOV 0x01 /* There was a recovered error */
130 1.2 bouyer #define WDC_ATA_ERR 0x02 /* Drive reports an error */
131 1.2 bouyer
132 1.2 bouyer /*
133 1.2 bouyer * Handle block I/O operation. Return WDC_COMPLETE, WDC_QUEUED, or
134 1.29 jdolecek * WDC_TRY_AGAIN. Must be called at splbio().
135 1.2 bouyer */
136 1.2 bouyer int
137 1.2 bouyer wdc_ata_bio(drvp, ata_bio)
138 1.2 bouyer struct ata_drive_datas *drvp;
139 1.2 bouyer struct ata_bio *ata_bio;
140 1.2 bouyer {
141 1.2 bouyer struct wdc_xfer *xfer;
142 1.2 bouyer struct channel_softc *chp = drvp->chnl_softc;
143 1.2 bouyer
144 1.2 bouyer xfer = wdc_get_xfer(WDC_NOSLEEP);
145 1.2 bouyer if (xfer == NULL)
146 1.2 bouyer return WDC_TRY_AGAIN;
147 1.30 bjh21 if (chp->wdc->cap & WDC_CAPABILITY_NOIRQ)
148 1.30 bjh21 ata_bio->flags |= ATA_POLL;
149 1.2 bouyer if (ata_bio->flags & ATA_POLL)
150 1.2 bouyer xfer->c_flags |= C_POLL;
151 1.2 bouyer if ((drvp->drive_flags & (DRIVE_DMA | DRIVE_UDMA)) &&
152 1.2 bouyer (ata_bio->flags & ATA_SINGLE) == 0)
153 1.2 bouyer xfer->c_flags |= C_DMA;
154 1.2 bouyer xfer->drive = drvp->drive;
155 1.2 bouyer xfer->cmd = ata_bio;
156 1.2 bouyer xfer->databuf = ata_bio->databuf;
157 1.2 bouyer xfer->c_bcount = ata_bio->bcount;
158 1.2 bouyer xfer->c_start = wdc_ata_bio_start;
159 1.2 bouyer xfer->c_intr = wdc_ata_bio_intr;
160 1.22 enami xfer->c_kill_xfer = wdc_ata_bio_kill_xfer;
161 1.2 bouyer wdc_exec_xfer(chp, xfer);
162 1.2 bouyer return (ata_bio->flags & ATA_ITSDONE) ? WDC_COMPLETE : WDC_QUEUED;
163 1.2 bouyer }
164 1.2 bouyer
165 1.2 bouyer void
166 1.2 bouyer wdc_ata_bio_start(chp, xfer)
167 1.2 bouyer struct channel_softc *chp;
168 1.2 bouyer struct wdc_xfer *xfer;
169 1.2 bouyer {
170 1.2 bouyer struct ata_bio *ata_bio = xfer->cmd;
171 1.20 bouyer WDCDEBUG_PRINT(("wdc_ata_bio_start %s:%d:%d\n",
172 1.20 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive),
173 1.20 bouyer DEBUG_XFERS);
174 1.20 bouyer
175 1.20 bouyer /* start timeout machinery */
176 1.20 bouyer if ((ata_bio->flags & ATA_POLL) == 0)
177 1.24 thorpej callout_reset(&chp->ch_callout, ATA_DELAY / 1000 * hz,
178 1.24 thorpej wdctimeout, chp);
179 1.20 bouyer _wdc_ata_bio_start(chp, xfer);
180 1.20 bouyer }
181 1.20 bouyer
182 1.20 bouyer void
183 1.20 bouyer _wdc_ata_bio_start(chp, xfer)
184 1.20 bouyer struct channel_softc *chp;
185 1.20 bouyer struct wdc_xfer *xfer;
186 1.20 bouyer {
187 1.20 bouyer struct ata_bio *ata_bio = xfer->cmd;
188 1.2 bouyer struct ata_drive_datas *drvp = &chp->ch_drive[xfer->drive];
189 1.2 bouyer u_int16_t cyl;
190 1.2 bouyer u_int8_t head, sect, cmd = 0;
191 1.2 bouyer int nblks;
192 1.16 bouyer int ata_delay;
193 1.2 bouyer int dma_flags = 0;
194 1.2 bouyer
195 1.20 bouyer WDCDEBUG_PRINT(("_wdc_ata_bio_start %s:%d:%d\n",
196 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive),
197 1.20 bouyer DEBUG_INTR | DEBUG_XFERS);
198 1.2 bouyer /* Do control operations specially. */
199 1.2 bouyer if (drvp->state < READY) {
200 1.2 bouyer /*
201 1.2 bouyer * Actually, we want to be careful not to mess with the control
202 1.2 bouyer * state if the device is currently busy, but we can assume
203 1.2 bouyer * that we never get to this point if that's the case.
204 1.2 bouyer */
205 1.2 bouyer /* at this point, we should only be in RECAL state */
206 1.26 bouyer if (drvp->state != RESET) {
207 1.20 bouyer printf("%s:%d:%d: bad state %d in _wdc_ata_bio_start\n",
208 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel,
209 1.2 bouyer xfer->drive, drvp->state);
210 1.20 bouyer panic("_wdc_ata_bio_start: bad state");
211 1.2 bouyer }
212 1.26 bouyer drvp->state = RECAL;
213 1.2 bouyer xfer->c_intr = wdc_ata_ctrl_intr;
214 1.2 bouyer bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_sdh,
215 1.2 bouyer WDSD_IBM | (xfer->drive << 4));
216 1.17 bouyer if (wdcwait(chp, WDCS_DRDY, WDCS_DRDY, ATA_DELAY) != 0)
217 1.2 bouyer goto timeout;
218 1.2 bouyer wdccommandshort(chp, xfer->drive, WDCC_RECAL);
219 1.2 bouyer drvp->state = RECAL_WAIT;
220 1.2 bouyer if ((ata_bio->flags & ATA_POLL) == 0) {
221 1.2 bouyer chp->ch_flags |= WDCF_IRQ_WAIT;
222 1.2 bouyer } else {
223 1.2 bouyer /* Wait for at last 400ns for status bit to be valid */
224 1.19 bouyer DELAY(1);
225 1.19 bouyer wdc_ata_ctrl_intr(chp, xfer, 0);
226 1.2 bouyer }
227 1.2 bouyer return;
228 1.2 bouyer }
229 1.2 bouyer
230 1.2 bouyer if (xfer->c_flags & C_DMA) {
231 1.23 bouyer if (drvp->n_xfers <= NXFER)
232 1.23 bouyer drvp->n_xfers++;
233 1.2 bouyer dma_flags = (ata_bio->flags & ATA_READ) ? WDC_DMA_READ : 0;
234 1.2 bouyer }
235 1.16 bouyer if (ata_bio->flags & ATA_SINGLE)
236 1.17 bouyer ata_delay = ATA_DELAY;
237 1.16 bouyer else
238 1.17 bouyer ata_delay = ATA_DELAY;
239 1.2 bouyer again:
240 1.2 bouyer /*
241 1.2 bouyer *
242 1.2 bouyer * When starting a multi-sector transfer, or doing single-sector
243 1.2 bouyer * transfers...
244 1.2 bouyer */
245 1.2 bouyer if (xfer->c_skip == 0 || (ata_bio->flags & ATA_SINGLE) != 0) {
246 1.2 bouyer if (ata_bio->flags & ATA_SINGLE)
247 1.2 bouyer nblks = 1;
248 1.2 bouyer else
249 1.2 bouyer nblks = xfer->c_bcount / ata_bio->lp->d_secsize;
250 1.2 bouyer /* Check for bad sectors and adjust transfer, if necessary. */
251 1.2 bouyer if ((ata_bio->lp->d_flags & D_BADSECT) != 0) {
252 1.2 bouyer long blkdiff;
253 1.2 bouyer int i;
254 1.2 bouyer for (i = 0; (blkdiff = ata_bio->badsect[i]) != -1;
255 1.2 bouyer i++) {
256 1.2 bouyer blkdiff -= ata_bio->blkno;
257 1.2 bouyer if (blkdiff < 0)
258 1.2 bouyer continue;
259 1.2 bouyer if (blkdiff == 0) {
260 1.2 bouyer /* Replace current block of transfer. */
261 1.2 bouyer ata_bio->blkno =
262 1.2 bouyer ata_bio->lp->d_secperunit -
263 1.2 bouyer ata_bio->lp->d_nsectors - i - 1;
264 1.2 bouyer }
265 1.2 bouyer if (blkdiff < nblks) {
266 1.2 bouyer /* Bad block inside transfer. */
267 1.2 bouyer ata_bio->flags |= ATA_SINGLE;
268 1.2 bouyer nblks = 1;
269 1.2 bouyer }
270 1.2 bouyer break;
271 1.2 bouyer }
272 1.2 bouyer /* Transfer is okay now. */
273 1.2 bouyer }
274 1.2 bouyer if (ata_bio->flags & ATA_LBA) {
275 1.2 bouyer sect = (ata_bio->blkno >> 0) & 0xff;
276 1.2 bouyer cyl = (ata_bio->blkno >> 8) & 0xffff;
277 1.2 bouyer head = (ata_bio->blkno >> 24) & 0x0f;
278 1.2 bouyer head |= WDSD_LBA;
279 1.2 bouyer } else {
280 1.2 bouyer int blkno = ata_bio->blkno;
281 1.2 bouyer sect = blkno % ata_bio->lp->d_nsectors;
282 1.2 bouyer sect++; /* Sectors begin with 1, not 0. */
283 1.2 bouyer blkno /= ata_bio->lp->d_nsectors;
284 1.2 bouyer head = blkno % ata_bio->lp->d_ntracks;
285 1.2 bouyer blkno /= ata_bio->lp->d_ntracks;
286 1.2 bouyer cyl = blkno;
287 1.2 bouyer head |= WDSD_CHS;
288 1.2 bouyer }
289 1.2 bouyer if (xfer->c_flags & C_DMA) {
290 1.2 bouyer ata_bio->nblks = nblks;
291 1.2 bouyer ata_bio->nbytes = xfer->c_bcount;
292 1.2 bouyer cmd = (ata_bio->flags & ATA_READ) ?
293 1.2 bouyer WDCC_READDMA : WDCC_WRITEDMA;
294 1.2 bouyer /* Init the DMA channel. */
295 1.2 bouyer if ((*chp->wdc->dma_init)(chp->wdc->dma_arg,
296 1.2 bouyer chp->channel, xfer->drive,
297 1.11 augustss (char *)xfer->databuf + xfer->c_skip,
298 1.11 augustss ata_bio->nbytes, dma_flags) != 0) {
299 1.2 bouyer ata_bio->error = ERR_DMA;
300 1.2 bouyer ata_bio->r_error = 0;
301 1.2 bouyer wdc_ata_bio_done(chp, xfer);
302 1.2 bouyer return;
303 1.2 bouyer }
304 1.2 bouyer /* Initiate command */
305 1.2 bouyer bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_sdh,
306 1.2 bouyer WDSD_IBM | (xfer->drive << 4));
307 1.16 bouyer if (wait_for_ready(chp, ata_delay) < 0)
308 1.2 bouyer goto timeout;
309 1.2 bouyer wdccommand(chp, xfer->drive, cmd, cyl,
310 1.2 bouyer head, sect, nblks, 0);
311 1.2 bouyer /* start the DMA channel */
312 1.2 bouyer (*chp->wdc->dma_start)(chp->wdc->dma_arg,
313 1.26 bouyer chp->channel, xfer->drive);
314 1.26 bouyer chp->ch_flags |= WDCF_DMA_WAIT;
315 1.2 bouyer /* wait for irq */
316 1.2 bouyer goto intr;
317 1.2 bouyer } /* else not DMA */
318 1.2 bouyer ata_bio->nblks = min(nblks, ata_bio->multi);
319 1.2 bouyer ata_bio->nbytes = ata_bio->nblks * ata_bio->lp->d_secsize;
320 1.2 bouyer if (ata_bio->nblks > 1 && (ata_bio->flags & ATA_SINGLE) == 0) {
321 1.2 bouyer cmd = (ata_bio->flags & ATA_READ) ?
322 1.2 bouyer WDCC_READMULTI : WDCC_WRITEMULTI;
323 1.2 bouyer } else {
324 1.2 bouyer cmd = (ata_bio->flags & ATA_READ) ?
325 1.2 bouyer WDCC_READ : WDCC_WRITE;
326 1.2 bouyer }
327 1.2 bouyer /* Initiate command! */
328 1.2 bouyer bus_space_write_1(chp->cmd_iot, chp->cmd_ioh, wd_sdh,
329 1.2 bouyer WDSD_IBM | (xfer->drive << 4));
330 1.16 bouyer if (wait_for_ready(chp, ata_delay) < 0)
331 1.2 bouyer goto timeout;
332 1.2 bouyer wdccommand(chp, xfer->drive, cmd, cyl,
333 1.2 bouyer head, sect, nblks,
334 1.2 bouyer (ata_bio->lp->d_type == DTYPE_ST506) ?
335 1.2 bouyer ata_bio->lp->d_precompcyl / 4 : 0);
336 1.2 bouyer } else if (ata_bio->nblks > 1) {
337 1.2 bouyer /* The number of blocks in the last stretch may be smaller. */
338 1.2 bouyer nblks = xfer->c_bcount / ata_bio->lp->d_secsize;
339 1.2 bouyer if (ata_bio->nblks > nblks) {
340 1.2 bouyer ata_bio->nblks = nblks;
341 1.2 bouyer ata_bio->nbytes = xfer->c_bcount;
342 1.2 bouyer }
343 1.2 bouyer }
344 1.2 bouyer /* If this was a write and not using DMA, push the data. */
345 1.2 bouyer if ((ata_bio->flags & ATA_READ) == 0) {
346 1.16 bouyer if (wait_for_drq(chp, ata_delay) != 0) {
347 1.2 bouyer printf("%s:%d:%d: timeout waiting for DRQ, "
348 1.2 bouyer "st=0x%02x, err=0x%02x\n",
349 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel,
350 1.2 bouyer xfer->drive, chp->ch_status, chp->ch_error);
351 1.16 bouyer if (wdc_ata_err(drvp, ata_bio) != WDC_ATA_ERR)
352 1.2 bouyer ata_bio->error = TIMEOUT;
353 1.2 bouyer wdc_ata_bio_done(chp, xfer);
354 1.2 bouyer return;
355 1.2 bouyer }
356 1.16 bouyer if (wdc_ata_err(drvp, ata_bio) == WDC_ATA_ERR) {
357 1.2 bouyer wdc_ata_bio_done(chp, xfer);
358 1.2 bouyer return;
359 1.2 bouyer }
360 1.2 bouyer if ((chp->wdc->cap & WDC_CAPABILITY_ATA_NOSTREAM)) {
361 1.2 bouyer if (drvp->drive_flags & DRIVE_CAP32) {
362 1.2 bouyer bus_space_write_multi_4(chp->data32iot,
363 1.2 bouyer chp->data32ioh, 0,
364 1.12 thorpej (u_int32_t *)((char *)xfer->databuf +
365 1.12 thorpej xfer->c_skip),
366 1.2 bouyer ata_bio->nbytes >> 2);
367 1.2 bouyer } else {
368 1.2 bouyer bus_space_write_multi_2(chp->cmd_iot,
369 1.2 bouyer chp->cmd_ioh, wd_data,
370 1.12 thorpej (u_int16_t *)((char *)xfer->databuf +
371 1.12 thorpej xfer->c_skip),
372 1.2 bouyer ata_bio->nbytes >> 1);
373 1.2 bouyer }
374 1.2 bouyer } else {
375 1.2 bouyer if (drvp->drive_flags & DRIVE_CAP32) {
376 1.2 bouyer bus_space_write_multi_stream_4(chp->data32iot,
377 1.2 bouyer chp->data32ioh, 0,
378 1.12 thorpej (u_int32_t *)((char *)xfer->databuf +
379 1.12 thorpej xfer->c_skip),
380 1.2 bouyer ata_bio->nbytes >> 2);
381 1.2 bouyer } else {
382 1.2 bouyer bus_space_write_multi_stream_2(chp->cmd_iot,
383 1.2 bouyer chp->cmd_ioh, wd_data,
384 1.12 thorpej (u_int16_t *)((char *)xfer->databuf +
385 1.12 thorpej xfer->c_skip),
386 1.2 bouyer ata_bio->nbytes >> 1);
387 1.2 bouyer }
388 1.2 bouyer }
389 1.2 bouyer }
390 1.2 bouyer
391 1.2 bouyer intr: /* Wait for IRQ (either real or polled) */
392 1.2 bouyer if ((ata_bio->flags & ATA_POLL) == 0) {
393 1.2 bouyer chp->ch_flags |= WDCF_IRQ_WAIT;
394 1.2 bouyer } else {
395 1.2 bouyer /* Wait for at last 400ns for status bit to be valid */
396 1.2 bouyer delay(1);
397 1.26 bouyer if (chp->ch_flags & WDCF_DMA_WAIT) {
398 1.26 bouyer wdc_dmawait(chp, xfer, ATA_DELAY);
399 1.26 bouyer chp->ch_flags &= ~WDCF_DMA_WAIT;
400 1.26 bouyer }
401 1.19 bouyer wdc_ata_bio_intr(chp, xfer, 0);
402 1.2 bouyer if ((ata_bio->flags & ATA_ITSDONE) == 0)
403 1.2 bouyer goto again;
404 1.2 bouyer }
405 1.2 bouyer return;
406 1.2 bouyer timeout:
407 1.2 bouyer printf("%s:%d:%d: not ready, st=0x%02x, err=0x%02x\n",
408 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,
409 1.2 bouyer chp->ch_status, chp->ch_error);
410 1.16 bouyer if (wdc_ata_err(drvp, ata_bio) != WDC_ATA_ERR)
411 1.2 bouyer ata_bio->error = TIMEOUT;
412 1.2 bouyer wdc_ata_bio_done(chp, xfer);
413 1.2 bouyer return;
414 1.2 bouyer }
415 1.2 bouyer
416 1.2 bouyer int
417 1.19 bouyer wdc_ata_bio_intr(chp, xfer, irq)
418 1.2 bouyer struct channel_softc *chp;
419 1.2 bouyer struct wdc_xfer *xfer;
420 1.19 bouyer int irq;
421 1.2 bouyer {
422 1.2 bouyer struct ata_bio *ata_bio = xfer->cmd;
423 1.2 bouyer struct ata_drive_datas *drvp = &chp->ch_drive[xfer->drive];
424 1.2 bouyer int drv_err;
425 1.2 bouyer
426 1.2 bouyer WDCDEBUG_PRINT(("wdc_ata_bio_intr %s:%d:%d\n",
427 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive),
428 1.2 bouyer DEBUG_INTR | DEBUG_XFERS);
429 1.2 bouyer
430 1.2 bouyer
431 1.2 bouyer /* Is it not a transfer, but a control operation? */
432 1.2 bouyer if (drvp->state < READY) {
433 1.2 bouyer printf("%s:%d:%d: bad state %d in wdc_ata_bio_intr\n",
434 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,
435 1.2 bouyer drvp->state);
436 1.2 bouyer panic("wdc_ata_bio_intr: bad state\n");
437 1.2 bouyer }
438 1.2 bouyer
439 1.20 bouyer /*
440 1.20 bouyer * if we missed an interrupt in a PIO transfer, reset and restart.
441 1.20 bouyer * Don't try to continue transfer, we may have missed cycles.
442 1.20 bouyer */
443 1.20 bouyer if ((xfer->c_flags & (C_TIMEOU | C_DMA)) == C_TIMEOU) {
444 1.20 bouyer ata_bio->error = TIMEOUT;
445 1.20 bouyer wdc_ata_bio_done(chp, xfer);
446 1.20 bouyer return 1;
447 1.20 bouyer }
448 1.20 bouyer
449 1.2 bouyer /* Ack interrupt done by wait_for_unbusy */
450 1.18 bouyer if (wait_for_unbusy(chp,
451 1.19 bouyer (irq == 0) ? ATA_DELAY : 0) < 0) {
452 1.19 bouyer if (irq && (xfer->c_flags & C_TIMEOU) == 0)
453 1.18 bouyer return 0; /* IRQ was not for us */
454 1.2 bouyer printf("%s:%d:%d: device timeout, c_bcount=%d, c_skip%d\n",
455 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,
456 1.2 bouyer xfer->c_bcount, xfer->c_skip);
457 1.26 bouyer /* if we were using DMA, flag a DMA error */
458 1.10 bouyer if (xfer->c_flags & C_DMA) {
459 1.23 bouyer ata_dmaerr(drvp);
460 1.10 bouyer }
461 1.2 bouyer ata_bio->error = TIMEOUT;
462 1.2 bouyer wdc_ata_bio_done(chp, xfer);
463 1.2 bouyer return 1;
464 1.2 bouyer }
465 1.28 bouyer if (chp->wdc->cap & WDC_CAPABILITY_IRQACK)
466 1.28 bouyer chp->wdc->irqack(chp);
467 1.2 bouyer
468 1.16 bouyer drv_err = wdc_ata_err(drvp, ata_bio);
469 1.2 bouyer
470 1.2 bouyer /* If we were using DMA, Turn off the DMA channel and check for error */
471 1.2 bouyer if (xfer->c_flags & C_DMA) {
472 1.2 bouyer if (ata_bio->flags & ATA_POLL) {
473 1.2 bouyer /*
474 1.13 bouyer * IDE drives deassert WDCS_BSY before transfer is
475 1.2 bouyer * complete when using DMA. Polling for DRQ to deassert
476 1.2 bouyer * is not enouth DRQ is not required to be
477 1.7 bouyer * asserted for DMA transfers, so poll for DRDY.
478 1.2 bouyer */
479 1.2 bouyer if (wdcwait(chp, WDCS_DRDY | WDCS_DRQ, WDCS_DRDY,
480 1.17 bouyer ATA_DELAY) < 0) {
481 1.7 bouyer printf("%s:%d:%d: polled transfer timed out "
482 1.2 bouyer "(st=0x%x)\n", chp->wdc->sc_dev.dv_xname,
483 1.2 bouyer chp->channel, xfer->drive, chp->ch_status);
484 1.2 bouyer ata_bio->error = TIMEOUT;
485 1.10 bouyer drv_err = WDC_ATA_ERR;
486 1.10 bouyer }
487 1.10 bouyer }
488 1.26 bouyer if (chp->wdc->dma_status != 0) {
489 1.10 bouyer if (drv_err != WDC_ATA_ERR) {
490 1.10 bouyer ata_bio->error = ERR_DMA;
491 1.10 bouyer drv_err = WDC_ATA_ERR;
492 1.2 bouyer }
493 1.2 bouyer }
494 1.2 bouyer if (chp->ch_status & WDCS_DRQ) {
495 1.2 bouyer if (drv_err != WDC_ATA_ERR) {
496 1.2 bouyer printf("%s:%d:%d: intr with DRQ (st=0x%x)\n",
497 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel,
498 1.2 bouyer xfer->drive, chp->ch_status);
499 1.2 bouyer ata_bio->error = TIMEOUT;
500 1.2 bouyer drv_err = WDC_ATA_ERR;
501 1.2 bouyer }
502 1.2 bouyer }
503 1.2 bouyer if (drv_err != WDC_ATA_ERR)
504 1.2 bouyer goto end;
505 1.23 bouyer ata_dmaerr(drvp);
506 1.2 bouyer }
507 1.2 bouyer
508 1.2 bouyer /* if we had an error, end */
509 1.2 bouyer if (drv_err == WDC_ATA_ERR) {
510 1.2 bouyer wdc_ata_bio_done(chp, xfer);
511 1.2 bouyer return 1;
512 1.2 bouyer }
513 1.2 bouyer
514 1.2 bouyer /* If this was a read and not using DMA, fetch the data. */
515 1.2 bouyer if ((ata_bio->flags & ATA_READ) != 0) {
516 1.14 bouyer if ((chp->ch_status & WDCS_DRQ) != WDCS_DRQ) {
517 1.2 bouyer printf("%s:%d:%d: read intr before drq\n",
518 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel,
519 1.2 bouyer xfer->drive);
520 1.2 bouyer ata_bio->error = TIMEOUT;
521 1.2 bouyer wdc_ata_bio_done(chp, xfer);
522 1.2 bouyer return 1;
523 1.2 bouyer }
524 1.2 bouyer if ((chp->wdc->cap & WDC_CAPABILITY_ATA_NOSTREAM)) {
525 1.2 bouyer if (drvp->drive_flags & DRIVE_CAP32) {
526 1.2 bouyer bus_space_read_multi_4(chp->data32iot,
527 1.2 bouyer chp->data32ioh, 0,
528 1.12 thorpej (u_int32_t *)((char *)xfer->databuf +
529 1.12 thorpej xfer->c_skip),
530 1.2 bouyer ata_bio->nbytes >> 2);
531 1.2 bouyer } else {
532 1.2 bouyer bus_space_read_multi_2(chp->cmd_iot,
533 1.2 bouyer chp->cmd_ioh, wd_data,
534 1.12 thorpej (u_int16_t *)((char *)xfer->databuf +
535 1.12 thorpej xfer->c_skip),
536 1.2 bouyer ata_bio->nbytes >> 1);
537 1.2 bouyer }
538 1.2 bouyer } else {
539 1.2 bouyer if (drvp->drive_flags & DRIVE_CAP32) {
540 1.2 bouyer bus_space_read_multi_stream_4(chp->data32iot,
541 1.2 bouyer chp->data32ioh, 0,
542 1.12 thorpej (u_int32_t *)((char *)xfer->databuf +
543 1.12 thorpej xfer->c_skip),
544 1.2 bouyer ata_bio->nbytes >> 2);
545 1.2 bouyer } else {
546 1.2 bouyer bus_space_read_multi_stream_2(chp->cmd_iot,
547 1.2 bouyer chp->cmd_ioh, wd_data,
548 1.12 thorpej (u_int16_t *)((char *)xfer->databuf +
549 1.12 thorpej xfer->c_skip),
550 1.2 bouyer ata_bio->nbytes >> 1);
551 1.2 bouyer }
552 1.2 bouyer }
553 1.2 bouyer }
554 1.2 bouyer
555 1.2 bouyer end:
556 1.2 bouyer ata_bio->blkno += ata_bio->nblks;
557 1.2 bouyer ata_bio->blkdone += ata_bio->nblks;
558 1.2 bouyer xfer->c_skip += ata_bio->nbytes;
559 1.2 bouyer xfer->c_bcount -= ata_bio->nbytes;
560 1.2 bouyer /* See if this transfer is complete. */
561 1.2 bouyer if (xfer->c_bcount > 0) {
562 1.2 bouyer if ((ata_bio->flags & ATA_POLL) == 0) {
563 1.2 bouyer /* Start the next operation */
564 1.20 bouyer _wdc_ata_bio_start(chp, xfer);
565 1.2 bouyer } else {
566 1.20 bouyer /* Let _wdc_ata_bio_start do the loop */
567 1.2 bouyer return 1;
568 1.2 bouyer }
569 1.2 bouyer } else { /* Done with this transfer */
570 1.2 bouyer ata_bio->error = NOERROR;
571 1.2 bouyer wdc_ata_bio_done(chp, xfer);
572 1.2 bouyer }
573 1.2 bouyer return 1;
574 1.22 enami }
575 1.22 enami
576 1.22 enami void
577 1.22 enami wdc_ata_kill_pending(drvp)
578 1.22 enami struct ata_drive_datas *drvp;
579 1.22 enami {
580 1.22 enami struct channel_softc *chp = drvp->chnl_softc;
581 1.22 enami
582 1.22 enami wdc_kill_pending(chp);
583 1.22 enami }
584 1.22 enami
585 1.22 enami void
586 1.22 enami wdc_ata_bio_kill_xfer(chp, xfer)
587 1.22 enami struct channel_softc *chp;
588 1.22 enami struct wdc_xfer *xfer;
589 1.22 enami {
590 1.22 enami struct ata_bio *ata_bio = xfer->cmd;
591 1.22 enami int drive = xfer->drive;
592 1.22 enami
593 1.24 thorpej callout_stop(&chp->ch_callout);
594 1.22 enami /* remove this command from xfer queue */
595 1.22 enami wdc_free_xfer(chp, xfer);
596 1.22 enami
597 1.22 enami ata_bio->flags |= ATA_ITSDONE;
598 1.22 enami ata_bio->error = ERR_NODEV;
599 1.22 enami ata_bio->r_error = WDCE_ABRT;
600 1.30 bjh21 WDCDEBUG_PRINT(("wdc_ata_done: wddone\n"), DEBUG_XFERS);
601 1.30 bjh21 wddone(chp->ch_drive[drive].drv_softc);
602 1.2 bouyer }
603 1.2 bouyer
604 1.2 bouyer void
605 1.2 bouyer wdc_ata_bio_done(chp, xfer)
606 1.2 bouyer struct channel_softc *chp;
607 1.2 bouyer struct wdc_xfer *xfer;
608 1.2 bouyer {
609 1.2 bouyer struct ata_bio *ata_bio = xfer->cmd;
610 1.2 bouyer int drive = xfer->drive;
611 1.2 bouyer
612 1.5 bouyer WDCDEBUG_PRINT(("wdc_ata_bio_done %s:%d:%d: flags 0x%x\n",
613 1.5 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,
614 1.5 bouyer (u_int)xfer->c_flags),
615 1.4 bouyer DEBUG_XFERS);
616 1.10 bouyer
617 1.24 thorpej callout_stop(&chp->ch_callout);
618 1.2 bouyer
619 1.2 bouyer /* feed back residual bcount to our caller */
620 1.2 bouyer ata_bio->bcount = xfer->c_bcount;
621 1.2 bouyer
622 1.2 bouyer /* remove this command from xfer queue */
623 1.2 bouyer wdc_free_xfer(chp, xfer);
624 1.2 bouyer
625 1.2 bouyer ata_bio->flags |= ATA_ITSDONE;
626 1.30 bjh21 WDCDEBUG_PRINT(("wdc_ata_done: wddone\n"), DEBUG_XFERS);
627 1.30 bjh21 wddone(chp->ch_drive[drive].drv_softc);
628 1.2 bouyer WDCDEBUG_PRINT(("wdcstart from wdc_ata_done, flags 0x%x\n",
629 1.4 bouyer chp->ch_flags), DEBUG_XFERS);
630 1.9 drochner wdcstart(chp);
631 1.2 bouyer }
632 1.2 bouyer
633 1.2 bouyer /*
634 1.2 bouyer * Implement operations needed before read/write.
635 1.2 bouyer */
636 1.2 bouyer int
637 1.19 bouyer wdc_ata_ctrl_intr(chp, xfer, irq)
638 1.2 bouyer struct channel_softc *chp;
639 1.2 bouyer struct wdc_xfer *xfer;
640 1.19 bouyer int irq;
641 1.2 bouyer {
642 1.2 bouyer struct ata_bio *ata_bio = xfer->cmd;
643 1.2 bouyer struct ata_drive_datas *drvp = &chp->ch_drive[xfer->drive];
644 1.2 bouyer char *errstring = NULL;
645 1.19 bouyer int delay = (irq == 0) ? ATA_DELAY : 0;
646 1.18 bouyer
647 1.2 bouyer WDCDEBUG_PRINT(("wdc_ata_ctrl_intr: state %d\n", drvp->state),
648 1.18 bouyer DEBUG_FUNCS);
649 1.2 bouyer
650 1.2 bouyer again:
651 1.2 bouyer switch (drvp->state) {
652 1.2 bouyer case RECAL: /* Should not be in this state here */
653 1.2 bouyer panic("wdc_ata_ctrl_intr: state==RECAL");
654 1.2 bouyer break;
655 1.2 bouyer
656 1.2 bouyer case RECAL_WAIT:
657 1.2 bouyer errstring = "recal";
658 1.18 bouyer if (wdcwait(chp, WDCS_DRDY, WDCS_DRDY, delay))
659 1.2 bouyer goto timeout;
660 1.28 bouyer if (chp->wdc->cap & WDC_CAPABILITY_IRQACK)
661 1.28 bouyer chp->wdc->irqack(chp);
662 1.2 bouyer if (chp->ch_status & (WDCS_ERR | WDCS_DWF))
663 1.2 bouyer goto error;
664 1.2 bouyer /* fall through */
665 1.2 bouyer
666 1.2 bouyer case PIOMODE:
667 1.2 bouyer /* Don't try to set modes if controller can't be adjusted */
668 1.2 bouyer if ((chp->wdc->cap & WDC_CAPABILITY_MODE) == 0)
669 1.6 bouyer goto geometry;
670 1.6 bouyer /* Also don't try if the drive didn't report its mode */
671 1.6 bouyer if ((drvp->drive_flags & DRIVE_MODE) == 0)
672 1.2 bouyer goto geometry;
673 1.2 bouyer wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
674 1.2 bouyer 0x08 | drvp->PIO_mode, WDSF_SET_MODE);
675 1.2 bouyer drvp->state = PIOMODE_WAIT;
676 1.2 bouyer break;
677 1.2 bouyer
678 1.2 bouyer case PIOMODE_WAIT:
679 1.2 bouyer errstring = "piomode";
680 1.18 bouyer if (wdcwait(chp, WDCS_DRDY, WDCS_DRDY, delay))
681 1.2 bouyer goto timeout;
682 1.28 bouyer if (chp->wdc->cap & WDC_CAPABILITY_IRQACK)
683 1.28 bouyer chp->wdc->irqack(chp);
684 1.2 bouyer if (chp->ch_status & (WDCS_ERR | WDCS_DWF))
685 1.2 bouyer goto error;
686 1.2 bouyer /* fall through */
687 1.2 bouyer
688 1.2 bouyer case DMAMODE:
689 1.2 bouyer if (drvp->drive_flags & DRIVE_UDMA) {
690 1.2 bouyer wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
691 1.2 bouyer 0x40 | drvp->UDMA_mode, WDSF_SET_MODE);
692 1.2 bouyer } else if (drvp->drive_flags & DRIVE_DMA) {
693 1.2 bouyer wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,
694 1.2 bouyer 0x20 | drvp->DMA_mode, WDSF_SET_MODE);
695 1.2 bouyer } else {
696 1.2 bouyer goto geometry;
697 1.2 bouyer }
698 1.2 bouyer drvp->state = DMAMODE_WAIT;
699 1.2 bouyer break;
700 1.2 bouyer case DMAMODE_WAIT:
701 1.2 bouyer errstring = "dmamode";
702 1.18 bouyer if (wdcwait(chp, WDCS_DRDY, WDCS_DRDY, delay))
703 1.2 bouyer goto timeout;
704 1.28 bouyer if (chp->wdc->cap & WDC_CAPABILITY_IRQACK)
705 1.28 bouyer chp->wdc->irqack(chp);
706 1.2 bouyer if (chp->ch_status & (WDCS_ERR | WDCS_DWF))
707 1.2 bouyer goto error;
708 1.2 bouyer /* fall through */
709 1.2 bouyer
710 1.2 bouyer case GEOMETRY:
711 1.2 bouyer geometry:
712 1.2 bouyer if (ata_bio->flags & ATA_LBA)
713 1.2 bouyer goto multimode;
714 1.2 bouyer wdccommand(chp, xfer->drive, WDCC_IDP,
715 1.2 bouyer ata_bio->lp->d_ncylinders,
716 1.2 bouyer ata_bio->lp->d_ntracks - 1, 0, ata_bio->lp->d_nsectors,
717 1.2 bouyer (ata_bio->lp->d_type == DTYPE_ST506) ?
718 1.2 bouyer ata_bio->lp->d_precompcyl / 4 : 0);
719 1.2 bouyer drvp->state = GEOMETRY_WAIT;
720 1.2 bouyer break;
721 1.2 bouyer
722 1.2 bouyer case GEOMETRY_WAIT:
723 1.2 bouyer errstring = "geometry";
724 1.18 bouyer if (wdcwait(chp, WDCS_DRDY, WDCS_DRDY, delay))
725 1.2 bouyer goto timeout;
726 1.28 bouyer if (chp->wdc->cap & WDC_CAPABILITY_IRQACK)
727 1.28 bouyer chp->wdc->irqack(chp);
728 1.2 bouyer if (chp->ch_status & (WDCS_ERR | WDCS_DWF))
729 1.2 bouyer goto error;
730 1.2 bouyer /* fall through */
731 1.2 bouyer
732 1.2 bouyer case MULTIMODE:
733 1.2 bouyer multimode:
734 1.2 bouyer if (ata_bio->multi == 1)
735 1.2 bouyer goto ready;
736 1.2 bouyer wdccommand(chp, xfer->drive, WDCC_SETMULTI, 0, 0, 0,
737 1.2 bouyer ata_bio->multi, 0);
738 1.2 bouyer drvp->state = MULTIMODE_WAIT;
739 1.2 bouyer break;
740 1.2 bouyer
741 1.2 bouyer case MULTIMODE_WAIT:
742 1.2 bouyer errstring = "setmulti";
743 1.18 bouyer if (wdcwait(chp, WDCS_DRDY, WDCS_DRDY, delay))
744 1.2 bouyer goto timeout;
745 1.28 bouyer if (chp->wdc->cap & WDC_CAPABILITY_IRQACK)
746 1.28 bouyer chp->wdc->irqack(chp);
747 1.2 bouyer if (chp->ch_status & (WDCS_ERR | WDCS_DWF))
748 1.2 bouyer goto error;
749 1.2 bouyer /* fall through */
750 1.2 bouyer
751 1.2 bouyer case READY:
752 1.2 bouyer ready:
753 1.2 bouyer drvp->state = READY;
754 1.2 bouyer /*
755 1.2 bouyer * The drive is usable now
756 1.2 bouyer */
757 1.2 bouyer xfer->c_intr = wdc_ata_bio_intr;
758 1.20 bouyer _wdc_ata_bio_start(chp, xfer);
759 1.2 bouyer return 1;
760 1.2 bouyer }
761 1.2 bouyer
762 1.2 bouyer if ((ata_bio->flags & ATA_POLL) == 0) {
763 1.2 bouyer chp->ch_flags |= WDCF_IRQ_WAIT;
764 1.2 bouyer } else {
765 1.2 bouyer goto again;
766 1.2 bouyer }
767 1.2 bouyer return 1;
768 1.2 bouyer
769 1.2 bouyer timeout:
770 1.19 bouyer if (irq && (xfer->c_flags & C_TIMEOU) == 0) {
771 1.2 bouyer return 0; /* IRQ was not for us */
772 1.2 bouyer }
773 1.2 bouyer printf("%s:%d:%d: %s timed out\n",
774 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive, errstring);
775 1.2 bouyer ata_bio->error = TIMEOUT;
776 1.2 bouyer drvp->state = 0;
777 1.2 bouyer wdc_ata_bio_done(chp, xfer);
778 1.2 bouyer return 0;
779 1.2 bouyer error:
780 1.2 bouyer printf("%s:%d:%d: %s ",
781 1.2 bouyer chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,
782 1.2 bouyer errstring);
783 1.2 bouyer if (chp->ch_status & WDCS_DWF) {
784 1.2 bouyer printf("drive fault\n");
785 1.2 bouyer ata_bio->error = ERR_DF;
786 1.2 bouyer } else {
787 1.2 bouyer printf("error (%x)\n", chp->ch_error);
788 1.2 bouyer ata_bio->r_error = chp->ch_error;
789 1.2 bouyer ata_bio->error = ERROR;
790 1.2 bouyer }
791 1.2 bouyer drvp->state = 0;
792 1.2 bouyer wdc_ata_bio_done(chp, xfer);
793 1.2 bouyer return 1;
794 1.2 bouyer }
795 1.2 bouyer
796 1.2 bouyer int
797 1.16 bouyer wdc_ata_err(drvp, ata_bio)
798 1.16 bouyer struct ata_drive_datas *drvp;
799 1.2 bouyer struct ata_bio *ata_bio;
800 1.2 bouyer {
801 1.16 bouyer struct channel_softc *chp = drvp->chnl_softc;
802 1.2 bouyer ata_bio->error = 0;
803 1.2 bouyer if (chp->ch_status & WDCS_BSY) {
804 1.2 bouyer ata_bio->error = TIMEOUT;
805 1.2 bouyer return WDC_ATA_ERR;
806 1.2 bouyer }
807 1.2 bouyer
808 1.2 bouyer if (chp->ch_status & WDCS_DWF) {
809 1.2 bouyer ata_bio->error = ERR_DF;
810 1.2 bouyer return WDC_ATA_ERR;
811 1.2 bouyer }
812 1.2 bouyer
813 1.2 bouyer if (chp->ch_status & WDCS_ERR) {
814 1.2 bouyer ata_bio->error = ERROR;
815 1.2 bouyer ata_bio->r_error = chp->ch_error;
816 1.16 bouyer if (drvp->drive_flags & DRIVE_UDMA &&
817 1.16 bouyer (ata_bio->r_error & WDCE_CRC)) {
818 1.16 bouyer /*
819 1.16 bouyer * Record the CRC error, to avoid downgrading to
820 1.16 bouyer * multiword DMA
821 1.16 bouyer */
822 1.16 bouyer drvp->drive_flags |= DRIVE_DMAERR;
823 1.16 bouyer }
824 1.2 bouyer if (ata_bio->r_error & (WDCE_BBK | WDCE_UNC | WDCE_IDNF |
825 1.2 bouyer WDCE_ABRT | WDCE_TK0NF | WDCE_AMNF))
826 1.2 bouyer return WDC_ATA_ERR;
827 1.2 bouyer return WDC_ATA_NOERR;
828 1.2 bouyer }
829 1.2 bouyer
830 1.2 bouyer if (chp->ch_status & WDCS_CORR)
831 1.2 bouyer ata_bio->flags |= ATA_CORR;
832 1.2 bouyer return WDC_ATA_NOERR;
833 1.8 thorpej }
834 1.8 thorpej
835 1.8 thorpej int
836 1.8 thorpej wdc_ata_addref(drvp)
837 1.8 thorpej struct ata_drive_datas *drvp;
838 1.8 thorpej {
839 1.8 thorpej struct channel_softc *chp = drvp->chnl_softc;
840 1.8 thorpej
841 1.8 thorpej return (wdc_addref(chp));
842 1.8 thorpej }
843 1.8 thorpej
844 1.8 thorpej void
845 1.8 thorpej wdc_ata_delref(drvp)
846 1.8 thorpej struct ata_drive_datas *drvp;
847 1.8 thorpej {
848 1.8 thorpej struct channel_softc *chp = drvp->chnl_softc;
849 1.8 thorpej
850 1.8 thorpej wdc_delref(chp);
851 1.2 bouyer }
852