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;
1056 // printk("IDE Taskfile ...\n");
1058 req_task = kmalloc(tasksize, GFP_KERNEL);
1059 if (req_task == NULL) return -ENOMEM;
1060 memset(req_task, 0, tasksize);
1061 if (copy_from_user(req_task, (void *) arg, tasksize)) {
1066 taskout = (int) req_task->out_size;
1067 taskin = (int) req_task->in_size;
1070 int outtotal = tasksize;
1071 outbuf = kmalloc(taskout, GFP_KERNEL);
1072 if (outbuf == NULL) {
1076 memset(outbuf, 0, taskout);
1077 if (copy_from_user(outbuf, (void *)arg + outtotal, taskout)) {
1084 int intotal = tasksize + taskout;
1085 inbuf = kmalloc(taskin, GFP_KERNEL);
1086 if (inbuf == NULL) {
1090 memset(inbuf, 0, taskin);
1091 if (copy_from_user(inbuf, (void *)arg + intotal , taskin)) {
1097 memset(&args, 0, sizeof(ide_task_t));
1098 memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
1099 memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE);
1101 args.tf_in_flags = req_task->in_flags;
1102 args.tf_out_flags = req_task->out_flags;
1103 args.data_phase = req_task->data_phase;
1104 args.command_type = req_task->req_cmd;
1106 drive->io_32bit = 0;
1107 switch(req_task->data_phase) {
1108 case TASKFILE_OUT_DMAQ:
1109 case TASKFILE_OUT_DMA:
1110 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1112 case TASKFILE_IN_DMAQ:
1113 case TASKFILE_IN_DMA:
1114 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1116 case TASKFILE_IN_OUT:
1118 args.prehandler = &pre_task_out_intr;
1119 args.handler = &task_out_intr;
1120 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1121 args.prehandler = NULL;
1122 args.handler = &task_in_intr;
1123 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1129 case TASKFILE_MULTI_OUT:
1130 if (!drive->mult_count) {
1131 /* (hs): give up if multcount is not set */
1132 printk(KERN_ERR "%s: %s Multimode Write " \
1133 "multcount is not set\n",
1134 drive->name, __FUNCTION__);
1138 if (args.tf_out_flags.all != 0) {
1139 args.prehandler = &flagged_pre_task_mulout_intr;
1140 args.handler = &flagged_task_mulout_intr;
1142 args.prehandler = &pre_task_mulout_intr;
1143 args.handler = &task_mulout_intr;
1145 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1148 if (args.tf_out_flags.all != 0) {
1149 args.prehandler = &flagged_pre_task_out_intr;
1150 args.handler = &flagged_task_out_intr;
1152 args.prehandler = &pre_task_out_intr;
1153 args.handler = &task_out_intr;
1155 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1157 case TASKFILE_MULTI_IN:
1158 if (!drive->mult_count) {
1159 /* (hs): give up if multcount is not set */
1160 printk(KERN_ERR "%s: %s Multimode Read failure " \
1161 "multcount is not set\n",
1162 drive->name, __FUNCTION__);
1166 if (args.tf_out_flags.all != 0) {
1167 args.handler = &flagged_task_mulin_intr;
1169 args.handler = &task_mulin_intr;
1171 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1174 if (args.tf_out_flags.all != 0) {
1175 args.handler = &flagged_task_in_intr;
1177 args.handler = &task_in_intr;
1179 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1181 case TASKFILE_NO_DATA:
1182 if (args.tf_out_flags.all != 0) {
1183 args.handler = &flagged_task_no_data_intr;
1185 args.handler = &task_no_data_intr;
1187 err = ide_diag_taskfile(drive, &args, 0, NULL);
1194 memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE);
1195 memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE);
1196 req_task->in_flags = args.tf_in_flags;
1197 req_task->out_flags = args.tf_out_flags;
1199 if (copy_to_user((void *)arg, req_task, tasksize)) {
1204 int outtotal = tasksize;
1205 if (copy_to_user((void *)arg+outtotal, outbuf, taskout)) {
1211 int intotal = tasksize + taskout;
1212 if (copy_to_user((void *)arg+intotal, inbuf, taskin)) {
1224 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
1226 drive->io_32bit = io_32bit;
1231 EXPORT_SYMBOL(ide_taskfile_ioctl);
1233 int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1240 memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors);
1241 ide_init_drive_cmd(&rq);
1247 return ide_do_drive_cmd(drive, &rq, ide_wait);
1250 EXPORT_SYMBOL(ide_wait_cmd);
1253 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1255 int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1258 u8 args[4], *argbuf = args;
1263 if (NULL == (void *) arg) {
1265 ide_init_drive_cmd(&rq);
1266 return ide_do_drive_cmd(drive, &rq, ide_wait);
1269 if (copy_from_user(args, (void *)arg, 4))
1272 memset(&tfargs, 0, sizeof(ide_task_t));
1273 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
1274 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
1275 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
1276 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
1277 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
1278 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
1279 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
1282 argsize = 4 + (SECTOR_WORDS * 4 * args[3]);
1283 argbuf = kmalloc(argsize, GFP_KERNEL);
1286 memcpy(argbuf, args, 4);
1288 if (set_transfer(drive, &tfargs)) {
1289 xfer_rate = args[1];
1290 if (ide_ata66_check(drive, &tfargs))
1294 err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf);
1296 if (!err && xfer_rate) {
1297 /* active-retuning-calls future */
1298 ide_set_xfer_rate(drive, xfer_rate);
1299 ide_driveid_update(drive);
1302 if (copy_to_user((void *)arg, argbuf, argsize))
1309 EXPORT_SYMBOL(ide_cmd_ioctl);
1311 int ide_wait_cmd_task (ide_drive_t *drive, u8 *buf)
1315 ide_init_drive_cmd(&rq);
1316 rq.flags = REQ_DRIVE_TASK;
1318 return ide_do_drive_cmd(drive, &rq, ide_wait);
1321 EXPORT_SYMBOL(ide_wait_cmd_task);
1324 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1326 int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1329 u8 args[7], *argbuf = args;
1332 if (copy_from_user(args, (void *)arg, 7))
1334 err = ide_wait_cmd_task(drive, argbuf);
1335 if (copy_to_user((void *)arg, argbuf, argsize))
1340 EXPORT_SYMBOL(ide_task_ioctl);
1343 * NOTICE: This is additions from IBM to provide a discrete interface,
1344 * for selective taskregister access operations. Nice JOB Klaus!!!
1345 * Glad to be able to work and co-develop this with you and IBM.
1347 ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task)
1349 ide_hwif_t *hwif = HWIF(drive);
1350 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
1351 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
1357 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1358 void debug_taskfile(drive, task);
1359 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1362 * (ks) Check taskfile in/out flags.
1363 * If set, then execute as it is defined.
1364 * If not set, then define default settings.
1365 * The default values are:
1366 * write and read all taskfile registers (except data)
1367 * write and read the hob registers (sector,nsector,lcyl,hcyl)
1369 if (task->tf_out_flags.all == 0) {
1370 task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS;
1371 if (drive->addressing == 1)
1372 task->tf_out_flags.all |= (IDE_HOB_STD_OUT_FLAGS << 8);
1375 if (task->tf_in_flags.all == 0) {
1376 task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
1377 if (drive->addressing == 1)
1378 task->tf_in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
1381 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
1382 if (IDE_CONTROL_REG)
1384 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
1385 SELECT_MASK(drive, 0);
1388 status = hwif->INB(IDE_STATUS_REG);
1389 if (status & 0x80) {
1390 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status);
1392 status = hwif->INB(IDE_STATUS_REG);
1393 printk("flagged_taskfile -> Status = %02x\n", status);
1397 if (task->tf_out_flags.b.data) {
1398 u16 data = taskfile->data + (hobfile->data << 8);
1399 hwif->OUTW(data, IDE_DATA_REG);
1402 /* (ks) send hob registers first */
1403 if (task->tf_out_flags.b.nsector_hob)
1404 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
1405 if (task->tf_out_flags.b.sector_hob)
1406 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
1407 if (task->tf_out_flags.b.lcyl_hob)
1408 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
1409 if (task->tf_out_flags.b.hcyl_hob)
1410 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
1412 /* (ks) Send now the standard registers */
1413 if (task->tf_out_flags.b.error_feature)
1414 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
1415 /* refers to number of sectors to transfer */
1416 if (task->tf_out_flags.b.nsector)
1417 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
1418 /* refers to sector offset or start sector */
1419 if (task->tf_out_flags.b.sector)
1420 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
1421 if (task->tf_out_flags.b.lcyl)
1422 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
1423 if (task->tf_out_flags.b.hcyl)
1424 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
1427 * (ks) In the flagged taskfile approch, we will used all specified
1428 * registers and the register value will not be changed. Except the
1429 * select bit (master/slave) in the drive_head register. We must make
1430 * sure that the desired drive is selected.
1432 hwif->OUTB(taskfile->device_head | drive->select.all, IDE_SELECT_REG);
1433 switch(task->data_phase) {
1435 case TASKFILE_OUT_DMAQ:
1436 case TASKFILE_OUT_DMA:
1437 hwif->ide_dma_write(drive);
1440 case TASKFILE_IN_DMAQ:
1441 case TASKFILE_IN_DMA:
1442 hwif->ide_dma_read(drive);
1446 if (task->handler == NULL)
1449 /* Issue the command */
1450 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
1451 if (task->prehandler != NULL)
1452 return task->prehandler(drive, HWGROUP(drive)->rq);
1458 EXPORT_SYMBOL(flagged_taskfile);
1460 ide_startstop_t flagged_task_no_data_intr (ide_drive_t *drive)
1462 ide_hwif_t *hwif = HWIF(drive);
1467 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) {
1468 if (stat & ERR_STAT) {
1469 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr", stat);
1472 * (ks) Unexpected ATA data phase detected.
1473 * This should not happen. But, it can !
1474 * I am not sure, which function is best to clean up
1475 * this situation. I choose: ide_error(...)
1477 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr (unexpected phase)", stat);
1480 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
1486 * Handler for command with PIO data-in phase
1488 ide_startstop_t flagged_task_in_intr (ide_drive_t *drive)
1490 ide_hwif_t *hwif = HWIF(drive);
1491 u8 stat = hwif->INB(IDE_STATUS_REG);
1492 struct request *rq = HWGROUP(drive)->rq;
1496 if (rq->current_nr_sectors == 0)
1497 return DRIVER(drive)->error(drive, "flagged_task_in_intr (no data requested)", stat);
1499 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1500 if (stat & ERR_STAT) {
1501 return DRIVER(drive)->error(drive, "flagged_task_in_intr", stat);
1504 * (ks) Unexpected ATA data phase detected.
1505 * This should not happen. But, it can !
1506 * I am not sure, which function is best to clean up
1507 * this situation. I choose: ide_error(...)
1509 return DRIVER(drive)->error(drive, "flagged_task_in_intr (unexpected data phase)", stat);
1512 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1513 DTF("Read - rq->current_nr_sectors: %d, status: %02x\n", (int) rq->current_nr_sectors, stat);
1515 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
1517 if (--rq->current_nr_sectors != 0) {
1519 * (ks) We don't know which command was executed.
1520 * So, we wait the 'WORSTCASE' value.
1522 ide_set_handler(drive, &flagged_task_in_intr, WAIT_WORSTCASE, NULL);
1526 * (ks) Last sector was transfered, wait until drive is ready.
1527 * This can take up to 10 usec. We willl wait max 50 us.
1529 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
1531 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1536 ide_startstop_t flagged_task_mulin_intr (ide_drive_t *drive)
1538 ide_hwif_t *hwif = HWIF(drive);
1539 u8 stat = hwif->INB(IDE_STATUS_REG);
1540 struct request *rq = HWGROUP(drive)->rq;
1543 unsigned int msect, nsect;
1545 if (rq->current_nr_sectors == 0)
1546 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (no data requested)", stat);
1548 msect = drive->mult_count;
1550 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (multimode not set)", stat);
1552 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1553 if (stat & ERR_STAT) {
1554 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr", stat);
1557 * (ks) Unexpected ATA data phase detected.
1558 * This should not happen. But, it can !
1559 * I am not sure, which function is best to clean up
1560 * this situation. I choose: ide_error(...)
1562 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (unexpected data phase)", stat);
1565 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1566 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1568 DTF("Multiread: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1569 pBuf, nsect, rq->current_nr_sectors);
1571 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
1573 rq->current_nr_sectors -= nsect;
1574 if (rq->current_nr_sectors != 0) {
1576 * (ks) We don't know which command was executed.
1577 * So, we wait the 'WORSTCASE' value.
1579 ide_set_handler(drive, &flagged_task_mulin_intr, WAIT_WORSTCASE, NULL);
1584 * (ks) Last sector was transfered, wait until drive is ready.
1585 * This can take up to 10 usec. We willl wait max 50 us.
1587 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
1589 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1595 * Pre handler for command with PIO data-out phase
1597 ide_startstop_t flagged_pre_task_out_intr (ide_drive_t *drive, struct request *rq)
1599 ide_hwif_t *hwif = HWIF(drive);
1600 u8 stat = hwif->INB(IDE_STATUS_REG);
1601 ide_startstop_t startstop;
1603 if (!rq->current_nr_sectors) {
1604 return DRIVER(drive)->error(drive, "flagged_pre_task_out_intr (write data not specified)", stat);
1607 if (ide_wait_stat(&startstop, drive, DATA_READY,
1608 BAD_W_STAT, WAIT_DRQ)) {
1609 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
1613 taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
1614 --rq->current_nr_sectors;
1619 ide_startstop_t flagged_task_out_intr (ide_drive_t *drive)
1621 ide_hwif_t *hwif = HWIF(drive);
1622 u8 stat = hwif->INB(IDE_STATUS_REG);
1623 struct request *rq = HWGROUP(drive)->rq;
1626 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
1627 return DRIVER(drive)->error(drive, "flagged_task_out_intr", stat);
1629 if (!rq->current_nr_sectors) {
1630 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1634 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
1636 * (ks) Unexpected ATA data phase detected.
1637 * This should not happen. But, it can !
1638 * I am not sure, which function is best to clean up
1639 * this situation. I choose: ide_error(...)
1641 return DRIVER(drive)->error(drive, "flagged_task_out_intr (unexpected data phase)", stat);
1644 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1645 DTF("Write - rq->current_nr_sectors: %d, status: %02x\n",
1646 (int) rq->current_nr_sectors, stat);
1648 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
1649 --rq->current_nr_sectors;
1652 * (ks) We don't know which command was executed.
1653 * So, we wait the 'WORSTCASE' value.
1655 ide_set_handler(drive, &flagged_task_out_intr, WAIT_WORSTCASE, NULL);
1660 ide_startstop_t flagged_pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
1662 ide_hwif_t *hwif = HWIF(drive);
1663 u8 stat = hwif->INB(IDE_STATUS_REG);
1665 ide_startstop_t startstop;
1666 unsigned int msect, nsect;
1668 if (!rq->current_nr_sectors)
1669 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (write data not specified)", stat);
1671 msect = drive->mult_count;
1673 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (multimode not set)", stat);
1675 if (ide_wait_stat(&startstop, drive, DATA_READY,
1676 BAD_W_STAT, WAIT_DRQ)) {
1677 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
1681 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1682 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1683 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1684 pBuf, nsect, rq->current_nr_sectors);
1686 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
1688 rq->current_nr_sectors -= nsect;
1693 ide_startstop_t flagged_task_mulout_intr (ide_drive_t *drive)
1695 ide_hwif_t *hwif = HWIF(drive);
1696 u8 stat = hwif->INB(IDE_STATUS_REG);
1697 struct request *rq = HWGROUP(drive)->rq;
1699 unsigned int msect, nsect;
1701 msect = drive->mult_count;
1703 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (multimode not set)", stat);
1705 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
1706 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr", stat);
1708 if (!rq->current_nr_sectors) {
1709 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1713 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
1715 * (ks) Unexpected ATA data phase detected.
1716 * This should not happen. But, it can !
1717 * I am not sure, which function is best to clean up
1718 * this situation. I choose: ide_error(...)
1720 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (unexpected data phase)", stat);
1723 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1724 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1725 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1726 pBuf, nsect, rq->current_nr_sectors);
1728 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
1729 rq->current_nr_sectors -= nsect;
1732 * (ks) We don't know which command was executed.
1733 * So, we wait the 'WORSTCASE' value.
1735 ide_set_handler(drive, &flagged_task_mulout_intr, WAIT_WORSTCASE, NULL);