2 * Device-independent level for ATAPI drivers.
4 * Copyright (C) 1995 Cronyx Ltd.
5 * Author Serge Vakulenko, <vak@cronyx.ru>
7 * This software is distributed with NO WARRANTIES, not even the implied
8 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 * Authors grant any other persons or organisations permission to use
11 * or modify this software as long as this message is kept with the software,
12 * all derivative works or modified versions.
14 * Version 1.9, Mon Oct 9 22:34:47 MSK 1995
16 * $FreeBSD: src/sys/i386/isa/atapi.c,v 1.36.2.1 2000/04/03 20:13:06 n_hibma Exp $
17 * $DragonFly: src/sys/i386/isa/Attic/atapi.c,v 1.5 2004/10/14 03:05:54 dillon Exp $
21 * The ATAPI level is implemented as a machine-dependent layer
22 * between the device driver and the IDE controller.
23 * All the machine- and controller dependency is isolated inside
24 * the ATAPI level, while all the device dependency is located
25 * in the device subdriver.
27 * It seems that an ATAPI bus will became popular for medium-speed
28 * storage devices such as CD-ROMs, magneto-optical disks, tape streamers etc.
30 * To ease the development of new ATAPI drivers, the subdriver
31 * interface was designed to be as simple as possible.
33 * Three routines are available for the subdriver to access the device:
35 * struct atapires atapi_request_wait (ata, unit, cmd, a1, a2, a3, a4, a5,
36 * a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, addr, count);
37 * struct atapi *ata; -- atapi controller descriptor
38 * int unit; -- device unit number on the IDE bus
39 * u_char cmd; -- ATAPI command code
40 * u_char a1..a15; -- ATAPI command arguments
41 * char *addr; -- address of the data buffer for i/o
42 * int count; -- data length, >0 for read ops, <0 for write ops
44 * The atapi_request_wait() function puts the op in the queue of ATAPI
45 * commands for the IDE controller, starts the controller, the waits for
46 * operation to be completed (using tsleep).
47 * The function should be called from the user phase only (open(), close(),
49 * Ata and unit args are the values which the subdriver gets from the ATAPI
50 * level via attach() call.
51 * Buffer pointed to by *addr should be placed in core memory, static
52 * or dynamic, but not in stack.
53 * The function returns the error code structure, which consists of:
54 * - atapi driver code value
55 * - controller status port value
56 * - controller error port value
58 * struct atapires atapi_request_immediate (ata, unit, cmd, a1, a2, a3,
59 * a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15,
62 * The atapi_request_immediate() function is similar to atapi_request_wait(),
63 * but it does not use interrupts for performing the request.
64 * It should be used during an attach phase to get parameters from the device.
66 * void atapi_request_callback (ata, unit, cmd, a1, a2, a3, a4, a5,
67 * a6, a7, a8, a9, a10, a11, a12, a13, a14, a15,
68 * addr, count, done, x, y);
69 * struct atapi *ata; -- atapi controller descriptor
70 * int unit; -- device unit number on the IDE bus
71 * u_char cmd; -- ATAPI command code
72 * u_char a1..a15; -- ATAPI command arguments
73 * char *addr; -- address of the data buffer for i/o
74 * int count; -- data length, >0 for read ops, <0 for write ops
75 * void (*done)(); -- function to call when op finished
76 * void *x, *y; -- arguments for done() function
78 * The atapi_request_callback() function puts the op in the queue of ATAPI
79 * commands for the IDE controller, starts the controller, then returns.
80 * When the operation finishes, then the callback function done()
81 * will be called on the interrupt level.
82 * The function is designed to be callable from the interrupt phase.
83 * The done() functions is called with the following arguments:
84 * (void) (*done) (x, y, count, errcode)
85 * void *x, *y; -- arguments from the atapi_request_callback()
86 * int count; -- the data residual count
87 * struct atapires errcode; -- error code structure, see above
89 * The new driver could be added in three steps:
90 * 1. Add entries for the new driver to bdevsw and cdevsw tables in conf.c.
91 * You will need to make at least three routines: open(), close(),
92 * strategy() and possibly ioctl().
93 * 2. Make attach() routine, which should allocate all the needed data
94 * structures and print the device description string (see xxxattach()).
95 * 3. Add an appropriate case to the switch in atapi_attach() routine,
96 * call attach() routine of the new driver here. Add the appropriate
97 * #include line at the top of attach.c.
100 * Use #define DEBUG in atapi.c to enable tracing of all i/o operations
109 /* #include "wmd.h" -- add your driver here */
113 #include <sys/param.h>
114 #include <sys/systm.h>
115 #include <sys/malloc.h>
117 #include <machine/clock.h>
119 #include <i386/isa/atapi.h>
121 /* this code is compiled part of the module */
124 # define print(s) printf s
126 # define print(s) {/*void*/}
130 * ATAPI packet command phase.
132 #define PHASE_CMDOUT (ARS_DRQ | ARI_CMD)
133 #define PHASE_DATAIN (ARS_DRQ | ARI_IN)
134 #define PHASE_DATAOUT ARS_DRQ
135 #define PHASE_COMPLETED (ARI_IN | ARI_CMD)
136 #define PHASE_ABORTED 0 /* nonstandard - for NEC 260 */
138 static struct atapi atapitab[NWDC];
140 static struct atapi_params *atapi_probe (int port, int unit);
141 static int atapi_wait (int port, u_char bits_wanted);
142 static void atapi_send_cmd (struct atapi *ata, struct atapicmd *ac);
143 static int atapi_io (struct atapi *ata, struct atapicmd *ac);
144 static int atapi_strt_cmd (struct atapi *ata, struct atapicmd *ac);
145 static int atapi_wait_cmd (struct atapi *ata, struct atapicmd *ac);
147 extern void wdstart (int ctrlr);
148 extern int acdattach(struct atapi*, int, struct atapi_params*, int);
149 extern int wfdattach(struct atapi*, int, struct atapi_params*, int);
150 extern int wstattach(struct atapi*, int, struct atapi_params*, int);
153 * Probe the ATAPI device at IDE controller `ctlr', drive `unit'.
154 * Called at splbio().
156 int atapi_attach (int ctlr, int unit, int port)
158 struct atapi *ata = atapitab + ctlr;
159 struct atapi_params *ap;
160 char buf [sizeof(ap->model) + 1];
161 char revbuf [sizeof(ap->revision) + 1];
164 print (("atapi%d.%d at 0x%x: attach called\n", ctlr, unit, port));
165 ap = atapi_probe (port, unit);
169 bcopy (ap->model, buf, sizeof(buf)-1);
170 buf[sizeof(buf)-1] = 0;
172 bcopy (ap->revision, revbuf, sizeof(revbuf)-1);
173 revbuf[sizeof(revbuf)-1] = 0;
175 printf ("wdc%d: unit %d (atapi): <%s/%s>", ctlr, unit, buf, revbuf);
177 /* device is removable */
179 printf (", removable");
181 /* packet command size */
183 case AT_PSIZE_12: break;
184 case AT_PSIZE_16: printf (", cmd16"); ata->cmd16 = 1; break;
185 default: printf (", cmd%d", ap->cmdsz);
189 switch (ap->drqtype) {
190 case AT_DRQT_MPROC: ata->slow = 1; break;
191 case AT_DRQT_INTR: printf (", intr"); ata->intrcmd = 1; break;
192 case AT_DRQT_ACCEL: printf (", accel"); ata->accel = 1; break;
193 default: printf (", drq%d", ap->drqtype);
199 * If we have two devices, one supporting INTR and one ACCEL, we
200 * have to pessimise - clear INTR and set slow.
202 if (ata->accel && ata->intrcmd) {
207 /* overlap operation supported */
211 /* interleaved DMA supported */
215 else if (ap->dmaflag)
218 /* IORDY can be disabled */
221 /* IORDY supported */
222 else if (ap->iordyflag)
229 ata->attached[unit] = 0;
235 /* Initialize free queue. */
236 ata->cmdrq[15].next = 0;
237 for (ac = ata->cmdrq+14; ac >= ata->cmdrq; --ac)
239 ata->free = ata->cmdrq;
241 if (ap->proto != AT_PROTO_ATAPI) {
242 printf ("wdc%d: unit %d: unknown ATAPI protocol=%d\n",
243 ctlr, unit, ap->proto);
247 switch (ap->devtype) {
249 /* unknown ATAPI device */
250 printf ("wdc%d: unit %d: unknown ATAPI type=%d\n",
251 ctlr, unit, ap->devtype);
254 case AT_TYPE_DIRECT: /* direct-access */
256 /* ATAPI Floppy(LS-120) */
257 if (wfdattach (ata, unit, ap, ata->debug) < 0)
259 /* Device attached successfully. */
260 ata->attached[unit] = 1;
263 printf ("wdc%d: ATAPI Floppies not configured\n", ctlr);
266 case AT_TYPE_CDROM: /* CD-ROM device */
268 /* ATAPI CD-ROM & CD-R/RW drives */
269 if (acdattach (ata, unit, ap, ata->debug) < 0)
271 ata->attached[unit] = 1;
274 printf ("wdc%d: ATAPI CD-ROMs not configured\n", ctlr);
278 case AT_TYPE_TAPE: /* streaming tape */
280 /* ATAPI Streaming Tape */
281 if (wstattach (ata, unit, ap, ata->debug) < 0)
283 /* Device attached successfully. */
284 ata->attached[unit] = 1;
287 printf ("wdc%d: ATAPI streaming tapes not configured\n", ctlr);
291 case AT_TYPE_OPTICAL: /* optical disk */
293 /* Add your driver here */
295 printf ("wdc%d: ATAPI optical disks not supported yet\n", ctlr);
304 static char *cmdname (u_char cmd)
309 case 0x00: return ("TEST_UNIT_READY");
310 case 0x01: return ("REZERO_UNIT");
311 case 0x03: return ("REQUEST_SENSE");
312 case 0x04: return ("FORMAT_UNIT");
313 case 0x1b: return ("START_STOP");
314 case 0x1e: return ("PREVENT_ALLOW");
315 case 0x25: return ("READ_CAPACITY");
316 case 0x28: return ("READ_BIG");
317 case 0x2a: return ("WRITE_BIG");
318 case 0x35: return ("SYNCHRONIZE_CACHE");
319 case 0x42: return ("READ_SUBCHANNEL");
320 case 0x43: return ("READ_TOC");
321 case 0x51: return ("READ_DISC_INFO");
322 case 0x52: return ("READ_TRACK_INFO");
323 case 0x53: return ("RESERVE_TRACK");
324 case 0x54: return ("SEND_OPC_INFO");
325 case 0x55: return ("MODE_SELECT");
326 case 0x58: return ("REPAIR_TRACK");
327 case 0x59: return ("READ_MASTER_CUE");
328 case 0x5a: return ("MODE_SENSE");
329 case 0x5b: return ("CLOSE_TRACK/SESSION");
330 case 0x5c: return ("READ_BUFFER_CAPACITY");
331 case 0x5d: return ("SEND_CUE_SHEET");
332 case 0x47: return ("PLAY_MSF");
333 case 0x4b: return ("PAUSE");
334 case 0x48: return ("PLAY_TRACK");
335 case 0xa1: return ("BLANK_CMD");
336 case 0xa5: return ("PLAY_BIG");
337 case 0xb4: return ("PLAY_CD");
338 case 0xbd: return ("ATAPI_MECH_STATUS");
339 case 0xbe: return ("READ_CD");
341 snprintf (buf, sizeof(buf), "[0x%x]", cmd);
345 static void bswap (char *buf, int len)
347 u_short *p = (u_short*) (buf + len);
348 while (--p >= (u_short*) buf)
352 static void btrim (char *buf, int len)
356 /* Remove the trailing spaces. */
357 for (p=buf; p<buf+len; ++p)
360 for (p=buf+len-1; p>=buf && *p==' '; --p)
365 * Issue IDENTIFY command to ATAPI drive to ask it what it is.
367 static struct atapi_params *atapi_probe (int port, int unit)
369 struct atapi_params *ap;
372 /* Wait for controller not busy. */
373 outb (port + AR_DRIVE, unit ? ARD_DRIVE1 : ARD_DRIVE0);
374 if (atapi_wait (port, 0) < 0) {
375 print (("atapiX.%d at 0x%x: controller busy, status=%b\n",
376 unit, port, inb (port + AR_STATUS), ARS_BITS));
380 /* Issue ATAPI IDENTIFY command. */
381 outb (port + AR_DRIVE, unit ? ARD_DRIVE1 : ARD_DRIVE0);
382 outb (port + AR_COMMAND, ATAPIC_IDENTIFY);
384 /* Check that device is present. */
385 if (inb (port + AR_STATUS) == 0xff) {
386 print (("atapiX.%d at 0x%x: no device\n", unit, port));
389 outb (port + AR_DRIVE, ARD_DRIVE0);
393 /* Wait for data ready. */
394 if (atapi_wait (port, ARS_DRQ) != 0) {
395 print (("atapiX.%d at 0x%x: identify not ready, status=%b\n",
396 unit, port, inb (port + AR_STATUS), ARS_BITS));
399 outb (port + AR_DRIVE, ARD_DRIVE0);
403 /* check that DRQ isn't a fake */
404 if (inb (port + AR_STATUS) == 0xff) {
405 print (("atapiX.%d at 0x%x: no device\n", unit, port));
408 outb (port + AR_DRIVE, ARD_DRIVE0);
412 /* Obtain parameters. */
413 insw (port + AR_DATA, tb, sizeof(tb) / sizeof(short));
415 ap = malloc (sizeof *ap, M_TEMP, M_INTWAIT);
418 bcopy (tb, ap, sizeof *ap);
421 * Shuffle string byte order.
422 * Mitsumi and NEC drives don't need this.
424 if (! ((ap->model[0] == 'N' && ap->model[1] == 'E') ||
425 (ap->model[0] == 'F' && ap->model[1] == 'X')))
426 bswap (ap->model, sizeof(ap->model));
427 bswap (ap->serial, sizeof(ap->serial));
428 bswap (ap->revision, sizeof(ap->revision));
430 /* Clean up the model name, serial and revision numbers. */
431 btrim (ap->model, sizeof(ap->model));
432 btrim (ap->serial, sizeof(ap->serial));
433 btrim (ap->revision, sizeof(ap->revision));
438 * Wait uninterruptibly until controller is not busy and certain
439 * status bits are set.
440 * The wait is usually short unless it is for the controller to process
441 * an entire critical command.
442 * Return 1 for (possibly stale) controller errors, -1 for timeout errors,
443 * or 0 for no errors.
445 static int atapi_wait (int port, u_char bits_wanted)
450 /* Wait 5 sec for BUSY deassert. */
451 for (cnt=500000; cnt>0; --cnt) {
452 s = inb (port + AR_STATUS);
460 return (s & ARS_CHECK);
462 /* Wait 50 msec for bits wanted. */
463 for (cnt=5000; cnt>0; --cnt) {
464 s = inb (port + AR_STATUS);
465 if ((s & bits_wanted) == bits_wanted)
466 return (s & ARS_CHECK);
472 void atapi_debug (struct atapi *ata, int on)
477 static struct atapicmd *atapi_alloc (struct atapi *ata)
482 tsleep ((caddr_t)ata, 0, "atacmd", 100);
484 ata->free = ac->next;
489 static void atapi_free (struct atapi *ata, struct atapicmd *ac)
492 wakeup ((caddr_t)ata);
494 ac->next = ata->free;
499 * Add new command request to the end of the queue.
501 static void atapi_enqueue (struct atapi *ata, struct atapicmd *ac)
505 ata->tail->next = ac;
511 static void atapi_done (struct atapi *ata)
513 struct atapicmd *ac = ata->queue;
516 return; /* cannot happen */
518 ata->queue = ac->next;
523 (*ac->callback) (ac->cbarg1, ac->cbarg2, ac->count, ac->result);
524 atapi_free (ata, ac);
526 wakeup ((caddr_t)ac);
530 * Start new packet op. Called from wdstart().
531 * Return 1 if op started, and we are waiting for interrupt.
532 * Return 0 when idle.
534 int atapi_strt (int ctrlr)
536 struct atapi *ata = atapitab + ctrlr;
543 /* Start packet command. */
544 if (atapi_strt_cmd (ata, ac) < 0) {
550 /* Wait for interrupt before sending packet command */
554 if (atapi_wait_cmd (ata, ac) < 0) {
559 /* Send packet command. */
560 atapi_send_cmd (ata, ac);
565 * Start new packet op. Returns -1 on errors.
567 int atapi_strt_cmd (struct atapi *ata, struct atapicmd *ac)
569 ac->result.error = 0;
570 ac->result.status = 0;
572 outb (ata->port + AR_DRIVE, ac->unit ? ARD_DRIVE1 : ARD_DRIVE0);
573 if (atapi_wait (ata->port, 0) < 0) {
574 printf ("atapi%d.%d: controller not ready for cmd\n",
575 ata->ctrlr, ac->unit);
576 ac->result.code = RES_NOTRDY;
580 /* Set up the controller registers. */
581 outb (ata->port + AR_FEATURES, 0);
582 outb (ata->port + AR_IREASON, 0);
583 outb (ata->port + AR_TAG, 0);
584 outb (ata->port + AR_CNTLO, ac->count & 0xff);
585 outb (ata->port + AR_CNTHI, ac->count >> 8);
586 outb (ata->port + AR_COMMAND, ATAPIC_PACKET);
589 printf ("atapi%d.%d: start\n", ata->ctrlr, ac->unit);
594 * Wait for DRQ before sending packet cmd. Returns -1 on errors.
596 int atapi_wait_cmd (struct atapi *ata, struct atapicmd *ac)
598 /* Wait for DRQ from 100 usec to 3 msec for slow devices */
599 int cnt = ata->intrcmd ? 10000 : ata->slow ? 3000 : 100;
600 int ireason = 0, phase = 0;
602 /* Wait for command phase. */
603 for (; cnt>0; cnt-=10) {
604 ireason = inb (ata->port + AR_IREASON);
605 ac->result.status = inb (ata->port + AR_STATUS);
606 phase = (ireason & (ARI_CMD | ARI_IN)) |
607 (ac->result.status & (ARS_DRQ | ARS_BSY));
608 if (phase == PHASE_CMDOUT)
613 if (phase != PHASE_CMDOUT) {
614 ac->result.code = RES_NODRQ;
615 ac->result.error = inb (ata->port + AR_ERROR);
616 printf ("atapi%d.%d: invalid command phase, ireason=0x%x, status=%b, error=%b\n",
617 ata->ctrlr, ac->unit, ireason,
618 ac->result.status, ARS_BITS,
619 ac->result.error, AER_BITS);
628 void atapi_send_cmd (struct atapi *ata, struct atapicmd *ac)
630 outsw (ata->port + AR_DATA, ac->cmd, ata->cmd16 ? 8 : 6);
632 printf ("atapi%d.%d: send cmd %s %x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x\n",
633 ata->ctrlr, ac->unit, cmdname (ac->cmd[0]), ac->cmd[0],
634 ac->cmd[1], ac->cmd[2], ac->cmd[3], ac->cmd[4],
635 ac->cmd[5], ac->cmd[6], ac->cmd[7], ac->cmd[8],
636 ac->cmd[9], ac->cmd[10], ac->cmd[11], ac->cmd[12],
637 ac->cmd[13], ac->cmd[14], ac->cmd[15]);
641 * Interrupt routine for the controller. Called from wdintr().
642 * Finish the started op, wakeup wait-type commands,
643 * run callbacks for callback-type commands, then return.
644 * Do not start new op here, it will be done by wdstart,
645 * which is called just after us.
646 * Return 1 if op continues, and we are waiting for new interrupt.
647 * Return 0 when idle.
649 int atapi_intr (int ctrlr)
651 struct atapi *ata = atapitab + ctrlr;
652 struct atapicmd *ac = ata->queue;
655 printf ("atapi%d: stray interrupt\n", ata->ctrlr);
658 if (atapi_io (ata, ac) > 0)
665 * Process the i/o phase, transferring the command/data to/from the device.
666 * Return 1 if op continues, and we are waiting for new interrupt.
667 * Return 0 when idle.
669 int atapi_io (struct atapi *ata, struct atapicmd *ac)
674 if (atapi_wait (ata->port, 0) < 0) {
675 ac->result.status = inb (ata->port + AR_STATUS);
676 ac->result.error = inb (ata->port + AR_ERROR);
677 ac->result.code = RES_NOTRDY;
678 printf ("atapi%d.%d: controller not ready, status=%b, error=%b\n",
679 ata->ctrlr, ac->unit, ac->result.status, ARS_BITS,
680 ac->result.error, AER_BITS);
684 ac->result.status = inb (ata->port + AR_STATUS);
685 ac->result.error = inb (ata->port + AR_ERROR);
686 len = inb (ata->port + AR_CNTLO);
687 len |= inb (ata->port + AR_CNTHI) << 8;
688 ireason = inb (ata->port + AR_IREASON);
691 printf ("atapi%d.%d: intr ireason=0x%x, len=%d, status=%b, error=%b\n",
692 ata->ctrlr, ac->unit, ireason, len,
693 ac->result.status, ARS_BITS,
694 ac->result.error, AER_BITS);
696 switch ((ireason & (ARI_CMD | ARI_IN)) | (ac->result.status & ARS_DRQ)) {
698 printf ("atapi%d.%d: unknown phase\n", ata->ctrlr, ac->unit);
699 ac->result.code = RES_ERR;
703 /* Send packet command. */
704 if (! (ac->result.status & ARS_DRQ)) {
705 printf ("atapi%d.%d: no cmd drq\n",
706 ata->ctrlr, ac->unit);
707 ac->result.code = RES_NODRQ;
710 atapi_send_cmd (ata, ac);
716 printf ("atapi%d.%d: invalid data direction\n",
717 ata->ctrlr, ac->unit);
718 ac->result.code = RES_INVDIR;
721 if (-ac->count < len) {
722 print (("atapi%d.%d: send data underrun, %d bytes left\n",
723 ata->ctrlr, ac->unit, -ac->count));
724 ac->result.code = RES_UNDERRUN;
725 outsw (ata->port + AR_DATA, ac->addr,
726 -ac->count / sizeof(short));
727 for (i= -ac->count; i<len; i+=sizeof(short))
728 outw (ata->port + AR_DATA, 0);
730 outsw (ata->port + AR_DATA, ac->addr,
731 len / sizeof(short));
739 printf ("atapi%d.%d: invalid data direction\n",
740 ata->ctrlr, ac->unit);
741 ac->result.code = RES_INVDIR;
744 if (ac->count < len) {
745 print (("atapi%d.%d: recv data overrun, %d bytes left\n",
746 ata->ctrlr, ac->unit, ac->count));
747 ac->result.code = RES_OVERRUN;
748 insw (ata->port + AR_DATA, ac->addr,
749 ac->count / sizeof(short));
750 for (i=ac->count; i<len; i+=sizeof(short))
751 inw (ata->port + AR_DATA);
753 insw (ata->port + AR_DATA, ac->addr,
754 len / sizeof(short));
760 case PHASE_COMPLETED:
761 if (ac->result.status & (ARS_CHECK | ARS_DF))
762 ac->result.code = RES_ERR;
763 else if (ac->count < 0) {
764 print (("atapi%d.%d: send data overrun, %d bytes left\n",
765 ata->ctrlr, ac->unit, -ac->count));
766 ac->result.code = RES_OVERRUN;
767 } else if (ac->count > 0) {
768 print (("atapi%d.%d: recv data underrun, %d bytes left\n",
769 ata->ctrlr, ac->unit, ac->count));
770 ac->result.code = RES_UNDERRUN;
771 bzero (ac->addr, ac->count);
773 ac->result.code = RES_OK;
780 * Queue new packet request, then call wdstart().
781 * Called on splbio().
783 void atapi_request_callback (struct atapi *ata, int unit,
784 u_char cmd, u_char a1, u_char a2, u_char a3, u_char a4,
785 u_char a5, u_char a6, u_char a7, u_char a8, u_char a9,
786 u_char a10, u_char a11, u_char a12, u_char a13, u_char a14, u_char a15,
787 char *addr, int count, atapi_callback_t *done, void *x, void *y)
791 ac = atapi_alloc (ata);
792 ac->cmd[0] = cmd; ac->cmd[1] = a1;
793 ac->cmd[2] = a2; ac->cmd[3] = a3;
794 ac->cmd[4] = a4; ac->cmd[5] = a5;
795 ac->cmd[6] = a6; ac->cmd[7] = a7;
796 ac->cmd[8] = a8; ac->cmd[9] = a9;
797 ac->cmd[10] = a10; ac->cmd[11] = a11;
798 ac->cmd[12] = a12; ac->cmd[13] = a13;
799 ac->cmd[14] = a14; ac->cmd[15] = a15;
808 printf ("atapi%d.%d: req cb %x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x len=%d\n",
809 ata->ctrlr, ac->unit, ac->cmd[0], ac->cmd[1],
810 ac->cmd[2], ac->cmd[3], ac->cmd[4], ac->cmd[5],
811 ac->cmd[6], ac->cmd[7], ac->cmd[8], ac->cmd[9],
812 ac->cmd[10], ac->cmd[11], ac->cmd[12],
813 ac->cmd[13], ac->cmd[14], ac->cmd[15], count);
814 atapi_enqueue (ata, ac);
815 wdstart (ata->ctrlr);
819 * Queue new packet request, then call wdstart().
820 * Wait until the request is finished.
822 * Return atapi error.
823 * Buffer pointed to by *addr should be placed in core memory, not in stack!
825 struct atapires atapi_request_wait (struct atapi *ata, int unit,
826 u_char cmd, u_char a1, u_char a2, u_char a3, u_char a4,
827 u_char a5, u_char a6, u_char a7, u_char a8, u_char a9,
828 u_char a10, u_char a11, u_char a12, u_char a13, u_char a14, u_char a15,
829 char *addr, int count)
833 struct atapires result;
835 ac = atapi_alloc (ata);
836 ac->cmd[0] = cmd; ac->cmd[1] = a1;
837 ac->cmd[2] = a2; ac->cmd[3] = a3;
838 ac->cmd[4] = a4; ac->cmd[5] = a5;
839 ac->cmd[6] = a6; ac->cmd[7] = a7;
840 ac->cmd[8] = a8; ac->cmd[9] = a9;
841 ac->cmd[10] = a10; ac->cmd[11] = a11;
842 ac->cmd[12] = a12; ac->cmd[13] = a13;
843 ac->cmd[14] = a14; ac->cmd[15] = a15;
852 printf ("atapi%d.%d: req w %x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x len=%d\n",
853 ata->ctrlr, ac->unit, ac->cmd[0], ac->cmd[1],
854 ac->cmd[2], ac->cmd[3], ac->cmd[4], ac->cmd[5],
855 ac->cmd[6], ac->cmd[7], ac->cmd[8], ac->cmd[9],
856 ac->cmd[10], ac->cmd[11], ac->cmd[12],
857 ac->cmd[13], ac->cmd[14], ac->cmd[15], count);
858 atapi_enqueue (ata, ac);
859 wdstart (ata->ctrlr);
861 tsleep ((caddr_t)ac, 0, "atareq", 0);
864 atapi_free (ata, ac);
870 * Perform a packet command on the device.
871 * Should be called on splbio().
872 * Return atapi error.
874 struct atapires atapi_request_immediate (struct atapi *ata, int unit,
875 u_char cmd, u_char a1, u_char a2, u_char a3, u_char a4,
876 u_char a5, u_char a6, u_char a7, u_char a8, u_char a9,
877 u_char a10, u_char a11, u_char a12, u_char a13, u_char a14, u_char a15,
878 char *addr, int count)
880 struct atapicmd cmdbuf, *ac = &cmdbuf;
883 ac->cmd[0] = cmd; ac->cmd[1] = a1;
884 ac->cmd[2] = a2; ac->cmd[3] = a3;
885 ac->cmd[4] = a4; ac->cmd[5] = a5;
886 ac->cmd[6] = a6; ac->cmd[7] = a7;
887 ac->cmd[8] = a8; ac->cmd[9] = a9;
888 ac->cmd[10] = a10; ac->cmd[11] = a11;
889 ac->cmd[12] = a12; ac->cmd[13] = a13;
890 ac->cmd[14] = a14; ac->cmd[15] = a15;
899 printf ("atapi%d.%d: req im %x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x len=%d\n",
900 ata->ctrlr, ac->unit, ac->cmd[0], ac->cmd[1],
901 ac->cmd[2], ac->cmd[3], ac->cmd[4], ac->cmd[5],
902 ac->cmd[6], ac->cmd[7], ac->cmd[8], ac->cmd[9],
903 ac->cmd[10], ac->cmd[11], ac->cmd[12],
904 ac->cmd[13], ac->cmd[14], ac->cmd[15], count);
906 /* Start packet command, wait for DRQ. */
907 if (atapi_strt_cmd (ata, ac) >= 0 && atapi_wait_cmd (ata, ac) >= 0) {
908 /* Send packet command. */
909 atapi_send_cmd (ata, ac);
911 /* Wait for data i/o phase. */
912 for (cnt=20000; cnt>0; --cnt)
913 if (((inb (ata->port + AR_IREASON) & (ARI_CMD | ARI_IN)) |
914 (inb (ata->port + AR_STATUS) & ARS_DRQ)) != PHASE_CMDOUT)
917 /* Do all needed i/o. */
918 while (atapi_io (ata, ac))
919 /* Wait for DRQ deassert. */
920 for (cnt=2000; cnt>0; --cnt) {
921 if (! (inb (ata->port + AR_STATUS) & ARS_DRQ))