siisata.c revision 1.33 1 /* $NetBSD: siisata.c,v 1.33 2017/04/24 21:14:32 jakllsch Exp $ */
2
3 /* from ahcisata_core.c */
4
5 /*
6 * Copyright (c) 2006 Manuel Bouyer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 /* from atapi_wdc.c */
31
32 /*
33 * Copyright (c) 1998, 2001 Manuel Bouyer.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
48 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
53 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
55
56 /*
57 * Copyright (c) 2007, 2008, 2009, 2010 Jonathan A. Kollasch.
58 * All rights reserved.
59 *
60 * Redistribution and use in source and binary forms, with or without
61 * modification, are permitted provided that the following conditions
62 * are met:
63 * 1. Redistributions of source code must retain the above copyright
64 * notice, this list of conditions and the following disclaimer.
65 * 2. Redistributions in binary form must reproduce the above copyright
66 * notice, this list of conditions and the following disclaimer in the
67 * documentation and/or other materials provided with the distribution.
68 *
69 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
70 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
71 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
72 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
73 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
74 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
75 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
76 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
77 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
78 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79 */
80
81 #include <sys/cdefs.h>
82 __KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.33 2017/04/24 21:14:32 jakllsch Exp $");
83
84 #include <sys/types.h>
85 #include <sys/malloc.h>
86 #include <sys/param.h>
87 #include <sys/kernel.h>
88 #include <sys/systm.h>
89 #include <sys/syslog.h>
90 #include <sys/disklabel.h>
91 #include <sys/buf.h>
92 #include <sys/proc.h>
93
94 #include <dev/ata/atareg.h>
95 #include <dev/ata/satavar.h>
96 #include <dev/ata/satareg.h>
97 #include <dev/ata/satafisvar.h>
98 #include <dev/ata/satafisreg.h>
99 #include <dev/ata/satapmpreg.h>
100 #include <dev/ic/siisatavar.h>
101 #include <dev/ic/siisatareg.h>
102
103 #include <dev/scsipi/scsi_all.h> /* for SCSI status */
104
105 #include "atapibus.h"
106
107 #ifdef SIISATA_DEBUG
108 int siisata_debug_mask = 0;
109 #endif
110
111 #define ATA_DELAY 10000 /* 10s for a drive I/O */
112
113 #ifndef __BUS_SPACE_HAS_STREAM_METHODS
114 #if _BYTE_ORDER == _LITTLE_ENDIAN
115 #define bus_space_read_stream_4 bus_space_read_4
116 #define bus_space_read_region_stream_4 bus_space_read_region_4
117 #else
118 static inline uint32_t
119 bus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
120 {
121 return htole32(bus_space_read_4(t, h, o));
122 }
123
124 static inline void
125 bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
126 bus_size_t o, uint32_t *p, bus_size_t c)
127 {
128 bus_space_read_region_4(t, h, o, p, c);
129 for (bus_size_t i = 0; i < c; i++) {
130 p[i] = htole32(p[i]);
131 }
132 }
133 #endif
134 #endif
135
136 static void siisata_attach_port(struct siisata_softc *, int);
137 static void siisata_intr_port(struct siisata_channel *);
138
139 void siisata_probe_drive(struct ata_channel *);
140 void siisata_setup_channel(struct ata_channel *);
141
142 int siisata_ata_bio(struct ata_drive_datas *, struct ata_bio *);
143 void siisata_reset_drive(struct ata_drive_datas *, int, uint32_t *);
144 void siisata_reset_channel(struct ata_channel *, int);
145 int siisata_ata_addref(struct ata_drive_datas *);
146 void siisata_ata_delref(struct ata_drive_datas *);
147 void siisata_killpending(struct ata_drive_datas *);
148
149 void siisata_cmd_start(struct ata_channel *, struct ata_xfer *);
150 int siisata_cmd_complete(struct ata_channel *, struct ata_xfer *, int);
151 void siisata_cmd_done(struct ata_channel *, struct ata_xfer *, int);
152 void siisata_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
153
154 void siisata_bio_start(struct ata_channel *, struct ata_xfer *);
155 int siisata_bio_complete(struct ata_channel *, struct ata_xfer *, int);
156 void siisata_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
157 int siisata_exec_command(struct ata_drive_datas *, struct ata_command *);
158
159 void siisata_timeout(void *);
160
161 static void siisata_reinit_port(struct ata_channel *);
162 static void siisata_device_reset(struct ata_channel *);
163 static void siisata_activate_prb(struct siisata_channel *, int);
164 static void siisata_deactivate_prb(struct siisata_channel *, int);
165 static int siisata_dma_setup(struct ata_channel *chp, int, void *,
166 size_t, int);
167
168 #if NATAPIBUS > 0
169 void siisata_atapibus_attach(struct atabus_softc *);
170 void siisata_atapi_probe_device(struct atapibus_softc *, int);
171 void siisata_atapi_minphys(struct buf *);
172 void siisata_atapi_start(struct ata_channel *,struct ata_xfer *);
173 int siisata_atapi_complete(struct ata_channel *, struct ata_xfer *, int);
174 void siisata_atapi_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
175 void siisata_atapi_scsipi_request(struct scsipi_channel *,
176 scsipi_adapter_req_t, void *);
177 void siisata_atapi_kill_pending(struct scsipi_periph *);
178 #endif /* NATAPIBUS */
179
180 const struct ata_bustype siisata_ata_bustype = {
181 SCSIPI_BUSTYPE_ATA,
182 siisata_ata_bio,
183 siisata_reset_drive,
184 siisata_reset_channel,
185 siisata_exec_command,
186 ata_get_params,
187 siisata_ata_addref,
188 siisata_ata_delref,
189 siisata_killpending
190 };
191
192 #if NATAPIBUS > 0
193 static const struct scsipi_bustype siisata_atapi_bustype = {
194 SCSIPI_BUSTYPE_ATAPI,
195 atapi_scsipi_cmd,
196 atapi_interpret_sense,
197 atapi_print_addr,
198 siisata_atapi_kill_pending,
199 NULL,
200 };
201 #endif /* NATAPIBUS */
202
203
204 void
205 siisata_attach(struct siisata_softc *sc)
206 {
207 int i;
208
209 SIISATA_DEBUG_PRINT(("%s: %s: GR_GC: 0x%08x\n",
210 SIISATANAME(sc), __func__, GRREAD(sc, GR_GC)), DEBUG_FUNCS);
211
212 sc->sc_atac.atac_cap = ATAC_CAP_DMA | ATAC_CAP_UDMA;
213 sc->sc_atac.atac_pio_cap = 4;
214 sc->sc_atac.atac_dma_cap = 2;
215 sc->sc_atac.atac_udma_cap = 6;
216 sc->sc_atac.atac_channels = sc->sc_chanarray;
217 sc->sc_atac.atac_probe = siisata_probe_drive;
218 sc->sc_atac.atac_bustype_ata = &siisata_ata_bustype;
219 sc->sc_atac.atac_set_modes = siisata_setup_channel;
220 #if NATAPIBUS > 0
221 sc->sc_atac.atac_atapibus_attach = siisata_atapibus_attach;
222 #endif
223
224 /* come out of reset state */
225 GRWRITE(sc, GR_GC, 0);
226
227 for (i = 0; i < sc->sc_atac.atac_nchannels; i++) {
228 siisata_attach_port(sc, i);
229 }
230
231 SIISATA_DEBUG_PRINT(("%s: %s: GR_GC: 0x%08x\n", SIISATANAME(sc),
232 __func__, GRREAD(sc, GR_GC)), DEBUG_FUNCS);
233 return;
234 }
235
236 static void
237 siisata_disable_port_interrupt(struct ata_channel *chp)
238 {
239 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
240
241 PRWRITE(sc, PRX(chp->ch_channel, PRO_PIEC), 0xffffffff);
242 }
243
244 static void
245 siisata_enable_port_interrupt(struct ata_channel *chp)
246 {
247 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
248
249 /* clear any interrupts */
250 (void)PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
251 PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff);
252 /* and enable CmdErrr+CmdCmpl interrupting */
253 PRWRITE(sc, PRX(chp->ch_channel, PRO_PIES),
254 PR_PIS_CMDERRR | PR_PIS_CMDCMPL);
255 }
256
257 static void
258 siisata_init_port(struct siisata_softc *sc, int port)
259 {
260 struct siisata_channel *schp;
261 struct ata_channel *chp;
262
263 schp = &sc->sc_channels[port];
264 chp = (struct ata_channel *)schp;
265
266 /* come out of reset, 64-bit activation */
267 PRWRITE(sc, PRX(chp->ch_channel, PRO_PCC),
268 PR_PC_32BA | PR_PC_PORT_RESET);
269 /* initialize port */
270 siisata_reinit_port(chp);
271 /* enable CmdErrr+CmdCmpl interrupting */
272 siisata_enable_port_interrupt(chp);
273 /* enable port interrupt */
274 GRWRITE(sc, GR_GC, GRREAD(sc, GR_GC) | GR_GC_PXIE(chp->ch_channel));
275 }
276
277 static void
278 siisata_attach_port(struct siisata_softc *sc, int port)
279 {
280 int j;
281 int dmasize;
282 int error;
283 void *prbp;
284 struct siisata_channel *schp;
285 struct ata_channel *chp;
286
287 schp = &sc->sc_channels[port];
288 chp = (struct ata_channel *)schp;
289 sc->sc_chanarray[port] = chp;
290 chp->ch_channel = port;
291 chp->ch_atac = &sc->sc_atac;
292 chp->ch_queue = malloc(sizeof(struct ata_queue),
293 M_DEVBUF, M_NOWAIT|M_ZERO);
294 if (chp->ch_queue == NULL) {
295 aprint_error_dev(sc->sc_atac.atac_dev,
296 "port %d: can't allocate memory "
297 "for command queue\n", chp->ch_channel);
298 return;
299 }
300
301 dmasize = SIISATA_CMD_SIZE * SIISATA_MAX_SLOTS;
302
303 SIISATA_DEBUG_PRINT(("%s: %s: dmasize: %d\n", SIISATANAME(sc),
304 __func__, dmasize), DEBUG_FUNCS);
305
306 error = bus_dmamem_alloc(sc->sc_dmat, dmasize, PAGE_SIZE, 0,
307 &schp->sch_prb_seg, 1, &schp->sch_prb_nseg, BUS_DMA_NOWAIT);
308 if (error) {
309 aprint_error_dev(sc->sc_atac.atac_dev,
310 "unable to allocate PRB table memory, "
311 "error=%d\n", error);
312 return;
313 }
314
315 error = bus_dmamem_map(sc->sc_dmat,
316 &schp->sch_prb_seg, schp->sch_prb_nseg,
317 dmasize, &prbp, BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
318 if (error) {
319 aprint_error_dev(sc->sc_atac.atac_dev,
320 "unable to map PRB table memory, "
321 "error=%d\n", error);
322 bus_dmamem_free(sc->sc_dmat,
323 &schp->sch_prb_seg, schp->sch_prb_nseg);
324 return;
325 }
326
327 error = bus_dmamap_create(sc->sc_dmat, dmasize, 1, dmasize, 0,
328 BUS_DMA_NOWAIT, &schp->sch_prbd);
329 if (error) {
330 aprint_error_dev(sc->sc_atac.atac_dev,
331 "unable to create PRB table map, "
332 "error=%d\n", error);
333 bus_dmamem_unmap(sc->sc_dmat, prbp, dmasize);
334 bus_dmamem_free(sc->sc_dmat,
335 &schp->sch_prb_seg, schp->sch_prb_nseg);
336 return;
337 }
338
339 error = bus_dmamap_load(sc->sc_dmat, schp->sch_prbd,
340 prbp, dmasize, NULL, BUS_DMA_NOWAIT);
341 if (error) {
342 aprint_error_dev(sc->sc_atac.atac_dev,
343 "unable to load PRB table map, "
344 "error=%d\n", error);
345 bus_dmamap_destroy(sc->sc_dmat, schp->sch_prbd);
346 bus_dmamem_unmap(sc->sc_dmat, prbp, dmasize);
347 bus_dmamem_free(sc->sc_dmat,
348 &schp->sch_prb_seg, schp->sch_prb_nseg);
349 return;
350 }
351
352 for (j = 0; j < SIISATA_MAX_SLOTS; j++) {
353 schp->sch_prb[j] = (struct siisata_prb *)
354 ((char *)prbp + SIISATA_CMD_SIZE * j);
355 schp->sch_bus_prb[j] =
356 schp->sch_prbd->dm_segs[0].ds_addr +
357 SIISATA_CMD_SIZE * j;
358 error = bus_dmamap_create(sc->sc_dmat, MAXPHYS,
359 SIISATA_NSGE, MAXPHYS, 0,
360 BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
361 &schp->sch_datad[j]);
362 if (error) {
363 aprint_error_dev(sc->sc_atac.atac_dev,
364 "couldn't create xfer DMA map, error=%d\n",
365 error);
366 return;
367 }
368 }
369
370 if (bus_space_subregion(sc->sc_prt, sc->sc_prh,
371 PRX(chp->ch_channel, PRO_SSTATUS), 4, &schp->sch_sstatus) != 0) {
372 aprint_error_dev(sc->sc_atac.atac_dev,
373 "couldn't map port %d SStatus regs\n",
374 chp->ch_channel);
375 return;
376 }
377 if (bus_space_subregion(sc->sc_prt, sc->sc_prh,
378 PRX(chp->ch_channel, PRO_SCONTROL), 4, &schp->sch_scontrol) != 0) {
379 aprint_error_dev(sc->sc_atac.atac_dev,
380 "couldn't map port %d SControl regs\n",
381 chp->ch_channel);
382 return;
383 }
384 if (bus_space_subregion(sc->sc_prt, sc->sc_prh,
385 PRX(chp->ch_channel, PRO_SERROR), 4, &schp->sch_serror) != 0) {
386 aprint_error_dev(sc->sc_atac.atac_dev,
387 "couldn't map port %d SError regs\n",
388 chp->ch_channel);
389 return;
390 }
391
392 siisata_init_port(sc, port);
393
394 ata_channel_attach(chp);
395
396 return;
397 }
398
399 int
400 siisata_detach(struct siisata_softc *sc, int flags)
401 {
402 struct atac_softc *atac = &sc->sc_atac;
403 struct scsipi_adapter *adapt = &atac->atac_atapi_adapter._generic;
404 struct siisata_channel *schp;
405 struct ata_channel *chp;
406 int i, j, error;
407
408 for (i = 0; i < sc->sc_atac.atac_nchannels; i++) {
409 schp = &sc->sc_channels[i];
410 chp = sc->sc_chanarray[i];
411
412 if (chp->atabus == NULL)
413 continue;
414 if ((error = config_detach(chp->atabus, flags)) != 0)
415 return error;
416
417 for (j = 0; j < SIISATA_MAX_SLOTS; j++)
418 bus_dmamap_destroy(sc->sc_dmat, schp->sch_datad[j]);
419
420 bus_dmamap_unload(sc->sc_dmat, schp->sch_prbd);
421 bus_dmamap_destroy(sc->sc_dmat, schp->sch_prbd);
422 bus_dmamem_unmap(sc->sc_dmat, schp->sch_prb[0],
423 SIISATA_CMD_SIZE * SIISATA_MAX_SLOTS);
424 bus_dmamem_free(sc->sc_dmat,
425 &schp->sch_prb_seg, schp->sch_prb_nseg);
426
427 free(chp->ch_queue, M_DEVBUF);
428 chp->atabus = NULL;
429 }
430
431 if (adapt->adapt_refcnt != 0)
432 return EBUSY;
433
434 /* leave the chip in reset */
435 GRWRITE(sc, GR_GC, GR_GC_GLBLRST);
436
437 return 0;
438 }
439
440 void
441 siisata_resume(struct siisata_softc *sc)
442 {
443 int i;
444
445 /* come out of reset state */
446 GRWRITE(sc, GR_GC, 0);
447
448 for (i = 0; i < sc->sc_atac.atac_nchannels; i++) {
449 siisata_init_port(sc, i);
450 }
451
452 }
453
454 int
455 siisata_intr(void *v)
456 {
457 struct siisata_softc *sc = v;
458 uint32_t is;
459 int i, r = 0;
460 while ((is = GRREAD(sc, GR_GIS))) {
461 SIISATA_DEBUG_PRINT(("%s: %s: GR_GIS: 0x%08x\n",
462 SIISATANAME(sc), __func__, is), DEBUG_INTR);
463 r = 1;
464 for (i = 0; i < sc->sc_atac.atac_nchannels; i++)
465 if (is & GR_GIS_PXIS(i))
466 siisata_intr_port(&sc->sc_channels[i]);
467 }
468 return r;
469 }
470
471 static void
472 siisata_intr_port(struct siisata_channel *schp)
473 {
474 struct siisata_softc *sc;
475 struct ata_channel *chp;
476 struct ata_xfer *xfer;
477 int slot;
478 uint32_t pss, pis;
479 uint32_t prbfis;
480
481 sc = (struct siisata_softc *)schp->ata_channel.ch_atac;
482 chp = &schp->ata_channel;
483 xfer = chp->ch_queue->active_xfer;
484 slot = SIISATA_NON_NCQ_SLOT;
485
486 pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS));
487
488 SIISATA_DEBUG_PRINT(("%s: %s port %d, pis 0x%x ", SIISATANAME(sc),
489 __func__, chp->ch_channel, pis), DEBUG_INTR);
490
491 if (pis & PR_PIS_CMDCMPL) {
492 /* get slot status, clearing completion interrupt */
493 pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
494 SIISATA_DEBUG_PRINT(("pss 0x%x\n", pss), DEBUG_INTR);
495 /* is this expected? */
496 /* XXX improve */
497 if ((schp->sch_active_slots & __BIT(slot)) == 0) {
498 aprint_error( "%s: unexpected command "
499 "completion on port %d\n",
500 SIISATANAME(sc), chp->ch_channel);
501 return;
502 }
503 if ((~pss & __BIT(slot)) == 0) {
504 aprint_error( "%s: unknown slot "
505 "completion on port %d, pss 0x%x\n",
506 SIISATANAME(sc), chp->ch_channel, pss);
507 return;
508 }
509 } else if (pis & PR_PIS_CMDERRR) {
510 uint32_t ec;
511
512 /* emulate a CRC error by default */
513 chp->ch_status = WDCS_ERR;
514 chp->ch_error = WDCE_CRC;
515
516 ec = PRREAD(sc, PRX(chp->ch_channel, PRO_PCE));
517 SIISATA_DEBUG_PRINT(("ec %d\n", ec), DEBUG_INTR);
518 if (ec <= PR_PCE_DATAFISERROR) {
519 if (ec == PR_PCE_DEVICEERROR && xfer != NULL) {
520 /* read in specific information about error */
521 prbfis = bus_space_read_stream_4(
522 sc->sc_prt, sc->sc_prh,
523 PRSX(chp->ch_channel, slot, PRSO_FIS));
524 /* set ch_status and ch_error */
525 satafis_rdh_parse(chp, (uint8_t *)&prbfis);
526 }
527 siisata_reinit_port(chp);
528 } else {
529 aprint_error_dev(sc->sc_atac.atac_dev, "fatal error %d"
530 " on channel %d (ctx 0x%x), resetting\n",
531 ec, chp->ch_channel,
532 PRREAD(sc, PRX(chp->ch_channel, PRO_PCR)));
533 /* okay, we have a "Fatal Error" */
534 siisata_device_reset(chp);
535 }
536 }
537
538 /* clear some (ok, all) ints */
539 PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff);
540 if (xfer && xfer->c_intr)
541 xfer->c_intr(chp, xfer, slot);
542
543 return;
544 }
545
546 void
547 siisata_reset_drive(struct ata_drive_datas *drvp, int flags, uint32_t *sigp)
548 {
549 struct ata_channel *chp = drvp->chnl_softc;
550 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
551 struct siisata_channel *schp = (struct siisata_channel *)chp;
552 struct siisata_prb *prb;
553 int slot = SIISATA_NON_NCQ_SLOT;
554 int i;
555
556 /* wait for ready */
557 while (!(PRREAD(sc, PRX(chp->ch_channel, PRO_PS)) & PR_PS_PORT_READY))
558 DELAY(10);
559
560 prb = schp->sch_prb[slot];
561 memset(prb, 0, SIISATA_CMD_SIZE);
562 prb->prb_control =
563 htole16(PRB_CF_SOFT_RESET | PRB_CF_INTERRUPT_MASK);
564 KASSERT(drvp->drive <= PMP_PORT_CTL);
565 prb->prb_fis[rhd_c] = drvp->drive;
566
567 siisata_activate_prb(schp, slot);
568
569 for(i = 0; i < 3100; i++) {
570 if ((PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)) &
571 PR_PXSS(slot)) == 0)
572 break;
573 if (flags & AT_WAIT)
574 tsleep(schp, PRIBIO, "siiprb", mstohz(10));
575 else
576 DELAY(10000);
577 }
578
579 siisata_deactivate_prb(schp, slot);
580 if (i == 3100) {
581 /* timeout */
582 siisata_device_reset(chp);
583 if (sigp)
584 *sigp = 0xffffffff;
585 } else {
586 /* read the signature out of the FIS */
587 if (sigp) {
588 *sigp = 0;
589 *sigp |= (PRREAD(sc, PRSX(chp->ch_channel, slot,
590 PRSO_FIS+0x4)) & 0x00ffffff) << 8;
591 *sigp |= PRREAD(sc, PRSX(chp->ch_channel, slot,
592 PRSO_FIS+0xc)) & 0xff;
593 }
594 }
595
596 #if 1
597 /* attempt to downgrade signaling in event of CRC error */
598 /* XXX should be part of the MI (S)ATA subsystem */
599 if (chp->ch_status == 0x51 && chp->ch_error == 0x84) {
600 bus_space_write_4(sc->sc_prt, schp->sch_scontrol, 0,
601 SControl_IPM_NONE | SControl_SPD_G1 | SControl_DET_INIT);
602 DELAY(10);
603 bus_space_write_4(sc->sc_prt, schp->sch_scontrol, 0,
604 SControl_IPM_NONE | SControl_SPD_G1);
605 DELAY(10);
606 for (;;) {
607 if ((bus_space_read_4(sc->sc_prt, schp->sch_sstatus, 0)
608 & SStatus_DET_mask) == SStatus_DET_DEV)
609 break;
610 DELAY(10);
611 }
612 }
613 #endif
614
615 #if 1
616 chp->ch_status = 0;
617 chp->ch_error = 0;
618 #endif
619 return;
620 }
621
622 void
623 siisata_reset_channel(struct ata_channel *chp, int flags)
624 {
625 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
626 struct siisata_channel *schp = (struct siisata_channel *)chp;
627
628 SIISATA_DEBUG_PRINT(("%s: %s\n", SIISATANAME(sc), __func__),
629 DEBUG_FUNCS);
630
631 if (sata_reset_interface(chp, sc->sc_prt, schp->sch_scontrol,
632 schp->sch_sstatus, flags) != SStatus_DET_DEV) {
633 aprint_error("%s port %d: reset failed\n",
634 SIISATANAME(sc), chp->ch_channel);
635 /* XXX and then ? */
636 }
637 /* wait for ready */
638 while (!(PRREAD(sc, PRX(chp->ch_channel, PRO_PS)) & PR_PS_PORT_READY))
639 DELAY(10);
640 PRWRITE(sc, PRX(chp->ch_channel, PRO_SERROR),
641 PRREAD(sc, PRX(chp->ch_channel, PRO_SERROR)));
642 if (chp->ch_queue->active_xfer) {
643 chp->ch_queue->active_xfer->c_kill_xfer(chp,
644 chp->ch_queue->active_xfer, KILL_RESET);
645 }
646
647 return;
648 }
649
650 int
651 siisata_ata_addref(struct ata_drive_datas *drvp)
652 {
653 return 0;
654 }
655
656 void
657 siisata_ata_delref(struct ata_drive_datas *drvp)
658 {
659 return;
660 }
661
662 void
663 siisata_killpending(struct ata_drive_datas *drvp)
664 {
665 return;
666 }
667
668 void
669 siisata_probe_drive(struct ata_channel *chp)
670 {
671 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
672 struct siisata_channel *schp = (struct siisata_channel *)chp;
673 int i;
674 uint32_t sig;
675 int slot = SIISATA_NON_NCQ_SLOT;
676 struct siisata_prb *prb;
677 bool timed_out;
678
679 SIISATA_DEBUG_PRINT(("%s: %s: port %d start\n", SIISATANAME(sc),
680 __func__, chp->ch_channel), DEBUG_FUNCS);
681
682 /*
683 * disable port interrupt as we're polling for PHY up and
684 * prb completion
685 */
686 siisata_disable_port_interrupt(chp);
687
688 switch(sata_reset_interface(chp, sc->sc_prt, schp->sch_scontrol,
689 schp->sch_sstatus, AT_WAIT)) {
690 case SStatus_DET_DEV:
691 /* clear any interrupts */
692 (void)PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
693 PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0xffffffff);
694 /* wait for ready */
695 while (!(PRREAD(sc, PRX(chp->ch_channel, PRO_PS))
696 & PR_PS_PORT_READY))
697 DELAY(10);
698 prb = schp->sch_prb[slot];
699 memset(prb, 0, SIISATA_CMD_SIZE);
700 prb->prb_control = htole16(PRB_CF_SOFT_RESET);
701 prb->prb_fis[rhd_c] = PMP_PORT_CTL;
702
703 siisata_activate_prb(schp, slot);
704
705 timed_out = 1;
706 for(i = 0; i < 3100; i++) {
707 if ((PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)) &
708 PR_PXSS(slot)) == 0) {
709 /* prb completed */
710 timed_out = 0;
711 break;
712 }
713 if (PRREAD(sc, PRX(chp->ch_channel, PRO_PIS)) &
714 (PR_PIS_CMDERRR << 16)) {
715 /* we got an error; handle as timeout */
716 break;
717 }
718
719 tsleep(schp, PRIBIO, "siiprb", mstohz(10));
720 }
721
722 siisata_deactivate_prb(schp, slot);
723 if (timed_out) {
724 aprint_error_dev(sc->sc_atac.atac_dev,
725 "SOFT_RESET failed on port %d (error %d PSS 0x%x), "
726 "resetting\n", chp->ch_channel,
727 PRREAD(sc, PRX(chp->ch_channel, PRO_PCE)),
728 PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)));
729 siisata_reinit_port(chp);
730 break;
731 }
732
733 /* read the signature out of the FIS */
734 sig = 0;
735 sig |= (PRREAD(sc, PRSX(chp->ch_channel, slot,
736 PRSO_FIS+0x4)) & 0x00ffffff) << 8;
737 sig |= PRREAD(sc, PRSX(chp->ch_channel, slot,
738 PRSO_FIS+0xc)) & 0xff;
739
740 SIISATA_DEBUG_PRINT(("%s: %s: sig=0x%08x\n", SIISATANAME(sc),
741 __func__, sig), DEBUG_PROBE);
742
743 if (sig == 0x96690101)
744 PRWRITE(sc, PRX(chp->ch_channel, PRO_PCS),
745 PR_PC_PMP_ENABLE);
746 sata_interpret_sig(chp, 0, sig);
747 break;
748 default:
749 break;
750 }
751
752 siisata_enable_port_interrupt(chp);
753 SIISATA_DEBUG_PRINT(("%s: %s: port %d done\n", SIISATANAME(sc),
754 __func__, chp->ch_channel), DEBUG_PROBE);
755 return;
756 }
757
758 void
759 siisata_setup_channel(struct ata_channel *chp)
760 {
761 return;
762 }
763
764 int
765 siisata_exec_command(struct ata_drive_datas *drvp, struct ata_command *ata_c)
766 {
767 struct ata_channel *chp = drvp->chnl_softc;
768 struct ata_xfer *xfer;
769 int ret;
770 int s;
771
772 SIISATA_DEBUG_PRINT(("%s: %s begins\n",
773 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
774 DEBUG_FUNCS);
775
776 xfer = ata_get_xfer(ata_c->flags & AT_WAIT ?
777 ATAXF_CANSLEEP : ATAXF_NOSLEEP);
778 if (xfer == NULL)
779 return ATACMD_TRY_AGAIN;
780 if (ata_c->flags & AT_POLL)
781 xfer->c_flags |= C_POLL;
782 if (ata_c->flags & AT_WAIT)
783 xfer->c_flags |= C_WAIT;
784 xfer->c_drive = drvp->drive;
785 xfer->c_databuf = ata_c->data;
786 xfer->c_bcount = ata_c->bcount;
787 xfer->c_cmd = ata_c;
788 xfer->c_start = siisata_cmd_start;
789 xfer->c_intr = siisata_cmd_complete;
790 xfer->c_kill_xfer = siisata_cmd_kill_xfer;
791 s = splbio();
792 ata_exec_xfer(chp, xfer);
793 #ifdef DIAGNOSTIC
794 if ((ata_c->flags & AT_POLL) != 0 &&
795 (ata_c->flags & AT_DONE) == 0)
796 panic("%s: polled command not done", __func__);
797 #endif
798 if (ata_c->flags & AT_DONE) {
799 ret = ATACMD_COMPLETE;
800 } else {
801 if (ata_c->flags & AT_WAIT) {
802 while ((ata_c->flags & AT_DONE) == 0) {
803 SIISATA_DEBUG_PRINT(("%s: %s: sleeping\n",
804 SIISATANAME(
805 (struct siisata_softc *)chp->ch_atac),
806 __func__), DEBUG_FUNCS);
807 tsleep(ata_c, PRIBIO, "siicmd", 0);
808 }
809 ret = ATACMD_COMPLETE;
810 } else {
811 ret = ATACMD_QUEUED;
812 }
813 }
814 splx(s);
815 SIISATA_DEBUG_PRINT( ("%s: %s ends\n",
816 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
817 DEBUG_FUNCS);
818 return ret;
819 }
820
821 void
822 siisata_cmd_start(struct ata_channel *chp, struct ata_xfer *xfer)
823 {
824 struct siisata_channel *schp = (struct siisata_channel *)chp;
825 struct ata_command *ata_c = xfer->c_cmd;
826 int slot = SIISATA_NON_NCQ_SLOT;
827 struct siisata_prb *prb;
828 int i;
829
830 SIISATA_DEBUG_PRINT(("%s: %s port %d drive %d command 0x%x, slot %d\n",
831 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__,
832 chp->ch_channel, xfer->c_drive, ata_c->r_command, slot),
833 DEBUG_FUNCS|DEBUG_XFERS);
834
835 chp->ch_status = 0;
836 chp->ch_error = 0;
837
838 prb = schp->sch_prb[slot];
839 memset(prb, 0, SIISATA_CMD_SIZE);
840
841 satafis_rhd_construct_cmd(ata_c, prb->prb_fis);
842 KASSERT(xfer->c_drive <= PMP_PORT_CTL);
843 prb->prb_fis[rhd_c] |= xfer->c_drive;
844
845 if (ata_c->r_command == ATA_DATA_SET_MANAGEMENT) {
846 prb->prb_control |= htole16(PRB_CF_PROTOCOL_OVERRIDE);
847 prb->prb_protocol_override |= htole16(PRB_PO_WRITE);
848 }
849
850 if (siisata_dma_setup(chp, slot,
851 (ata_c->flags & (AT_READ | AT_WRITE)) ? ata_c->data : NULL,
852 ata_c->bcount,
853 (ata_c->flags & AT_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) {
854 ata_c->flags |= AT_DF;
855 siisata_cmd_complete(chp, xfer, slot);
856 return;
857 }
858
859 if (xfer->c_flags & C_POLL) {
860 /* polled command, disable interrupts */
861 prb->prb_control = htole16(PRB_CF_INTERRUPT_MASK);
862 siisata_disable_port_interrupt(chp);
863 }
864
865 /* go for it */
866 siisata_activate_prb(schp, slot);
867
868 if ((ata_c->flags & AT_POLL) == 0) {
869 chp->ch_flags |= ATACH_IRQ_WAIT; /* wait for interrupt */
870 callout_reset(&chp->ch_callout, mstohz(ata_c->timeout),
871 siisata_timeout, chp);
872 goto out;
873 }
874
875 /*
876 * polled command
877 */
878 for (i = 0; i < ata_c->timeout / 10; i++) {
879 if (ata_c->flags & AT_DONE)
880 break;
881 siisata_intr_port(schp);
882 DELAY(1000);
883 }
884
885 if ((ata_c->flags & AT_DONE) == 0) {
886 siisata_timeout(chp);
887 }
888
889 /* reenable interrupts */
890 siisata_enable_port_interrupt(chp);
891 out:
892 SIISATA_DEBUG_PRINT(("%s: %s: done\n",
893 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
894 DEBUG_FUNCS);
895 return;
896 }
897
898 void
899 siisata_cmd_kill_xfer(struct ata_channel *chp, struct ata_xfer *xfer,
900 int reason)
901 {
902 int slot = SIISATA_NON_NCQ_SLOT;
903
904 struct ata_command *ata_c = xfer->c_cmd;
905 switch (reason) {
906 case KILL_GONE:
907 ata_c->flags |= AT_GONE;
908 break;
909 case KILL_RESET:
910 ata_c->flags |= AT_RESET;
911 break;
912 default:
913 panic("%s: port %d: unknown reason %d",
914 __func__, chp->ch_channel, reason);
915 }
916 siisata_cmd_done(chp, xfer, slot);
917 }
918
919 int
920 siisata_cmd_complete(struct ata_channel *chp, struct ata_xfer *xfer, int slot)
921 {
922 struct ata_command *ata_c = xfer->c_cmd;
923 #ifdef SIISATA_DEBUG
924 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
925 #endif
926
927 SIISATA_DEBUG_PRINT(("%s: %s\n", SIISATANAME(sc), __func__),
928 DEBUG_FUNCS|DEBUG_XFERS);
929
930 chp->ch_flags &= ~ATACH_IRQ_WAIT;
931 if (xfer->c_flags & C_TIMEOU)
932 ata_c->flags |= AT_TIMEOU;
933 else
934 callout_stop(&chp->ch_callout);
935
936 if (chp->ch_status & WDCS_BSY) {
937 ata_c->flags |= AT_TIMEOU;
938 } else if (chp->ch_status & WDCS_ERR) {
939 ata_c->r_error = chp->ch_error;
940 ata_c->flags |= AT_ERROR;
941 }
942
943 if (chp->ch_drive[xfer->c_drive].drive_flags & ATA_DRIVE_WAITDRAIN) {
944 siisata_cmd_kill_xfer(chp, xfer, KILL_GONE);
945 chp->ch_drive[xfer->c_drive].drive_flags &=
946 ~ATA_DRIVE_WAITDRAIN;
947 wakeup(&chp->ch_queue->active_xfer);
948 return 0;
949 } else
950 siisata_cmd_done(chp, xfer, slot);
951
952 return 0;
953 }
954
955 void
956 siisata_cmd_done(struct ata_channel *chp, struct ata_xfer *xfer, int slot)
957 {
958 uint32_t fis[howmany(RDH_FISLEN,sizeof(uint32_t))];
959 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
960 struct siisata_channel *schp = (struct siisata_channel *)chp;
961 struct ata_command *ata_c = xfer->c_cmd;
962 uint16_t *idwordbuf;
963 int i;
964
965 SIISATA_DEBUG_PRINT(("%s: %s flags 0x%x error 0x%x\n", SIISATANAME(sc),
966 __func__, ata_c->flags, ata_c->r_error), DEBUG_FUNCS|DEBUG_XFERS);
967
968 siisata_deactivate_prb(schp, slot);
969
970 if (ata_c->flags & (AT_READ | AT_WRITE)) {
971 bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[slot], 0,
972 schp->sch_datad[slot]->dm_mapsize,
973 (ata_c->flags & AT_READ) ? BUS_DMASYNC_POSTREAD :
974 BUS_DMASYNC_POSTWRITE);
975 bus_dmamap_unload(sc->sc_dmat, schp->sch_datad[slot]);
976 }
977
978 if (ata_c->flags & AT_READREG) {
979 bus_space_read_region_stream_4(sc->sc_prt, sc->sc_prh,
980 PRSX(chp->ch_channel, slot, PRSO_FIS),
981 fis, __arraycount(fis));
982 satafis_rdh_cmd_readreg(ata_c, (uint8_t *)fis);
983 }
984
985 /* correct the endianess of IDENTIFY data */
986 if (ata_c->r_command == WDCC_IDENTIFY ||
987 ata_c->r_command == ATAPI_IDENTIFY_DEVICE) {
988 idwordbuf = xfer->c_databuf;
989 for (i = 0; i < (xfer->c_bcount / sizeof(*idwordbuf)); i++) {
990 idwordbuf[i] = le16toh(idwordbuf[i]);
991 }
992 }
993
994 ata_c->flags |= AT_DONE;
995 if (PRREAD(sc, PRSX(chp->ch_channel, slot, PRSO_RTC)))
996 ata_c->flags |= AT_XFDONE;
997
998 chp->ch_queue->active_xfer = NULL;
999 ata_free_xfer(chp, xfer);
1000 if (ata_c->flags & AT_WAIT)
1001 wakeup(ata_c);
1002 else if (ata_c->callback)
1003 ata_c->callback(ata_c->callback_arg);
1004 atastart(chp);
1005 return;
1006 }
1007
1008 int
1009 siisata_ata_bio(struct ata_drive_datas *drvp, struct ata_bio *ata_bio)
1010 {
1011 struct ata_channel *chp = drvp->chnl_softc;
1012 struct ata_xfer *xfer;
1013
1014 SIISATA_DEBUG_PRINT(("%s: %s.\n",
1015 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
1016 DEBUG_FUNCS);
1017
1018 xfer = ata_get_xfer(ATAXF_NOSLEEP);
1019 if (xfer == NULL)
1020 return ATACMD_TRY_AGAIN;
1021 if (ata_bio->flags & ATA_POLL)
1022 xfer->c_flags |= C_POLL;
1023 xfer->c_drive = drvp->drive;
1024 xfer->c_cmd = ata_bio;
1025 xfer->c_databuf = ata_bio->databuf;
1026 xfer->c_bcount = ata_bio->bcount;
1027 xfer->c_start = siisata_bio_start;
1028 xfer->c_intr = siisata_bio_complete;
1029 xfer->c_kill_xfer = siisata_bio_kill_xfer;
1030 ata_exec_xfer(chp, xfer);
1031 return (ata_bio->flags & ATA_ITSDONE) ?
1032 ATACMD_COMPLETE : ATACMD_QUEUED;
1033 }
1034
1035 void
1036 siisata_bio_start(struct ata_channel *chp, struct ata_xfer *xfer)
1037 {
1038 struct siisata_channel *schp = (struct siisata_channel *)chp;
1039 struct siisata_prb *prb;
1040 struct ata_bio *ata_bio = xfer->c_cmd;
1041 int slot = SIISATA_NON_NCQ_SLOT;
1042 int i;
1043
1044 SIISATA_DEBUG_PRINT(("%s: %s port %d, slot %d\n",
1045 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__,
1046 chp->ch_channel, slot), DEBUG_FUNCS);
1047
1048 chp->ch_status = 0;
1049 chp->ch_error = 0;
1050
1051 prb = schp->sch_prb[slot];
1052 memset(prb, 0, SIISATA_CMD_SIZE);
1053
1054 satafis_rhd_construct_bio(xfer, prb->prb_fis);
1055 KASSERT(xfer->c_drive <= PMP_PORT_CTL);
1056 prb->prb_fis[rhd_c] |= xfer->c_drive;
1057
1058 if (siisata_dma_setup(chp, slot, ata_bio->databuf, ata_bio->bcount,
1059 (ata_bio->flags & ATA_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) {
1060 ata_bio->error = ERR_DMA;
1061 ata_bio->r_error = 0;
1062 siisata_bio_complete(chp, xfer, slot);
1063 return;
1064 }
1065
1066 if (xfer->c_flags & C_POLL) {
1067 /* polled command, disable interrupts */
1068 prb->prb_control = htole16(PRB_CF_INTERRUPT_MASK);
1069 siisata_disable_port_interrupt(chp);
1070 }
1071
1072 siisata_activate_prb(schp, slot);
1073
1074 if ((ata_bio->flags & ATA_POLL) == 0) {
1075 chp->ch_flags |= ATACH_IRQ_WAIT; /* wait for interrupt */
1076 callout_reset(&chp->ch_callout, mstohz(ATA_DELAY),
1077 siisata_timeout, chp);
1078 goto out;
1079 }
1080
1081 /*
1082 * polled command
1083 */
1084 for (i = 0; i < ATA_DELAY / 10; i++) {
1085 if (ata_bio->flags & ATA_ITSDONE)
1086 break;
1087 siisata_intr_port(schp);
1088 DELAY(1000);
1089 }
1090
1091 siisata_enable_port_interrupt(chp);
1092 out:
1093 SIISATA_DEBUG_PRINT(("%s: %s: done\n",
1094 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
1095 DEBUG_FUNCS);
1096 return;
1097 }
1098
1099 void
1100 siisata_bio_kill_xfer(struct ata_channel *chp, struct ata_xfer *xfer,
1101 int reason)
1102 {
1103 struct siisata_channel *schp = (struct siisata_channel *)chp;
1104 struct ata_bio *ata_bio = xfer->c_cmd;
1105 int drive = xfer->c_drive;
1106 int slot = SIISATA_NON_NCQ_SLOT;
1107
1108 SIISATA_DEBUG_PRINT(("%s: %s: port %d\n",
1109 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__,
1110 chp->ch_channel), DEBUG_FUNCS);
1111
1112 siisata_deactivate_prb(schp, slot);
1113
1114 ata_free_xfer(chp, xfer);
1115 ata_bio->flags |= ATA_ITSDONE;
1116 switch (reason) {
1117 case KILL_GONE:
1118 ata_bio->error = ERR_NODEV;
1119 break;
1120 case KILL_RESET:
1121 ata_bio->error = ERR_RESET;
1122 break;
1123 default:
1124 panic("%s: port %d: unknown reason %d",
1125 __func__, chp->ch_channel, reason);
1126 }
1127 ata_bio->r_error = WDCE_ABRT;
1128 (*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc);
1129 }
1130
1131 int
1132 siisata_bio_complete(struct ata_channel *chp, struct ata_xfer *xfer, int slot)
1133 {
1134 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
1135 struct siisata_channel *schp = (struct siisata_channel *)chp;
1136 struct ata_bio *ata_bio = xfer->c_cmd;
1137 int drive = xfer->c_drive;
1138
1139 schp->sch_active_slots &= ~__BIT(slot);
1140 chp->ch_flags &= ~ATACH_IRQ_WAIT;
1141 if (xfer->c_flags & C_TIMEOU) {
1142 ata_bio->error = TIMEOUT;
1143 } else {
1144 callout_stop(&chp->ch_callout);
1145 ata_bio->error = NOERROR;
1146 }
1147
1148 bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[slot], 0,
1149 schp->sch_datad[slot]->dm_mapsize,
1150 (ata_bio->flags & ATA_READ) ? BUS_DMASYNC_POSTREAD :
1151 BUS_DMASYNC_POSTWRITE);
1152 bus_dmamap_unload(sc->sc_dmat, schp->sch_datad[slot]);
1153
1154 if (chp->ch_drive[xfer->c_drive].drive_flags & ATA_DRIVE_WAITDRAIN) {
1155 siisata_bio_kill_xfer(chp, xfer, KILL_GONE);
1156 chp->ch_drive[xfer->c_drive].drive_flags &=
1157 ~ATA_DRIVE_WAITDRAIN;
1158 wakeup(&chp->ch_queue->active_xfer);
1159 return 0;
1160 }
1161
1162 chp->ch_queue->active_xfer = NULL;
1163 ata_free_xfer(chp, xfer);
1164 ata_bio->flags |= ATA_ITSDONE;
1165 if (chp->ch_status & WDCS_DWF) {
1166 ata_bio->error = ERR_DF;
1167 } else if (chp->ch_status & WDCS_ERR) {
1168 ata_bio->error = ERROR;
1169 ata_bio->r_error = chp->ch_error;
1170 } else if (chp->ch_status & WDCS_CORR)
1171 ata_bio->flags |= ATA_CORR;
1172
1173 SIISATA_DEBUG_PRINT(("%s: %s bcount: %ld", SIISATANAME(sc), __func__,
1174 ata_bio->bcount), DEBUG_XFERS);
1175 if (ata_bio->error == NOERROR) {
1176 if (ata_bio->flags & ATA_READ)
1177 ata_bio->bcount -=
1178 PRREAD(sc, PRSX(chp->ch_channel, slot, PRSO_RTC));
1179 else
1180 ata_bio->bcount = 0;
1181 }
1182 SIISATA_DEBUG_PRINT((" now %ld\n", ata_bio->bcount), DEBUG_XFERS);
1183 if (ata_bio->flags & ATA_POLL)
1184 return 1;
1185 (*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc);
1186 atastart(chp);
1187 return 0;
1188 }
1189
1190 void
1191 siisata_timeout(void *v)
1192 {
1193 struct ata_channel *chp = (struct ata_channel *)v;
1194 struct ata_xfer *xfer = chp->ch_queue->active_xfer;
1195 int slot = SIISATA_NON_NCQ_SLOT;
1196 int s = splbio();
1197 SIISATA_DEBUG_PRINT(("%s: %p\n", __func__, xfer), DEBUG_INTR);
1198 siisata_device_reset(chp);
1199 if ((chp->ch_flags & ATACH_IRQ_WAIT) != 0) {
1200 xfer->c_flags |= C_TIMEOU;
1201 xfer->c_intr(chp, xfer, slot);
1202 }
1203 splx(s);
1204 }
1205
1206 static int
1207 siisata_dma_setup(struct ata_channel *chp, int slot, void *data,
1208 size_t count, int op)
1209 {
1210
1211 int error, seg;
1212 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
1213 struct siisata_channel *schp = (struct siisata_channel *)chp;
1214
1215 struct siisata_prb *prbp;
1216
1217 prbp = schp->sch_prb[slot];
1218
1219 if (data == NULL) {
1220 goto end;
1221 }
1222
1223 error = bus_dmamap_load(sc->sc_dmat, schp->sch_datad[slot],
1224 data, count, NULL, BUS_DMA_NOWAIT | BUS_DMA_STREAMING | op);
1225 if (error) {
1226 aprint_error("%s port %d: "
1227 "failed to load xfer in slot %d: error %d\n",
1228 SIISATANAME(sc), chp->ch_channel, slot, error);
1229 return error;
1230 }
1231
1232 bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[slot], 0,
1233 schp->sch_datad[slot]->dm_mapsize,
1234 (op == BUS_DMA_READ) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
1235
1236 SIISATA_DEBUG_PRINT(("%s: %d segs, %ld count\n", __func__,
1237 schp->sch_datad[slot]->dm_nsegs, (long unsigned int) count),
1238 DEBUG_FUNCS | DEBUG_DEBUG);
1239
1240 for (seg = 0; seg < schp->sch_datad[slot]->dm_nsegs; seg++) {
1241 prbp->prb_sge[seg].sge_da =
1242 htole64(schp->sch_datad[slot]->dm_segs[seg].ds_addr);
1243 prbp->prb_sge[seg].sge_dc =
1244 htole32(schp->sch_datad[slot]->dm_segs[seg].ds_len);
1245 prbp->prb_sge[seg].sge_flags = htole32(0);
1246 }
1247 prbp->prb_sge[seg - 1].sge_flags |= htole32(SGE_FLAG_TRM);
1248 end:
1249 return 0;
1250 }
1251
1252 static void
1253 siisata_activate_prb(struct siisata_channel *schp, int slot)
1254 {
1255 struct siisata_softc *sc;
1256 bus_size_t offset;
1257 uint64_t pprb;
1258
1259 sc = (struct siisata_softc *)schp->ata_channel.ch_atac;
1260
1261 KASSERTMSG((schp->sch_active_slots & __BIT(slot)) != __BIT(slot),
1262 "%s: trying to activate active slot %d", SIISATANAME(sc), slot);
1263
1264 SIISATA_PRB_SYNC(sc, schp, slot, BUS_DMASYNC_PREWRITE);
1265 /* keep track of what's going on */
1266 schp->sch_active_slots |= __BIT(slot);
1267
1268 offset = PRO_CARX(schp->ata_channel.ch_channel, slot);
1269
1270 pprb = schp->sch_bus_prb[slot];
1271
1272 PRWRITE(sc, offset + 0, pprb >> 0);
1273 PRWRITE(sc, offset + 4, pprb >> 32);
1274 }
1275
1276 static void
1277 siisata_deactivate_prb(struct siisata_channel *schp, int slot)
1278 {
1279 struct siisata_softc *sc;
1280
1281 sc = (struct siisata_softc *)schp->ata_channel.ch_atac;
1282
1283 KASSERTMSG((schp->sch_active_slots & __BIT(slot)) != 0,
1284 "%s: trying to deactivate inactive slot %d", SIISATANAME(sc),
1285 slot);
1286
1287 schp->sch_active_slots &= ~__BIT(slot); /* mark free */
1288 SIISATA_PRB_SYNC(sc, schp, slot, BUS_DMASYNC_POSTWRITE);
1289 }
1290
1291 static void
1292 siisata_reinit_port(struct ata_channel *chp)
1293 {
1294 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
1295
1296 PRWRITE(sc, PRX(chp->ch_channel, PRO_PCS), PR_PC_PORT_INITIALIZE);
1297 while (!(PRREAD(sc, PRX(chp->ch_channel, PRO_PS)) & PR_PS_PORT_READY))
1298 DELAY(10);
1299 if (chp->ch_ndrives > 1)
1300 PRWRITE(sc, PRX(chp->ch_channel, PRO_PCS), PR_PC_PMP_ENABLE);
1301 }
1302
1303 static void
1304 siisata_device_reset(struct ata_channel *chp)
1305 {
1306 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
1307
1308 PRWRITE(sc, PRX(chp->ch_channel, PRO_PCS), PR_PC_DEVICE_RESET);
1309 while (!(PRREAD(sc, PRX(chp->ch_channel, PRO_PS)) & PR_PS_PORT_READY))
1310 DELAY(10);
1311 }
1312
1313
1314 #if NATAPIBUS > 0
1315 void
1316 siisata_atapibus_attach(struct atabus_softc *ata_sc)
1317 {
1318 struct ata_channel *chp = ata_sc->sc_chan;
1319 struct atac_softc *atac = chp->ch_atac;
1320 struct scsipi_adapter *adapt = &atac->atac_atapi_adapter._generic;
1321 struct scsipi_channel *chan = &chp->ch_atapi_channel;
1322
1323 /*
1324 * Fill in the scsipi_adapter.
1325 */
1326 adapt->adapt_dev = atac->atac_dev;
1327 adapt->adapt_nchannels = atac->atac_nchannels;
1328 adapt->adapt_request = siisata_atapi_scsipi_request;
1329 adapt->adapt_minphys = siisata_atapi_minphys;
1330 atac->atac_atapi_adapter.atapi_probe_device =
1331 siisata_atapi_probe_device;
1332
1333 /*
1334 * Fill in the scsipi_channel.
1335 */
1336 memset(chan, 0, sizeof(*chan));
1337 chan->chan_adapter = adapt;
1338 chan->chan_bustype = &siisata_atapi_bustype;
1339 chan->chan_channel = chp->ch_channel;
1340 chan->chan_flags = SCSIPI_CHAN_OPENINGS;
1341 chan->chan_openings = 1;
1342 chan->chan_max_periph = 1;
1343 chan->chan_ntargets = 1;
1344 chan->chan_nluns = 1;
1345
1346 chp->atapibus = config_found_ia(ata_sc->sc_dev, "atapi", chan,
1347 atapiprint);
1348 }
1349
1350 void
1351 siisata_atapi_minphys(struct buf *bp)
1352 {
1353 if (bp->b_bcount > MAXPHYS)
1354 bp->b_bcount = MAXPHYS;
1355 minphys(bp);
1356 }
1357
1358 /*
1359 * Kill off all pending xfers for a periph.
1360 *
1361 * Must be called at splbio().
1362 */
1363 void
1364 siisata_atapi_kill_pending(struct scsipi_periph *periph)
1365 {
1366 struct atac_softc *atac =
1367 device_private(periph->periph_channel->chan_adapter->adapt_dev);
1368 struct ata_channel *chp =
1369 atac->atac_channels[periph->periph_channel->chan_channel];
1370
1371 ata_kill_pending(&chp->ch_drive[periph->periph_target]);
1372 }
1373
1374 void
1375 siisata_atapi_kill_xfer(struct ata_channel *chp, struct ata_xfer *xfer,
1376 int reason)
1377 {
1378 struct scsipi_xfer *sc_xfer = xfer->c_cmd;
1379
1380 /* remove this command from xfer queue */
1381 switch (reason) {
1382 case KILL_GONE:
1383 sc_xfer->error = XS_DRIVER_STUFFUP;
1384 break;
1385 case KILL_RESET:
1386 sc_xfer->error = XS_RESET;
1387 break;
1388 default:
1389 panic("%s: port %d: unknown reason %d",
1390 __func__, chp->ch_channel, reason);
1391 }
1392 ata_free_xfer(chp, xfer);
1393 scsipi_done(sc_xfer);
1394 }
1395
1396 void
1397 siisata_atapi_probe_device(struct atapibus_softc *sc, int target)
1398 {
1399 struct scsipi_channel *chan = sc->sc_channel;
1400 struct scsipi_periph *periph;
1401 struct ataparams ids;
1402 struct ataparams *id = &ids;
1403 struct siisata_softc *siic =
1404 device_private(chan->chan_adapter->adapt_dev);
1405 struct atac_softc *atac = &siic->sc_atac;
1406 struct ata_channel *chp = atac->atac_channels[chan->chan_channel];
1407 struct ata_drive_datas *drvp = &chp->ch_drive[target];
1408 struct scsipibus_attach_args sa;
1409 char serial_number[21], model[41], firmware_revision[9];
1410 int s;
1411
1412 /* skip if already attached */
1413 if (scsipi_lookup_periph(chan, target, 0) != NULL)
1414 return;
1415
1416 /* if no ATAPI device detected at attach time, skip */
1417 if (drvp->drive_type != ATA_DRIVET_ATAPI) {
1418 SIISATA_DEBUG_PRINT(("%s: drive %d not present\n", __func__,
1419 target), DEBUG_PROBE);
1420 return;
1421 }
1422
1423 /* Some ATAPI devices need a bit more time after software reset. */
1424 DELAY(5000);
1425 if (ata_get_params(drvp, AT_WAIT, id) == 0) {
1426 #ifdef ATAPI_DEBUG_PROBE
1427 log(LOG_DEBUG, "%s drive %d: cmdsz 0x%x drqtype 0x%x\n",
1428 device_xname(sc->sc_dev), target,
1429 id->atap_config & ATAPI_CFG_CMD_MASK,
1430 id->atap_config & ATAPI_CFG_DRQ_MASK);
1431 #endif
1432 periph = scsipi_alloc_periph(M_NOWAIT);
1433 if (periph == NULL) {
1434 aprint_error_dev(sc->sc_dev,
1435 "%s: unable to allocate periph for "
1436 "channel %d drive %d\n", __func__,
1437 chp->ch_channel, target);
1438 return;
1439 }
1440 periph->periph_dev = NULL;
1441 periph->periph_channel = chan;
1442 periph->periph_switch = &atapi_probe_periphsw;
1443 periph->periph_target = target;
1444 periph->periph_lun = 0;
1445 periph->periph_quirks = PQUIRK_ONLYBIG;
1446
1447 #ifdef SCSIPI_DEBUG
1448 if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_ATAPI &&
1449 SCSIPI_DEBUG_TARGET == target)
1450 periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS;
1451 #endif
1452 periph->periph_type = ATAPI_CFG_TYPE(id->atap_config);
1453 if (id->atap_config & ATAPI_CFG_REMOV)
1454 periph->periph_flags |= PERIPH_REMOVABLE;
1455 sa.sa_periph = periph;
1456 sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
1457 sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
1458 T_REMOV : T_FIXED;
1459 strnvisx(model, sizeof(model), id->atap_model, 40,
1460 VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1461 strnvisx(serial_number, sizeof(serial_number),
1462 id->atap_serial, 20, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1463 strnvisx(firmware_revision, sizeof(firmware_revision),
1464 id->atap_revision, 8, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
1465 sa.sa_inqbuf.vendor = model;
1466 sa.sa_inqbuf.product = serial_number;
1467 sa.sa_inqbuf.revision = firmware_revision;
1468
1469 /*
1470 * Determine the operating mode capabilities of the device.
1471 */
1472 if ((id->atap_config & ATAPI_CFG_CMD_MASK)
1473 == ATAPI_CFG_CMD_16) {
1474 periph->periph_cap |= PERIPH_CAP_CMD16;
1475
1476 /* configure port for packet length */
1477 PRWRITE(siic, PRX(chp->ch_channel, PRO_PCS),
1478 PR_PC_PACKET_LENGTH);
1479 } else {
1480 PRWRITE(siic, PRX(chp->ch_channel, PRO_PCC),
1481 PR_PC_PACKET_LENGTH);
1482 }
1483
1484 /* XXX This is gross. */
1485 periph->periph_cap |= (id->atap_config & ATAPI_CFG_DRQ_MASK);
1486
1487 drvp->drv_softc = atapi_probe_device(sc, target, periph, &sa);
1488
1489 if (drvp->drv_softc)
1490 ata_probe_caps(drvp);
1491 else {
1492 s = splbio();
1493 drvp->drive_type &= ATA_DRIVET_NONE;
1494 splx(s);
1495 }
1496 } else {
1497 SIISATA_DEBUG_PRINT(("%s: ATAPI_IDENTIFY_DEVICE "
1498 "failed for drive %s:%d:%d: error 0x%x\n",
1499 __func__, SIISATANAME(siic), chp->ch_channel, target,
1500 chp->ch_error), DEBUG_PROBE);
1501 s = splbio();
1502 drvp->drive_type &= ATA_DRIVET_NONE;
1503 splx(s);
1504 }
1505 }
1506
1507 void
1508 siisata_atapi_scsipi_request(struct scsipi_channel *chan,
1509 scsipi_adapter_req_t req, void *arg)
1510 {
1511 struct scsipi_adapter *adapt = chan->chan_adapter;
1512 struct scsipi_periph *periph;
1513 struct scsipi_xfer *sc_xfer;
1514 struct siisata_softc *sc = device_private(adapt->adapt_dev);
1515 struct atac_softc *atac = &sc->sc_atac;
1516 struct ata_xfer *xfer;
1517 int channel = chan->chan_channel;
1518 int drive, s;
1519
1520 switch (req) {
1521 case ADAPTER_REQ_RUN_XFER:
1522 sc_xfer = arg;
1523 periph = sc_xfer->xs_periph;
1524 drive = periph->periph_target;
1525
1526 SIISATA_DEBUG_PRINT(("%s: %s:%d:%d\n", __func__,
1527 device_xname(atac->atac_dev), channel, drive),
1528 DEBUG_XFERS);
1529
1530 if (!device_is_active(atac->atac_dev)) {
1531 sc_xfer->error = XS_DRIVER_STUFFUP;
1532 scsipi_done(sc_xfer);
1533 return;
1534 }
1535 xfer = ata_get_xfer(ATAXF_NOSLEEP);
1536 if (xfer == NULL) {
1537 sc_xfer->error = XS_RESOURCE_SHORTAGE;
1538 scsipi_done(sc_xfer);
1539 return;
1540 }
1541
1542 if (sc_xfer->xs_control & XS_CTL_POLL)
1543 xfer->c_flags |= C_POLL;
1544 xfer->c_drive = drive;
1545 xfer->c_flags |= C_ATAPI;
1546 xfer->c_cmd = sc_xfer;
1547 xfer->c_databuf = sc_xfer->data;
1548 xfer->c_bcount = sc_xfer->datalen;
1549 xfer->c_start = siisata_atapi_start;
1550 xfer->c_intr = siisata_atapi_complete;
1551 xfer->c_kill_xfer = siisata_atapi_kill_xfer;
1552 xfer->c_dscpoll = 0;
1553 s = splbio();
1554 ata_exec_xfer(atac->atac_channels[channel], xfer);
1555 #ifdef DIAGNOSTIC
1556 if ((sc_xfer->xs_control & XS_CTL_POLL) != 0 &&
1557 (sc_xfer->xs_status & XS_STS_DONE) == 0)
1558 panic("%s: polled command not done", __func__);
1559 #endif
1560 splx(s);
1561 return;
1562
1563 default:
1564 /* Not supported, nothing to do. */
1565 ;
1566 }
1567 }
1568
1569 void
1570 siisata_atapi_start(struct ata_channel *chp, struct ata_xfer *xfer)
1571 {
1572 struct siisata_channel *schp = (struct siisata_channel *)chp;
1573 struct siisata_prb *prbp;
1574
1575 struct scsipi_xfer *sc_xfer = xfer->c_cmd;
1576
1577 int slot = SIISATA_NON_NCQ_SLOT;
1578 int i;
1579
1580 SIISATA_DEBUG_PRINT( ("%s: %s:%d:%d, scsi flags 0x%x\n", __func__,
1581 SIISATANAME((struct siisata_softc *)chp->ch_atac), chp->ch_channel,
1582 chp->ch_drive[xfer->c_drive].drive, sc_xfer->xs_control),
1583 DEBUG_XFERS);
1584
1585 chp->ch_status = 0;
1586 chp->ch_error = 0;
1587
1588 prbp = schp->sch_prb[slot];
1589 memset(prbp, 0, SIISATA_CMD_SIZE);
1590
1591 /* fill in direction for ATAPI command */
1592 if ((sc_xfer->xs_control & XS_CTL_DATA_IN))
1593 prbp->prb_control |= htole16(PRB_CF_PACKET_READ);
1594 if ((sc_xfer->xs_control & XS_CTL_DATA_OUT))
1595 prbp->prb_control |= htole16(PRB_CF_PACKET_WRITE);
1596
1597 satafis_rhd_construct_atapi(xfer, prbp->prb_fis);
1598 KASSERT(xfer->c_drive <= PMP_PORT_CTL);
1599 prbp->prb_fis[rhd_c] |= xfer->c_drive;
1600
1601 /* copy over ATAPI command */
1602 memcpy(prbp->prb_atapi, sc_xfer->cmd, sc_xfer->cmdlen);
1603
1604 if (siisata_dma_setup(chp, slot,
1605 (sc_xfer->xs_control & (XS_CTL_DATA_IN | XS_CTL_DATA_OUT)) ?
1606 xfer->c_databuf : NULL,
1607 xfer->c_bcount,
1608 (sc_xfer->xs_control & XS_CTL_DATA_IN) ?
1609 BUS_DMA_READ : BUS_DMA_WRITE)
1610 )
1611 panic("%s", __func__);
1612
1613 if (xfer->c_flags & C_POLL) {
1614 /* polled command, disable interrupts */
1615 prbp->prb_control = htole16(PRB_CF_INTERRUPT_MASK);
1616 siisata_disable_port_interrupt(chp);
1617 }
1618
1619 siisata_activate_prb(schp, slot);
1620
1621 if ((xfer->c_flags & C_POLL) == 0) {
1622 chp->ch_flags |= ATACH_IRQ_WAIT; /* wait for interrupt */
1623 callout_reset(&chp->ch_callout, mstohz(sc_xfer->timeout),
1624 siisata_timeout, chp);
1625 goto out;
1626 }
1627
1628 /*
1629 * polled command
1630 */
1631 for (i = 0; i < ATA_DELAY / 10; i++) {
1632 if (sc_xfer->xs_status & XS_STS_DONE)
1633 break;
1634 siisata_intr_port(schp);
1635 DELAY(1000);
1636 }
1637 if ((sc_xfer->xs_status & XS_STS_DONE) == 0) {
1638 siisata_timeout(chp);
1639 }
1640 /* reenable interrupts */
1641 siisata_enable_port_interrupt(chp);
1642 out:
1643 SIISATA_DEBUG_PRINT(("%s: %s: done\n",
1644 SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
1645 DEBUG_FUNCS);
1646 return;
1647 }
1648
1649 int
1650 siisata_atapi_complete(struct ata_channel *chp, struct ata_xfer *xfer,
1651 int slot)
1652 {
1653 struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
1654 struct siisata_channel *schp = (struct siisata_channel *)chp;
1655 struct scsipi_xfer *sc_xfer = xfer->c_cmd;
1656
1657 SIISATA_DEBUG_PRINT(("%s: %s()\n", SIISATANAME(sc), __func__),
1658 DEBUG_INTR);
1659
1660 /* this command is not active any more */
1661 schp->sch_active_slots &= ~__BIT(slot);
1662 chp->ch_flags &= ~ATACH_IRQ_WAIT;
1663 if (xfer->c_flags & C_TIMEOU) {
1664 sc_xfer->error = XS_TIMEOUT;
1665 } else {
1666 callout_stop(&chp->ch_callout);
1667 sc_xfer->error = XS_NOERROR;
1668 }
1669
1670 bus_dmamap_sync(sc->sc_dmat, schp->sch_datad[slot], 0,
1671 schp->sch_datad[slot]->dm_mapsize,
1672 (sc_xfer->xs_control & XS_CTL_DATA_IN) ?
1673 BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
1674 bus_dmamap_unload(sc->sc_dmat, schp->sch_datad[slot]);
1675
1676 if (chp->ch_drive[xfer->c_drive].drive_flags & ATA_DRIVE_WAITDRAIN) {
1677 siisata_atapi_kill_xfer(chp, xfer, KILL_GONE);
1678 chp->ch_drive[xfer->c_drive].drive_flags &=
1679 ~ATA_DRIVE_WAITDRAIN;
1680 wakeup(&chp->ch_queue->active_xfer);
1681 return 0; /* XXX verify */
1682 }
1683
1684 chp->ch_queue->active_xfer = NULL;
1685 ata_free_xfer(chp, xfer);
1686 sc_xfer->resid = sc_xfer->datalen;
1687 sc_xfer->resid -= PRREAD(sc, PRSX(chp->ch_channel, slot, PRSO_RTC));
1688 SIISATA_DEBUG_PRINT(("%s: %s datalen %d resid %d\n", SIISATANAME(sc),
1689 __func__, sc_xfer->datalen, sc_xfer->resid), DEBUG_XFERS);
1690 if ((chp->ch_status & WDCS_ERR) &&
1691 ((sc_xfer->xs_control & XS_CTL_REQSENSE) == 0 ||
1692 sc_xfer->resid == sc_xfer->datalen)) {
1693 sc_xfer->error = XS_SHORTSENSE;
1694 sc_xfer->sense.atapi_sense = chp->ch_error;
1695 if ((sc_xfer->xs_periph->periph_quirks &
1696 PQUIRK_NOSENSE) == 0) {
1697 /* request sense */
1698 sc_xfer->error = XS_BUSY;
1699 sc_xfer->status = SCSI_CHECK;
1700 }
1701 }
1702 scsipi_done(sc_xfer);
1703 atastart(chp);
1704 return 0; /* XXX verify */
1705 }
1706
1707 #endif /* NATAPIBUS */
1708