2 * linux/drivers/ide/ide-taskfile.c Version 0.33 April 11, 2002
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
9 * The big the bad and the ugly.
11 * Problems to be fixed because of BH interface or the lack therefore.
13 * Fill me in stupid !!!
16 * General refers to the Controller and Driver "pair".
18 * Under the context of Linux it generally refers to an interrupt handler.
19 * However, it correctly describes the 'HOST'
21 * The amount of data needed to be transfered as predefined in the
22 * setup of the device.
24 * The 'DATA BLOCK' associated to the 'DATA HANDLER', and can be as
25 * small as a single sector or as large as the entire command block
29 #include <linux/config.h>
30 #define __NO_VERSION__
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)
65 #define task_rq_offset(rq) \
66 (((rq)->nr_sectors - (rq)->current_nr_sectors) * SECTOR_SIZE)
69 * for now, taskfile requests are special :/
71 * However, upon the creation of the atapi version of packet_command
72 * data-phase ISR plus it own diagnostics and extensions for direct access
73 * (ioctl,read,write,rip,stream -- atapi), the kmap/kunmap for PIO will
76 inline char *task_map_rq (struct request *rq, unsigned long *flags)
79 return ide_map_buffer(rq, flags);
80 return rq->buffer + task_rq_offset(rq);
83 inline void task_unmap_rq (struct request *rq, char *buf, unsigned long *flags)
86 ide_unmap_buffer(buf, flags);
89 inline u32 task_read_24 (ide_drive_t *drive)
91 return (HWIF(drive)->INB(IDE_HCYL_REG)<<16) |
92 (HWIF(drive)->INB(IDE_LCYL_REG)<<8) |
93 HWIF(drive)->INB(IDE_SECTOR_REG);
96 EXPORT_SYMBOL(task_read_24);
98 static void ata_bswap_data (void *buffer, int wcount)
103 *p = *p << 8 | *p >> 8; p++;
104 *p = *p << 8 | *p >> 8; p++;
109 void taskfile_input_data (ide_drive_t *drive, void *buffer, u32 wcount)
111 HWIF(drive)->ata_input_data(drive, buffer, wcount);
113 ata_bswap_data(buffer, wcount);
116 EXPORT_SYMBOL(taskfile_input_data);
118 void taskfile_output_data (ide_drive_t *drive, void *buffer, u32 wcount)
121 ata_bswap_data(buffer, wcount);
122 HWIF(drive)->ata_output_data(drive, buffer, wcount);
123 ata_bswap_data(buffer, wcount);
125 HWIF(drive)->ata_output_data(drive, buffer, wcount);
129 EXPORT_SYMBOL(taskfile_output_data);
131 int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
134 memset(&args, 0, sizeof(ide_task_t));
135 args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01;
136 if (drive->media == ide_disk)
137 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_IDENTIFY;
139 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_PIDENTIFY;
140 args.command_type = ide_cmd_type_parser(&args);
141 return ide_raw_taskfile(drive, &args, buf);
144 EXPORT_SYMBOL(taskfile_lib_get_identify);
146 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
147 void debug_taskfile (ide_drive_t *drive, ide_task_t *args)
149 printk(KERN_INFO "%s: ", drive->name);
150 // printk("TF.0=x%02x ", args->tfRegister[IDE_DATA_OFFSET]);
151 printk("TF.1=x%02x ", args->tfRegister[IDE_FEATURE_OFFSET]);
152 printk("TF.2=x%02x ", args->tfRegister[IDE_NSECTOR_OFFSET]);
153 printk("TF.3=x%02x ", args->tfRegister[IDE_SECTOR_OFFSET]);
154 printk("TF.4=x%02x ", args->tfRegister[IDE_LCYL_OFFSET]);
155 printk("TF.5=x%02x ", args->tfRegister[IDE_HCYL_OFFSET]);
156 printk("TF.6=x%02x ", args->tfRegister[IDE_SELECT_OFFSET]);
157 printk("TF.7=x%02x\n", args->tfRegister[IDE_COMMAND_OFFSET]);
158 printk(KERN_INFO "%s: ", drive->name);
159 // printk("HTF.0=x%02x ", args->hobRegister[IDE_DATA_OFFSET_HOB]);
160 printk("HTF.1=x%02x ", args->hobRegister[IDE_FEATURE_OFFSET_HOB]);
161 printk("HTF.2=x%02x ", args->hobRegister[IDE_NSECTOR_OFFSET_HOB]);
162 printk("HTF.3=x%02x ", args->hobRegister[IDE_SECTOR_OFFSET_HOB]);
163 printk("HTF.4=x%02x ", args->hobRegister[IDE_LCYL_OFFSET_HOB]);
164 printk("HTF.5=x%02x ", args->hobRegister[IDE_HCYL_OFFSET_HOB]);
165 printk("HTF.6=x%02x ", args->hobRegister[IDE_SELECT_OFFSET_HOB]);
166 printk("HTF.7=x%02x\n", args->hobRegister[IDE_CONTROL_OFFSET_HOB]);
168 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
170 ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
172 ide_hwif_t *hwif = HWIF(drive);
173 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
174 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
175 u8 HIHI = (drive->addressing == 1) ? 0xE0 : 0xEF;
177 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
178 void debug_taskfile(drive, task);
179 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
181 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
182 if (IDE_CONTROL_REG) {
184 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
186 SELECT_MASK(drive, 0);
188 if (drive->addressing == 1) {
189 hwif->OUTB(hobfile->feature, IDE_FEATURE_REG);
190 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
191 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
192 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
193 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
196 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
197 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
198 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
199 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
200 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
202 hwif->OUTB((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG);
203 if (task->handler != NULL) {
204 ide_set_handler(drive, task->handler, WAIT_WORSTCASE, NULL);
205 hwif->OUTB(taskfile->command, IDE_COMMAND_REG);
206 if (task->prehandler != NULL)
207 return task->prehandler(drive, task->rq);
210 /* for dma commands we down set the handler */
212 if (blk_fs_request(task->rq) && drive->using_dma) {
213 if (rq_data_dir(task->rq) == READ) {
214 if (hwif->ide_dma_read(drive))
217 if (hwif->ide_dma_write(drive))
221 if (!drive->using_dma && (task->handler == NULL))
224 switch(taskfile->command) {
225 case WIN_WRITEDMA_ONCE:
227 case WIN_WRITEDMA_EXT:
228 hwif->ide_dma_write(drive);
230 case WIN_READDMA_ONCE:
232 case WIN_READDMA_EXT:
233 case WIN_IDENTIFY_DMA:
234 hwif->ide_dma_read(drive);
237 if (task->handler == NULL)
243 switch(taskfile->command) {
244 case WIN_WRITEDMA_ONCE:
246 case WIN_WRITEDMA_EXT:
247 if (drive->using_dma && !(hwif->ide_dma_write(drive)));
249 case WIN_READDMA_ONCE:
251 case WIN_READDMA_EXT:
252 case WIN_IDENTIFY_DMA:
253 if (drive->using_dma && !(hwif->ide_dma_read(drive)));
262 EXPORT_SYMBOL(do_rw_taskfile);
265 * Error reporting, in human readable form (luxurious, but a memory hog).
267 u8 taskfile_dump_status (ide_drive_t *drive, const char *msg, u8 stat)
269 ide_hwif_t *hwif = HWIF(drive);
273 local_irq_set(flags);
274 printk("%s: %s: status=0x%02x", drive->name, msg, stat);
275 #if FANCY_STATUS_DUMPS
277 if (stat & BUSY_STAT) {
280 if (stat & READY_STAT) printk("DriveReady ");
281 if (stat & WRERR_STAT) printk("DeviceFault ");
282 if (stat & SEEK_STAT) printk("SeekComplete ");
283 if (stat & DRQ_STAT) printk("DataRequest ");
284 if (stat & ECC_STAT) printk("CorrectedError ");
285 if (stat & INDEX_STAT) printk("Index ");
286 if (stat & ERR_STAT) printk("Error ");
289 #endif /* FANCY_STATUS_DUMPS */
291 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
292 err = hwif->INB(IDE_ERROR_REG);
293 printk("%s: %s: error=0x%02x", drive->name, msg, err);
294 #if FANCY_STATUS_DUMPS
295 if (drive->media == ide_disk)
299 if (err & ABRT_ERR) printk("DriveStatusError ");
300 if (err & ICRC_ERR) printk("Bad%s", (err & ABRT_ERR) ? "CRC " : "Sector ");
301 if (err & ECC_ERR) printk("UncorrectableError ");
302 if (err & ID_ERR) printk("SectorIdNotFound ");
303 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
304 if (err & MARK_ERR) printk("AddrMarkNotFound ");
306 if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR ||
307 (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
308 if (drive->addressing == 1) {
311 u32 low = task_read_24(drive);
312 hwif->OUTB(0x80, IDE_CONTROL_REG);
313 high = task_read_24(drive);
314 sectors = ((u64)high << 24) | low;
315 printk(", LBAsect=%lld", sectors);
317 u8 cur = hwif->INB(IDE_SELECT_REG);
318 u8 low = hwif->INB(IDE_LCYL_REG);
319 u8 high = hwif->INB(IDE_HCYL_REG);
320 u8 sect = hwif->INB(IDE_SECTOR_REG);
323 printk(", LBAsect=%d", (u32)
324 ((cur&0xf)<<24)|(high<<16)|
327 printk(", CHS=%d/%d/%d",
332 if (HWGROUP(drive)->rq)
333 printk(", sector=%lu",
334 HWGROUP(drive)->rq->sector);
337 #endif /* FANCY_STATUS_DUMPS */
340 local_irq_restore(flags);
344 EXPORT_SYMBOL(taskfile_dump_status);
347 * Clean up after success/failure of an explicit taskfile operation.
349 void ide_end_taskfile (ide_drive_t *drive, u8 stat, u8 err)
351 ide_hwif_t *hwif = HWIF(drive);
355 task_ioreg_t command;
357 spin_lock_irqsave(&io_request_lock, flags);
358 rq = HWGROUP(drive)->rq;
359 spin_unlock_irqrestore(&io_request_lock, flags);
360 args = (ide_task_t *) rq->special;
362 command = args->tfRegister[IDE_COMMAND_OFFSET];
365 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
367 if (args->tf_in_flags.b.data) {
368 u16 data = hwif->INW(IDE_DATA_REG);
369 args->tfRegister[IDE_DATA_OFFSET] = (data) & 0xFF;
370 args->hobRegister[IDE_DATA_OFFSET_HOB] = (data >> 8) & 0xFF;
372 args->tfRegister[IDE_ERROR_OFFSET] = err;
373 args->tfRegister[IDE_NSECTOR_OFFSET] = hwif->INB(IDE_NSECTOR_REG);
374 args->tfRegister[IDE_SECTOR_OFFSET] = hwif->INB(IDE_SECTOR_REG);
375 args->tfRegister[IDE_LCYL_OFFSET] = hwif->INB(IDE_LCYL_REG);
376 args->tfRegister[IDE_HCYL_OFFSET] = hwif->INB(IDE_HCYL_REG);
377 args->tfRegister[IDE_SELECT_OFFSET] = hwif->INB(IDE_SELECT_REG);
378 args->tfRegister[IDE_STATUS_OFFSET] = stat;
379 if ((drive->id->command_set_2 & 0x0400) &&
380 (drive->id->cfs_enable_2 & 0x0400) &&
381 (drive->addressing == 1)) {
382 hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG_HOB);
383 args->hobRegister[IDE_FEATURE_OFFSET_HOB] = hwif->INB(IDE_FEATURE_REG);
384 args->hobRegister[IDE_NSECTOR_OFFSET_HOB] = hwif->INB(IDE_NSECTOR_REG);
385 args->hobRegister[IDE_SECTOR_OFFSET_HOB] = hwif->INB(IDE_SECTOR_REG);
386 args->hobRegister[IDE_LCYL_OFFSET_HOB] = hwif->INB(IDE_LCYL_REG);
387 args->hobRegister[IDE_HCYL_OFFSET_HOB] = hwif->INB(IDE_HCYL_REG);
391 /* taskfile_settings_update(drive, args, command); */
393 if (args->posthandler != NULL)
394 args->posthandler(drive, args);
397 spin_lock_irqsave(&io_request_lock, flags);
398 blkdev_dequeue_request(rq);
399 HWGROUP(drive)->rq = NULL;
400 end_that_request_last(rq);
401 spin_unlock_irqrestore(&io_request_lock, flags);
404 EXPORT_SYMBOL(ide_end_taskfile);
407 * try_to_flush_leftover_data() is invoked in response to a drive
408 * unexpectedly having its DRQ_STAT bit set. As an alternative to
409 * resetting the drive, this routine tries to clear the condition
410 * by read a sector's worth of data from the drive. Of course,
411 * this may not help if the drive is *waiting* for data from *us*.
413 void task_try_to_flush_leftover_data (ide_drive_t *drive)
415 int i = (drive->mult_count ? drive->mult_count : 1) * SECTOR_WORDS;
417 if (drive->media != ide_disk)
421 unsigned int wcount = (i > 16) ? 16 : i;
423 taskfile_input_data(drive, buffer, wcount);
427 EXPORT_SYMBOL(task_try_to_flush_leftover_data);
430 * taskfile_error() takes action based on the error returned by the drive.
432 ide_startstop_t taskfile_error (ide_drive_t *drive, const char *msg, u8 stat)
438 err = taskfile_dump_status(drive, msg, stat);
439 if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL)
443 /* retry only "normal" I/O: */
444 if (rq->cmd == IDE_DRIVE_TASKFILE) {
446 ide_end_taskfile(drive, stat, err);
449 if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) {
450 /* other bits are useless when BUSY */
451 rq->errors |= ERROR_RESET;
453 if (drive->media != ide_disk)
455 if (stat & ERR_STAT) {
456 /* err has different meaning on cdrom and tape */
457 if (err == ABRT_ERR) {
458 if (drive->select.b.lba &&
459 (hwif->INB(IDE_COMMAND_REG) == WIN_SPECIFY))
460 /* some newer drives don't
461 * support WIN_SPECIFY
464 } else if ((err & BAD_CRC) == BAD_CRC) {
465 /* UDMA crc error -- just retry the operation */
467 } else if (err & (BBD_ERR | ECC_ERR)) {
468 /* retries won't help these */
469 rq->errors = ERROR_MAX;
470 } else if (err & TRK0_ERR) {
471 /* help it find track zero */
472 rq->errors |= ERROR_RECAL;
476 if ((stat & DRQ_STAT) && rq_data_dir(rq) != WRITE)
477 task_try_to_flush_leftover_data(drive);
479 if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT)) {
481 hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
483 if (rq->errors >= ERROR_MAX) {
484 DRIVER(drive)->end_request(drive, 0);
486 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
488 return ide_do_reset(drive);
490 if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
491 drive->special.b.recalibrate = 1;
497 EXPORT_SYMBOL(taskfile_error);
500 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
502 ide_startstop_t set_multmode_intr (ide_drive_t *drive)
504 ide_hwif_t *hwif = HWIF(drive);
507 if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
508 drive->mult_count = drive->mult_req;
510 drive->mult_req = drive->mult_count = 0;
511 drive->special.b.recalibrate = 1;
512 (void) ide_dump_status(drive, "set_multmode", stat);
517 EXPORT_SYMBOL(set_multmode_intr);
520 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
522 ide_startstop_t set_geometry_intr (ide_drive_t *drive)
524 ide_hwif_t *hwif = HWIF(drive);
528 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
531 if (OK_STAT(stat, READY_STAT, BAD_STAT))
534 if (stat & (ERR_STAT|DRQ_STAT))
535 return DRIVER(drive)->error(drive, "set_geometry_intr", stat);
537 if (HWGROUP(drive)->handler != NULL)
539 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
543 EXPORT_SYMBOL(set_geometry_intr);
546 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
548 ide_startstop_t recal_intr (ide_drive_t *drive)
550 ide_hwif_t *hwif = HWIF(drive);
553 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT))
554 return DRIVER(drive)->error(drive, "recal_intr", stat);
558 EXPORT_SYMBOL(recal_intr);
561 * Handler for commands without a data phase
563 ide_startstop_t task_no_data_intr (ide_drive_t *drive)
565 ide_task_t *args = HWGROUP(drive)->rq->special;
566 ide_hwif_t *hwif = HWIF(drive);
570 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
571 DTF("%s: command opcode 0x%02x\n", drive->name,
572 args->tfRegister[IDE_COMMAND_OFFSET]);
573 return DRIVER(drive)->error(drive, "task_no_data_intr", stat);
574 /* calls ide_end_drive_cmd */
577 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
582 EXPORT_SYMBOL(task_no_data_intr);
585 * Handler for command with PIO data-in phase, READ
588 * FIXME before 2.4 enable ...
589 * DATA integrity issue upon error. <andre@linux-ide.org>
591 ide_startstop_t task_in_intr (ide_drive_t *drive)
593 struct request *rq = HWGROUP(drive)->rq;
594 ide_hwif_t *hwif = HWIF(drive);
599 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
600 if (stat & (ERR_STAT|DRQ_STAT)) {
602 DTF("%s: attempting to recover last " \
603 "sector counter status=0x%02x\n",
606 * Expect a BUG BOMB if we attempt to rewind the
607 * offset in the BH aka PAGE in the current BLOCK
608 * segment. This is different than the HOST segment.
612 rq->current_nr_sectors++;
613 return DRIVER(drive)->error(drive, "task_in_intr", stat);
615 if (!(stat & BUSY_STAT)) {
616 DTF("task_in_intr to Soon wait for next interrupt\n");
617 if (HWGROUP(drive)->handler == NULL)
618 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
625 * Holding point for a brain dump of a thought :-/
628 if (!OK_STAT(stat,DRIVE_READY,drive->bad_wstat)) {
629 DTF("%s: READ attempting to recover last " \
630 "sector counter status=0x%02x\n",
632 rq->current_nr_sectors++;
633 return DRIVER(drive)->error(drive, "task_in_intr", stat);
635 if (!rq->current_nr_sectors)
636 if (!DRIVER(drive)->end_request(drive, 1))
639 if (--rq->current_nr_sectors <= 0)
640 if (!DRIVER(drive)->end_request(drive, 1))
644 pBuf = task_map_rq(rq, &flags);
645 DTF("Read: %p, rq->current_nr_sectors: %d, stat: %02x\n",
646 pBuf, (int) rq->current_nr_sectors, stat);
647 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
648 task_unmap_rq(rq, pBuf, &flags);
650 * FIXME :: We really can not legally get a new page/bh
651 * regardless, if this is the end of our segment.
652 * BH walking or segment can only be updated after we have a good
653 * hwif->INB(IDE_STATUS_REG); return.
655 if (--rq->current_nr_sectors <= 0)
656 if (!DRIVER(drive)->end_request(drive, 1))
659 * ERM, it is techincally legal to leave/exit here but it makes
660 * a mess of the code ...
662 if (HWGROUP(drive)->handler == NULL)
663 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
667 EXPORT_SYMBOL(task_in_intr);
670 * Handler for command with Read Multiple
672 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
674 ide_hwif_t *hwif = HWIF(drive);
675 struct request *rq = HWGROUP(drive)->rq;
677 unsigned int msect = drive->mult_count;
682 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
683 if (stat & (ERR_STAT|DRQ_STAT)) {
685 rq->current_nr_sectors += drive->mult_count;
687 * NOTE: could rewind beyond beginning :-/
690 printk("%s: MULTI-READ assume all data " \
691 "transfered is bad status=0x%02x\n",
694 return DRIVER(drive)->error(drive, "task_mulin_intr", stat);
696 /* no data yet, so wait for another interrupt */
697 if (HWGROUP(drive)->handler == NULL)
698 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
703 nsect = rq->current_nr_sectors;
706 pBuf = task_map_rq(rq, &flags);
707 DTF("Multiread: %p, nsect: %d, msect: %d, " \
708 " rq->current_nr_sectors: %d\n",
709 pBuf, nsect, msect, rq->current_nr_sectors);
710 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
711 task_unmap_rq(rq, pBuf, &flags);
713 rq->current_nr_sectors -= nsect;
716 * FIXME :: We really can not legally get a new page/bh
717 * regardless, if this is the end of our segment.
718 * BH walking or segment can only be updated after we have a
719 * good hwif->INB(IDE_STATUS_REG); return.
721 if (!rq->current_nr_sectors) {
722 if (!DRIVER(drive)->end_request(drive, 1))
726 if (HWGROUP(drive)->handler == NULL)
727 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
731 EXPORT_SYMBOL(task_mulin_intr);
734 * VERIFY ME before 2.4 ... unexpected race is possible based on details
735 * RMK with 74LS245/373/374 TTL buffer logic because of passthrough.
737 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
741 ide_startstop_t startstop;
743 if (ide_wait_stat(&startstop, drive, DATA_READY,
744 drive->bad_wstat, WAIT_DRQ)) {
745 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
747 drive->addressing ? "_EXT" : "");
750 /* For Write_sectors we need to stuff the first sector */
751 pBuf = task_map_rq(rq, &flags);
752 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
753 rq->current_nr_sectors--;
754 task_unmap_rq(rq, pBuf, &flags);
758 EXPORT_SYMBOL(pre_task_out_intr);
761 * Handler for command with PIO data-out phase WRITE
763 * WOOHOO this is a CORRECT STATE DIAGRAM NOW, <andre@linux-ide.org>
765 ide_startstop_t task_out_intr (ide_drive_t *drive)
767 ide_hwif_t *hwif = HWIF(drive);
768 struct request *rq = HWGROUP(drive)->rq;
773 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), DRIVE_READY, drive->bad_wstat)) {
774 DTF("%s: WRITE attempting to recover last " \
775 "sector counter status=0x%02x\n",
777 rq->current_nr_sectors++;
778 return DRIVER(drive)->error(drive, "task_out_intr", stat);
781 * Safe to update request for partial completions.
782 * We have a good STATUS CHECK!!!
784 if (!rq->current_nr_sectors)
785 if (!DRIVER(drive)->end_request(drive, 1))
787 if ((rq->current_nr_sectors==1) ^ (stat & DRQ_STAT)) {
788 rq = HWGROUP(drive)->rq;
789 pBuf = task_map_rq(rq, &flags);
790 DTF("write: %p, rq->current_nr_sectors: %d\n",
791 pBuf, (int) rq->current_nr_sectors);
792 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
793 task_unmap_rq(rq, pBuf, &flags);
795 rq->current_nr_sectors--;
797 if (HWGROUP(drive)->handler == NULL)
798 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
802 EXPORT_SYMBOL(task_out_intr);
804 #undef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
806 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
808 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
809 ide_hwif_t *hwif = HWIF(drive);
811 unsigned int nsect = 0, msect = drive->mult_count;
814 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
816 ide_task_t *args = rq->special;
817 ide_startstop_t startstop;
821 * assign private copy for multi-write
823 memcpy(&HWGROUP(drive)->wrq, rq, sizeof(struct request));
826 if (ide_wait_stat(&startstop, drive, DATA_READY,
827 drive->bad_wstat, WAIT_DRQ)) {
828 printk(KERN_ERR "%s: no DRQ after issuing %s\n",
830 drive->addressing ? "MULTWRITE_EXT" : "MULTWRITE");
833 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
836 nsect = rq->current_nr_sectors;
839 pBuf = task_map_rq(rq, &flags);
840 DTF("Pre-Multiwrite: %p, nsect: %d, msect: %d, " \
841 "rq->current_nr_sectors: %ld\n",
842 pBuf, nsect, msect, rq->current_nr_sectors);
844 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
845 task_unmap_rq(rq, pBuf, &flags);
846 rq->current_nr_sectors -= nsect;
847 if (!rq->current_nr_sectors) {
848 if (!DRIVER(drive)->end_request(drive, 1))
850 stat = hwif->INB(IDE_STATUS_REG);
857 #else /* ! ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
860 if (wait_for_ready(drive, 100))
861 IDE_DEBUG(__LINE__); //BUG();
863 if (!(drive_is_ready(drive))) {
865 for (i=0; i<100; i++) {
866 if (drive_is_ready(drive))
872 * WARNING :: if the drive as not acked good status we may not
873 * move the DATA-TRANSFER T-Bar as BSY != 0. <andre@linux-ide.org>
875 return args->handler(drive);
876 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
879 EXPORT_SYMBOL(pre_task_mulout_intr);
882 * FIXME before enabling in 2.4 ... DATA integrity issue upon error.
885 * Handler for command write multiple
886 * Called directly from execute_drive_cmd for the first bunch of sectors,
887 * afterwards only by the ISR
889 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
891 ide_hwif_t *hwif = HWIF(drive);
892 u8 stat = hwif->INB(IDE_STATUS_REG);
893 struct request *rq = HWGROUP(drive)->rq;
895 ide_startstop_t startstop = ide_stopped;
896 unsigned int msect = drive->mult_count;
901 * (ks/hs): Handle last IRQ on multi-sector transfer,
902 * occurs after all data was sent in this chunk
904 if (rq->current_nr_sectors == 0) {
905 if (stat & (ERR_STAT|DRQ_STAT)) {
907 rq->current_nr_sectors += drive->mult_count;
909 * NOTE: could rewind beyond beginning :-/
912 printk("%s: MULTI-WRITE assume all data " \
913 "transfered is bad status=0x%02x\n",
916 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
919 DRIVER(drive)->end_request(drive, 1);
923 * DON'T be lazy code the above and below togather !!!
925 if (!OK_STAT(stat,DATA_READY,BAD_R_STAT)) {
926 if (stat & (ERR_STAT|DRQ_STAT)) {
928 rq->current_nr_sectors += drive->mult_count;
930 * NOTE: could rewind beyond beginning :-/
933 printk("%s: MULTI-WRITE assume all data " \
934 "transfered is bad status=0x%02x\n",
937 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
939 /* no data yet, so wait for another interrupt */
940 if (HWGROUP(drive)->handler == NULL)
941 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
945 #ifndef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
946 if (HWGROUP(drive)->handler != NULL) {
947 unsigned long lflags;
948 spin_lock_irqsave(&io_request_lock, lflags);
949 HWGROUP(drive)->handler = NULL;
950 del_timer(&HWGROUP(drive)->timer);
951 spin_unlock_irqrestore(&io_request_lock, lflags);
953 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
956 nsect = rq->current_nr_sectors;
959 pBuf = task_map_rq(rq, &flags);
960 DTF("Multiwrite: %p, nsect: %d, msect: %d, " \
961 "rq->current_nr_sectors: %ld\n",
962 pBuf, nsect, msect, rq->current_nr_sectors);
964 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
965 task_unmap_rq(rq, pBuf, &flags);
966 rq->current_nr_sectors -= nsect;
968 * FIXME :: We really can not legally get a new page/bh
969 * regardless, if this is the end of our segment.
970 * BH walking or segment can only be updated after we
971 * have a good hwif->INB(IDE_STATUS_REG); return.
973 if (!rq->current_nr_sectors) {
974 if (!DRIVER(drive)->end_request(drive, 1))
980 if (HWGROUP(drive)->handler == NULL)
981 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
985 EXPORT_SYMBOL(task_mulout_intr);
987 /* Called by internal to feature out type of command being called */
988 //ide_pre_handler_t * ide_pre_handler_parser (task_struct_t *taskfile, hob_struct_t *hobfile)
989 ide_pre_handler_t * ide_pre_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
991 switch(taskfile->command) {
992 /* IDE_DRIVE_TASK_RAW_WRITE */
993 case CFA_WRITE_MULTI_WO_ERASE:
994 // case WIN_WRITE_LONG:
995 // case WIN_WRITE_LONG_ONCE:
997 case WIN_MULTWRITE_EXT:
998 return &pre_task_mulout_intr;
1000 /* IDE_DRIVE_TASK_OUT */
1002 // case WIN_WRITE_ONCE:
1004 case WIN_WRITE_VERIFY:
1005 case WIN_WRITE_BUFFER:
1006 case CFA_WRITE_SECT_WO_ERASE:
1007 case WIN_DOWNLOAD_MICROCODE:
1008 return &pre_task_out_intr;
1009 /* IDE_DRIVE_TASK_OUT */
1011 if (taskfile->feature == SMART_WRITE_LOG_SECTOR)
1012 return &pre_task_out_intr;
1014 // case WIN_WRITEDMA_ONCE:
1015 case WIN_WRITEDMA_QUEUED:
1016 case WIN_WRITEDMA_EXT:
1017 case WIN_WRITEDMA_QUEUED_EXT:
1018 /* IDE_DRIVE_TASK_OUT */
1025 EXPORT_SYMBOL(ide_pre_handler_parser);
1027 /* Called by internal to feature out type of command being called */
1028 //ide_handler_t * ide_handler_parser (task_struct_t *taskfile, hob_struct_t *hobfile)
1029 ide_handler_t * ide_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
1031 switch(taskfile->command) {
1034 case CFA_TRANSLATE_SECTOR:
1035 case WIN_READ_BUFFER:
1037 // case WIN_READ_ONCE:
1039 return &task_in_intr;
1040 case WIN_SECURITY_DISABLE:
1041 case WIN_SECURITY_ERASE_UNIT:
1042 case WIN_SECURITY_SET_PASS:
1043 case WIN_SECURITY_UNLOCK:
1044 case WIN_DOWNLOAD_MICROCODE:
1045 case CFA_WRITE_SECT_WO_ERASE:
1046 case WIN_WRITE_BUFFER:
1047 case WIN_WRITE_VERIFY:
1049 // case WIN_WRITE_ONCE:
1051 return &task_out_intr;
1052 // case WIN_READ_LONG:
1053 // case WIN_READ_LONG_ONCE:
1055 case WIN_MULTREAD_EXT:
1056 return &task_mulin_intr;
1057 // case WIN_WRITE_LONG:
1058 // case WIN_WRITE_LONG_ONCE:
1059 case CFA_WRITE_MULTI_WO_ERASE:
1061 case WIN_MULTWRITE_EXT:
1062 return &task_mulout_intr;
1064 switch(taskfile->feature) {
1065 case SMART_READ_VALUES:
1066 case SMART_READ_THRESHOLDS:
1067 case SMART_READ_LOG_SECTOR:
1068 return &task_in_intr;
1069 case SMART_WRITE_LOG_SECTOR:
1070 return &task_out_intr;
1072 return &task_no_data_intr;
1074 case CFA_REQ_EXT_ERROR_CODE:
1075 case CFA_ERASE_SECTORS:
1077 // case WIN_VERIFY_ONCE:
1078 case WIN_VERIFY_EXT:
1080 return &task_no_data_intr;
1082 return &set_geometry_intr;
1084 // case WIN_RESTORE:
1088 case WIN_FLUSH_CACHE:
1089 case WIN_FLUSH_CACHE_EXT:
1090 case WIN_STANDBYNOW1:
1091 case WIN_STANDBYNOW2:
1095 case WIN_CHECKPOWERMODE1:
1096 case WIN_CHECKPOWERMODE2:
1097 case WIN_GETMEDIASTATUS:
1098 case WIN_MEDIAEJECT:
1099 return &task_no_data_intr;
1101 return &set_multmode_intr;
1102 case WIN_READ_NATIVE_MAX:
1104 case WIN_READ_NATIVE_MAX_EXT:
1105 case WIN_SET_MAX_EXT:
1106 case WIN_SECURITY_ERASE_PREPARE:
1107 case WIN_SECURITY_FREEZE_LOCK:
1109 case WIN_DOORUNLOCK:
1110 case WIN_SETFEATURES:
1111 return &task_no_data_intr;
1112 case DISABLE_SEAGATE:
1113 case EXABYTE_ENABLE_NEST:
1114 return &task_no_data_intr;
1115 #ifdef CONFIG_BLK_DEV_IDEDMA
1117 // case WIN_READDMA_ONCE:
1118 case WIN_IDENTIFY_DMA:
1119 case WIN_READDMA_QUEUED:
1120 case WIN_READDMA_EXT:
1121 case WIN_READDMA_QUEUED_EXT:
1123 // case WIN_WRITEDMA_ONCE:
1124 case WIN_WRITEDMA_QUEUED:
1125 case WIN_WRITEDMA_EXT:
1126 case WIN_WRITEDMA_QUEUED_EXT:
1130 case WIN_DEVICE_RESET:
1131 case WIN_QUEUED_SERVICE:
1138 EXPORT_SYMBOL(ide_handler_parser);
1140 ide_post_handler_t * ide_post_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
1142 switch(taskfile->command) {
1143 case WIN_SPECIFY: /* set_geometry_intr */
1144 case WIN_RESTORE: /* recal_intr */
1145 case WIN_SETMULT: /* set_multmode_intr */
1151 EXPORT_SYMBOL(ide_post_handler_parser);
1153 /* Called by ioctl to feature out type of command being called */
1154 int ide_cmd_type_parser (ide_task_t *args)
1157 task_struct_t *taskfile = (task_struct_t *) args->tfRegister;
1158 hob_struct_t *hobfile = (hob_struct_t *) args->hobRegister;
1160 args->prehandler = ide_pre_handler_parser(taskfile, hobfile);
1161 args->handler = ide_handler_parser(taskfile, hobfile);
1162 args->posthandler = ide_post_handler_parser(taskfile, hobfile);
1164 switch(args->tfRegister[IDE_COMMAND_OFFSET]) {
1167 return IDE_DRIVE_TASK_IN;
1168 case CFA_TRANSLATE_SECTOR:
1170 // case WIN_READ_ONCE:
1172 case WIN_READ_BUFFER:
1173 return IDE_DRIVE_TASK_IN;
1175 // case WIN_WRITE_ONCE:
1177 case WIN_WRITE_VERIFY:
1178 case WIN_WRITE_BUFFER:
1179 case CFA_WRITE_SECT_WO_ERASE:
1180 case WIN_DOWNLOAD_MICROCODE:
1181 return IDE_DRIVE_TASK_RAW_WRITE;
1182 // case WIN_READ_LONG:
1183 // case WIN_READ_LONG_ONCE:
1185 case WIN_MULTREAD_EXT:
1186 return IDE_DRIVE_TASK_IN;
1187 // case WIN_WRITE_LONG:
1188 // case WIN_WRITE_LONG_ONCE:
1189 case CFA_WRITE_MULTI_WO_ERASE:
1191 case WIN_MULTWRITE_EXT:
1192 return IDE_DRIVE_TASK_RAW_WRITE;
1193 case WIN_SECURITY_DISABLE:
1194 case WIN_SECURITY_ERASE_UNIT:
1195 case WIN_SECURITY_SET_PASS:
1196 case WIN_SECURITY_UNLOCK:
1197 return IDE_DRIVE_TASK_OUT;
1199 args->tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS;
1200 args->tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS;
1201 switch(args->tfRegister[IDE_FEATURE_OFFSET]) {
1202 case SMART_READ_VALUES:
1203 case SMART_READ_THRESHOLDS:
1204 case SMART_READ_LOG_SECTOR:
1205 return IDE_DRIVE_TASK_IN;
1206 case SMART_WRITE_LOG_SECTOR:
1207 return IDE_DRIVE_TASK_OUT;
1209 return IDE_DRIVE_TASK_NO_DATA;
1211 #ifdef CONFIG_BLK_DEV_IDEDMA
1213 // case WIN_READDMA_ONCE:
1214 case WIN_IDENTIFY_DMA:
1215 case WIN_READDMA_QUEUED:
1216 case WIN_READDMA_EXT:
1217 case WIN_READDMA_QUEUED_EXT:
1218 return IDE_DRIVE_TASK_IN;
1220 // case WIN_WRITEDMA_ONCE:
1221 case WIN_WRITEDMA_QUEUED:
1222 case WIN_WRITEDMA_EXT:
1223 case WIN_WRITEDMA_QUEUED_EXT:
1224 return IDE_DRIVE_TASK_RAW_WRITE;
1226 case WIN_SETFEATURES:
1227 switch(args->tfRegister[IDE_FEATURE_OFFSET]) {
1228 case SETFEATURES_EN_8BIT:
1229 case SETFEATURES_EN_WCACHE:
1230 return IDE_DRIVE_TASK_NO_DATA;
1231 case SETFEATURES_XFER:
1232 return IDE_DRIVE_TASK_SET_XFER;
1233 case SETFEATURES_DIS_DEFECT:
1234 case SETFEATURES_EN_APM:
1235 case SETFEATURES_DIS_MSN:
1236 case SETFEATURES_DIS_RETRY:
1237 case SETFEATURES_EN_AAM:
1238 case SETFEATURES_RW_LONG:
1239 case SETFEATURES_SET_CACHE:
1240 case SETFEATURES_DIS_RLA:
1241 case SETFEATURES_EN_RI:
1242 case SETFEATURES_EN_SI:
1243 case SETFEATURES_DIS_RPOD:
1244 case SETFEATURES_DIS_WCACHE:
1245 case SETFEATURES_EN_DEFECT:
1246 case SETFEATURES_DIS_APM:
1247 case SETFEATURES_EN_ECC:
1248 case SETFEATURES_EN_MSN:
1249 case SETFEATURES_EN_RETRY:
1250 case SETFEATURES_EN_RLA:
1251 case SETFEATURES_PREFETCH:
1252 case SETFEATURES_4B_RW_LONG:
1253 case SETFEATURES_DIS_AAM:
1254 case SETFEATURES_EN_RPOD:
1255 case SETFEATURES_DIS_RI:
1256 case SETFEATURES_DIS_SI:
1258 return IDE_DRIVE_TASK_NO_DATA;
1261 case CFA_REQ_EXT_ERROR_CODE:
1262 case CFA_ERASE_SECTORS:
1264 // case WIN_VERIFY_ONCE:
1265 case WIN_VERIFY_EXT:
1270 case WIN_FLUSH_CACHE:
1271 case WIN_FLUSH_CACHE_EXT:
1272 case WIN_STANDBYNOW1:
1273 case WIN_STANDBYNOW2:
1277 case DISABLE_SEAGATE:
1278 case WIN_CHECKPOWERMODE1:
1279 case WIN_CHECKPOWERMODE2:
1280 case WIN_GETMEDIASTATUS:
1281 case WIN_MEDIAEJECT:
1283 case WIN_READ_NATIVE_MAX:
1285 case WIN_READ_NATIVE_MAX_EXT:
1286 case WIN_SET_MAX_EXT:
1287 case WIN_SECURITY_ERASE_PREPARE:
1288 case WIN_SECURITY_FREEZE_LOCK:
1289 case EXABYTE_ENABLE_NEST:
1291 case WIN_DOORUNLOCK:
1292 return IDE_DRIVE_TASK_NO_DATA;
1295 case WIN_DEVICE_RESET:
1296 case WIN_QUEUED_SERVICE:
1299 return IDE_DRIVE_TASK_INVALID;
1303 EXPORT_SYMBOL(ide_cmd_type_parser);
1306 * This function is intended to be used prior to invoking ide_do_drive_cmd().
1308 void ide_init_drive_taskfile (struct request *rq)
1310 memset(rq, 0, sizeof(*rq));
1311 rq->cmd = IDE_DRIVE_TASK_NO_DATA;
1314 EXPORT_SYMBOL(ide_init_drive_taskfile);
1318 int ide_diag_taskfile (ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf)
1322 ide_init_drive_taskfile(&rq);
1323 rq.cmd = IDE_DRIVE_TASKFILE;
1327 * (ks) We transfer currently only whole sectors.
1328 * This is suffient for now. But, it would be great,
1329 * if we would find a solution to transfer any size.
1330 * To support special commands like READ LONG.
1332 if (args->command_type != IDE_DRIVE_TASK_NO_DATA) {
1334 rq.current_nr_sectors = rq.nr_sectors = (args->hobRegister[IDE_NSECTOR_OFFSET_HOB] << 8) | args->tfRegister[IDE_NSECTOR_OFFSET];
1335 /* rq.hard_cur_sectors */
1337 rq.current_nr_sectors = rq.nr_sectors = data_size / SECTOR_SIZE;
1338 /* rq.hard_cur_sectors */
1341 if (args->tf_out_flags.all == 0) {
1343 * clean up kernel settings for driver sanity, regardless.
1344 * except for discrete diag services.
1346 args->posthandler = ide_post_handler_parser(
1347 (struct hd_drive_task_hdr *) args->tfRegister,
1348 (struct hd_drive_hob_hdr *) args->hobRegister);
1352 return ide_do_drive_cmd(drive, &rq, ide_wait);
1357 int ide_diag_taskfile (ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf)
1360 unsigned long flags;
1361 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1362 unsigned int major = HWIF(drive)->major;
1363 struct list_head *queue_head = &drive->queue.queue_head;
1364 DECLARE_COMPLETION(wait);
1366 if (HWIF(drive)->chipset == ide_pdc4030 && buf != NULL)
1367 return -ENOSYS; /* special drive cmds not supported */
1369 memset(rq, 0, sizeof(*rq));
1370 rq->cmd = IDE_DRIVE_TASKFILE;
1374 * (ks) We transfer currently only whole sectors.
1375 * This is suffient for now. But, it would be great,
1376 * if we would find a solution to transfer any size.
1377 * To support special commands like READ LONG.
1379 if (args->command_type != IDE_DRIVE_TASK_NO_DATA) {
1380 if (data_size == 0) {
1381 ata_nsector_t nsector;
1382 nsector.b.low = args->hobRegister[IDE_NSECTOR_OFFSET_HOB];
1383 nsector.b.high = args->tfRegister[IDE_NSECTOR_OFFSET];
1384 rq.nr_sectors = nsector.all;
1386 rq.nr_sectors = data_size / SECTOR_SIZE;
1388 rq.current_nr_sectors = rq.nr_sectors;
1389 // rq.hard_cur_sectors = rq.nr_sectors;
1392 if (args->tf_out_flags.all == 0) {
1394 * clean up kernel settings for driver sanity, regardless.
1395 * except for discrete diag services.
1397 args->posthandler = ide_post_handler_parser(
1398 (struct hd_drive_task_hdr *) args->tfRegister,
1399 (struct hd_drive_hob_hdr *) args->hobRegister);
1403 rq->rq_status = RQ_ACTIVE;
1404 rq->rq_dev = MKDEV(major,(drive->select.b.unit)<<PARTN_BITS);
1405 rq->waiting = &wait;
1407 spin_lock_irqsave(&io_request_lock, flags);
1408 queue_head = queue_head->prev;
1409 list_add(&rq->queue, queue_head);
1410 ide_do_request(hwgroup, 0);
1411 spin_unlock_irqrestore(&io_request_lock, flags);
1413 wait_for_completion(&wait); /* wait for it to be serviced */
1414 return rq->errors ? -EIO : 0; /* return -EIO if errors */
1419 EXPORT_SYMBOL(ide_diag_taskfile);
1421 int ide_raw_taskfile (ide_drive_t *drive, ide_task_t *args, u8 *buf)
1423 return ide_diag_taskfile(drive, args, 0, buf);
1426 EXPORT_SYMBOL(ide_raw_taskfile);
1428 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1429 char * ide_ioctl_verbose (unsigned int cmd)
1434 char * ide_task_cmd_verbose (u8 task)
1438 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1440 #define MAX_DMA (256*SECTOR_WORDS)
1442 ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
1443 ide_startstop_t flagged_task_no_data_intr(ide_drive_t *);
1444 ide_startstop_t flagged_task_in_intr(ide_drive_t *);
1445 ide_startstop_t flagged_task_mulin_intr(ide_drive_t *);
1446 ide_startstop_t flagged_pre_task_out_intr(ide_drive_t *, struct request *);
1447 ide_startstop_t flagged_task_out_intr(ide_drive_t *);
1448 ide_startstop_t flagged_pre_task_mulout_intr(ide_drive_t *, struct request *);
1449 ide_startstop_t flagged_task_mulout_intr(ide_drive_t *);
1451 int ide_taskfile_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1453 ide_task_request_t *req_task;
1457 task_ioreg_t *argsptr = args.tfRegister;
1458 task_ioreg_t *hobsptr = args.hobRegister;
1460 int tasksize = sizeof(struct ide_task_request_s);
1463 u8 io_32bit = drive->io_32bit;
1465 // printk("IDE Taskfile ...\n");
1467 req_task = kmalloc(tasksize, GFP_KERNEL);
1468 if (req_task == NULL) return -ENOMEM;
1469 memset(req_task, 0, tasksize);
1470 if (copy_from_user(req_task, (void *) arg, tasksize)) {
1475 taskout = (int) req_task->out_size;
1476 taskin = (int) req_task->in_size;
1479 int outtotal = tasksize;
1480 outbuf = kmalloc(taskout, GFP_KERNEL);
1481 if (outbuf == NULL) {
1485 memset(outbuf, 0, taskout);
1486 if (copy_from_user(outbuf, (void *)arg + outtotal, taskout)) {
1493 int intotal = tasksize + taskout;
1494 inbuf = kmalloc(taskin, GFP_KERNEL);
1495 if (inbuf == NULL) {
1499 memset(inbuf, 0, taskin);
1500 if (copy_from_user(inbuf, (void *)arg + intotal , taskin)) {
1506 memset(&args, 0, sizeof(ide_task_t));
1507 memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
1508 memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE);
1510 args.tf_in_flags = req_task->in_flags;
1511 args.tf_out_flags = req_task->out_flags;
1512 args.data_phase = req_task->data_phase;
1513 args.command_type = req_task->req_cmd;
1515 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1516 DTF("%s: ide_ioctl_cmd %s: ide_task_cmd %s\n",
1518 ide_ioctl_verbose(cmd),
1519 ide_task_cmd_verbose(args.tfRegister[IDE_COMMAND_OFFSET]));
1520 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1522 drive->io_32bit = 0;
1523 switch(req_task->data_phase) {
1524 case TASKFILE_OUT_DMAQ:
1525 case TASKFILE_OUT_DMA:
1526 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1528 case TASKFILE_IN_DMAQ:
1529 case TASKFILE_IN_DMA:
1530 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1532 case TASKFILE_IN_OUT:
1534 args.prehandler = &pre_task_out_intr;
1535 args.handler = &task_out_intr;
1536 args.posthandler = NULL;
1537 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1538 args.prehandler = NULL;
1539 args.handler = &task_in_intr;
1540 args.posthandler = NULL;
1541 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1547 case TASKFILE_MULTI_OUT:
1548 if (!drive->mult_count) {
1549 /* (hs): give up if multcount is not set */
1550 printk("%s: %s Multimode Write " \
1551 "multcount is not set\n",
1552 drive->name, __FUNCTION__);
1556 if (args.tf_out_flags.all != 0) {
1557 args.prehandler = &flagged_pre_task_mulout_intr;
1558 args.handler = &flagged_task_mulout_intr;
1560 args.prehandler = &pre_task_mulout_intr;
1561 args.handler = &task_mulout_intr;
1563 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1566 if (args.tf_out_flags.all != 0) {
1567 args.prehandler = &flagged_pre_task_out_intr;
1568 args.handler = &flagged_task_out_intr;
1570 args.prehandler = &pre_task_out_intr;
1571 args.handler = &task_out_intr;
1573 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1575 case TASKFILE_MULTI_IN:
1576 if (!drive->mult_count) {
1577 /* (hs): give up if multcount is not set */
1578 printk("%s: %s Multimode Read failure " \
1579 "multcount is not set\n",
1580 drive->name, __FUNCTION__);
1584 if (args.tf_out_flags.all != 0) {
1585 args.handler = &flagged_task_mulin_intr;
1587 args.handler = &task_mulin_intr;
1589 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1592 if (args.tf_out_flags.all != 0) {
1593 args.handler = &flagged_task_in_intr;
1595 args.handler = &task_in_intr;
1597 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1599 case TASKFILE_NO_DATA:
1600 if (args.tf_out_flags.all != 0) {
1601 args.handler = &flagged_task_no_data_intr;
1603 args.handler = &task_no_data_intr;
1605 err = ide_diag_taskfile(drive, &args, 0, NULL);
1612 memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE);
1613 memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE);
1614 req_task->in_flags = args.tf_in_flags;
1615 req_task->out_flags = args.tf_out_flags;
1617 if (copy_to_user((void *)arg, req_task, tasksize)) {
1622 int outtotal = tasksize;
1623 if (copy_to_user((void *)arg+outtotal, outbuf, taskout)) {
1629 int intotal = tasksize + taskout;
1630 if (copy_to_user((void *)arg+intotal, inbuf, taskin)) {
1642 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
1644 drive->io_32bit = io_32bit;
1649 EXPORT_SYMBOL(ide_taskfile_ioctl);
1651 int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1658 memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors);
1659 ide_init_drive_cmd(&rq);
1665 return ide_do_drive_cmd(drive, &rq, ide_wait);
1668 EXPORT_SYMBOL(ide_wait_cmd);
1671 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1673 int ide_cmd_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1677 u8 args[4], *argbuf = args;
1682 if (NULL == (void *) arg) {
1684 ide_init_drive_cmd(&rq);
1685 return ide_do_drive_cmd(drive, &rq, ide_wait);
1688 if (copy_from_user(args, (void *)arg, 4))
1691 memset(&tfargs, 0, sizeof(ide_task_t));
1692 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
1693 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
1694 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
1695 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
1696 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
1697 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
1698 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
1701 argsize = 4 + (SECTOR_WORDS * 4 * args[3]);
1702 argbuf = kmalloc(argsize, GFP_KERNEL);
1705 memcpy(argbuf, args, 4);
1707 if (set_transfer(drive, &tfargs)) {
1708 xfer_rate = args[1];
1709 if (ide_ata66_check(drive, &tfargs))
1713 err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf);
1715 if (!err && xfer_rate) {
1716 /* active-retuning-calls future */
1717 ide_set_xfer_rate(drive, xfer_rate);
1718 ide_driveid_update(drive);
1721 if (copy_to_user((void *)arg, argbuf, argsize))
1730 u8 args[4], *argbuf = args;
1735 if (NULL == (void *) arg) {
1737 ide_init_drive_cmd(&rq);
1738 return ide_do_drive_cmd(drive, &rq, ide_wait);
1741 if (copy_from_user(args, (void *)arg, 4))
1744 memset(&tfargs, 0, sizeof(ide_task_t));
1745 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
1746 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
1747 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
1748 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
1749 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
1750 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
1751 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
1754 argsize = (SECTOR_WORDS * 4 * args[3]);
1755 argbuf = kmalloc(argsize, GFP_KERNEL);
1760 if (set_transfer(drive, &tfargs)) {
1761 xfer_rate = args[1];
1762 if (ide_ata66_check(drive, &tfargs))
1766 tfargs.command_type = ide_cmd_type_parser(&tfargs);
1767 err = ide_raw_taskfile(drive, &tfargs, argbuf);
1769 if (!err && xfer_rate) {
1770 /* active-retuning-calls future */
1771 ide_set_xfer_rate(drive, xfer_rate);
1772 ide_driveid_update(drive);
1775 args[0] = tfargs.tfRegister[IDE_COMMAND_OFFSET];
1776 args[1] = tfargs.tfRegister[IDE_FEATURE_OFFSET];
1777 args[2] = tfargs.tfRegister[IDE_NSECTOR_OFFSET];
1780 if (copy_to_user((void *)arg, argbuf, 4))
1782 if (argbuf != NULL) {
1783 if (copy_to_user((void *)arg, argbuf + 4, argsize))
1792 EXPORT_SYMBOL(ide_cmd_ioctl);
1794 int ide_wait_cmd_task (ide_drive_t *drive, u8 *buf)
1798 ide_init_drive_cmd(&rq);
1799 rq.cmd = IDE_DRIVE_TASK;
1801 return ide_do_drive_cmd(drive, &rq, ide_wait);
1804 EXPORT_SYMBOL(ide_wait_cmd_task);
1807 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1809 int ide_task_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1812 u8 args[7], *argbuf = args;
1815 if (copy_from_user(args, (void *)arg, 7))
1817 err = ide_wait_cmd_task(drive, argbuf);
1818 if (copy_to_user((void *)arg, argbuf, argsize))
1823 EXPORT_SYMBOL(ide_task_ioctl);
1826 * NOTICE: This is additions from IBM to provide a discrete interface,
1827 * for selective taskregister access operations. Nice JOB Klaus!!!
1828 * Glad to be able to work and co-develop this with you and IBM.
1830 ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task)
1832 ide_hwif_t *hwif = HWIF(drive);
1833 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
1834 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
1840 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1841 void debug_taskfile(drive, task);
1842 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1845 * (ks) Check taskfile in/out flags.
1846 * If set, then execute as it is defined.
1847 * If not set, then define default settings.
1848 * The default values are:
1849 * write and read all taskfile registers (except data)
1850 * write and read the hob registers (sector,nsector,lcyl,hcyl)
1852 if (task->tf_out_flags.all == 0) {
1853 task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS;
1854 if (drive->addressing == 1)
1855 task->tf_out_flags.all |= (IDE_HOB_STD_OUT_FLAGS << 8);
1858 if (task->tf_in_flags.all == 0) {
1859 task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
1860 if (drive->addressing == 1)
1861 task->tf_in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
1864 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
1865 if (IDE_CONTROL_REG)
1867 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
1868 SELECT_MASK(drive, 0);
1871 status = hwif->INB(IDE_STATUS_REG);
1872 if (status & 0x80) {
1873 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status);
1875 status = hwif->INB(IDE_STATUS_REG);
1876 printk("flagged_taskfile -> Status = %02x\n", status);
1880 if (task->tf_out_flags.b.data) {
1881 u16 data = taskfile->data + (hobfile->data << 8);
1882 hwif->OUTW(data, IDE_DATA_REG);
1885 /* (ks) send hob registers first */
1886 if (task->tf_out_flags.b.nsector_hob)
1887 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
1888 if (task->tf_out_flags.b.sector_hob)
1889 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
1890 if (task->tf_out_flags.b.lcyl_hob)
1891 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
1892 if (task->tf_out_flags.b.hcyl_hob)
1893 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
1895 /* (ks) Send now the standard registers */
1896 if (task->tf_out_flags.b.error_feature)
1897 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
1898 /* refers to number of sectors to transfer */
1899 if (task->tf_out_flags.b.nsector)
1900 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
1901 /* refers to sector offset or start sector */
1902 if (task->tf_out_flags.b.sector)
1903 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
1904 if (task->tf_out_flags.b.lcyl)
1905 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
1906 if (task->tf_out_flags.b.hcyl)
1907 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
1910 * (ks) In the flagged taskfile approch, we will used all specified
1911 * registers and the register value will not be changed. Except the
1912 * select bit (master/slave) in the drive_head register. We must make
1913 * sure that the desired drive is selected.
1915 hwif->OUTB(taskfile->device_head | drive->select.all, IDE_SELECT_REG);
1916 switch(task->data_phase) {
1918 case TASKFILE_OUT_DMAQ:
1919 case TASKFILE_OUT_DMA:
1920 hwif->ide_dma_write(drive);
1923 case TASKFILE_IN_DMAQ:
1924 case TASKFILE_IN_DMA:
1925 hwif->ide_dma_read(drive);
1929 if (task->handler == NULL)
1932 ide_set_handler(drive, task->handler, WAIT_WORSTCASE, NULL);
1933 /* Issue the command */
1934 hwif->OUTB(taskfile->command, IDE_COMMAND_REG);
1935 if (task->prehandler != NULL)
1936 return task->prehandler(drive, HWGROUP(drive)->rq);
1942 EXPORT_SYMBOL(flagged_taskfile);
1944 ide_startstop_t flagged_task_no_data_intr (ide_drive_t *drive)
1946 ide_hwif_t *hwif = HWIF(drive);
1951 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) {
1952 if (stat & ERR_STAT) {
1953 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr", stat);
1956 * (ks) Unexpected ATA data phase detected.
1957 * This should not happen. But, it can !
1958 * I am not sure, which function is best to clean up
1959 * this situation. I choose: ide_error(...)
1961 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr (unexpected phase)", stat);
1964 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
1970 * Handler for command with PIO data-in phase
1972 ide_startstop_t flagged_task_in_intr (ide_drive_t *drive)
1974 ide_hwif_t *hwif = HWIF(drive);
1975 u8 stat = hwif->INB(IDE_STATUS_REG);
1976 struct request *rq = HWGROUP(drive)->rq;
1980 if (rq->current_nr_sectors == 0)
1981 return DRIVER(drive)->error(drive, "flagged_task_in_intr (no data requested)", stat);
1983 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
1984 if (stat & ERR_STAT) {
1985 return DRIVER(drive)->error(drive, "flagged_task_in_intr", stat);
1988 * (ks) Unexpected ATA data phase detected.
1989 * This should not happen. But, it can !
1990 * I am not sure, which function is best to clean up
1991 * this situation. I choose: ide_error(...)
1993 return DRIVER(drive)->error(drive, "flagged_task_in_intr (unexpected data phase)", stat);
1996 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
1997 DTF("Read - rq->current_nr_sectors: %d, status: %02x\n", (int) rq->current_nr_sectors, stat);
1999 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
2001 if (--rq->current_nr_sectors != 0) {
2003 * (ks) We don't know which command was executed.
2004 * So, we wait the 'WORSTCASE' value.
2006 ide_set_handler(drive, &flagged_task_in_intr, WAIT_WORSTCASE, NULL);
2010 * (ks) Last sector was transfered, wait until drive is ready.
2011 * This can take up to 10 usec. We willl wait max 50 us.
2013 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
2015 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2020 ide_startstop_t flagged_task_mulin_intr (ide_drive_t *drive)
2022 ide_hwif_t *hwif = HWIF(drive);
2023 u8 stat = hwif->INB(IDE_STATUS_REG);
2024 struct request *rq = HWGROUP(drive)->rq;
2027 unsigned int msect, nsect;
2029 if (rq->current_nr_sectors == 0)
2030 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (no data requested)", stat);
2032 msect = drive->mult_count;
2034 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (multimode not set)", stat);
2036 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
2037 if (stat & ERR_STAT) {
2038 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr", stat);
2041 * (ks) Unexpected ATA data phase detected.
2042 * This should not happen. But, it can !
2043 * I am not sure, which function is best to clean up
2044 * this situation. I choose: ide_error(...)
2046 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (unexpected data phase)", stat);
2049 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
2050 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2052 DTF("Multiread: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
2053 pBuf, nsect, rq->current_nr_sectors);
2055 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
2057 rq->current_nr_sectors -= nsect;
2058 if (rq->current_nr_sectors != 0) {
2060 * (ks) We don't know which command was executed.
2061 * So, we wait the 'WORSTCASE' value.
2063 ide_set_handler(drive, &flagged_task_mulin_intr, WAIT_WORSTCASE, NULL);
2068 * (ks) Last sector was transfered, wait until drive is ready.
2069 * This can take up to 10 usec. We willl wait max 50 us.
2071 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
2073 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2079 * Pre handler for command with PIO data-out phase
2081 ide_startstop_t flagged_pre_task_out_intr (ide_drive_t *drive, struct request *rq)
2083 ide_hwif_t *hwif = HWIF(drive);
2084 u8 stat = hwif->INB(IDE_STATUS_REG);
2085 ide_startstop_t startstop;
2087 if (!rq->current_nr_sectors) {
2088 return DRIVER(drive)->error(drive, "flagged_pre_task_out_intr (write data not specified)", stat);
2091 if (ide_wait_stat(&startstop, drive, DATA_READY,
2092 BAD_W_STAT, WAIT_DRQ)) {
2093 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
2097 taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
2098 --rq->current_nr_sectors;
2103 ide_startstop_t flagged_task_out_intr (ide_drive_t *drive)
2105 ide_hwif_t *hwif = HWIF(drive);
2106 u8 stat = hwif->INB(IDE_STATUS_REG);
2107 struct request *rq = HWGROUP(drive)->rq;
2110 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
2111 return DRIVER(drive)->error(drive, "flagged_task_out_intr", stat);
2113 if (!rq->current_nr_sectors) {
2114 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2118 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
2120 * (ks) Unexpected ATA data phase detected.
2121 * This should not happen. But, it can !
2122 * I am not sure, which function is best to clean up
2123 * this situation. I choose: ide_error(...)
2125 return DRIVER(drive)->error(drive, "flagged_task_out_intr (unexpected data phase)", stat);
2128 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2129 DTF("Write - rq->current_nr_sectors: %d, status: %02x\n",
2130 (int) rq->current_nr_sectors, stat);
2132 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
2133 --rq->current_nr_sectors;
2136 * (ks) We don't know which command was executed.
2137 * So, we wait the 'WORSTCASE' value.
2139 ide_set_handler(drive, &flagged_task_out_intr, WAIT_WORSTCASE, NULL);
2144 ide_startstop_t flagged_pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
2146 ide_hwif_t *hwif = HWIF(drive);
2147 u8 stat = hwif->INB(IDE_STATUS_REG);
2149 ide_startstop_t startstop;
2150 unsigned int msect, nsect;
2152 if (!rq->current_nr_sectors)
2153 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (write data not specified)", stat);
2155 msect = drive->mult_count;
2157 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (multimode not set)", stat);
2159 if (ide_wait_stat(&startstop, drive, DATA_READY,
2160 BAD_W_STAT, WAIT_DRQ)) {
2161 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
2165 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
2166 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2167 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
2168 pBuf, nsect, rq->current_nr_sectors);
2170 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
2172 rq->current_nr_sectors -= nsect;
2177 ide_startstop_t flagged_task_mulout_intr (ide_drive_t *drive)
2179 ide_hwif_t *hwif = HWIF(drive);
2180 u8 stat = hwif->INB(IDE_STATUS_REG);
2181 struct request *rq = HWGROUP(drive)->rq;
2183 unsigned int msect, nsect;
2185 msect = drive->mult_count;
2187 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (multimode not set)", stat);
2189 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
2190 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr", stat);
2192 if (!rq->current_nr_sectors) {
2193 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2197 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
2199 * (ks) Unexpected ATA data phase detected.
2200 * This should not happen. But, it can !
2201 * I am not sure, which function is best to clean up
2202 * this situation. I choose: ide_error(...)
2204 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (unexpected data phase)", stat);
2207 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
2208 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2209 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
2210 pBuf, nsect, rq->current_nr_sectors);
2212 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
2213 rq->current_nr_sectors -= nsect;
2216 * (ks) We don't know which command was executed.
2217 * So, we wait the 'WORSTCASE' value.
2219 ide_set_handler(drive, &flagged_task_mulout_intr, WAIT_WORSTCASE, NULL);
2225 * Beginning of Taskfile OPCODE Library and feature sets.
2228 #ifdef CONFIG_PKT_TASK_IOCTL
2230 int pkt_taskfile_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2233 switch(req_task->data_phase) {
2234 case TASKFILE_P_OUT_DMAQ:
2235 case TASKFILE_P_IN_DMAQ:
2236 case TASKFILE_P_OUT_DMA:
2237 case TASKFILE_P_IN_DMA:
2238 case TASKFILE_P_OUT:
2245 EXPORT_SYMBOL(pkt_taskfile_ioctl);
2247 #endif /* CONFIG_PKT_TASK_IOCTL */