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_DRIVE_TASK_IN;
105 args.handler = &task_in_intr;
106 return ide_raw_taskfile(drive, &args, buf);
109 EXPORT_SYMBOL(taskfile_lib_get_identify);
111 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
112 void debug_taskfile (ide_drive_t *drive, ide_task_t *args)
114 printk(KERN_INFO "%s: ", drive->name);
115 // printk("TF.0=x%02x ", args->tfRegister[IDE_DATA_OFFSET]);
116 printk("TF.1=x%02x ", args->tfRegister[IDE_FEATURE_OFFSET]);
117 printk("TF.2=x%02x ", args->tfRegister[IDE_NSECTOR_OFFSET]);
118 printk("TF.3=x%02x ", args->tfRegister[IDE_SECTOR_OFFSET]);
119 printk("TF.4=x%02x ", args->tfRegister[IDE_LCYL_OFFSET]);
120 printk("TF.5=x%02x ", args->tfRegister[IDE_HCYL_OFFSET]);
121 printk("TF.6=x%02x ", args->tfRegister[IDE_SELECT_OFFSET]);
122 printk("TF.7=x%02x\n", args->tfRegister[IDE_COMMAND_OFFSET]);
123 printk(KERN_INFO "%s: ", drive->name);
124 // printk("HTF.0=x%02x ", args->hobRegister[IDE_DATA_OFFSET]);
125 printk("HTF.1=x%02x ", args->hobRegister[IDE_FEATURE_OFFSET]);
126 printk("HTF.2=x%02x ", args->hobRegister[IDE_NSECTOR_OFFSET]);
127 printk("HTF.3=x%02x ", args->hobRegister[IDE_SECTOR_OFFSET]);
128 printk("HTF.4=x%02x ", args->hobRegister[IDE_LCYL_OFFSET]);
129 printk("HTF.5=x%02x ", args->hobRegister[IDE_HCYL_OFFSET]);
130 printk("HTF.6=x%02x ", args->hobRegister[IDE_SELECT_OFFSET]);
131 printk("HTF.7=x%02x\n", args->hobRegister[IDE_CONTROL_OFFSET_HOB]);
133 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
135 ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
137 ide_hwif_t *hwif = HWIF(drive);
138 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
139 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
140 u8 HIHI = (drive->addressing == 1) ? 0xE0 : 0xEF;
142 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
143 void debug_taskfile(drive, task);
144 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
146 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
147 if (IDE_CONTROL_REG) {
149 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
151 SELECT_MASK(drive, 0);
153 if (drive->addressing == 1) {
154 hwif->OUTB(hobfile->feature, IDE_FEATURE_REG);
155 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
156 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
157 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
158 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
161 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
162 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
163 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
164 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
165 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
167 hwif->OUTB((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG);
168 #ifdef CONFIG_IDE_TASKFILE_IO
169 if (task->handler != NULL) {
170 if (task->prehandler != NULL) {
171 hwif->OUTBSYNC(drive, taskfile->command, IDE_COMMAND_REG);
172 ndelay(400); /* FIXME */
173 return task->prehandler(drive, task->rq);
175 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
179 if (task->handler != NULL) {
180 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
181 if (task->prehandler != NULL)
182 return task->prehandler(drive, task->rq);
187 if (!drive->using_dma)
190 switch (taskfile->command) {
191 case WIN_WRITEDMA_ONCE:
193 case WIN_WRITEDMA_EXT:
194 if (!hwif->ide_dma_write(drive))
197 case WIN_READDMA_ONCE:
199 case WIN_READDMA_EXT:
200 case WIN_IDENTIFY_DMA:
201 if (!hwif->ide_dma_read(drive))
204 #ifdef CONFIG_BLK_DEV_IDE_TCQ
205 case WIN_READDMA_QUEUED:
206 case WIN_READDMA_QUEUED_EXT:
207 return __ide_dma_queued_read(drive);
208 case WIN_WRITEDMA_QUEUED:
209 case WIN_WRITEDMA_QUEUED_EXT:
210 return __ide_dma_queued_write(drive);
213 if (task->handler == NULL)
220 EXPORT_SYMBOL(do_rw_taskfile);
223 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
225 ide_startstop_t set_multmode_intr (ide_drive_t *drive)
227 ide_hwif_t *hwif = HWIF(drive);
230 if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
231 drive->mult_count = drive->mult_req;
233 drive->mult_req = drive->mult_count = 0;
234 drive->special.b.recalibrate = 1;
235 (void) ide_dump_status(drive, "set_multmode", stat);
240 EXPORT_SYMBOL(set_multmode_intr);
243 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
245 ide_startstop_t set_geometry_intr (ide_drive_t *drive)
247 ide_hwif_t *hwif = HWIF(drive);
251 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
254 if (OK_STAT(stat, READY_STAT, BAD_STAT))
257 if (stat & (ERR_STAT|DRQ_STAT))
258 return DRIVER(drive)->error(drive, "set_geometry_intr", stat);
260 if (HWGROUP(drive)->handler != NULL)
262 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
266 EXPORT_SYMBOL(set_geometry_intr);
269 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
271 ide_startstop_t recal_intr (ide_drive_t *drive)
273 ide_hwif_t *hwif = HWIF(drive);
276 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT))
277 return DRIVER(drive)->error(drive, "recal_intr", stat);
281 EXPORT_SYMBOL(recal_intr);
284 * Handler for commands without a data phase
286 ide_startstop_t task_no_data_intr (ide_drive_t *drive)
288 ide_task_t *args = HWGROUP(drive)->rq->special;
289 ide_hwif_t *hwif = HWIF(drive);
293 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
294 DTF("%s: command opcode 0x%02x\n", drive->name,
295 args->tfRegister[IDE_COMMAND_OFFSET]);
296 return DRIVER(drive)->error(drive, "task_no_data_intr", stat);
297 /* calls ide_end_drive_cmd */
300 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
305 EXPORT_SYMBOL(task_no_data_intr);
308 * old taskfile PIO handlers, to be killed as soon as possible.
310 #ifndef CONFIG_IDE_TASKFILE_IO
312 #define task_map_rq(rq, flags) ide_map_buffer((rq), (flags))
313 #define task_unmap_rq(rq, buf, flags) ide_unmap_buffer((rq), (buf), (flags))
316 * Handler for command with PIO data-in phase, READ
319 * FIXME before 2.4 enable ...
320 * DATA integrity issue upon error. <andre@linux-ide.org>
322 ide_startstop_t task_in_intr (ide_drive_t *drive)
324 struct request *rq = HWGROUP(drive)->rq;
325 ide_hwif_t *hwif = HWIF(drive);
330 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
331 if (stat & (ERR_STAT|DRQ_STAT)) {
333 DTF("%s: attempting to recover last " \
334 "sector counter status=0x%02x\n",
337 * Expect a BUG BOMB if we attempt to rewind the
338 * offset in the BH aka PAGE in the current BLOCK
339 * segment. This is different than the HOST segment.
343 rq->current_nr_sectors++;
344 return DRIVER(drive)->error(drive, "task_in_intr", stat);
346 if (!(stat & BUSY_STAT)) {
347 DTF("task_in_intr to Soon wait for next interrupt\n");
348 if (HWGROUP(drive)->handler == NULL)
349 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
356 * Holding point for a brain dump of a thought :-/
359 if (!OK_STAT(stat,DRIVE_READY,drive->bad_wstat)) {
360 DTF("%s: READ attempting to recover last " \
361 "sector counter status=0x%02x\n",
363 rq->current_nr_sectors++;
364 return DRIVER(drive)->error(drive, "task_in_intr", stat);
366 if (!rq->current_nr_sectors)
367 if (!DRIVER(drive)->end_request(drive, 1, 0))
370 if (--rq->current_nr_sectors <= 0)
371 if (!DRIVER(drive)->end_request(drive, 1, 0))
375 pBuf = task_map_rq(rq, &flags);
376 DTF("Read: %p, rq->current_nr_sectors: %d, stat: %02x\n",
377 pBuf, (int) rq->current_nr_sectors, stat);
378 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
379 task_unmap_rq(rq, pBuf, &flags);
381 * FIXME :: We really can not legally get a new page/bh
382 * regardless, if this is the end of our segment.
383 * BH walking or segment can only be updated after we have a good
384 * hwif->INB(IDE_STATUS_REG); return.
386 if (--rq->current_nr_sectors <= 0)
387 if (!DRIVER(drive)->end_request(drive, 1, 0))
390 * ERM, it is techincally legal to leave/exit here but it makes
391 * a mess of the code ...
393 if (HWGROUP(drive)->handler == NULL)
394 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
398 EXPORT_SYMBOL(task_in_intr);
401 * Handler for command with Read Multiple
403 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
405 ide_hwif_t *hwif = HWIF(drive);
406 struct request *rq = HWGROUP(drive)->rq;
408 unsigned int msect = drive->mult_count;
413 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
414 if (stat & (ERR_STAT|DRQ_STAT)) {
416 rq->current_nr_sectors += drive->mult_count;
418 * NOTE: could rewind beyond beginning :-/
421 printk(KERN_ERR "%s: MULTI-READ assume all data " \
422 "transfered is bad status=0x%02x\n",
425 return DRIVER(drive)->error(drive, "task_mulin_intr", stat);
427 /* no data yet, so wait for another interrupt */
428 if (HWGROUP(drive)->handler == NULL)
429 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
434 nsect = rq->current_nr_sectors;
437 pBuf = task_map_rq(rq, &flags);
438 DTF("Multiread: %p, nsect: %d, msect: %d, " \
439 " rq->current_nr_sectors: %d\n",
440 pBuf, nsect, msect, rq->current_nr_sectors);
441 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
442 task_unmap_rq(rq, pBuf, &flags);
444 rq->current_nr_sectors -= nsect;
447 * FIXME :: We really can not legally get a new page/bh
448 * regardless, if this is the end of our segment.
449 * BH walking or segment can only be updated after we have a
450 * good hwif->INB(IDE_STATUS_REG); return.
452 if (!rq->current_nr_sectors) {
453 if (!DRIVER(drive)->end_request(drive, 1, 0))
457 if (HWGROUP(drive)->handler == NULL)
458 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
462 EXPORT_SYMBOL(task_mulin_intr);
465 * VERIFY ME before 2.4 ... unexpected race is possible based on details
466 * RMK with 74LS245/373/374 TTL buffer logic because of passthrough.
468 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
472 ide_startstop_t startstop;
474 if (ide_wait_stat(&startstop, drive, DATA_READY,
475 drive->bad_wstat, WAIT_DRQ)) {
476 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
478 drive->addressing ? "_EXT" : "");
481 /* For Write_sectors we need to stuff the first sector */
482 pBuf = task_map_rq(rq, &flags);
483 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
484 rq->current_nr_sectors--;
485 task_unmap_rq(rq, pBuf, &flags);
489 EXPORT_SYMBOL(pre_task_out_intr);
492 * Handler for command with PIO data-out phase WRITE
494 * WOOHOO this is a CORRECT STATE DIAGRAM NOW, <andre@linux-ide.org>
496 ide_startstop_t task_out_intr (ide_drive_t *drive)
498 ide_hwif_t *hwif = HWIF(drive);
499 struct request *rq = HWGROUP(drive)->rq;
504 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), DRIVE_READY, drive->bad_wstat)) {
505 DTF("%s: WRITE attempting to recover last " \
506 "sector counter status=0x%02x\n",
508 rq->current_nr_sectors++;
509 return DRIVER(drive)->error(drive, "task_out_intr", stat);
512 * Safe to update request for partial completions.
513 * We have a good STATUS CHECK!!!
515 if (!rq->current_nr_sectors)
516 if (!DRIVER(drive)->end_request(drive, 1, 0))
518 if ((rq->current_nr_sectors==1) ^ (stat & DRQ_STAT)) {
519 rq = HWGROUP(drive)->rq;
520 pBuf = task_map_rq(rq, &flags);
521 DTF("write: %p, rq->current_nr_sectors: %d\n",
522 pBuf, (int) rq->current_nr_sectors);
523 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
524 task_unmap_rq(rq, pBuf, &flags);
526 rq->current_nr_sectors--;
528 if (HWGROUP(drive)->handler == NULL)
529 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
533 EXPORT_SYMBOL(task_out_intr);
535 #undef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
537 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
539 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
540 ide_hwif_t *hwif = HWIF(drive);
542 unsigned int nsect = 0, msect = drive->mult_count;
545 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
547 ide_task_t *args = rq->special;
548 ide_startstop_t startstop;
552 * assign private copy for multi-write
554 memcpy(&HWGROUP(drive)->wrq, rq, sizeof(struct request));
557 if (ide_wait_stat(&startstop, drive, DATA_READY,
558 drive->bad_wstat, WAIT_DRQ)) {
559 printk(KERN_ERR "%s: no DRQ after issuing %s\n",
561 drive->addressing ? "MULTWRITE_EXT" : "MULTWRITE");
564 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
567 nsect = rq->current_nr_sectors;
570 pBuf = task_map_rq(rq, &flags);
571 DTF("Pre-Multiwrite: %p, nsect: %d, msect: %d, " \
572 "rq->current_nr_sectors: %ld\n",
573 pBuf, nsect, msect, rq->current_nr_sectors);
575 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
576 task_unmap_rq(rq, pBuf, &flags);
577 rq->current_nr_sectors -= nsect;
578 if (!rq->current_nr_sectors) {
579 if (!DRIVER(drive)->end_request(drive, 1, 0))
581 stat = hwif->INB(IDE_STATUS_REG);
588 #else /* ! ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
589 if (!(drive_is_ready(drive))) {
591 for (i=0; i<100; i++) {
592 if (drive_is_ready(drive))
598 * WARNING :: if the drive as not acked good status we may not
599 * move the DATA-TRANSFER T-Bar as BSY != 0. <andre@linux-ide.org>
601 return args->handler(drive);
602 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
605 EXPORT_SYMBOL(pre_task_mulout_intr);
608 * FIXME before enabling in 2.4 ... DATA integrity issue upon error.
611 * Handler for command write multiple
612 * Called directly from execute_drive_cmd for the first bunch of sectors,
613 * afterwards only by the ISR
615 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
617 ide_hwif_t *hwif = HWIF(drive);
618 u8 stat = hwif->INB(IDE_STATUS_REG);
619 struct request *rq = HWGROUP(drive)->rq;
621 ide_startstop_t startstop = ide_stopped;
622 unsigned int msect = drive->mult_count;
627 * (ks/hs): Handle last IRQ on multi-sector transfer,
628 * occurs after all data was sent in this chunk
630 if (rq->current_nr_sectors == 0) {
631 if (stat & (ERR_STAT|DRQ_STAT)) {
633 rq->current_nr_sectors += drive->mult_count;
635 * NOTE: could rewind beyond beginning :-/
638 printk(KERN_ERR "%s: MULTI-WRITE assume all data " \
639 "transfered is bad status=0x%02x\n",
642 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
645 DRIVER(drive)->end_request(drive, 1, 0);
649 * DON'T be lazy code the above and below togather !!!
651 if (!OK_STAT(stat,DATA_READY,BAD_R_STAT)) {
652 if (stat & (ERR_STAT|DRQ_STAT)) {
654 rq->current_nr_sectors += drive->mult_count;
656 * NOTE: could rewind beyond beginning :-/
659 printk("%s: MULTI-WRITE assume all data " \
660 "transfered is bad status=0x%02x\n",
663 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
665 /* no data yet, so wait for another interrupt */
666 if (HWGROUP(drive)->handler == NULL)
667 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
671 #ifndef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
672 if (HWGROUP(drive)->handler != NULL) {
673 unsigned long lflags;
674 spin_lock_irqsave(&ide_lock, lflags);
675 HWGROUP(drive)->handler = NULL;
676 del_timer(&HWGROUP(drive)->timer);
677 spin_unlock_irqrestore(&ide_lock, lflags);
679 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
682 nsect = rq->current_nr_sectors;
685 pBuf = task_map_rq(rq, &flags);
686 DTF("Multiwrite: %p, nsect: %d, msect: %d, " \
687 "rq->current_nr_sectors: %ld\n",
688 pBuf, nsect, msect, rq->current_nr_sectors);
690 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
691 task_unmap_rq(rq, pBuf, &flags);
692 rq->current_nr_sectors -= nsect;
694 * FIXME :: We really can not legally get a new page/bh
695 * regardless, if this is the end of our segment.
696 * BH walking or segment can only be updated after we
697 * have a good hwif->INB(IDE_STATUS_REG); return.
699 if (!rq->current_nr_sectors) {
700 if (!DRIVER(drive)->end_request(drive, 1, 0))
706 if (HWGROUP(drive)->handler == NULL)
707 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
711 EXPORT_SYMBOL(task_mulout_intr);
713 #else /* !CONFIG_IDE_TASKFILE_IO */
715 static u8 wait_drive_not_busy(ide_drive_t *drive)
717 ide_hwif_t *hwif = HWIF(drive);
722 * Last sector was transfered, wait until drive is ready.
723 * This can take up to 10 usec, but we will wait max 1 ms
724 * (drive_cmd_intr() waits that long).
726 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
730 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
736 * Handler for command with PIO data-in phase (Read).
738 ide_startstop_t task_in_intr (ide_drive_t *drive)
740 struct request *rq = HWGROUP(drive)->rq;
743 good_stat = DATA_READY;
744 stat = HWIF(drive)->INB(IDE_STATUS_REG);
746 if (!OK_STAT(stat, good_stat, BAD_R_STAT)) {
747 if (stat & (ERR_STAT | DRQ_STAT))
748 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
749 /* BUSY_STAT: No data yet, so wait for another IRQ. */
750 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
755 * Complete previously submitted bios (if any).
756 * Status was already verifyied.
758 while (rq->bio != rq->cbio)
759 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
761 /* Complete rq->buffer based request (ioctls). */
762 if (!rq->bio && !rq->nr_sectors) {
763 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
768 task_sectors(drive, rq, 1, IDE_PIO_IN);
770 /* If it was the last datablock check status and finish transfer. */
771 if (!rq->nr_sectors) {
773 stat = wait_drive_not_busy(drive);
777 /* Still data left to transfer. */
778 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
782 EXPORT_SYMBOL(task_in_intr);
785 * Handler for command with PIO data-in phase (Read Multiple).
787 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
789 struct request *rq = HWGROUP(drive)->rq;
790 unsigned int msect = drive->mult_count;
794 good_stat = DATA_READY;
795 stat = HWIF(drive)->INB(IDE_STATUS_REG);
797 if (!OK_STAT(stat, good_stat, BAD_R_STAT)) {
798 if (stat & (ERR_STAT | DRQ_STAT))
799 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
800 /* BUSY_STAT: No data yet, so wait for another IRQ. */
801 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
806 * Complete previously submitted bios (if any).
807 * Status was already verifyied.
809 while (rq->bio != rq->cbio)
810 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
812 /* Complete rq->buffer based request (ioctls). */
813 if (!rq->bio && !rq->nr_sectors) {
814 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
820 nsect = rq->current_nr_sectors;
824 task_sectors(drive, rq, nsect, IDE_PIO_IN);
832 /* If it was the last datablock check status and finish transfer. */
833 if (!rq->nr_sectors) {
835 stat = wait_drive_not_busy(drive);
839 /* Still data left to transfer. */
840 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
844 EXPORT_SYMBOL(task_mulin_intr);
847 * Handler for command with PIO data-out phase (Write).
849 ide_startstop_t task_out_intr (ide_drive_t *drive)
851 struct request *rq = HWGROUP(drive)->rq;
854 stat = HWIF(drive)->INB(IDE_STATUS_REG);
855 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) {
856 if ((stat & (ERR_STAT | DRQ_STAT)) ||
857 ((stat & WRERR_STAT) && !drive->nowerr))
858 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
859 if (stat & BUSY_STAT) {
860 /* Not ready yet, so wait for another IRQ. */
861 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
866 /* Deal with unexpected ATA data phase. */
867 if ((!(stat & DATA_READY) && rq->nr_sectors) ||
868 ((stat & DATA_READY) && !rq->nr_sectors))
869 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
872 * Complete previously submitted bios (if any).
873 * Status was already verifyied.
875 while (rq->bio != rq->cbio)
876 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
878 /* Complete rq->buffer based request (ioctls). */
879 if (!rq->bio && !rq->nr_sectors) {
880 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
884 /* Still data left to transfer. */
885 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
888 task_sectors(drive, rq, 1, IDE_PIO_OUT);
893 EXPORT_SYMBOL(task_out_intr);
895 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
897 ide_startstop_t startstop;
899 if (ide_wait_stat(&startstop, drive, DATA_READY,
900 drive->bad_wstat, WAIT_DRQ)) {
901 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
902 drive->name, drive->addressing ? "_EXT" : "");
909 return task_out_intr(drive);
911 EXPORT_SYMBOL(pre_task_out_intr);
914 * Handler for command with PIO data-out phase (Write Multiple).
916 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
918 struct request *rq = HWGROUP(drive)->rq;
919 unsigned int msect = drive->mult_count;
923 stat = HWIF(drive)->INB(IDE_STATUS_REG);
924 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) {
925 if ((stat & (ERR_STAT | DRQ_STAT)) ||
926 ((stat & WRERR_STAT) && !drive->nowerr))
927 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
928 if (stat & BUSY_STAT) {
929 /* Not ready yet, so wait for another IRQ. */
930 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
935 /* Deal with unexpected ATA data phase. */
936 if ((!(stat & DATA_READY) && rq->nr_sectors) ||
937 ((stat & DATA_READY) && !rq->nr_sectors))
938 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
941 * Complete previously submitted bios (if any).
942 * Status was already verifyied.
944 while (rq->bio != rq->cbio)
945 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
947 /* Complete rq->buffer based request (ioctls). */
948 if (!rq->bio && !rq->nr_sectors) {
949 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
953 /* Still data left to transfer. */
954 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
958 nsect = rq->current_nr_sectors;
962 task_sectors(drive, rq, nsect, IDE_PIO_OUT);
972 EXPORT_SYMBOL(task_mulout_intr);
974 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
976 ide_startstop_t startstop;
978 if (ide_wait_stat(&startstop, drive, DATA_READY,
979 drive->bad_wstat, WAIT_DRQ)) {
980 printk(KERN_ERR "%s: no DRQ after issuing MULTWRITE%s\n",
981 drive->name, drive->addressing ? "_EXT" : "");
988 return task_mulout_intr(drive);
990 EXPORT_SYMBOL(pre_task_mulout_intr);
992 #endif /* !CONFIG_IDE_TASKFILE_IO */
994 int ide_diag_taskfile (ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf)
998 memset(&rq, 0, sizeof(rq));
999 rq.flags = REQ_DRIVE_TASKFILE;
1003 * (ks) We transfer currently only whole sectors.
1004 * This is suffient for now. But, it would be great,
1005 * if we would find a solution to transfer any size.
1006 * To support special commands like READ LONG.
1008 if (args->command_type != IDE_DRIVE_TASK_NO_DATA) {
1010 rq.nr_sectors = (args->hobRegister[IDE_NSECTOR_OFFSET] << 8) | args->tfRegister[IDE_NSECTOR_OFFSET];
1012 rq.nr_sectors = data_size / SECTOR_SIZE;
1014 rq.hard_nr_sectors = rq.nr_sectors;
1015 rq.hard_cur_sectors = rq.current_nr_sectors = rq.nr_sectors;
1019 return ide_do_drive_cmd(drive, &rq, ide_wait);
1022 EXPORT_SYMBOL(ide_diag_taskfile);
1024 int ide_raw_taskfile (ide_drive_t *drive, ide_task_t *args, u8 *buf)
1026 return ide_diag_taskfile(drive, args, 0, buf);
1029 EXPORT_SYMBOL(ide_raw_taskfile);
1031 #define MAX_DMA (256*SECTOR_WORDS)
1033 ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
1034 ide_startstop_t flagged_task_no_data_intr(ide_drive_t *);
1035 ide_startstop_t flagged_task_in_intr(ide_drive_t *);
1036 ide_startstop_t flagged_task_mulin_intr(ide_drive_t *);
1037 ide_startstop_t flagged_pre_task_out_intr(ide_drive_t *, struct request *);
1038 ide_startstop_t flagged_task_out_intr(ide_drive_t *);
1039 ide_startstop_t flagged_pre_task_mulout_intr(ide_drive_t *, struct request *);
1040 ide_startstop_t flagged_task_mulout_intr(ide_drive_t *);
1042 int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1044 ide_task_request_t *req_task;
1048 task_ioreg_t *argsptr = args.tfRegister;
1049 task_ioreg_t *hobsptr = args.hobRegister;
1051 int tasksize = sizeof(struct ide_task_request_s);
1054 u8 io_32bit = drive->io_32bit;
1055 char __user *buf = (char __user *)arg;
1057 // printk("IDE Taskfile ...\n");
1059 req_task = kmalloc(tasksize, GFP_KERNEL);
1060 if (req_task == NULL) return -ENOMEM;
1061 memset(req_task, 0, tasksize);
1062 if (copy_from_user(req_task, buf, tasksize)) {
1067 taskout = (int) req_task->out_size;
1068 taskin = (int) req_task->in_size;
1071 int outtotal = tasksize;
1072 outbuf = kmalloc(taskout, GFP_KERNEL);
1073 if (outbuf == NULL) {
1077 memset(outbuf, 0, taskout);
1078 if (copy_from_user(outbuf, buf + outtotal, taskout)) {
1085 int intotal = tasksize + taskout;
1086 inbuf = kmalloc(taskin, GFP_KERNEL);
1087 if (inbuf == NULL) {
1091 memset(inbuf, 0, taskin);
1092 if (copy_from_user(inbuf, buf + intotal, taskin)) {
1098 memset(&args, 0, sizeof(ide_task_t));
1099 memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
1100 memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE);
1102 args.tf_in_flags = req_task->in_flags;
1103 args.tf_out_flags = req_task->out_flags;
1104 args.data_phase = req_task->data_phase;
1105 args.command_type = req_task->req_cmd;
1107 drive->io_32bit = 0;
1108 switch(req_task->data_phase) {
1109 case TASKFILE_OUT_DMAQ:
1110 case TASKFILE_OUT_DMA:
1111 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1113 case TASKFILE_IN_DMAQ:
1114 case TASKFILE_IN_DMA:
1115 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1117 case TASKFILE_IN_OUT:
1119 args.prehandler = &pre_task_out_intr;
1120 args.handler = &task_out_intr;
1121 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1122 args.prehandler = NULL;
1123 args.handler = &task_in_intr;
1124 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1130 case TASKFILE_MULTI_OUT:
1131 if (!drive->mult_count) {
1132 /* (hs): give up if multcount is not set */
1133 printk(KERN_ERR "%s: %s Multimode Write " \
1134 "multcount is not set\n",
1135 drive->name, __FUNCTION__);
1139 if (args.tf_out_flags.all != 0) {
1140 args.prehandler = &flagged_pre_task_mulout_intr;
1141 args.handler = &flagged_task_mulout_intr;
1143 args.prehandler = &pre_task_mulout_intr;
1144 args.handler = &task_mulout_intr;
1146 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1149 if (args.tf_out_flags.all != 0) {
1150 args.prehandler = &flagged_pre_task_out_intr;
1151 args.handler = &flagged_task_out_intr;
1153 args.prehandler = &pre_task_out_intr;
1154 args.handler = &task_out_intr;
1156 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1158 case TASKFILE_MULTI_IN:
1159 if (!drive->mult_count) {
1160 /* (hs): give up if multcount is not set */
1161 printk(KERN_ERR "%s: %s Multimode Read failure " \
1162 "multcount is not set\n",
1163 drive->name, __FUNCTION__);
1167 if (args.tf_out_flags.all != 0) {
1168 args.handler = &flagged_task_mulin_intr;
1170 args.handler = &task_mulin_intr;
1172 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1175 if (args.tf_out_flags.all != 0) {
1176 args.handler = &flagged_task_in_intr;
1178 args.handler = &task_in_intr;
1180 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1182 case TASKFILE_NO_DATA:
1183 if (args.tf_out_flags.all != 0) {
1184 args.handler = &flagged_task_no_data_intr;
1186 args.handler = &task_no_data_intr;
1188 err = ide_diag_taskfile(drive, &args, 0, NULL);
1195 memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE);
1196 memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE);
1197 req_task->in_flags = args.tf_in_flags;
1198 req_task->out_flags = args.tf_out_flags;
1200 if (copy_to_user(buf, req_task, tasksize)) {
1205 int outtotal = tasksize;
1206 if (copy_to_user(buf + outtotal, outbuf, taskout)) {
1212 int intotal = tasksize + taskout;
1213 if (copy_to_user(buf + intotal, inbuf, taskin)) {
1225 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
1227 drive->io_32bit = io_32bit;
1232 EXPORT_SYMBOL(ide_taskfile_ioctl);
1234 int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1241 memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors);
1242 ide_init_drive_cmd(&rq);
1248 return ide_do_drive_cmd(drive, &rq, ide_wait);
1251 EXPORT_SYMBOL(ide_wait_cmd);
1254 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1256 int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1259 u8 args[4], *argbuf = args;
1264 if (NULL == (void *) arg) {
1266 ide_init_drive_cmd(&rq);
1267 return ide_do_drive_cmd(drive, &rq, ide_wait);
1270 if (copy_from_user(args, (void __user *)arg, 4))
1273 memset(&tfargs, 0, sizeof(ide_task_t));
1274 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
1275 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
1276 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
1277 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
1278 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
1279 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
1280 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
1283 argsize = 4 + (SECTOR_WORDS * 4 * args[3]);
1284 argbuf = kmalloc(argsize, GFP_KERNEL);
1287 memcpy(argbuf, args, 4);
1289 if (set_transfer(drive, &tfargs)) {
1290 xfer_rate = args[1];
1291 if (ide_ata66_check(drive, &tfargs))
1295 err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf);
1297 if (!err && xfer_rate) {
1298 /* active-retuning-calls future */
1299 ide_set_xfer_rate(drive, xfer_rate);
1300 ide_driveid_update(drive);
1303 if (copy_to_user((void __user *)arg, argbuf, argsize))
1310 EXPORT_SYMBOL(ide_cmd_ioctl);
1312 int ide_wait_cmd_task (ide_drive_t *drive, u8 *buf)
1316 ide_init_drive_cmd(&rq);
1317 rq.flags = REQ_DRIVE_TASK;
1319 return ide_do_drive_cmd(drive, &rq, ide_wait);
1322 EXPORT_SYMBOL(ide_wait_cmd_task);
1325 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1327 int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1329 void __user *p = (void __user *)arg;
1331 u8 args[7], *argbuf = args;
1334 if (copy_from_user(args, p, 7))
1336 err = ide_wait_cmd_task(drive, argbuf);
1337 if (copy_to_user(p, argbuf, argsize))
1342 EXPORT_SYMBOL(ide_task_ioctl);
1345 * NOTICE: This is additions from IBM to provide a discrete interface,
1346 * for selective taskregister access operations. Nice JOB Klaus!!!
1347 * Glad to be able to work and co-develop this with you and IBM.
1349 ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task)
1351 ide_hwif_t *hwif = HWIF(drive);
1352 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
1353 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
1359 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1360 void debug_taskfile(drive, task);
1361 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1364 * (ks) Check taskfile in/out flags.
1365 * If set, then execute as it is defined.
1366 * If not set, then define default settings.
1367 * The default values are:
1368 * write and read all taskfile registers (except data)
1369 * write and read the hob registers (sector,nsector,lcyl,hcyl)
1371 if (task->tf_out_flags.all == 0) {
1372 task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS;
1373 if (drive->addressing == 1)
1374 task->tf_out_flags.all |= (IDE_HOB_STD_OUT_FLAGS << 8);
1377 if (task->tf_in_flags.all == 0) {
1378 task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
1379 if (drive->addressing == 1)
1380 task->tf_in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
1383 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
1384 if (IDE_CONTROL_REG)
1386 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
1387 SELECT_MASK(drive, 0);
1390 status = hwif->INB(IDE_STATUS_REG);
1391 if (status & 0x80) {
1392 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status);
1394 status = hwif->INB(IDE_STATUS_REG);
1395 printk("flagged_taskfile -> Status = %02x\n", status);
1399 if (task->tf_out_flags.b.data) {
1400 u16 data = taskfile->data + (hobfile->data << 8);
1401 hwif->OUTW(data, IDE_DATA_REG);
1404 /* (ks) send hob registers first */
1405 if (task->tf_out_flags.b.nsector_hob)
1406 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
1407 if (task->tf_out_flags.b.sector_hob)
1408 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
1409 if (task->tf_out_flags.b.lcyl_hob)
1410 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
1411 if (task->tf_out_flags.b.hcyl_hob)
1412 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
1414 /* (ks) Send now the standard registers */
1415 if (task->tf_out_flags.b.error_feature)
1416 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
1417 /* refers to number of sectors to transfer */
1418 if (task->tf_out_flags.b.nsector)
1419 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
1420 /* refers to sector offset or start sector */
1421 if (task->tf_out_flags.b.sector)
1422 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
1423 if (task->tf_out_flags.b.lcyl)
1424 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
1425 if (task->tf_out_flags.b.hcyl)
1426 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
1429 * (ks) In the flagged taskfile approch, we will used all specified
1430 * registers and the register value will not be changed. Except the
1431 * select bit (master/slave) in the drive_head register. We must make
1432 * sure that the desired drive is selected.
1434 hwif->OUTB(taskfile->device_head | drive->select.all, IDE_SELECT_REG);
1435 switch(task->data_phase) {
1437 case TASKFILE_OUT_DMAQ:
1438 case TASKFILE_OUT_DMA:
1439 hwif->ide_dma_write(drive);
1442 case TASKFILE_IN_DMAQ:
1443 case TASKFILE_IN_DMA:
1444 hwif->ide_dma_read(drive);
1448 if (task->handler == NULL)
1451 /* Issue the command */
1452 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
1453 if (task->prehandler != NULL)
1454 return task->prehandler(drive, HWGROUP(drive)->rq);
1460 EXPORT_SYMBOL(flagged_taskfile);
1462 ide_startstop_t flagged_task_no_data_intr (ide_drive_t *drive)
1464 ide_hwif_t *hwif = HWIF(drive);
1469 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) {
1470 if (stat & ERR_STAT) {
1471 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr", stat);
1474 * (ks) Unexpected ATA data phase detected.
1475 * This should not happen. But, it can !
1476 * I am not sure, which function is best to clean up
1477 * this situation. I choose: ide_error(...)
1479 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr (unexpected phase)", stat);
1482 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
1488 * Handler for command with PIO data-in phase
1490 ide_startstop_t flagged_task_in_intr (ide_drive_t *drive)
1492 ide_hwif_t *hwif = HWIF(drive);
1493 u8 stat = hwif->INB(IDE_STATUS_REG);
1494 struct request *rq = HWGROUP(drive)->rq;
1498 if (rq->current_nr_sectors == 0)
1499 return DRIVER(drive)->error(drive, "flagged_task_in_intr (no data requested)", stat);
1501 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1502 if (stat & ERR_STAT) {
1503 return DRIVER(drive)->error(drive, "flagged_task_in_intr", stat);
1506 * (ks) Unexpected ATA data phase detected.
1507 * This should not happen. But, it can !
1508 * I am not sure, which function is best to clean up
1509 * this situation. I choose: ide_error(...)
1511 return DRIVER(drive)->error(drive, "flagged_task_in_intr (unexpected data phase)", stat);
1514 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1515 DTF("Read - rq->current_nr_sectors: %d, status: %02x\n", (int) rq->current_nr_sectors, stat);
1517 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
1519 if (--rq->current_nr_sectors != 0) {
1521 * (ks) We don't know which command was executed.
1522 * So, we wait the 'WORSTCASE' value.
1524 ide_set_handler(drive, &flagged_task_in_intr, WAIT_WORSTCASE, NULL);
1528 * (ks) Last sector was transfered, wait until drive is ready.
1529 * This can take up to 10 usec. We willl wait max 50 us.
1531 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
1533 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1538 ide_startstop_t flagged_task_mulin_intr (ide_drive_t *drive)
1540 ide_hwif_t *hwif = HWIF(drive);
1541 u8 stat = hwif->INB(IDE_STATUS_REG);
1542 struct request *rq = HWGROUP(drive)->rq;
1545 unsigned int msect, nsect;
1547 if (rq->current_nr_sectors == 0)
1548 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (no data requested)", stat);
1550 msect = drive->mult_count;
1552 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (multimode not set)", stat);
1554 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1555 if (stat & ERR_STAT) {
1556 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr", stat);
1559 * (ks) Unexpected ATA data phase detected.
1560 * This should not happen. But, it can !
1561 * I am not sure, which function is best to clean up
1562 * this situation. I choose: ide_error(...)
1564 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (unexpected data phase)", stat);
1567 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1568 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1570 DTF("Multiread: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1571 pBuf, nsect, rq->current_nr_sectors);
1573 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
1575 rq->current_nr_sectors -= nsect;
1576 if (rq->current_nr_sectors != 0) {
1578 * (ks) We don't know which command was executed.
1579 * So, we wait the 'WORSTCASE' value.
1581 ide_set_handler(drive, &flagged_task_mulin_intr, WAIT_WORSTCASE, NULL);
1586 * (ks) Last sector was transfered, wait until drive is ready.
1587 * This can take up to 10 usec. We willl wait max 50 us.
1589 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
1591 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1597 * Pre handler for command with PIO data-out phase
1599 ide_startstop_t flagged_pre_task_out_intr (ide_drive_t *drive, struct request *rq)
1601 ide_hwif_t *hwif = HWIF(drive);
1602 u8 stat = hwif->INB(IDE_STATUS_REG);
1603 ide_startstop_t startstop;
1605 if (!rq->current_nr_sectors) {
1606 return DRIVER(drive)->error(drive, "flagged_pre_task_out_intr (write data not specified)", stat);
1609 if (ide_wait_stat(&startstop, drive, DATA_READY,
1610 BAD_W_STAT, WAIT_DRQ)) {
1611 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
1615 taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
1616 --rq->current_nr_sectors;
1621 ide_startstop_t flagged_task_out_intr (ide_drive_t *drive)
1623 ide_hwif_t *hwif = HWIF(drive);
1624 u8 stat = hwif->INB(IDE_STATUS_REG);
1625 struct request *rq = HWGROUP(drive)->rq;
1628 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
1629 return DRIVER(drive)->error(drive, "flagged_task_out_intr", stat);
1631 if (!rq->current_nr_sectors) {
1632 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1636 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
1638 * (ks) Unexpected ATA data phase detected.
1639 * This should not happen. But, it can !
1640 * I am not sure, which function is best to clean up
1641 * this situation. I choose: ide_error(...)
1643 return DRIVER(drive)->error(drive, "flagged_task_out_intr (unexpected data phase)", stat);
1646 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1647 DTF("Write - rq->current_nr_sectors: %d, status: %02x\n",
1648 (int) rq->current_nr_sectors, stat);
1650 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
1651 --rq->current_nr_sectors;
1654 * (ks) We don't know which command was executed.
1655 * So, we wait the 'WORSTCASE' value.
1657 ide_set_handler(drive, &flagged_task_out_intr, WAIT_WORSTCASE, NULL);
1662 ide_startstop_t flagged_pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
1664 ide_hwif_t *hwif = HWIF(drive);
1665 u8 stat = hwif->INB(IDE_STATUS_REG);
1667 ide_startstop_t startstop;
1668 unsigned int msect, nsect;
1670 if (!rq->current_nr_sectors)
1671 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (write data not specified)", stat);
1673 msect = drive->mult_count;
1675 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (multimode not set)", stat);
1677 if (ide_wait_stat(&startstop, drive, DATA_READY,
1678 BAD_W_STAT, WAIT_DRQ)) {
1679 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
1683 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1684 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1685 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1686 pBuf, nsect, rq->current_nr_sectors);
1688 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
1690 rq->current_nr_sectors -= nsect;
1695 ide_startstop_t flagged_task_mulout_intr (ide_drive_t *drive)
1697 ide_hwif_t *hwif = HWIF(drive);
1698 u8 stat = hwif->INB(IDE_STATUS_REG);
1699 struct request *rq = HWGROUP(drive)->rq;
1701 unsigned int msect, nsect;
1703 msect = drive->mult_count;
1705 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (multimode not set)", stat);
1707 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
1708 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr", stat);
1710 if (!rq->current_nr_sectors) {
1711 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1715 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
1717 * (ks) Unexpected ATA data phase detected.
1718 * This should not happen. But, it can !
1719 * I am not sure, which function is best to clean up
1720 * this situation. I choose: ide_error(...)
1722 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (unexpected data phase)", stat);
1725 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1726 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1727 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1728 pBuf, nsect, rq->current_nr_sectors);
1730 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
1731 rq->current_nr_sectors -= nsect;
1734 * (ks) We don't know which command was executed.
1735 * So, we wait the 'WORSTCASE' value.
1737 ide_set_handler(drive, &flagged_task_mulout_intr, WAIT_WORSTCASE, NULL);