2 * linux/drivers/ide/ide-taskfile.c Version 0.38 March 05, 2003
4 * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org>
5 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
6 * Copyright (C) 2001-2002 Klaus Smolin
7 * IBM Storage Technology Division
8 * Copyright (C) 2003 Bartlomiej Zolnierkiewicz
10 * The big the bad and the ugly.
12 * Problems to be fixed because of BH interface or the lack therefore.
14 * Fill me in stupid !!!
17 * General refers to the Controller and Driver "pair".
19 * Under the context of Linux it generally refers to an interrupt handler.
20 * However, it correctly describes the 'HOST'
22 * The amount of data needed to be transfered as predefined in the
23 * setup of the device.
25 * The 'DATA BLOCK' associated to the 'DATA HANDLER', and can be as
26 * small as a single sector or as large as the entire command block
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/string.h>
34 #include <linux/kernel.h>
35 #include <linux/timer.h>
37 #include <linux/interrupt.h>
38 #include <linux/major.h>
39 #include <linux/errno.h>
40 #include <linux/genhd.h>
41 #include <linux/blkpg.h>
42 #include <linux/slab.h>
43 #include <linux/pci.h>
44 #include <linux/delay.h>
45 #include <linux/hdreg.h>
46 #include <linux/ide.h>
48 #include <asm/byteorder.h>
50 #include <asm/uaccess.h>
52 #include <asm/bitops.h>
54 #define DEBUG_TASKFILE 0 /* unset when fixed */
57 #define DTF(x...) printk(x)
62 static void ata_bswap_data (void *buffer, int wcount)
67 *p = *p << 8 | *p >> 8; p++;
68 *p = *p << 8 | *p >> 8; p++;
73 void taskfile_input_data (ide_drive_t *drive, void *buffer, u32 wcount)
75 HWIF(drive)->ata_input_data(drive, buffer, wcount);
77 ata_bswap_data(buffer, wcount);
80 EXPORT_SYMBOL(taskfile_input_data);
82 void taskfile_output_data (ide_drive_t *drive, void *buffer, u32 wcount)
85 ata_bswap_data(buffer, wcount);
86 HWIF(drive)->ata_output_data(drive, buffer, wcount);
87 ata_bswap_data(buffer, wcount);
89 HWIF(drive)->ata_output_data(drive, buffer, wcount);
93 EXPORT_SYMBOL(taskfile_output_data);
95 int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
98 memset(&args, 0, sizeof(ide_task_t));
99 args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01;
100 if (drive->media == ide_disk)
101 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_IDENTIFY;
103 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_PIDENTIFY;
104 args.command_type = ide_cmd_type_parser(&args);
105 return ide_raw_taskfile(drive, &args, buf);
108 EXPORT_SYMBOL(taskfile_lib_get_identify);
110 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
111 void debug_taskfile (ide_drive_t *drive, ide_task_t *args)
113 printk(KERN_INFO "%s: ", drive->name);
114 // printk("TF.0=x%02x ", args->tfRegister[IDE_DATA_OFFSET]);
115 printk("TF.1=x%02x ", args->tfRegister[IDE_FEATURE_OFFSET]);
116 printk("TF.2=x%02x ", args->tfRegister[IDE_NSECTOR_OFFSET]);
117 printk("TF.3=x%02x ", args->tfRegister[IDE_SECTOR_OFFSET]);
118 printk("TF.4=x%02x ", args->tfRegister[IDE_LCYL_OFFSET]);
119 printk("TF.5=x%02x ", args->tfRegister[IDE_HCYL_OFFSET]);
120 printk("TF.6=x%02x ", args->tfRegister[IDE_SELECT_OFFSET]);
121 printk("TF.7=x%02x\n", args->tfRegister[IDE_COMMAND_OFFSET]);
122 printk(KERN_INFO "%s: ", drive->name);
123 // printk("HTF.0=x%02x ", args->hobRegister[IDE_DATA_OFFSET_HOB]);
124 printk("HTF.1=x%02x ", args->hobRegister[IDE_FEATURE_OFFSET_HOB]);
125 printk("HTF.2=x%02x ", args->hobRegister[IDE_NSECTOR_OFFSET_HOB]);
126 printk("HTF.3=x%02x ", args->hobRegister[IDE_SECTOR_OFFSET_HOB]);
127 printk("HTF.4=x%02x ", args->hobRegister[IDE_LCYL_OFFSET_HOB]);
128 printk("HTF.5=x%02x ", args->hobRegister[IDE_HCYL_OFFSET_HOB]);
129 printk("HTF.6=x%02x ", args->hobRegister[IDE_SELECT_OFFSET_HOB]);
130 printk("HTF.7=x%02x\n", args->hobRegister[IDE_CONTROL_OFFSET_HOB]);
132 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
134 ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
136 ide_hwif_t *hwif = HWIF(drive);
137 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
138 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
139 u8 HIHI = (drive->addressing == 1) ? 0xE0 : 0xEF;
141 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
142 void debug_taskfile(drive, task);
143 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
145 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
146 if (IDE_CONTROL_REG) {
148 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
150 SELECT_MASK(drive, 0);
152 if (drive->addressing == 1) {
153 hwif->OUTB(hobfile->feature, IDE_FEATURE_REG);
154 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
155 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
156 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
157 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
160 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
161 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
162 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
163 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
164 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
166 hwif->OUTB((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG);
167 #ifdef CONFIG_IDE_TASKFILE_IO
168 if (task->handler != NULL) {
169 if (task->prehandler != NULL) {
170 hwif->OUTBSYNC(drive, taskfile->command, IDE_COMMAND_REG);
171 ndelay(400); /* FIXME */
172 return task->prehandler(drive, task->rq);
174 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
178 if (task->handler != NULL) {
179 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
180 if (task->prehandler != NULL)
181 return task->prehandler(drive, task->rq);
186 if (!drive->using_dma)
189 switch (taskfile->command) {
190 case WIN_WRITEDMA_ONCE:
192 case WIN_WRITEDMA_EXT:
193 if (!hwif->ide_dma_write(drive))
196 case WIN_READDMA_ONCE:
198 case WIN_READDMA_EXT:
199 case WIN_IDENTIFY_DMA:
200 if (!hwif->ide_dma_read(drive))
203 #ifdef CONFIG_BLK_DEV_IDE_TCQ
204 case WIN_READDMA_QUEUED:
205 case WIN_READDMA_QUEUED_EXT:
206 return __ide_dma_queued_read(drive);
207 case WIN_WRITEDMA_QUEUED:
208 case WIN_WRITEDMA_QUEUED_EXT:
209 return __ide_dma_queued_write(drive);
212 if (task->handler == NULL)
219 EXPORT_SYMBOL(do_rw_taskfile);
222 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
224 ide_startstop_t set_multmode_intr (ide_drive_t *drive)
226 ide_hwif_t *hwif = HWIF(drive);
229 if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
230 drive->mult_count = drive->mult_req;
232 drive->mult_req = drive->mult_count = 0;
233 drive->special.b.recalibrate = 1;
234 (void) ide_dump_status(drive, "set_multmode", stat);
239 EXPORT_SYMBOL(set_multmode_intr);
242 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
244 ide_startstop_t set_geometry_intr (ide_drive_t *drive)
246 ide_hwif_t *hwif = HWIF(drive);
250 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
253 if (OK_STAT(stat, READY_STAT, BAD_STAT))
256 if (stat & (ERR_STAT|DRQ_STAT))
257 return DRIVER(drive)->error(drive, "set_geometry_intr", stat);
259 if (HWGROUP(drive)->handler != NULL)
261 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
265 EXPORT_SYMBOL(set_geometry_intr);
268 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
270 ide_startstop_t recal_intr (ide_drive_t *drive)
272 ide_hwif_t *hwif = HWIF(drive);
275 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT))
276 return DRIVER(drive)->error(drive, "recal_intr", stat);
280 EXPORT_SYMBOL(recal_intr);
283 * Handler for commands without a data phase
285 ide_startstop_t task_no_data_intr (ide_drive_t *drive)
287 ide_task_t *args = HWGROUP(drive)->rq->special;
288 ide_hwif_t *hwif = HWIF(drive);
292 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
293 DTF("%s: command opcode 0x%02x\n", drive->name,
294 args->tfRegister[IDE_COMMAND_OFFSET]);
295 return DRIVER(drive)->error(drive, "task_no_data_intr", stat);
296 /* calls ide_end_drive_cmd */
299 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
304 EXPORT_SYMBOL(task_no_data_intr);
307 * old taskfile PIO handlers, to be killed as soon as possible.
309 #ifndef CONFIG_IDE_TASKFILE_IO
311 #define task_map_rq(rq, flags) ide_map_buffer((rq), (flags))
312 #define task_unmap_rq(rq, buf, flags) ide_unmap_buffer((rq), (buf), (flags))
315 * Handler for command with PIO data-in phase, READ
318 * FIXME before 2.4 enable ...
319 * DATA integrity issue upon error. <andre@linux-ide.org>
321 ide_startstop_t task_in_intr (ide_drive_t *drive)
323 struct request *rq = HWGROUP(drive)->rq;
324 ide_hwif_t *hwif = HWIF(drive);
329 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
330 if (stat & (ERR_STAT|DRQ_STAT)) {
332 DTF("%s: attempting to recover last " \
333 "sector counter status=0x%02x\n",
336 * Expect a BUG BOMB if we attempt to rewind the
337 * offset in the BH aka PAGE in the current BLOCK
338 * segment. This is different than the HOST segment.
342 rq->current_nr_sectors++;
343 return DRIVER(drive)->error(drive, "task_in_intr", stat);
345 if (!(stat & BUSY_STAT)) {
346 DTF("task_in_intr to Soon wait for next interrupt\n");
347 if (HWGROUP(drive)->handler == NULL)
348 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
355 * Holding point for a brain dump of a thought :-/
358 if (!OK_STAT(stat,DRIVE_READY,drive->bad_wstat)) {
359 DTF("%s: READ attempting to recover last " \
360 "sector counter status=0x%02x\n",
362 rq->current_nr_sectors++;
363 return DRIVER(drive)->error(drive, "task_in_intr", stat);
365 if (!rq->current_nr_sectors)
366 if (!DRIVER(drive)->end_request(drive, 1, 0))
369 if (--rq->current_nr_sectors <= 0)
370 if (!DRIVER(drive)->end_request(drive, 1, 0))
374 pBuf = task_map_rq(rq, &flags);
375 DTF("Read: %p, rq->current_nr_sectors: %d, stat: %02x\n",
376 pBuf, (int) rq->current_nr_sectors, stat);
377 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
378 task_unmap_rq(rq, pBuf, &flags);
380 * FIXME :: We really can not legally get a new page/bh
381 * regardless, if this is the end of our segment.
382 * BH walking or segment can only be updated after we have a good
383 * hwif->INB(IDE_STATUS_REG); return.
385 if (--rq->current_nr_sectors <= 0)
386 if (!DRIVER(drive)->end_request(drive, 1, 0))
389 * ERM, it is techincally legal to leave/exit here but it makes
390 * a mess of the code ...
392 if (HWGROUP(drive)->handler == NULL)
393 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
397 EXPORT_SYMBOL(task_in_intr);
400 * Handler for command with Read Multiple
402 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
404 ide_hwif_t *hwif = HWIF(drive);
405 struct request *rq = HWGROUP(drive)->rq;
407 unsigned int msect = drive->mult_count;
412 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
413 if (stat & (ERR_STAT|DRQ_STAT)) {
415 rq->current_nr_sectors += drive->mult_count;
417 * NOTE: could rewind beyond beginning :-/
420 printk(KERN_ERR "%s: MULTI-READ assume all data " \
421 "transfered is bad status=0x%02x\n",
424 return DRIVER(drive)->error(drive, "task_mulin_intr", stat);
426 /* no data yet, so wait for another interrupt */
427 if (HWGROUP(drive)->handler == NULL)
428 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
433 nsect = rq->current_nr_sectors;
436 pBuf = task_map_rq(rq, &flags);
437 DTF("Multiread: %p, nsect: %d, msect: %d, " \
438 " rq->current_nr_sectors: %d\n",
439 pBuf, nsect, msect, rq->current_nr_sectors);
440 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
441 task_unmap_rq(rq, pBuf, &flags);
443 rq->current_nr_sectors -= nsect;
446 * FIXME :: We really can not legally get a new page/bh
447 * regardless, if this is the end of our segment.
448 * BH walking or segment can only be updated after we have a
449 * good hwif->INB(IDE_STATUS_REG); return.
451 if (!rq->current_nr_sectors) {
452 if (!DRIVER(drive)->end_request(drive, 1, 0))
456 if (HWGROUP(drive)->handler == NULL)
457 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
461 EXPORT_SYMBOL(task_mulin_intr);
464 * VERIFY ME before 2.4 ... unexpected race is possible based on details
465 * RMK with 74LS245/373/374 TTL buffer logic because of passthrough.
467 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
471 ide_startstop_t startstop;
473 if (ide_wait_stat(&startstop, drive, DATA_READY,
474 drive->bad_wstat, WAIT_DRQ)) {
475 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
477 drive->addressing ? "_EXT" : "");
480 /* For Write_sectors we need to stuff the first sector */
481 pBuf = task_map_rq(rq, &flags);
482 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
483 rq->current_nr_sectors--;
484 task_unmap_rq(rq, pBuf, &flags);
488 EXPORT_SYMBOL(pre_task_out_intr);
491 * Handler for command with PIO data-out phase WRITE
493 * WOOHOO this is a CORRECT STATE DIAGRAM NOW, <andre@linux-ide.org>
495 ide_startstop_t task_out_intr (ide_drive_t *drive)
497 ide_hwif_t *hwif = HWIF(drive);
498 struct request *rq = HWGROUP(drive)->rq;
503 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), DRIVE_READY, drive->bad_wstat)) {
504 DTF("%s: WRITE attempting to recover last " \
505 "sector counter status=0x%02x\n",
507 rq->current_nr_sectors++;
508 return DRIVER(drive)->error(drive, "task_out_intr", stat);
511 * Safe to update request for partial completions.
512 * We have a good STATUS CHECK!!!
514 if (!rq->current_nr_sectors)
515 if (!DRIVER(drive)->end_request(drive, 1, 0))
517 if ((rq->current_nr_sectors==1) ^ (stat & DRQ_STAT)) {
518 rq = HWGROUP(drive)->rq;
519 pBuf = task_map_rq(rq, &flags);
520 DTF("write: %p, rq->current_nr_sectors: %d\n",
521 pBuf, (int) rq->current_nr_sectors);
522 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
523 task_unmap_rq(rq, pBuf, &flags);
525 rq->current_nr_sectors--;
527 if (HWGROUP(drive)->handler == NULL)
528 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
532 EXPORT_SYMBOL(task_out_intr);
534 #undef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
536 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
538 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
539 ide_hwif_t *hwif = HWIF(drive);
541 unsigned int nsect = 0, msect = drive->mult_count;
544 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
546 ide_task_t *args = rq->special;
547 ide_startstop_t startstop;
551 * assign private copy for multi-write
553 memcpy(&HWGROUP(drive)->wrq, rq, sizeof(struct request));
556 if (ide_wait_stat(&startstop, drive, DATA_READY,
557 drive->bad_wstat, WAIT_DRQ)) {
558 printk(KERN_ERR "%s: no DRQ after issuing %s\n",
560 drive->addressing ? "MULTWRITE_EXT" : "MULTWRITE");
563 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
566 nsect = rq->current_nr_sectors;
569 pBuf = task_map_rq(rq, &flags);
570 DTF("Pre-Multiwrite: %p, nsect: %d, msect: %d, " \
571 "rq->current_nr_sectors: %ld\n",
572 pBuf, nsect, msect, rq->current_nr_sectors);
574 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
575 task_unmap_rq(rq, pBuf, &flags);
576 rq->current_nr_sectors -= nsect;
577 if (!rq->current_nr_sectors) {
578 if (!DRIVER(drive)->end_request(drive, 1, 0))
580 stat = hwif->INB(IDE_STATUS_REG);
587 #else /* ! ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
588 if (!(drive_is_ready(drive))) {
590 for (i=0; i<100; i++) {
591 if (drive_is_ready(drive))
597 * WARNING :: if the drive as not acked good status we may not
598 * move the DATA-TRANSFER T-Bar as BSY != 0. <andre@linux-ide.org>
600 return args->handler(drive);
601 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
604 EXPORT_SYMBOL(pre_task_mulout_intr);
607 * FIXME before enabling in 2.4 ... DATA integrity issue upon error.
610 * Handler for command write multiple
611 * Called directly from execute_drive_cmd for the first bunch of sectors,
612 * afterwards only by the ISR
614 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
616 ide_hwif_t *hwif = HWIF(drive);
617 u8 stat = hwif->INB(IDE_STATUS_REG);
618 struct request *rq = HWGROUP(drive)->rq;
620 ide_startstop_t startstop = ide_stopped;
621 unsigned int msect = drive->mult_count;
626 * (ks/hs): Handle last IRQ on multi-sector transfer,
627 * occurs after all data was sent in this chunk
629 if (rq->current_nr_sectors == 0) {
630 if (stat & (ERR_STAT|DRQ_STAT)) {
632 rq->current_nr_sectors += drive->mult_count;
634 * NOTE: could rewind beyond beginning :-/
637 printk(KERN_ERR "%s: MULTI-WRITE assume all data " \
638 "transfered is bad status=0x%02x\n",
641 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
644 DRIVER(drive)->end_request(drive, 1, 0);
648 * DON'T be lazy code the above and below togather !!!
650 if (!OK_STAT(stat,DATA_READY,BAD_R_STAT)) {
651 if (stat & (ERR_STAT|DRQ_STAT)) {
653 rq->current_nr_sectors += drive->mult_count;
655 * NOTE: could rewind beyond beginning :-/
658 printk("%s: MULTI-WRITE assume all data " \
659 "transfered is bad status=0x%02x\n",
662 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
664 /* no data yet, so wait for another interrupt */
665 if (HWGROUP(drive)->handler == NULL)
666 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
670 #ifndef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
671 if (HWGROUP(drive)->handler != NULL) {
672 unsigned long lflags;
673 spin_lock_irqsave(&ide_lock, lflags);
674 HWGROUP(drive)->handler = NULL;
675 del_timer(&HWGROUP(drive)->timer);
676 spin_unlock_irqrestore(&ide_lock, lflags);
678 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
681 nsect = rq->current_nr_sectors;
684 pBuf = task_map_rq(rq, &flags);
685 DTF("Multiwrite: %p, nsect: %d, msect: %d, " \
686 "rq->current_nr_sectors: %ld\n",
687 pBuf, nsect, msect, rq->current_nr_sectors);
689 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
690 task_unmap_rq(rq, pBuf, &flags);
691 rq->current_nr_sectors -= nsect;
693 * FIXME :: We really can not legally get a new page/bh
694 * regardless, if this is the end of our segment.
695 * BH walking or segment can only be updated after we
696 * have a good hwif->INB(IDE_STATUS_REG); return.
698 if (!rq->current_nr_sectors) {
699 if (!DRIVER(drive)->end_request(drive, 1, 0))
705 if (HWGROUP(drive)->handler == NULL)
706 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
710 EXPORT_SYMBOL(task_mulout_intr);
712 #else /* !CONFIG_IDE_TASKFILE_IO */
714 static u8 wait_drive_not_busy(ide_drive_t *drive)
716 ide_hwif_t *hwif = HWIF(drive);
721 * Last sector was transfered, wait until drive is ready.
722 * This can take up to 10 usec, but we will wait max 1 ms
723 * (drive_cmd_intr() waits that long).
725 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
729 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
735 * Handler for command with PIO data-in phase (Read).
737 ide_startstop_t task_in_intr (ide_drive_t *drive)
739 struct request *rq = HWGROUP(drive)->rq;
742 good_stat = DATA_READY;
743 stat = HWIF(drive)->INB(IDE_STATUS_REG);
745 if (!OK_STAT(stat, good_stat, BAD_R_STAT)) {
746 if (stat & (ERR_STAT | DRQ_STAT))
747 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
748 /* BUSY_STAT: No data yet, so wait for another IRQ. */
749 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
754 * Complete previously submitted bios (if any).
755 * Status was already verifyied.
757 while (rq->bio != rq->cbio)
758 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
760 /* Complete rq->buffer based request (ioctls). */
761 if (!rq->bio && !rq->nr_sectors) {
762 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
767 task_sectors(drive, rq, 1, IDE_PIO_IN);
769 /* If it was the last datablock check status and finish transfer. */
770 if (!rq->nr_sectors) {
772 stat = wait_drive_not_busy(drive);
776 /* Still data left to transfer. */
777 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
781 EXPORT_SYMBOL(task_in_intr);
784 * Handler for command with PIO data-in phase (Read Multiple).
786 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
788 struct request *rq = HWGROUP(drive)->rq;
789 unsigned int msect = drive->mult_count;
793 good_stat = DATA_READY;
794 stat = HWIF(drive)->INB(IDE_STATUS_REG);
796 if (!OK_STAT(stat, good_stat, BAD_R_STAT)) {
797 if (stat & (ERR_STAT | DRQ_STAT))
798 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
799 /* BUSY_STAT: No data yet, so wait for another IRQ. */
800 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
805 * Complete previously submitted bios (if any).
806 * Status was already verifyied.
808 while (rq->bio != rq->cbio)
809 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
811 /* Complete rq->buffer based request (ioctls). */
812 if (!rq->bio && !rq->nr_sectors) {
813 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
819 nsect = rq->current_nr_sectors;
823 task_sectors(drive, rq, nsect, IDE_PIO_IN);
831 /* If it was the last datablock check status and finish transfer. */
832 if (!rq->nr_sectors) {
834 stat = wait_drive_not_busy(drive);
838 /* Still data left to transfer. */
839 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
843 EXPORT_SYMBOL(task_mulin_intr);
846 * Handler for command with PIO data-out phase (Write).
848 ide_startstop_t task_out_intr (ide_drive_t *drive)
850 struct request *rq = HWGROUP(drive)->rq;
853 stat = HWIF(drive)->INB(IDE_STATUS_REG);
854 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) {
855 if ((stat & (ERR_STAT | DRQ_STAT)) ||
856 ((stat & WRERR_STAT) && !drive->nowerr))
857 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
858 if (stat & BUSY_STAT) {
859 /* Not ready yet, so wait for another IRQ. */
860 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
865 /* Deal with unexpected ATA data phase. */
866 if ((!(stat & DATA_READY) && rq->nr_sectors) ||
867 ((stat & DATA_READY) && !rq->nr_sectors))
868 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
871 * Complete previously submitted bios (if any).
872 * Status was already verifyied.
874 while (rq->bio != rq->cbio)
875 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
877 /* Complete rq->buffer based request (ioctls). */
878 if (!rq->bio && !rq->nr_sectors) {
879 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
883 /* Still data left to transfer. */
884 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
887 task_sectors(drive, rq, 1, IDE_PIO_OUT);
892 EXPORT_SYMBOL(task_out_intr);
894 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
896 ide_startstop_t startstop;
898 if (ide_wait_stat(&startstop, drive, DATA_READY,
899 drive->bad_wstat, WAIT_DRQ)) {
900 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
901 drive->name, drive->addressing ? "_EXT" : "");
908 return task_out_intr(drive);
910 EXPORT_SYMBOL(pre_task_out_intr);
913 * Handler for command with PIO data-out phase (Write Multiple).
915 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
917 struct request *rq = HWGROUP(drive)->rq;
918 unsigned int msect = drive->mult_count;
922 stat = HWIF(drive)->INB(IDE_STATUS_REG);
923 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) {
924 if ((stat & (ERR_STAT | DRQ_STAT)) ||
925 ((stat & WRERR_STAT) && !drive->nowerr))
926 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
927 if (stat & BUSY_STAT) {
928 /* Not ready yet, so wait for another IRQ. */
929 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
934 /* Deal with unexpected ATA data phase. */
935 if ((!(stat & DATA_READY) && rq->nr_sectors) ||
936 ((stat & DATA_READY) && !rq->nr_sectors))
937 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
940 * Complete previously submitted bios (if any).
941 * Status was already verifyied.
943 while (rq->bio != rq->cbio)
944 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
946 /* Complete rq->buffer based request (ioctls). */
947 if (!rq->bio && !rq->nr_sectors) {
948 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
952 /* Still data left to transfer. */
953 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
957 nsect = rq->current_nr_sectors;
961 task_sectors(drive, rq, nsect, IDE_PIO_OUT);
971 EXPORT_SYMBOL(task_mulout_intr);
973 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
975 ide_startstop_t startstop;
977 if (ide_wait_stat(&startstop, drive, DATA_READY,
978 drive->bad_wstat, WAIT_DRQ)) {
979 printk(KERN_ERR "%s: no DRQ after issuing MULTWRITE%s\n",
980 drive->name, drive->addressing ? "_EXT" : "");
987 return task_mulout_intr(drive);
989 EXPORT_SYMBOL(pre_task_mulout_intr);
991 #endif /* !CONFIG_IDE_TASKFILE_IO */
993 /* Called by internal to feature out type of command being called */
994 //ide_pre_handler_t * ide_pre_handler_parser (task_struct_t *taskfile, hob_struct_t *hobfile)
995 ide_pre_handler_t * ide_pre_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
997 switch(taskfile->command) {
998 /* IDE_DRIVE_TASK_RAW_WRITE */
999 case CFA_WRITE_MULTI_WO_ERASE:
1000 // case WIN_WRITE_LONG:
1001 // case WIN_WRITE_LONG_ONCE:
1003 case WIN_MULTWRITE_EXT:
1004 return &pre_task_mulout_intr;
1006 /* IDE_DRIVE_TASK_OUT */
1008 // case WIN_WRITE_ONCE:
1010 case WIN_WRITE_VERIFY:
1011 case WIN_WRITE_BUFFER:
1012 case CFA_WRITE_SECT_WO_ERASE:
1013 case WIN_DOWNLOAD_MICROCODE:
1014 return &pre_task_out_intr;
1015 /* IDE_DRIVE_TASK_OUT */
1017 if (taskfile->feature == SMART_WRITE_LOG_SECTOR)
1018 return &pre_task_out_intr;
1020 // case WIN_WRITEDMA_ONCE:
1021 case WIN_WRITEDMA_QUEUED:
1022 case WIN_WRITEDMA_EXT:
1023 case WIN_WRITEDMA_QUEUED_EXT:
1024 /* IDE_DRIVE_TASK_OUT */
1031 EXPORT_SYMBOL(ide_pre_handler_parser);
1033 /* Called by internal to feature out type of command being called */
1034 //ide_handler_t * ide_handler_parser (task_struct_t *taskfile, hob_struct_t *hobfile)
1035 ide_handler_t * ide_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
1037 switch(taskfile->command) {
1040 case CFA_TRANSLATE_SECTOR:
1041 case WIN_READ_BUFFER:
1043 // case WIN_READ_ONCE:
1045 return &task_in_intr;
1046 case WIN_SECURITY_DISABLE:
1047 case WIN_SECURITY_ERASE_UNIT:
1048 case WIN_SECURITY_SET_PASS:
1049 case WIN_SECURITY_UNLOCK:
1050 case WIN_DOWNLOAD_MICROCODE:
1051 case CFA_WRITE_SECT_WO_ERASE:
1052 case WIN_WRITE_BUFFER:
1053 case WIN_WRITE_VERIFY:
1055 // case WIN_WRITE_ONCE:
1057 return &task_out_intr;
1058 // case WIN_READ_LONG:
1059 // case WIN_READ_LONG_ONCE:
1061 case WIN_MULTREAD_EXT:
1062 return &task_mulin_intr;
1063 // case WIN_WRITE_LONG:
1064 // case WIN_WRITE_LONG_ONCE:
1065 case CFA_WRITE_MULTI_WO_ERASE:
1067 case WIN_MULTWRITE_EXT:
1068 return &task_mulout_intr;
1070 switch(taskfile->feature) {
1071 case SMART_READ_VALUES:
1072 case SMART_READ_THRESHOLDS:
1073 case SMART_READ_LOG_SECTOR:
1074 return &task_in_intr;
1075 case SMART_WRITE_LOG_SECTOR:
1076 return &task_out_intr;
1078 return &task_no_data_intr;
1080 case CFA_REQ_EXT_ERROR_CODE:
1081 case CFA_ERASE_SECTORS:
1083 // case WIN_VERIFY_ONCE:
1084 case WIN_VERIFY_EXT:
1086 return &task_no_data_intr;
1088 return &set_geometry_intr;
1090 // case WIN_RESTORE:
1094 case WIN_FLUSH_CACHE:
1095 case WIN_FLUSH_CACHE_EXT:
1096 case WIN_STANDBYNOW1:
1097 case WIN_STANDBYNOW2:
1101 case WIN_CHECKPOWERMODE1:
1102 case WIN_CHECKPOWERMODE2:
1103 case WIN_GETMEDIASTATUS:
1104 case WIN_MEDIAEJECT:
1105 return &task_no_data_intr;
1107 return &set_multmode_intr;
1108 case WIN_READ_NATIVE_MAX:
1110 case WIN_READ_NATIVE_MAX_EXT:
1111 case WIN_SET_MAX_EXT:
1112 case WIN_SECURITY_ERASE_PREPARE:
1113 case WIN_SECURITY_FREEZE_LOCK:
1115 case WIN_DOORUNLOCK:
1116 case WIN_SETFEATURES:
1117 return &task_no_data_intr;
1118 case DISABLE_SEAGATE:
1119 case EXABYTE_ENABLE_NEST:
1120 return &task_no_data_intr;
1122 // case WIN_READDMA_ONCE:
1123 case WIN_IDENTIFY_DMA:
1124 case WIN_READDMA_QUEUED:
1125 case WIN_READDMA_EXT:
1126 case WIN_READDMA_QUEUED_EXT:
1128 // case WIN_WRITEDMA_ONCE:
1129 case WIN_WRITEDMA_QUEUED:
1130 case WIN_WRITEDMA_EXT:
1131 case WIN_WRITEDMA_QUEUED_EXT:
1134 case WIN_DEVICE_RESET:
1135 case WIN_QUEUED_SERVICE:
1142 EXPORT_SYMBOL(ide_handler_parser);
1144 ide_post_handler_t * ide_post_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
1146 switch(taskfile->command) {
1147 case WIN_SPECIFY: /* set_geometry_intr */
1148 case WIN_RESTORE: /* recal_intr */
1149 case WIN_SETMULT: /* set_multmode_intr */
1155 EXPORT_SYMBOL(ide_post_handler_parser);
1157 /* Called by ioctl to feature out type of command being called */
1158 int ide_cmd_type_parser (ide_task_t *args)
1161 task_struct_t *taskfile = (task_struct_t *) args->tfRegister;
1162 hob_struct_t *hobfile = (hob_struct_t *) args->hobRegister;
1164 args->prehandler = ide_pre_handler_parser(taskfile, hobfile);
1165 args->handler = ide_handler_parser(taskfile, hobfile);
1166 args->posthandler = ide_post_handler_parser(taskfile, hobfile);
1168 switch(args->tfRegister[IDE_COMMAND_OFFSET]) {
1171 return IDE_DRIVE_TASK_IN;
1172 case CFA_TRANSLATE_SECTOR:
1174 // case WIN_READ_ONCE:
1176 case WIN_READ_BUFFER:
1177 return IDE_DRIVE_TASK_IN;
1179 // case WIN_WRITE_ONCE:
1181 case WIN_WRITE_VERIFY:
1182 case WIN_WRITE_BUFFER:
1183 case CFA_WRITE_SECT_WO_ERASE:
1184 case WIN_DOWNLOAD_MICROCODE:
1185 return IDE_DRIVE_TASK_RAW_WRITE;
1186 // case WIN_READ_LONG:
1187 // case WIN_READ_LONG_ONCE:
1189 case WIN_MULTREAD_EXT:
1190 return IDE_DRIVE_TASK_IN;
1191 // case WIN_WRITE_LONG:
1192 // case WIN_WRITE_LONG_ONCE:
1193 case CFA_WRITE_MULTI_WO_ERASE:
1195 case WIN_MULTWRITE_EXT:
1196 return IDE_DRIVE_TASK_RAW_WRITE;
1197 case WIN_SECURITY_DISABLE:
1198 case WIN_SECURITY_ERASE_UNIT:
1199 case WIN_SECURITY_SET_PASS:
1200 case WIN_SECURITY_UNLOCK:
1201 return IDE_DRIVE_TASK_OUT;
1203 args->tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS;
1204 args->tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS;
1205 switch(args->tfRegister[IDE_FEATURE_OFFSET]) {
1206 case SMART_READ_VALUES:
1207 case SMART_READ_THRESHOLDS:
1208 case SMART_READ_LOG_SECTOR:
1209 return IDE_DRIVE_TASK_IN;
1210 case SMART_WRITE_LOG_SECTOR:
1211 return IDE_DRIVE_TASK_OUT;
1213 return IDE_DRIVE_TASK_NO_DATA;
1216 // case WIN_READDMA_ONCE:
1217 case WIN_IDENTIFY_DMA:
1218 case WIN_READDMA_QUEUED:
1219 case WIN_READDMA_EXT:
1220 case WIN_READDMA_QUEUED_EXT:
1221 return IDE_DRIVE_TASK_IN;
1223 // case WIN_WRITEDMA_ONCE:
1224 case WIN_WRITEDMA_QUEUED:
1225 case WIN_WRITEDMA_EXT:
1226 case WIN_WRITEDMA_QUEUED_EXT:
1227 return IDE_DRIVE_TASK_RAW_WRITE;
1228 case WIN_SETFEATURES:
1229 switch(args->tfRegister[IDE_FEATURE_OFFSET]) {
1230 case SETFEATURES_EN_8BIT:
1231 case SETFEATURES_EN_WCACHE:
1232 return IDE_DRIVE_TASK_NO_DATA;
1233 case SETFEATURES_XFER:
1234 return IDE_DRIVE_TASK_SET_XFER;
1235 case SETFEATURES_DIS_DEFECT:
1236 case SETFEATURES_EN_APM:
1237 case SETFEATURES_DIS_MSN:
1238 case SETFEATURES_DIS_RETRY:
1239 case SETFEATURES_EN_AAM:
1240 case SETFEATURES_RW_LONG:
1241 case SETFEATURES_SET_CACHE:
1242 case SETFEATURES_DIS_RLA:
1243 case SETFEATURES_EN_RI:
1244 case SETFEATURES_EN_SI:
1245 case SETFEATURES_DIS_RPOD:
1246 case SETFEATURES_DIS_WCACHE:
1247 case SETFEATURES_EN_DEFECT:
1248 case SETFEATURES_DIS_APM:
1249 case SETFEATURES_EN_ECC:
1250 case SETFEATURES_EN_MSN:
1251 case SETFEATURES_EN_RETRY:
1252 case SETFEATURES_EN_RLA:
1253 case SETFEATURES_PREFETCH:
1254 case SETFEATURES_4B_RW_LONG:
1255 case SETFEATURES_DIS_AAM:
1256 case SETFEATURES_EN_RPOD:
1257 case SETFEATURES_DIS_RI:
1258 case SETFEATURES_DIS_SI:
1260 return IDE_DRIVE_TASK_NO_DATA;
1263 case CFA_REQ_EXT_ERROR_CODE:
1264 case CFA_ERASE_SECTORS:
1266 // case WIN_VERIFY_ONCE:
1267 case WIN_VERIFY_EXT:
1272 case WIN_FLUSH_CACHE:
1273 case WIN_FLUSH_CACHE_EXT:
1274 case WIN_STANDBYNOW1:
1275 case WIN_STANDBYNOW2:
1279 case DISABLE_SEAGATE:
1280 case WIN_CHECKPOWERMODE1:
1281 case WIN_CHECKPOWERMODE2:
1282 case WIN_GETMEDIASTATUS:
1283 case WIN_MEDIAEJECT:
1285 case WIN_READ_NATIVE_MAX:
1287 case WIN_READ_NATIVE_MAX_EXT:
1288 case WIN_SET_MAX_EXT:
1289 case WIN_SECURITY_ERASE_PREPARE:
1290 case WIN_SECURITY_FREEZE_LOCK:
1291 case EXABYTE_ENABLE_NEST:
1293 case WIN_DOORUNLOCK:
1294 return IDE_DRIVE_TASK_NO_DATA;
1297 case WIN_DEVICE_RESET:
1298 case WIN_QUEUED_SERVICE:
1301 return IDE_DRIVE_TASK_INVALID;
1305 EXPORT_SYMBOL(ide_cmd_type_parser);
1308 * This function is intended to be used prior to invoking ide_do_drive_cmd().
1310 void ide_init_drive_taskfile (struct request *rq)
1312 memset(rq, 0, sizeof(*rq));
1313 rq->flags = REQ_DRIVE_TASKFILE;
1316 EXPORT_SYMBOL(ide_init_drive_taskfile);
1318 int ide_diag_taskfile (ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf)
1322 ide_init_drive_taskfile(&rq);
1323 rq.flags = REQ_DRIVE_TASKFILE;
1327 * (ks) We transfer currently only whole sectors.
1328 * This is suffient for now. But, it would be great,
1329 * if we would find a solution to transfer any size.
1330 * To support special commands like READ LONG.
1332 if (args->command_type != IDE_DRIVE_TASK_NO_DATA) {
1334 rq.nr_sectors = (args->hobRegister[IDE_NSECTOR_OFFSET_HOB] << 8) | args->tfRegister[IDE_NSECTOR_OFFSET];
1336 rq.nr_sectors = data_size / SECTOR_SIZE;
1338 rq.hard_nr_sectors = rq.nr_sectors;
1339 rq.hard_cur_sectors = rq.current_nr_sectors = rq.nr_sectors;
1342 if (args->tf_out_flags.all == 0) {
1344 * clean up kernel settings for driver sanity, regardless.
1345 * except for discrete diag services.
1347 args->posthandler = ide_post_handler_parser(
1348 (struct hd_drive_task_hdr *) args->tfRegister,
1349 (struct hd_drive_hob_hdr *) args->hobRegister);
1353 return ide_do_drive_cmd(drive, &rq, ide_wait);
1356 EXPORT_SYMBOL(ide_diag_taskfile);
1358 int ide_raw_taskfile (ide_drive_t *drive, ide_task_t *args, u8 *buf)
1360 return ide_diag_taskfile(drive, args, 0, buf);
1363 EXPORT_SYMBOL(ide_raw_taskfile);
1365 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1366 char * ide_ioctl_verbose (unsigned int cmd)
1371 char * ide_task_cmd_verbose (u8 task)
1375 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1377 #define MAX_DMA (256*SECTOR_WORDS)
1379 ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
1380 ide_startstop_t flagged_task_no_data_intr(ide_drive_t *);
1381 ide_startstop_t flagged_task_in_intr(ide_drive_t *);
1382 ide_startstop_t flagged_task_mulin_intr(ide_drive_t *);
1383 ide_startstop_t flagged_pre_task_out_intr(ide_drive_t *, struct request *);
1384 ide_startstop_t flagged_task_out_intr(ide_drive_t *);
1385 ide_startstop_t flagged_pre_task_mulout_intr(ide_drive_t *, struct request *);
1386 ide_startstop_t flagged_task_mulout_intr(ide_drive_t *);
1388 int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1390 ide_task_request_t *req_task;
1394 task_ioreg_t *argsptr = args.tfRegister;
1395 task_ioreg_t *hobsptr = args.hobRegister;
1397 int tasksize = sizeof(struct ide_task_request_s);
1400 u8 io_32bit = drive->io_32bit;
1402 // printk("IDE Taskfile ...\n");
1404 req_task = kmalloc(tasksize, GFP_KERNEL);
1405 if (req_task == NULL) return -ENOMEM;
1406 memset(req_task, 0, tasksize);
1407 if (copy_from_user(req_task, (void *) arg, tasksize)) {
1412 taskout = (int) req_task->out_size;
1413 taskin = (int) req_task->in_size;
1416 int outtotal = tasksize;
1417 outbuf = kmalloc(taskout, GFP_KERNEL);
1418 if (outbuf == NULL) {
1422 memset(outbuf, 0, taskout);
1423 if (copy_from_user(outbuf, (void *)arg + outtotal, taskout)) {
1430 int intotal = tasksize + taskout;
1431 inbuf = kmalloc(taskin, GFP_KERNEL);
1432 if (inbuf == NULL) {
1436 memset(inbuf, 0, taskin);
1437 if (copy_from_user(inbuf, (void *)arg + intotal , taskin)) {
1443 memset(&args, 0, sizeof(ide_task_t));
1444 memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
1445 memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE);
1447 args.tf_in_flags = req_task->in_flags;
1448 args.tf_out_flags = req_task->out_flags;
1449 args.data_phase = req_task->data_phase;
1450 args.command_type = req_task->req_cmd;
1452 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1453 DTF("%s: ide_ioctl_cmd %s: ide_task_cmd %s\n",
1455 ide_ioctl_verbose(cmd),
1456 ide_task_cmd_verbose(args.tfRegister[IDE_COMMAND_OFFSET]));
1457 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1459 drive->io_32bit = 0;
1460 switch(req_task->data_phase) {
1461 case TASKFILE_OUT_DMAQ:
1462 case TASKFILE_OUT_DMA:
1463 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1465 case TASKFILE_IN_DMAQ:
1466 case TASKFILE_IN_DMA:
1467 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1469 case TASKFILE_IN_OUT:
1471 args.prehandler = &pre_task_out_intr;
1472 args.handler = &task_out_intr;
1473 args.posthandler = NULL;
1474 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1475 args.prehandler = NULL;
1476 args.handler = &task_in_intr;
1477 args.posthandler = NULL;
1478 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1484 case TASKFILE_MULTI_OUT:
1485 if (!drive->mult_count) {
1486 /* (hs): give up if multcount is not set */
1487 printk(KERN_ERR "%s: %s Multimode Write " \
1488 "multcount is not set\n",
1489 drive->name, __FUNCTION__);
1493 if (args.tf_out_flags.all != 0) {
1494 args.prehandler = &flagged_pre_task_mulout_intr;
1495 args.handler = &flagged_task_mulout_intr;
1497 args.prehandler = &pre_task_mulout_intr;
1498 args.handler = &task_mulout_intr;
1500 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1503 if (args.tf_out_flags.all != 0) {
1504 args.prehandler = &flagged_pre_task_out_intr;
1505 args.handler = &flagged_task_out_intr;
1507 args.prehandler = &pre_task_out_intr;
1508 args.handler = &task_out_intr;
1510 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1512 case TASKFILE_MULTI_IN:
1513 if (!drive->mult_count) {
1514 /* (hs): give up if multcount is not set */
1515 printk(KERN_ERR "%s: %s Multimode Read failure " \
1516 "multcount is not set\n",
1517 drive->name, __FUNCTION__);
1521 if (args.tf_out_flags.all != 0) {
1522 args.handler = &flagged_task_mulin_intr;
1524 args.handler = &task_mulin_intr;
1526 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1529 if (args.tf_out_flags.all != 0) {
1530 args.handler = &flagged_task_in_intr;
1532 args.handler = &task_in_intr;
1534 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1536 case TASKFILE_NO_DATA:
1537 if (args.tf_out_flags.all != 0) {
1538 args.handler = &flagged_task_no_data_intr;
1540 args.handler = &task_no_data_intr;
1542 err = ide_diag_taskfile(drive, &args, 0, NULL);
1549 memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE);
1550 memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE);
1551 req_task->in_flags = args.tf_in_flags;
1552 req_task->out_flags = args.tf_out_flags;
1554 if (copy_to_user((void *)arg, req_task, tasksize)) {
1559 int outtotal = tasksize;
1560 if (copy_to_user((void *)arg+outtotal, outbuf, taskout)) {
1566 int intotal = tasksize + taskout;
1567 if (copy_to_user((void *)arg+intotal, inbuf, taskin)) {
1579 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
1581 drive->io_32bit = io_32bit;
1586 EXPORT_SYMBOL(ide_taskfile_ioctl);
1588 int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1595 memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors);
1596 ide_init_drive_cmd(&rq);
1602 return ide_do_drive_cmd(drive, &rq, ide_wait);
1605 EXPORT_SYMBOL(ide_wait_cmd);
1608 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1610 int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1613 u8 args[4], *argbuf = args;
1618 if (NULL == (void *) arg) {
1620 ide_init_drive_cmd(&rq);
1621 return ide_do_drive_cmd(drive, &rq, ide_wait);
1624 if (copy_from_user(args, (void *)arg, 4))
1627 memset(&tfargs, 0, sizeof(ide_task_t));
1628 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
1629 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
1630 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
1631 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
1632 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
1633 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
1634 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
1637 argsize = 4 + (SECTOR_WORDS * 4 * args[3]);
1638 argbuf = kmalloc(argsize, GFP_KERNEL);
1641 memcpy(argbuf, args, 4);
1643 if (set_transfer(drive, &tfargs)) {
1644 xfer_rate = args[1];
1645 if (ide_ata66_check(drive, &tfargs))
1649 err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf);
1651 if (!err && xfer_rate) {
1652 /* active-retuning-calls future */
1653 ide_set_xfer_rate(drive, xfer_rate);
1654 ide_driveid_update(drive);
1657 if (copy_to_user((void *)arg, argbuf, argsize))
1664 EXPORT_SYMBOL(ide_cmd_ioctl);
1666 int ide_wait_cmd_task (ide_drive_t *drive, u8 *buf)
1670 ide_init_drive_cmd(&rq);
1671 rq.flags = REQ_DRIVE_TASK;
1673 return ide_do_drive_cmd(drive, &rq, ide_wait);
1676 EXPORT_SYMBOL(ide_wait_cmd_task);
1679 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1681 int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1684 u8 args[7], *argbuf = args;
1687 if (copy_from_user(args, (void *)arg, 7))
1689 err = ide_wait_cmd_task(drive, argbuf);
1690 if (copy_to_user((void *)arg, argbuf, argsize))
1695 EXPORT_SYMBOL(ide_task_ioctl);
1698 * NOTICE: This is additions from IBM to provide a discrete interface,
1699 * for selective taskregister access operations. Nice JOB Klaus!!!
1700 * Glad to be able to work and co-develop this with you and IBM.
1702 ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task)
1704 ide_hwif_t *hwif = HWIF(drive);
1705 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
1706 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
1712 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1713 void debug_taskfile(drive, task);
1714 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1717 * (ks) Check taskfile in/out flags.
1718 * If set, then execute as it is defined.
1719 * If not set, then define default settings.
1720 * The default values are:
1721 * write and read all taskfile registers (except data)
1722 * write and read the hob registers (sector,nsector,lcyl,hcyl)
1724 if (task->tf_out_flags.all == 0) {
1725 task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS;
1726 if (drive->addressing == 1)
1727 task->tf_out_flags.all |= (IDE_HOB_STD_OUT_FLAGS << 8);
1730 if (task->tf_in_flags.all == 0) {
1731 task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
1732 if (drive->addressing == 1)
1733 task->tf_in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
1736 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
1737 if (IDE_CONTROL_REG)
1739 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
1740 SELECT_MASK(drive, 0);
1743 status = hwif->INB(IDE_STATUS_REG);
1744 if (status & 0x80) {
1745 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status);
1747 status = hwif->INB(IDE_STATUS_REG);
1748 printk("flagged_taskfile -> Status = %02x\n", status);
1752 if (task->tf_out_flags.b.data) {
1753 u16 data = taskfile->data + (hobfile->data << 8);
1754 hwif->OUTW(data, IDE_DATA_REG);
1757 /* (ks) send hob registers first */
1758 if (task->tf_out_flags.b.nsector_hob)
1759 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
1760 if (task->tf_out_flags.b.sector_hob)
1761 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
1762 if (task->tf_out_flags.b.lcyl_hob)
1763 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
1764 if (task->tf_out_flags.b.hcyl_hob)
1765 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
1767 /* (ks) Send now the standard registers */
1768 if (task->tf_out_flags.b.error_feature)
1769 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
1770 /* refers to number of sectors to transfer */
1771 if (task->tf_out_flags.b.nsector)
1772 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
1773 /* refers to sector offset or start sector */
1774 if (task->tf_out_flags.b.sector)
1775 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
1776 if (task->tf_out_flags.b.lcyl)
1777 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
1778 if (task->tf_out_flags.b.hcyl)
1779 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
1782 * (ks) In the flagged taskfile approch, we will used all specified
1783 * registers and the register value will not be changed. Except the
1784 * select bit (master/slave) in the drive_head register. We must make
1785 * sure that the desired drive is selected.
1787 hwif->OUTB(taskfile->device_head | drive->select.all, IDE_SELECT_REG);
1788 switch(task->data_phase) {
1790 case TASKFILE_OUT_DMAQ:
1791 case TASKFILE_OUT_DMA:
1792 hwif->ide_dma_write(drive);
1795 case TASKFILE_IN_DMAQ:
1796 case TASKFILE_IN_DMA:
1797 hwif->ide_dma_read(drive);
1801 if (task->handler == NULL)
1804 /* Issue the command */
1805 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
1806 if (task->prehandler != NULL)
1807 return task->prehandler(drive, HWGROUP(drive)->rq);
1813 EXPORT_SYMBOL(flagged_taskfile);
1815 ide_startstop_t flagged_task_no_data_intr (ide_drive_t *drive)
1817 ide_hwif_t *hwif = HWIF(drive);
1822 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) {
1823 if (stat & ERR_STAT) {
1824 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr", stat);
1827 * (ks) Unexpected ATA data phase detected.
1828 * This should not happen. But, it can !
1829 * I am not sure, which function is best to clean up
1830 * this situation. I choose: ide_error(...)
1832 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr (unexpected phase)", stat);
1835 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
1841 * Handler for command with PIO data-in phase
1843 ide_startstop_t flagged_task_in_intr (ide_drive_t *drive)
1845 ide_hwif_t *hwif = HWIF(drive);
1846 u8 stat = hwif->INB(IDE_STATUS_REG);
1847 struct request *rq = HWGROUP(drive)->rq;
1851 if (rq->current_nr_sectors == 0)
1852 return DRIVER(drive)->error(drive, "flagged_task_in_intr (no data requested)", stat);
1854 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1855 if (stat & ERR_STAT) {
1856 return DRIVER(drive)->error(drive, "flagged_task_in_intr", stat);
1859 * (ks) Unexpected ATA data phase detected.
1860 * This should not happen. But, it can !
1861 * I am not sure, which function is best to clean up
1862 * this situation. I choose: ide_error(...)
1864 return DRIVER(drive)->error(drive, "flagged_task_in_intr (unexpected data phase)", stat);
1867 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1868 DTF("Read - rq->current_nr_sectors: %d, status: %02x\n", (int) rq->current_nr_sectors, stat);
1870 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
1872 if (--rq->current_nr_sectors != 0) {
1874 * (ks) We don't know which command was executed.
1875 * So, we wait the 'WORSTCASE' value.
1877 ide_set_handler(drive, &flagged_task_in_intr, WAIT_WORSTCASE, NULL);
1881 * (ks) Last sector was transfered, wait until drive is ready.
1882 * This can take up to 10 usec. We willl wait max 50 us.
1884 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
1886 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1891 ide_startstop_t flagged_task_mulin_intr (ide_drive_t *drive)
1893 ide_hwif_t *hwif = HWIF(drive);
1894 u8 stat = hwif->INB(IDE_STATUS_REG);
1895 struct request *rq = HWGROUP(drive)->rq;
1898 unsigned int msect, nsect;
1900 if (rq->current_nr_sectors == 0)
1901 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (no data requested)", stat);
1903 msect = drive->mult_count;
1905 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (multimode not set)", stat);
1907 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1908 if (stat & ERR_STAT) {
1909 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr", stat);
1912 * (ks) Unexpected ATA data phase detected.
1913 * This should not happen. But, it can !
1914 * I am not sure, which function is best to clean up
1915 * this situation. I choose: ide_error(...)
1917 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (unexpected data phase)", stat);
1920 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1921 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1923 DTF("Multiread: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1924 pBuf, nsect, rq->current_nr_sectors);
1926 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
1928 rq->current_nr_sectors -= nsect;
1929 if (rq->current_nr_sectors != 0) {
1931 * (ks) We don't know which command was executed.
1932 * So, we wait the 'WORSTCASE' value.
1934 ide_set_handler(drive, &flagged_task_mulin_intr, WAIT_WORSTCASE, NULL);
1939 * (ks) Last sector was transfered, wait until drive is ready.
1940 * This can take up to 10 usec. We willl wait max 50 us.
1942 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
1944 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1950 * Pre handler for command with PIO data-out phase
1952 ide_startstop_t flagged_pre_task_out_intr (ide_drive_t *drive, struct request *rq)
1954 ide_hwif_t *hwif = HWIF(drive);
1955 u8 stat = hwif->INB(IDE_STATUS_REG);
1956 ide_startstop_t startstop;
1958 if (!rq->current_nr_sectors) {
1959 return DRIVER(drive)->error(drive, "flagged_pre_task_out_intr (write data not specified)", stat);
1962 if (ide_wait_stat(&startstop, drive, DATA_READY,
1963 BAD_W_STAT, WAIT_DRQ)) {
1964 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
1968 taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
1969 --rq->current_nr_sectors;
1974 ide_startstop_t flagged_task_out_intr (ide_drive_t *drive)
1976 ide_hwif_t *hwif = HWIF(drive);
1977 u8 stat = hwif->INB(IDE_STATUS_REG);
1978 struct request *rq = HWGROUP(drive)->rq;
1981 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
1982 return DRIVER(drive)->error(drive, "flagged_task_out_intr", stat);
1984 if (!rq->current_nr_sectors) {
1985 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1989 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
1991 * (ks) Unexpected ATA data phase detected.
1992 * This should not happen. But, it can !
1993 * I am not sure, which function is best to clean up
1994 * this situation. I choose: ide_error(...)
1996 return DRIVER(drive)->error(drive, "flagged_task_out_intr (unexpected data phase)", stat);
1999 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2000 DTF("Write - rq->current_nr_sectors: %d, status: %02x\n",
2001 (int) rq->current_nr_sectors, stat);
2003 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
2004 --rq->current_nr_sectors;
2007 * (ks) We don't know which command was executed.
2008 * So, we wait the 'WORSTCASE' value.
2010 ide_set_handler(drive, &flagged_task_out_intr, WAIT_WORSTCASE, NULL);
2015 ide_startstop_t flagged_pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
2017 ide_hwif_t *hwif = HWIF(drive);
2018 u8 stat = hwif->INB(IDE_STATUS_REG);
2020 ide_startstop_t startstop;
2021 unsigned int msect, nsect;
2023 if (!rq->current_nr_sectors)
2024 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (write data not specified)", stat);
2026 msect = drive->mult_count;
2028 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (multimode not set)", stat);
2030 if (ide_wait_stat(&startstop, drive, DATA_READY,
2031 BAD_W_STAT, WAIT_DRQ)) {
2032 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
2036 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
2037 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2038 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
2039 pBuf, nsect, rq->current_nr_sectors);
2041 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
2043 rq->current_nr_sectors -= nsect;
2048 ide_startstop_t flagged_task_mulout_intr (ide_drive_t *drive)
2050 ide_hwif_t *hwif = HWIF(drive);
2051 u8 stat = hwif->INB(IDE_STATUS_REG);
2052 struct request *rq = HWGROUP(drive)->rq;
2054 unsigned int msect, nsect;
2056 msect = drive->mult_count;
2058 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (multimode not set)", stat);
2060 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
2061 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr", stat);
2063 if (!rq->current_nr_sectors) {
2064 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2068 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
2070 * (ks) Unexpected ATA data phase detected.
2071 * This should not happen. But, it can !
2072 * I am not sure, which function is best to clean up
2073 * this situation. I choose: ide_error(...)
2075 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (unexpected data phase)", stat);
2078 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
2079 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2080 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
2081 pBuf, nsect, rq->current_nr_sectors);
2083 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
2084 rq->current_nr_sectors -= nsect;
2087 * (ks) We don't know which command was executed.
2088 * So, we wait the 'WORSTCASE' value.
2090 ide_set_handler(drive, &flagged_task_mulout_intr, WAIT_WORSTCASE, NULL);