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 */
56 static void ata_bswap_data (void *buffer, int wcount)
61 *p = *p << 8 | *p >> 8; p++;
62 *p = *p << 8 | *p >> 8; p++;
67 void taskfile_input_data (ide_drive_t *drive, void *buffer, u32 wcount)
69 HWIF(drive)->ata_input_data(drive, buffer, wcount);
71 ata_bswap_data(buffer, wcount);
74 EXPORT_SYMBOL(taskfile_input_data);
76 void taskfile_output_data (ide_drive_t *drive, void *buffer, u32 wcount)
79 ata_bswap_data(buffer, wcount);
80 HWIF(drive)->ata_output_data(drive, buffer, wcount);
81 ata_bswap_data(buffer, wcount);
83 HWIF(drive)->ata_output_data(drive, buffer, wcount);
87 EXPORT_SYMBOL(taskfile_output_data);
89 int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
92 memset(&args, 0, sizeof(ide_task_t));
93 args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01;
94 if (drive->media == ide_disk)
95 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_IDENTIFY;
97 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_PIDENTIFY;
98 args.command_type = IDE_DRIVE_TASK_IN;
99 args.data_phase = TASKFILE_IN;
100 args.handler = &task_in_intr;
101 return ide_raw_taskfile(drive, &args, buf);
104 EXPORT_SYMBOL(taskfile_lib_get_identify);
106 ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
108 ide_hwif_t *hwif = HWIF(drive);
109 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
110 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
111 u8 HIHI = (drive->addressing == 1) ? 0xE0 : 0xEF;
113 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
114 if (IDE_CONTROL_REG) {
116 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
118 SELECT_MASK(drive, 0);
120 if (drive->addressing == 1) {
121 hwif->OUTB(hobfile->feature, IDE_FEATURE_REG);
122 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
123 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
124 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
125 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
128 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
129 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
130 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
131 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
132 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
134 hwif->OUTB((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG);
136 if (task->handler != NULL) {
137 if (task->prehandler != NULL) {
138 hwif->OUTBSYNC(drive, taskfile->command, IDE_COMMAND_REG);
139 ndelay(400); /* FIXME */
140 return task->prehandler(drive, task->rq);
142 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
146 if (!drive->using_dma)
149 switch (taskfile->command) {
150 case WIN_WRITEDMA_ONCE:
152 case WIN_WRITEDMA_EXT:
153 if (!hwif->ide_dma_write(drive))
156 case WIN_READDMA_ONCE:
158 case WIN_READDMA_EXT:
159 case WIN_IDENTIFY_DMA:
160 if (!hwif->ide_dma_read(drive))
164 if (task->handler == NULL)
171 EXPORT_SYMBOL(do_rw_taskfile);
174 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
176 ide_startstop_t set_multmode_intr (ide_drive_t *drive)
178 ide_hwif_t *hwif = HWIF(drive);
181 if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
182 drive->mult_count = drive->mult_req;
184 drive->mult_req = drive->mult_count = 0;
185 drive->special.b.recalibrate = 1;
186 (void) ide_dump_status(drive, "set_multmode", stat);
191 EXPORT_SYMBOL(set_multmode_intr);
194 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
196 ide_startstop_t set_geometry_intr (ide_drive_t *drive)
198 ide_hwif_t *hwif = HWIF(drive);
202 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
205 if (OK_STAT(stat, READY_STAT, BAD_STAT))
208 if (stat & (ERR_STAT|DRQ_STAT))
209 return DRIVER(drive)->error(drive, "set_geometry_intr", stat);
211 if (HWGROUP(drive)->handler != NULL)
213 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
217 EXPORT_SYMBOL(set_geometry_intr);
220 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
222 ide_startstop_t recal_intr (ide_drive_t *drive)
224 ide_hwif_t *hwif = HWIF(drive);
227 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT))
228 return DRIVER(drive)->error(drive, "recal_intr", stat);
232 EXPORT_SYMBOL(recal_intr);
235 * Handler for commands without a data phase
237 ide_startstop_t task_no_data_intr (ide_drive_t *drive)
239 ide_task_t *args = HWGROUP(drive)->rq->special;
240 ide_hwif_t *hwif = HWIF(drive);
244 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
245 return DRIVER(drive)->error(drive, "task_no_data_intr", stat);
246 /* calls ide_end_drive_cmd */
249 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
254 EXPORT_SYMBOL(task_no_data_intr);
256 static void task_buffer_sectors(ide_drive_t *drive, struct request *rq,
257 unsigned nsect, unsigned rw)
259 char *buf = rq->buffer + blk_rq_offset(rq);
262 rq->current_nr_sectors -= nsect;
263 rq->nr_sectors -= nsect;
264 __task_sectors(drive, buf, nsect, rw);
267 static inline void task_buffer_multi_sectors(ide_drive_t *drive,
268 struct request *rq, unsigned rw)
270 unsigned int msect = drive->mult_count, nsect;
272 nsect = rq->current_nr_sectors;
276 task_buffer_sectors(drive, rq, nsect, rw);
279 #ifdef CONFIG_IDE_TASKFILE_IO
280 static void task_sectors(ide_drive_t *drive, struct request *rq,
281 unsigned nsect, unsigned rw)
283 if (rq->cbio) { /* fs request */
285 task_bio_sectors(drive, rq, nsect, rw);
286 } else /* task request */
287 task_buffer_sectors(drive, rq, nsect, rw);
290 static inline void task_bio_multi_sectors(ide_drive_t *drive,
291 struct request *rq, unsigned rw)
293 unsigned int nsect, msect = drive->mult_count;
296 nsect = rq->current_nr_sectors;
300 task_bio_sectors(drive, rq, nsect, rw);
309 static void task_multi_sectors(ide_drive_t *drive,
310 struct request *rq, unsigned rw)
312 if (rq->cbio) { /* fs request */
314 task_bio_multi_sectors(drive, rq, rw);
315 } else /* task request */
316 task_buffer_multi_sectors(drive, rq, rw);
319 # define task_sectors(d, rq, nsect, rw) task_buffer_sectors(d, rq, nsect, rw)
320 # define task_multi_sectors(d, rq, rw) task_buffer_multi_sectors(d, rq, rw)
321 #endif /* CONFIG_IDE_TASKFILE_IO */
323 static u8 wait_drive_not_busy(ide_drive_t *drive)
325 ide_hwif_t *hwif = HWIF(drive);
330 * Last sector was transfered, wait until drive is ready.
331 * This can take up to 10 usec, but we will wait max 1 ms
332 * (drive_cmd_intr() waits that long).
334 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
338 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
343 static inline void ide_pio_datablock(ide_drive_t *drive, struct request *rq,
346 switch (drive->hwif->data_phase) {
347 case TASKFILE_MULTI_IN:
348 case TASKFILE_MULTI_OUT:
349 task_multi_sectors(drive, rq, write);
352 task_sectors(drive, rq, 1, write);
357 #ifdef CONFIG_IDE_TASKFILE_IO
358 static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
359 const char *s, u8 stat)
362 int sectors = rq->hard_nr_sectors - rq->nr_sectors;
364 switch (drive->hwif->data_phase) {
372 case TASKFILE_MULTI_IN:
376 case TASKFILE_MULTI_OUT:
377 sectors -= drive->mult_count;
383 drive->driver->end_request(drive, 1, sectors);
385 return drive->driver->error(drive, s, stat);
388 # define task_error(d, rq, s, stat) drive->driver->error(d, s, stat)
391 static void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
393 if (rq->flags & REQ_DRIVE_TASKFILE) {
394 ide_task_t *task = rq->special;
396 if (task->tf_out_flags.all) {
397 u8 err = drive->hwif->INB(IDE_ERROR_REG);
398 ide_end_drive_cmd(drive, stat, err);
402 drive->driver->end_request(drive, 1, rq->hard_nr_sectors);
406 * Handler for command with PIO data-in phase (Read/Read Multiple).
408 ide_startstop_t task_in_intr (ide_drive_t *drive)
410 struct request *rq = HWGROUP(drive)->rq;
411 u8 stat = HWIF(drive)->INB(IDE_STATUS_REG);
413 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
414 if (stat & (ERR_STAT | DRQ_STAT))
415 return task_error(drive, rq, __FUNCTION__, stat);
416 /* No data yet, so wait for another IRQ. */
417 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
421 ide_pio_datablock(drive, rq, 0);
423 /* If it was the last datablock check status and finish transfer. */
424 if (!rq->nr_sectors) {
425 stat = wait_drive_not_busy(drive);
426 if (!OK_STAT(stat, 0, BAD_R_STAT))
427 return task_error(drive, rq, __FUNCTION__, stat);
428 task_end_request(drive, rq, stat);
432 /* Still data left to transfer. */
433 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
437 EXPORT_SYMBOL(task_in_intr);
440 * Handler for command with PIO data-out phase (Write/Write Multiple).
442 ide_startstop_t task_out_intr (ide_drive_t *drive)
444 struct request *rq = HWGROUP(drive)->rq;
447 stat = HWIF(drive)->INB(IDE_STATUS_REG);
448 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
449 return task_error(drive, rq, __FUNCTION__, stat);
451 /* Deal with unexpected ATA data phase. */
452 if (((stat & DRQ_STAT) == 0) ^ !rq->nr_sectors)
453 return task_error(drive, rq, __FUNCTION__, stat);
455 if (!rq->nr_sectors) {
456 task_end_request(drive, rq, stat);
460 /* Still data left to transfer. */
461 ide_pio_datablock(drive, rq, 1);
462 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
467 EXPORT_SYMBOL(task_out_intr);
469 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
471 ide_startstop_t startstop;
473 if (ide_wait_stat(&startstop, drive, DATA_READY,
474 drive->bad_wstat, WAIT_DRQ)) {
475 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
477 drive->hwif->data_phase ? "MULT" : "",
478 drive->addressing ? "_EXT" : "");
485 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
486 ide_pio_datablock(drive, rq, 1);
490 EXPORT_SYMBOL(pre_task_out_intr);
492 int ide_diag_taskfile (ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf)
496 memset(&rq, 0, sizeof(rq));
497 rq.flags = REQ_DRIVE_TASKFILE;
501 * (ks) We transfer currently only whole sectors.
502 * This is suffient for now. But, it would be great,
503 * if we would find a solution to transfer any size.
504 * To support special commands like READ LONG.
506 if (args->command_type != IDE_DRIVE_TASK_NO_DATA) {
508 rq.nr_sectors = (args->hobRegister[IDE_NSECTOR_OFFSET] << 8) | args->tfRegister[IDE_NSECTOR_OFFSET];
510 rq.nr_sectors = data_size / SECTOR_SIZE;
512 if (!rq.nr_sectors) {
513 printk(KERN_ERR "%s: in/out command without data\n",
518 rq.hard_nr_sectors = rq.nr_sectors;
519 rq.hard_cur_sectors = rq.current_nr_sectors = rq.nr_sectors;
523 return ide_do_drive_cmd(drive, &rq, ide_wait);
526 EXPORT_SYMBOL(ide_diag_taskfile);
528 int ide_raw_taskfile (ide_drive_t *drive, ide_task_t *args, u8 *buf)
530 return ide_diag_taskfile(drive, args, 0, buf);
533 EXPORT_SYMBOL(ide_raw_taskfile);
535 #define MAX_DMA (256*SECTOR_WORDS)
537 ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
539 int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
541 ide_task_request_t *req_task;
545 task_ioreg_t *argsptr = args.tfRegister;
546 task_ioreg_t *hobsptr = args.hobRegister;
548 int tasksize = sizeof(struct ide_task_request_s);
551 u8 io_32bit = drive->io_32bit;
552 char __user *buf = (char __user *)arg;
554 // printk("IDE Taskfile ...\n");
556 req_task = kmalloc(tasksize, GFP_KERNEL);
557 if (req_task == NULL) return -ENOMEM;
558 memset(req_task, 0, tasksize);
559 if (copy_from_user(req_task, buf, tasksize)) {
564 taskout = (int) req_task->out_size;
565 taskin = (int) req_task->in_size;
568 int outtotal = tasksize;
569 outbuf = kmalloc(taskout, GFP_KERNEL);
570 if (outbuf == NULL) {
574 memset(outbuf, 0, taskout);
575 if (copy_from_user(outbuf, buf + outtotal, taskout)) {
582 int intotal = tasksize + taskout;
583 inbuf = kmalloc(taskin, GFP_KERNEL);
588 memset(inbuf, 0, taskin);
589 if (copy_from_user(inbuf, buf + intotal, taskin)) {
595 memset(&args, 0, sizeof(ide_task_t));
596 memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
597 memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE);
599 args.tf_in_flags = req_task->in_flags;
600 args.tf_out_flags = req_task->out_flags;
601 args.data_phase = req_task->data_phase;
602 args.command_type = req_task->req_cmd;
605 switch(req_task->data_phase) {
606 case TASKFILE_OUT_DMAQ:
607 case TASKFILE_OUT_DMA:
608 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
610 case TASKFILE_IN_DMAQ:
611 case TASKFILE_IN_DMA:
612 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
614 case TASKFILE_MULTI_OUT:
615 if (!drive->mult_count) {
616 /* (hs): give up if multcount is not set */
617 printk(KERN_ERR "%s: %s Multimode Write " \
618 "multcount is not set\n",
619 drive->name, __FUNCTION__);
625 args.prehandler = &pre_task_out_intr;
626 args.handler = &task_out_intr;
627 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
629 case TASKFILE_MULTI_IN:
630 if (!drive->mult_count) {
631 /* (hs): give up if multcount is not set */
632 printk(KERN_ERR "%s: %s Multimode Read failure " \
633 "multcount is not set\n",
634 drive->name, __FUNCTION__);
640 args.handler = &task_in_intr;
641 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
643 case TASKFILE_NO_DATA:
644 args.handler = &task_no_data_intr;
645 err = ide_diag_taskfile(drive, &args, 0, NULL);
652 memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE);
653 memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE);
654 req_task->in_flags = args.tf_in_flags;
655 req_task->out_flags = args.tf_out_flags;
657 if (copy_to_user(buf, req_task, tasksize)) {
662 int outtotal = tasksize;
663 if (copy_to_user(buf + outtotal, outbuf, taskout)) {
669 int intotal = tasksize + taskout;
670 if (copy_to_user(buf + intotal, inbuf, taskin)) {
682 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
684 drive->io_32bit = io_32bit;
689 EXPORT_SYMBOL(ide_taskfile_ioctl);
691 int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
698 memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors);
699 ide_init_drive_cmd(&rq);
705 return ide_do_drive_cmd(drive, &rq, ide_wait);
708 EXPORT_SYMBOL(ide_wait_cmd);
711 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
713 int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
716 u8 args[4], *argbuf = args;
721 if (NULL == (void *) arg) {
723 ide_init_drive_cmd(&rq);
724 return ide_do_drive_cmd(drive, &rq, ide_wait);
727 if (copy_from_user(args, (void __user *)arg, 4))
730 memset(&tfargs, 0, sizeof(ide_task_t));
731 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
732 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
733 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
734 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
735 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
736 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
737 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
740 argsize = 4 + (SECTOR_WORDS * 4 * args[3]);
741 argbuf = kmalloc(argsize, GFP_KERNEL);
744 memcpy(argbuf, args, 4);
746 if (set_transfer(drive, &tfargs)) {
748 if (ide_ata66_check(drive, &tfargs))
752 err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf);
754 if (!err && xfer_rate) {
755 /* active-retuning-calls future */
756 ide_set_xfer_rate(drive, xfer_rate);
757 ide_driveid_update(drive);
760 if (copy_to_user((void __user *)arg, argbuf, argsize))
767 EXPORT_SYMBOL(ide_cmd_ioctl);
769 int ide_wait_cmd_task (ide_drive_t *drive, u8 *buf)
773 ide_init_drive_cmd(&rq);
774 rq.flags = REQ_DRIVE_TASK;
776 return ide_do_drive_cmd(drive, &rq, ide_wait);
779 EXPORT_SYMBOL(ide_wait_cmd_task);
782 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
784 int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
786 void __user *p = (void __user *)arg;
788 u8 args[7], *argbuf = args;
791 if (copy_from_user(args, p, 7))
793 err = ide_wait_cmd_task(drive, argbuf);
794 if (copy_to_user(p, argbuf, argsize))
799 EXPORT_SYMBOL(ide_task_ioctl);
802 * NOTICE: This is additions from IBM to provide a discrete interface,
803 * for selective taskregister access operations. Nice JOB Klaus!!!
804 * Glad to be able to work and co-develop this with you and IBM.
806 ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task)
808 ide_hwif_t *hwif = HWIF(drive);
809 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
810 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
815 if (task->data_phase == TASKFILE_MULTI_IN ||
816 task->data_phase == TASKFILE_MULTI_OUT) {
817 if (!drive->mult_count) {
818 printk(KERN_ERR "%s: multimode not set!\n", drive->name);
824 * (ks) Check taskfile in/out flags.
825 * If set, then execute as it is defined.
826 * If not set, then define default settings.
827 * The default values are:
828 * write and read all taskfile registers (except data)
829 * write and read the hob registers (sector,nsector,lcyl,hcyl)
831 if (task->tf_out_flags.all == 0) {
832 task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS;
833 if (drive->addressing == 1)
834 task->tf_out_flags.all |= (IDE_HOB_STD_OUT_FLAGS << 8);
837 if (task->tf_in_flags.all == 0) {
838 task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
839 if (drive->addressing == 1)
840 task->tf_in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
843 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
846 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
847 SELECT_MASK(drive, 0);
850 status = hwif->INB(IDE_STATUS_REG);
852 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status);
854 status = hwif->INB(IDE_STATUS_REG);
855 printk("flagged_taskfile -> Status = %02x\n", status);
859 if (task->tf_out_flags.b.data) {
860 u16 data = taskfile->data + (hobfile->data << 8);
861 hwif->OUTW(data, IDE_DATA_REG);
864 /* (ks) send hob registers first */
865 if (task->tf_out_flags.b.nsector_hob)
866 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
867 if (task->tf_out_flags.b.sector_hob)
868 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
869 if (task->tf_out_flags.b.lcyl_hob)
870 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
871 if (task->tf_out_flags.b.hcyl_hob)
872 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
874 /* (ks) Send now the standard registers */
875 if (task->tf_out_flags.b.error_feature)
876 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
877 /* refers to number of sectors to transfer */
878 if (task->tf_out_flags.b.nsector)
879 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
880 /* refers to sector offset or start sector */
881 if (task->tf_out_flags.b.sector)
882 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
883 if (task->tf_out_flags.b.lcyl)
884 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
885 if (task->tf_out_flags.b.hcyl)
886 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
889 * (ks) In the flagged taskfile approch, we will used all specified
890 * registers and the register value will not be changed. Except the
891 * select bit (master/slave) in the drive_head register. We must make
892 * sure that the desired drive is selected.
894 hwif->OUTB(taskfile->device_head | drive->select.all, IDE_SELECT_REG);
895 switch(task->data_phase) {
897 case TASKFILE_OUT_DMAQ:
898 case TASKFILE_OUT_DMA:
899 hwif->ide_dma_write(drive);
902 case TASKFILE_IN_DMAQ:
903 case TASKFILE_IN_DMA:
904 hwif->ide_dma_read(drive);
908 if (task->handler == NULL)
911 /* Issue the command */
912 if (task->prehandler) {
913 hwif->OUTBSYNC(drive, taskfile->command, IDE_COMMAND_REG);
914 ndelay(400); /* FIXME */
915 return task->prehandler(drive, task->rq);
917 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
923 EXPORT_SYMBOL(flagged_taskfile);