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))
205 if (task->handler == NULL)
212 EXPORT_SYMBOL(do_rw_taskfile);
215 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
217 ide_startstop_t set_multmode_intr (ide_drive_t *drive)
219 ide_hwif_t *hwif = HWIF(drive);
222 if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
223 drive->mult_count = drive->mult_req;
225 drive->mult_req = drive->mult_count = 0;
226 drive->special.b.recalibrate = 1;
227 (void) ide_dump_status(drive, "set_multmode", stat);
232 EXPORT_SYMBOL(set_multmode_intr);
235 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
237 ide_startstop_t set_geometry_intr (ide_drive_t *drive)
239 ide_hwif_t *hwif = HWIF(drive);
243 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
246 if (OK_STAT(stat, READY_STAT, BAD_STAT))
249 if (stat & (ERR_STAT|DRQ_STAT))
250 return DRIVER(drive)->error(drive, "set_geometry_intr", stat);
252 if (HWGROUP(drive)->handler != NULL)
254 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
258 EXPORT_SYMBOL(set_geometry_intr);
261 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
263 ide_startstop_t recal_intr (ide_drive_t *drive)
265 ide_hwif_t *hwif = HWIF(drive);
268 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT))
269 return DRIVER(drive)->error(drive, "recal_intr", stat);
273 EXPORT_SYMBOL(recal_intr);
276 * Handler for commands without a data phase
278 ide_startstop_t task_no_data_intr (ide_drive_t *drive)
280 ide_task_t *args = HWGROUP(drive)->rq->special;
281 ide_hwif_t *hwif = HWIF(drive);
285 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
286 DTF("%s: command opcode 0x%02x\n", drive->name,
287 args->tfRegister[IDE_COMMAND_OFFSET]);
288 return DRIVER(drive)->error(drive, "task_no_data_intr", stat);
289 /* calls ide_end_drive_cmd */
292 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
297 EXPORT_SYMBOL(task_no_data_intr);
300 * old taskfile PIO handlers, to be killed as soon as possible.
302 #ifndef CONFIG_IDE_TASKFILE_IO
305 * Handler for command with PIO data-in phase, READ
307 ide_startstop_t task_in_intr (ide_drive_t *drive)
309 struct request *rq = HWGROUP(drive)->rq;
310 ide_hwif_t *hwif = HWIF(drive);
314 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
315 if (stat & (ERR_STAT|DRQ_STAT)) {
316 return DRIVER(drive)->error(drive, "task_in_intr", stat);
318 if (!(stat & BUSY_STAT)) {
319 DTF("task_in_intr to Soon wait for next interrupt\n");
320 if (HWGROUP(drive)->handler == NULL)
321 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
326 pBuf = rq->buffer + task_rq_offset(rq);
327 DTF("Read: %p, rq->current_nr_sectors: %d, stat: %02x\n",
328 pBuf, (int) rq->current_nr_sectors, stat);
329 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
331 /* FIXME: check drive status */
332 if (--rq->current_nr_sectors <= 0)
333 if (!DRIVER(drive)->end_request(drive, 1, 0))
336 * ERM, it is techincally legal to leave/exit here but it makes
337 * a mess of the code ...
339 if (HWGROUP(drive)->handler == NULL)
340 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
344 EXPORT_SYMBOL(task_in_intr);
347 * Handler for command with Read Multiple
349 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
351 ide_hwif_t *hwif = HWIF(drive);
352 struct request *rq = HWGROUP(drive)->rq;
354 unsigned int msect = drive->mult_count;
358 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
359 if (stat & (ERR_STAT|DRQ_STAT)) {
360 return DRIVER(drive)->error(drive, "task_mulin_intr", stat);
362 /* no data yet, so wait for another interrupt */
363 if (HWGROUP(drive)->handler == NULL)
364 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
369 nsect = rq->current_nr_sectors;
372 pBuf = rq->buffer + task_rq_offset(rq);
373 DTF("Multiread: %p, nsect: %d, msect: %d, " \
374 " rq->current_nr_sectors: %d\n",
375 pBuf, nsect, msect, rq->current_nr_sectors);
376 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
378 rq->current_nr_sectors -= nsect;
381 /* FIXME: check drive status */
382 if (!rq->current_nr_sectors) {
383 if (!DRIVER(drive)->end_request(drive, 1, 0))
387 if (HWGROUP(drive)->handler == NULL)
388 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
392 EXPORT_SYMBOL(task_mulin_intr);
395 * VERIFY ME before 2.4 ... unexpected race is possible based on details
396 * RMK with 74LS245/373/374 TTL buffer logic because of passthrough.
398 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
400 ide_startstop_t startstop;
402 if (ide_wait_stat(&startstop, drive, DATA_READY,
403 drive->bad_wstat, WAIT_DRQ)) {
404 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
406 drive->addressing ? "_EXT" : "");
409 /* For Write_sectors we need to stuff the first sector */
410 taskfile_output_data(drive, rq->buffer + task_rq_offset(rq), SECTOR_WORDS);
411 rq->current_nr_sectors--;
415 EXPORT_SYMBOL(pre_task_out_intr);
418 * Handler for command with PIO data-out phase WRITE
420 * WOOHOO this is a CORRECT STATE DIAGRAM NOW, <andre@linux-ide.org>
422 ide_startstop_t task_out_intr (ide_drive_t *drive)
424 ide_hwif_t *hwif = HWIF(drive);
425 struct request *rq = HWGROUP(drive)->rq;
429 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), DRIVE_READY, drive->bad_wstat)) {
430 return DRIVER(drive)->error(drive, "task_out_intr", stat);
433 * Safe to update request for partial completions.
434 * We have a good STATUS CHECK!!!
436 if (!rq->current_nr_sectors)
437 if (!DRIVER(drive)->end_request(drive, 1, 0))
439 if ((rq->current_nr_sectors==1) ^ (stat & DRQ_STAT)) {
440 rq = HWGROUP(drive)->rq;
441 pBuf = rq->buffer + task_rq_offset(rq);
442 DTF("write: %p, rq->current_nr_sectors: %d\n",
443 pBuf, (int) rq->current_nr_sectors);
444 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
446 rq->current_nr_sectors--;
448 if (HWGROUP(drive)->handler == NULL)
449 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
453 EXPORT_SYMBOL(task_out_intr);
455 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
457 ide_task_t *args = rq->special;
458 ide_startstop_t startstop;
460 if (ide_wait_stat(&startstop, drive, DATA_READY,
461 drive->bad_wstat, WAIT_DRQ)) {
462 printk(KERN_ERR "%s: no DRQ after issuing %s\n",
464 drive->addressing ? "MULTWRITE_EXT" : "MULTWRITE");
467 if (!(drive_is_ready(drive))) {
469 for (i=0; i<100; i++) {
470 if (drive_is_ready(drive))
476 * WARNING :: if the drive as not acked good status we may not
477 * move the DATA-TRANSFER T-Bar as BSY != 0. <andre@linux-ide.org>
479 return args->handler(drive);
482 EXPORT_SYMBOL(pre_task_mulout_intr);
485 * Handler for command write multiple
486 * Called directly from execute_drive_cmd for the first bunch of sectors,
487 * afterwards only by the ISR
489 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
491 ide_hwif_t *hwif = HWIF(drive);
492 u8 stat = hwif->INB(IDE_STATUS_REG);
493 struct request *rq = HWGROUP(drive)->rq;
495 unsigned int msect = drive->mult_count;
498 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT) || !rq->current_nr_sectors) {
499 if (stat & (ERR_STAT|DRQ_STAT)) {
500 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
502 /* Handle last IRQ, occurs after all data was sent. */
503 if (!rq->current_nr_sectors) {
504 DRIVER(drive)->end_request(drive, 1, 0);
507 /* no data yet, so wait for another interrupt */
508 if (HWGROUP(drive)->handler == NULL)
509 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
513 if (HWGROUP(drive)->handler != NULL) {
514 unsigned long lflags;
515 spin_lock_irqsave(&ide_lock, lflags);
516 HWGROUP(drive)->handler = NULL;
517 del_timer(&HWGROUP(drive)->timer);
518 spin_unlock_irqrestore(&ide_lock, lflags);
522 nsect = rq->current_nr_sectors;
525 pBuf = rq->buffer + task_rq_offset(rq);
526 DTF("Multiwrite: %p, nsect: %d, msect: %d, " \
527 "rq->current_nr_sectors: %ld\n",
528 pBuf, nsect, msect, rq->current_nr_sectors);
530 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
531 rq->current_nr_sectors -= nsect;
533 /* FIXME: check drive status */
534 if (!rq->current_nr_sectors) {
535 if (!DRIVER(drive)->end_request(drive, 1, 0))
541 if (HWGROUP(drive)->handler == NULL)
542 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
546 EXPORT_SYMBOL(task_mulout_intr);
548 #else /* !CONFIG_IDE_TASKFILE_IO */
550 static u8 wait_drive_not_busy(ide_drive_t *drive)
552 ide_hwif_t *hwif = HWIF(drive);
557 * Last sector was transfered, wait until drive is ready.
558 * This can take up to 10 usec, but we will wait max 1 ms
559 * (drive_cmd_intr() waits that long).
561 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
565 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
571 * Handler for command with PIO data-in phase (Read).
573 ide_startstop_t task_in_intr (ide_drive_t *drive)
575 struct request *rq = HWGROUP(drive)->rq;
578 good_stat = DATA_READY;
579 stat = HWIF(drive)->INB(IDE_STATUS_REG);
581 if (!OK_STAT(stat, good_stat, BAD_R_STAT)) {
582 if (stat & (ERR_STAT | DRQ_STAT))
583 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
584 /* BUSY_STAT: No data yet, so wait for another IRQ. */
585 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
590 * Complete previously submitted bios (if any).
591 * Status was already verifyied.
593 while (rq->bio != rq->cbio)
594 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
596 /* Complete rq->buffer based request (ioctls). */
597 if (!rq->bio && !rq->nr_sectors) {
598 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
603 task_sectors(drive, rq, 1, IDE_PIO_IN);
605 /* If it was the last datablock check status and finish transfer. */
606 if (!rq->nr_sectors) {
608 stat = wait_drive_not_busy(drive);
612 /* Still data left to transfer. */
613 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
617 EXPORT_SYMBOL(task_in_intr);
620 * Handler for command with PIO data-in phase (Read Multiple).
622 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
624 struct request *rq = HWGROUP(drive)->rq;
625 unsigned int msect = drive->mult_count;
629 good_stat = DATA_READY;
630 stat = HWIF(drive)->INB(IDE_STATUS_REG);
632 if (!OK_STAT(stat, good_stat, BAD_R_STAT)) {
633 if (stat & (ERR_STAT | DRQ_STAT))
634 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
635 /* BUSY_STAT: No data yet, so wait for another IRQ. */
636 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
641 * Complete previously submitted bios (if any).
642 * Status was already verifyied.
644 while (rq->bio != rq->cbio)
645 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
647 /* Complete rq->buffer based request (ioctls). */
648 if (!rq->bio && !rq->nr_sectors) {
649 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
655 nsect = rq->current_nr_sectors;
659 task_sectors(drive, rq, nsect, IDE_PIO_IN);
667 /* If it was the last datablock check status and finish transfer. */
668 if (!rq->nr_sectors) {
670 stat = wait_drive_not_busy(drive);
674 /* Still data left to transfer. */
675 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
679 EXPORT_SYMBOL(task_mulin_intr);
682 * Handler for command with PIO data-out phase (Write).
684 ide_startstop_t task_out_intr (ide_drive_t *drive)
686 struct request *rq = HWGROUP(drive)->rq;
689 stat = HWIF(drive)->INB(IDE_STATUS_REG);
690 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) {
691 if ((stat & (ERR_STAT | DRQ_STAT)) ||
692 ((stat & WRERR_STAT) && !drive->nowerr))
693 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
694 if (stat & BUSY_STAT) {
695 /* Not ready yet, so wait for another IRQ. */
696 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
701 /* Deal with unexpected ATA data phase. */
702 if ((!(stat & DATA_READY) && rq->nr_sectors) ||
703 ((stat & DATA_READY) && !rq->nr_sectors))
704 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
707 * Complete previously submitted bios (if any).
708 * Status was already verifyied.
710 while (rq->bio != rq->cbio)
711 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
713 /* Complete rq->buffer based request (ioctls). */
714 if (!rq->bio && !rq->nr_sectors) {
715 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
719 /* Still data left to transfer. */
720 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
723 task_sectors(drive, rq, 1, IDE_PIO_OUT);
728 EXPORT_SYMBOL(task_out_intr);
730 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
732 ide_startstop_t startstop;
734 if (ide_wait_stat(&startstop, drive, DATA_READY,
735 drive->bad_wstat, WAIT_DRQ)) {
736 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
737 drive->name, drive->addressing ? "_EXT" : "");
744 return task_out_intr(drive);
746 EXPORT_SYMBOL(pre_task_out_intr);
749 * Handler for command with PIO data-out phase (Write Multiple).
751 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
753 struct request *rq = HWGROUP(drive)->rq;
754 unsigned int msect = drive->mult_count;
758 stat = HWIF(drive)->INB(IDE_STATUS_REG);
759 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) {
760 if ((stat & (ERR_STAT | DRQ_STAT)) ||
761 ((stat & WRERR_STAT) && !drive->nowerr))
762 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
763 if (stat & BUSY_STAT) {
764 /* Not ready yet, so wait for another IRQ. */
765 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
770 /* Deal with unexpected ATA data phase. */
771 if ((!(stat & DATA_READY) && rq->nr_sectors) ||
772 ((stat & DATA_READY) && !rq->nr_sectors))
773 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
776 * Complete previously submitted bios (if any).
777 * Status was already verifyied.
779 while (rq->bio != rq->cbio)
780 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
782 /* Complete rq->buffer based request (ioctls). */
783 if (!rq->bio && !rq->nr_sectors) {
784 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
788 /* Still data left to transfer. */
789 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
793 nsect = rq->current_nr_sectors;
797 task_sectors(drive, rq, nsect, IDE_PIO_OUT);
807 EXPORT_SYMBOL(task_mulout_intr);
809 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
811 ide_startstop_t startstop;
813 if (ide_wait_stat(&startstop, drive, DATA_READY,
814 drive->bad_wstat, WAIT_DRQ)) {
815 printk(KERN_ERR "%s: no DRQ after issuing MULTWRITE%s\n",
816 drive->name, drive->addressing ? "_EXT" : "");
823 return task_mulout_intr(drive);
825 EXPORT_SYMBOL(pre_task_mulout_intr);
827 #endif /* !CONFIG_IDE_TASKFILE_IO */
829 int ide_diag_taskfile (ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf)
833 memset(&rq, 0, sizeof(rq));
834 rq.flags = REQ_DRIVE_TASKFILE;
838 * (ks) We transfer currently only whole sectors.
839 * This is suffient for now. But, it would be great,
840 * if we would find a solution to transfer any size.
841 * To support special commands like READ LONG.
843 if (args->command_type != IDE_DRIVE_TASK_NO_DATA) {
845 rq.nr_sectors = (args->hobRegister[IDE_NSECTOR_OFFSET] << 8) | args->tfRegister[IDE_NSECTOR_OFFSET];
847 rq.nr_sectors = data_size / SECTOR_SIZE;
849 if (!rq.nr_sectors) {
850 printk(KERN_ERR "%s: in/out command without data\n",
855 rq.hard_nr_sectors = rq.nr_sectors;
856 rq.hard_cur_sectors = rq.current_nr_sectors = rq.nr_sectors;
860 return ide_do_drive_cmd(drive, &rq, ide_wait);
863 EXPORT_SYMBOL(ide_diag_taskfile);
865 int ide_raw_taskfile (ide_drive_t *drive, ide_task_t *args, u8 *buf)
867 return ide_diag_taskfile(drive, args, 0, buf);
870 EXPORT_SYMBOL(ide_raw_taskfile);
872 #define MAX_DMA (256*SECTOR_WORDS)
874 ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
875 ide_startstop_t flagged_task_no_data_intr(ide_drive_t *);
876 ide_startstop_t flagged_task_in_intr(ide_drive_t *);
877 ide_startstop_t flagged_task_mulin_intr(ide_drive_t *);
878 ide_startstop_t flagged_pre_task_out_intr(ide_drive_t *, struct request *);
879 ide_startstop_t flagged_task_out_intr(ide_drive_t *);
880 ide_startstop_t flagged_pre_task_mulout_intr(ide_drive_t *, struct request *);
881 ide_startstop_t flagged_task_mulout_intr(ide_drive_t *);
883 int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
885 ide_task_request_t *req_task;
889 task_ioreg_t *argsptr = args.tfRegister;
890 task_ioreg_t *hobsptr = args.hobRegister;
892 int tasksize = sizeof(struct ide_task_request_s);
895 u8 io_32bit = drive->io_32bit;
896 char __user *buf = (char __user *)arg;
898 // printk("IDE Taskfile ...\n");
900 req_task = kmalloc(tasksize, GFP_KERNEL);
901 if (req_task == NULL) return -ENOMEM;
902 memset(req_task, 0, tasksize);
903 if (copy_from_user(req_task, buf, tasksize)) {
908 taskout = (int) req_task->out_size;
909 taskin = (int) req_task->in_size;
912 int outtotal = tasksize;
913 outbuf = kmalloc(taskout, GFP_KERNEL);
914 if (outbuf == NULL) {
918 memset(outbuf, 0, taskout);
919 if (copy_from_user(outbuf, buf + outtotal, taskout)) {
926 int intotal = tasksize + taskout;
927 inbuf = kmalloc(taskin, GFP_KERNEL);
932 memset(inbuf, 0, taskin);
933 if (copy_from_user(inbuf, buf + intotal, taskin)) {
939 memset(&args, 0, sizeof(ide_task_t));
940 memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
941 memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE);
943 args.tf_in_flags = req_task->in_flags;
944 args.tf_out_flags = req_task->out_flags;
945 args.data_phase = req_task->data_phase;
946 args.command_type = req_task->req_cmd;
949 switch(req_task->data_phase) {
950 case TASKFILE_OUT_DMAQ:
951 case TASKFILE_OUT_DMA:
952 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
954 case TASKFILE_IN_DMAQ:
955 case TASKFILE_IN_DMA:
956 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
958 case TASKFILE_IN_OUT:
960 args.prehandler = &pre_task_out_intr;
961 args.handler = &task_out_intr;
962 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
963 args.prehandler = NULL;
964 args.handler = &task_in_intr;
965 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
971 case TASKFILE_MULTI_OUT:
972 if (!drive->mult_count) {
973 /* (hs): give up if multcount is not set */
974 printk(KERN_ERR "%s: %s Multimode Write " \
975 "multcount is not set\n",
976 drive->name, __FUNCTION__);
980 if (args.tf_out_flags.all != 0) {
981 args.prehandler = &flagged_pre_task_mulout_intr;
982 args.handler = &flagged_task_mulout_intr;
984 args.prehandler = &pre_task_mulout_intr;
985 args.handler = &task_mulout_intr;
987 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
990 if (args.tf_out_flags.all != 0) {
991 args.prehandler = &flagged_pre_task_out_intr;
992 args.handler = &flagged_task_out_intr;
994 args.prehandler = &pre_task_out_intr;
995 args.handler = &task_out_intr;
997 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
999 case TASKFILE_MULTI_IN:
1000 if (!drive->mult_count) {
1001 /* (hs): give up if multcount is not set */
1002 printk(KERN_ERR "%s: %s Multimode Read failure " \
1003 "multcount is not set\n",
1004 drive->name, __FUNCTION__);
1008 if (args.tf_out_flags.all != 0) {
1009 args.handler = &flagged_task_mulin_intr;
1011 args.handler = &task_mulin_intr;
1013 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1016 if (args.tf_out_flags.all != 0) {
1017 args.handler = &flagged_task_in_intr;
1019 args.handler = &task_in_intr;
1021 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1023 case TASKFILE_NO_DATA:
1024 if (args.tf_out_flags.all != 0) {
1025 args.handler = &flagged_task_no_data_intr;
1027 args.handler = &task_no_data_intr;
1029 err = ide_diag_taskfile(drive, &args, 0, NULL);
1036 memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE);
1037 memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE);
1038 req_task->in_flags = args.tf_in_flags;
1039 req_task->out_flags = args.tf_out_flags;
1041 if (copy_to_user(buf, req_task, tasksize)) {
1046 int outtotal = tasksize;
1047 if (copy_to_user(buf + outtotal, outbuf, taskout)) {
1053 int intotal = tasksize + taskout;
1054 if (copy_to_user(buf + intotal, inbuf, taskin)) {
1066 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
1068 drive->io_32bit = io_32bit;
1073 EXPORT_SYMBOL(ide_taskfile_ioctl);
1075 int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1082 memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors);
1083 ide_init_drive_cmd(&rq);
1089 return ide_do_drive_cmd(drive, &rq, ide_wait);
1092 EXPORT_SYMBOL(ide_wait_cmd);
1095 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1097 int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1100 u8 args[4], *argbuf = args;
1105 if (NULL == (void *) arg) {
1107 ide_init_drive_cmd(&rq);
1108 return ide_do_drive_cmd(drive, &rq, ide_wait);
1111 if (copy_from_user(args, (void __user *)arg, 4))
1114 memset(&tfargs, 0, sizeof(ide_task_t));
1115 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
1116 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
1117 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
1118 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
1119 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
1120 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
1121 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
1124 argsize = 4 + (SECTOR_WORDS * 4 * args[3]);
1125 argbuf = kmalloc(argsize, GFP_KERNEL);
1128 memcpy(argbuf, args, 4);
1130 if (set_transfer(drive, &tfargs)) {
1131 xfer_rate = args[1];
1132 if (ide_ata66_check(drive, &tfargs))
1136 err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf);
1138 if (!err && xfer_rate) {
1139 /* active-retuning-calls future */
1140 ide_set_xfer_rate(drive, xfer_rate);
1141 ide_driveid_update(drive);
1144 if (copy_to_user((void __user *)arg, argbuf, argsize))
1151 EXPORT_SYMBOL(ide_cmd_ioctl);
1153 int ide_wait_cmd_task (ide_drive_t *drive, u8 *buf)
1157 ide_init_drive_cmd(&rq);
1158 rq.flags = REQ_DRIVE_TASK;
1160 return ide_do_drive_cmd(drive, &rq, ide_wait);
1163 EXPORT_SYMBOL(ide_wait_cmd_task);
1166 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1168 int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1170 void __user *p = (void __user *)arg;
1172 u8 args[7], *argbuf = args;
1175 if (copy_from_user(args, p, 7))
1177 err = ide_wait_cmd_task(drive, argbuf);
1178 if (copy_to_user(p, argbuf, argsize))
1183 EXPORT_SYMBOL(ide_task_ioctl);
1186 * NOTICE: This is additions from IBM to provide a discrete interface,
1187 * for selective taskregister access operations. Nice JOB Klaus!!!
1188 * Glad to be able to work and co-develop this with you and IBM.
1190 ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task)
1192 ide_hwif_t *hwif = HWIF(drive);
1193 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
1194 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
1200 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1201 void debug_taskfile(drive, task);
1202 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1205 * (ks) Check taskfile in/out flags.
1206 * If set, then execute as it is defined.
1207 * If not set, then define default settings.
1208 * The default values are:
1209 * write and read all taskfile registers (except data)
1210 * write and read the hob registers (sector,nsector,lcyl,hcyl)
1212 if (task->tf_out_flags.all == 0) {
1213 task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS;
1214 if (drive->addressing == 1)
1215 task->tf_out_flags.all |= (IDE_HOB_STD_OUT_FLAGS << 8);
1218 if (task->tf_in_flags.all == 0) {
1219 task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
1220 if (drive->addressing == 1)
1221 task->tf_in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
1224 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
1225 if (IDE_CONTROL_REG)
1227 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
1228 SELECT_MASK(drive, 0);
1231 status = hwif->INB(IDE_STATUS_REG);
1232 if (status & 0x80) {
1233 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status);
1235 status = hwif->INB(IDE_STATUS_REG);
1236 printk("flagged_taskfile -> Status = %02x\n", status);
1240 if (task->tf_out_flags.b.data) {
1241 u16 data = taskfile->data + (hobfile->data << 8);
1242 hwif->OUTW(data, IDE_DATA_REG);
1245 /* (ks) send hob registers first */
1246 if (task->tf_out_flags.b.nsector_hob)
1247 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
1248 if (task->tf_out_flags.b.sector_hob)
1249 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
1250 if (task->tf_out_flags.b.lcyl_hob)
1251 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
1252 if (task->tf_out_flags.b.hcyl_hob)
1253 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
1255 /* (ks) Send now the standard registers */
1256 if (task->tf_out_flags.b.error_feature)
1257 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
1258 /* refers to number of sectors to transfer */
1259 if (task->tf_out_flags.b.nsector)
1260 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
1261 /* refers to sector offset or start sector */
1262 if (task->tf_out_flags.b.sector)
1263 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
1264 if (task->tf_out_flags.b.lcyl)
1265 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
1266 if (task->tf_out_flags.b.hcyl)
1267 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
1270 * (ks) In the flagged taskfile approch, we will used all specified
1271 * registers and the register value will not be changed. Except the
1272 * select bit (master/slave) in the drive_head register. We must make
1273 * sure that the desired drive is selected.
1275 hwif->OUTB(taskfile->device_head | drive->select.all, IDE_SELECT_REG);
1276 switch(task->data_phase) {
1278 case TASKFILE_OUT_DMAQ:
1279 case TASKFILE_OUT_DMA:
1280 hwif->ide_dma_write(drive);
1283 case TASKFILE_IN_DMAQ:
1284 case TASKFILE_IN_DMA:
1285 hwif->ide_dma_read(drive);
1289 if (task->handler == NULL)
1292 /* Issue the command */
1293 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
1294 if (task->prehandler != NULL)
1295 return task->prehandler(drive, HWGROUP(drive)->rq);
1301 EXPORT_SYMBOL(flagged_taskfile);
1303 ide_startstop_t flagged_task_no_data_intr (ide_drive_t *drive)
1305 ide_hwif_t *hwif = HWIF(drive);
1310 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) {
1311 if (stat & ERR_STAT) {
1312 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr", stat);
1315 * (ks) Unexpected ATA data phase detected.
1316 * This should not happen. But, it can !
1317 * I am not sure, which function is best to clean up
1318 * this situation. I choose: ide_error(...)
1320 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr (unexpected phase)", stat);
1323 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
1329 * Handler for command with PIO data-in phase
1331 ide_startstop_t flagged_task_in_intr (ide_drive_t *drive)
1333 ide_hwif_t *hwif = HWIF(drive);
1334 u8 stat = hwif->INB(IDE_STATUS_REG);
1335 struct request *rq = HWGROUP(drive)->rq;
1339 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1340 if (stat & ERR_STAT) {
1341 return DRIVER(drive)->error(drive, "flagged_task_in_intr", stat);
1344 * (ks) Unexpected ATA data phase detected.
1345 * This should not happen. But, it can !
1346 * I am not sure, which function is best to clean up
1347 * this situation. I choose: ide_error(...)
1349 return DRIVER(drive)->error(drive, "flagged_task_in_intr (unexpected data phase)", stat);
1352 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1353 DTF("Read - rq->current_nr_sectors: %d, status: %02x\n", (int) rq->current_nr_sectors, stat);
1355 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
1357 if (--rq->current_nr_sectors != 0) {
1359 * (ks) We don't know which command was executed.
1360 * So, we wait the 'WORSTCASE' value.
1362 ide_set_handler(drive, &flagged_task_in_intr, WAIT_WORSTCASE, NULL);
1366 * (ks) Last sector was transfered, wait until drive is ready.
1367 * This can take up to 10 usec. We willl wait max 50 us.
1369 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
1371 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1376 ide_startstop_t flagged_task_mulin_intr (ide_drive_t *drive)
1378 ide_hwif_t *hwif = HWIF(drive);
1379 u8 stat = hwif->INB(IDE_STATUS_REG);
1380 struct request *rq = HWGROUP(drive)->rq;
1383 unsigned int msect, nsect;
1385 msect = drive->mult_count;
1387 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (multimode not set)", stat);
1389 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1390 if (stat & ERR_STAT) {
1391 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr", stat);
1394 * (ks) Unexpected ATA data phase detected.
1395 * This should not happen. But, it can !
1396 * I am not sure, which function is best to clean up
1397 * this situation. I choose: ide_error(...)
1399 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (unexpected data phase)", stat);
1402 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1403 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1405 DTF("Multiread: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1406 pBuf, nsect, rq->current_nr_sectors);
1408 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
1410 rq->current_nr_sectors -= nsect;
1411 if (rq->current_nr_sectors != 0) {
1413 * (ks) We don't know which command was executed.
1414 * So, we wait the 'WORSTCASE' value.
1416 ide_set_handler(drive, &flagged_task_mulin_intr, WAIT_WORSTCASE, NULL);
1421 * (ks) Last sector was transfered, wait until drive is ready.
1422 * This can take up to 10 usec. We willl wait max 50 us.
1424 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
1426 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1432 * Pre handler for command with PIO data-out phase
1434 ide_startstop_t flagged_pre_task_out_intr (ide_drive_t *drive, struct request *rq)
1436 ide_startstop_t startstop;
1438 if (ide_wait_stat(&startstop, drive, DATA_READY,
1439 BAD_W_STAT, WAIT_DRQ)) {
1440 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
1444 taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
1445 --rq->current_nr_sectors;
1450 ide_startstop_t flagged_task_out_intr (ide_drive_t *drive)
1452 ide_hwif_t *hwif = HWIF(drive);
1453 u8 stat = hwif->INB(IDE_STATUS_REG);
1454 struct request *rq = HWGROUP(drive)->rq;
1457 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
1458 return DRIVER(drive)->error(drive, "flagged_task_out_intr", stat);
1460 if (!rq->current_nr_sectors) {
1461 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1465 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
1467 * (ks) Unexpected ATA data phase detected.
1468 * This should not happen. But, it can !
1469 * I am not sure, which function is best to clean up
1470 * this situation. I choose: ide_error(...)
1472 return DRIVER(drive)->error(drive, "flagged_task_out_intr (unexpected data phase)", stat);
1475 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1476 DTF("Write - rq->current_nr_sectors: %d, status: %02x\n",
1477 (int) rq->current_nr_sectors, stat);
1479 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
1480 --rq->current_nr_sectors;
1483 * (ks) We don't know which command was executed.
1484 * So, we wait the 'WORSTCASE' value.
1486 ide_set_handler(drive, &flagged_task_out_intr, WAIT_WORSTCASE, NULL);
1491 ide_startstop_t flagged_pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
1493 ide_hwif_t *hwif = HWIF(drive);
1494 u8 stat = hwif->INB(IDE_STATUS_REG);
1496 ide_startstop_t startstop;
1497 unsigned int msect, nsect;
1499 msect = drive->mult_count;
1501 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (multimode not set)", stat);
1503 if (ide_wait_stat(&startstop, drive, DATA_READY,
1504 BAD_W_STAT, WAIT_DRQ)) {
1505 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
1509 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1510 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1511 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1512 pBuf, nsect, rq->current_nr_sectors);
1514 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
1516 rq->current_nr_sectors -= nsect;
1521 ide_startstop_t flagged_task_mulout_intr (ide_drive_t *drive)
1523 ide_hwif_t *hwif = HWIF(drive);
1524 u8 stat = hwif->INB(IDE_STATUS_REG);
1525 struct request *rq = HWGROUP(drive)->rq;
1527 unsigned int msect, nsect;
1529 msect = drive->mult_count;
1531 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (multimode not set)", stat);
1533 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
1534 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr", stat);
1536 if (!rq->current_nr_sectors) {
1537 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
1541 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
1543 * (ks) Unexpected ATA data phase detected.
1544 * This should not happen. But, it can !
1545 * I am not sure, which function is best to clean up
1546 * this situation. I choose: ide_error(...)
1548 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (unexpected data phase)", stat);
1551 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
1552 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1553 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
1554 pBuf, nsect, rq->current_nr_sectors);
1556 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
1557 rq->current_nr_sectors -= nsect;
1560 * (ks) We don't know which command was executed.
1561 * So, we wait the 'WORSTCASE' value.
1563 ide_set_handler(drive, &flagged_task_mulout_intr, WAIT_WORSTCASE, NULL);