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-2004 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>
47 #include <linux/bitops.h>
49 #include <asm/byteorder.h>
51 #include <asm/uaccess.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
++;
66 static void taskfile_input_data(ide_drive_t
*drive
, void *buffer
, u32 wcount
)
68 HWIF(drive
)->ata_input_data(drive
, buffer
, wcount
);
70 ata_bswap_data(buffer
, wcount
);
73 static void taskfile_output_data(ide_drive_t
*drive
, void *buffer
, u32 wcount
)
76 ata_bswap_data(buffer
, wcount
);
77 HWIF(drive
)->ata_output_data(drive
, buffer
, wcount
);
78 ata_bswap_data(buffer
, wcount
);
80 HWIF(drive
)->ata_output_data(drive
, buffer
, wcount
);
84 int taskfile_lib_get_identify (ide_drive_t
*drive
, u8
*buf
)
87 memset(&args
, 0, sizeof(ide_task_t
));
88 args
.tfRegister
[IDE_NSECTOR_OFFSET
] = 0x01;
89 if (drive
->media
== ide_disk
)
90 args
.tfRegister
[IDE_COMMAND_OFFSET
] = WIN_IDENTIFY
;
92 args
.tfRegister
[IDE_COMMAND_OFFSET
] = WIN_PIDENTIFY
;
93 args
.command_type
= IDE_DRIVE_TASK_IN
;
94 args
.data_phase
= TASKFILE_IN
;
95 args
.handler
= &task_in_intr
;
96 return ide_raw_taskfile(drive
, &args
, buf
);
99 ide_startstop_t
do_rw_taskfile (ide_drive_t
*drive
, ide_task_t
*task
)
101 ide_hwif_t
*hwif
= HWIF(drive
);
102 task_struct_t
*taskfile
= (task_struct_t
*) task
->tfRegister
;
103 hob_struct_t
*hobfile
= (hob_struct_t
*) task
->hobRegister
;
104 u8 HIHI
= (drive
->addressing
== 1) ? 0xE0 : 0xEF;
106 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
107 if (IDE_CONTROL_REG
) {
109 hwif
->OUTB(drive
->ctl
, IDE_CONTROL_REG
);
111 SELECT_MASK(drive
, 0);
113 if (drive
->addressing
== 1) {
114 hwif
->OUTB(hobfile
->feature
, IDE_FEATURE_REG
);
115 hwif
->OUTB(hobfile
->sector_count
, IDE_NSECTOR_REG
);
116 hwif
->OUTB(hobfile
->sector_number
, IDE_SECTOR_REG
);
117 hwif
->OUTB(hobfile
->low_cylinder
, IDE_LCYL_REG
);
118 hwif
->OUTB(hobfile
->high_cylinder
, IDE_HCYL_REG
);
121 hwif
->OUTB(taskfile
->feature
, IDE_FEATURE_REG
);
122 hwif
->OUTB(taskfile
->sector_count
, IDE_NSECTOR_REG
);
123 hwif
->OUTB(taskfile
->sector_number
, IDE_SECTOR_REG
);
124 hwif
->OUTB(taskfile
->low_cylinder
, IDE_LCYL_REG
);
125 hwif
->OUTB(taskfile
->high_cylinder
, IDE_HCYL_REG
);
127 hwif
->OUTB((taskfile
->device_head
& HIHI
) | drive
->select
.all
, IDE_SELECT_REG
);
129 if (task
->handler
!= NULL
) {
130 if (task
->prehandler
!= NULL
) {
131 hwif
->OUTBSYNC(drive
, taskfile
->command
, IDE_COMMAND_REG
);
132 ndelay(400); /* FIXME */
133 return task
->prehandler(drive
, task
->rq
);
135 ide_execute_command(drive
, taskfile
->command
, task
->handler
, WAIT_WORSTCASE
, NULL
);
139 if (!drive
->using_dma
)
142 switch (taskfile
->command
) {
143 case WIN_WRITEDMA_ONCE
:
145 case WIN_WRITEDMA_EXT
:
146 case WIN_READDMA_ONCE
:
148 case WIN_READDMA_EXT
:
149 case WIN_IDENTIFY_DMA
:
150 if (!hwif
->dma_setup(drive
)) {
151 hwif
->dma_exec_cmd(drive
, taskfile
->command
);
152 hwif
->dma_start(drive
);
157 if (task
->handler
== NULL
)
164 EXPORT_SYMBOL(do_rw_taskfile
);
167 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
169 ide_startstop_t
set_multmode_intr (ide_drive_t
*drive
)
171 ide_hwif_t
*hwif
= HWIF(drive
);
174 if (OK_STAT(stat
= hwif
->INB(IDE_STATUS_REG
),READY_STAT
,BAD_STAT
)) {
175 drive
->mult_count
= drive
->mult_req
;
177 drive
->mult_req
= drive
->mult_count
= 0;
178 drive
->special
.b
.recalibrate
= 1;
179 (void) ide_dump_status(drive
, "set_multmode", stat
);
185 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
187 ide_startstop_t
set_geometry_intr (ide_drive_t
*drive
)
189 ide_hwif_t
*hwif
= HWIF(drive
);
193 while (((stat
= hwif
->INB(IDE_STATUS_REG
)) & BUSY_STAT
) && retries
--)
196 if (OK_STAT(stat
, READY_STAT
, BAD_STAT
))
199 if (stat
& (ERR_STAT
|DRQ_STAT
))
200 return ide_error(drive
, "set_geometry_intr", stat
);
202 if (HWGROUP(drive
)->handler
!= NULL
)
204 ide_set_handler(drive
, &set_geometry_intr
, WAIT_WORSTCASE
, NULL
);
209 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
211 ide_startstop_t
recal_intr (ide_drive_t
*drive
)
213 ide_hwif_t
*hwif
= HWIF(drive
);
216 if (!OK_STAT(stat
= hwif
->INB(IDE_STATUS_REG
), READY_STAT
, BAD_STAT
))
217 return ide_error(drive
, "recal_intr", stat
);
222 * Handler for commands without a data phase
224 ide_startstop_t
task_no_data_intr (ide_drive_t
*drive
)
226 ide_task_t
*args
= HWGROUP(drive
)->rq
->special
;
227 ide_hwif_t
*hwif
= HWIF(drive
);
231 if (!OK_STAT(stat
= hwif
->INB(IDE_STATUS_REG
),READY_STAT
,BAD_STAT
)) {
232 return ide_error(drive
, "task_no_data_intr", stat
);
233 /* calls ide_end_drive_cmd */
236 ide_end_drive_cmd(drive
, stat
, hwif
->INB(IDE_ERROR_REG
));
241 EXPORT_SYMBOL(task_no_data_intr
);
243 static u8
wait_drive_not_busy(ide_drive_t
*drive
)
245 ide_hwif_t
*hwif
= HWIF(drive
);
250 * Last sector was transfered, wait until drive is ready.
251 * This can take up to 10 usec, but we will wait max 1 ms
252 * (drive_cmd_intr() waits that long).
254 while (((stat
= hwif
->INB(IDE_STATUS_REG
)) & BUSY_STAT
) && retries
--)
258 printk(KERN_ERR
"%s: drive still BUSY!\n", drive
->name
);
263 static void ide_pio_sector(ide_drive_t
*drive
, unsigned int write
)
265 ide_hwif_t
*hwif
= drive
->hwif
;
266 struct scatterlist
*sg
= hwif
->sg_table
;
268 #ifdef CONFIG_HIGHMEM
274 page
= sg
[hwif
->cursg
].page
;
275 offset
= sg
[hwif
->cursg
].offset
+ hwif
->cursg_ofs
* SECTOR_SIZE
;
277 /* get the current page and offset */
278 page
= nth_page(page
, (offset
>> PAGE_SHIFT
));
281 #ifdef CONFIG_HIGHMEM
282 local_irq_save(flags
);
284 buf
= kmap_atomic(page
, KM_BIO_SRC_IRQ
) + offset
;
289 if ((hwif
->cursg_ofs
* SECTOR_SIZE
) == sg
[hwif
->cursg
].length
) {
294 /* do the actual data transfer */
296 taskfile_output_data(drive
, buf
, SECTOR_WORDS
);
298 taskfile_input_data(drive
, buf
, SECTOR_WORDS
);
300 kunmap_atomic(buf
, KM_BIO_SRC_IRQ
);
301 #ifdef CONFIG_HIGHMEM
302 local_irq_restore(flags
);
306 static void ide_pio_multi(ide_drive_t
*drive
, unsigned int write
)
310 nsect
= min_t(unsigned int, drive
->hwif
->nleft
, drive
->mult_count
);
312 ide_pio_sector(drive
, write
);
315 static inline void ide_pio_datablock(ide_drive_t
*drive
, struct request
*rq
,
318 if (rq
->bio
) /* fs request */
321 switch (drive
->hwif
->data_phase
) {
322 case TASKFILE_MULTI_IN
:
323 case TASKFILE_MULTI_OUT
:
324 ide_pio_multi(drive
, write
);
327 ide_pio_sector(drive
, write
);
332 static ide_startstop_t
task_error(ide_drive_t
*drive
, struct request
*rq
,
333 const char *s
, u8 stat
)
336 ide_hwif_t
*hwif
= drive
->hwif
;
337 int sectors
= hwif
->nsect
- hwif
->nleft
;
339 switch (hwif
->data_phase
) {
347 case TASKFILE_MULTI_IN
:
351 case TASKFILE_MULTI_OUT
:
352 sectors
-= drive
->mult_count
;
360 drv
= *(ide_driver_t
**)rq
->rq_disk
->private_data
;
361 drv
->end_request(drive
, 1, sectors
);
364 return ide_error(drive
, s
, stat
);
367 static void task_end_request(ide_drive_t
*drive
, struct request
*rq
, u8 stat
)
369 if (rq
->flags
& REQ_DRIVE_TASKFILE
) {
370 ide_task_t
*task
= rq
->special
;
372 if (task
->tf_out_flags
.all
) {
373 u8 err
= drive
->hwif
->INB(IDE_ERROR_REG
);
374 ide_end_drive_cmd(drive
, stat
, err
);
379 ide_end_request(drive
, 1, rq
->hard_nr_sectors
);
383 * Handler for command with PIO data-in phase (Read/Read Multiple).
385 ide_startstop_t
task_in_intr (ide_drive_t
*drive
)
387 ide_hwif_t
*hwif
= drive
->hwif
;
388 struct request
*rq
= HWGROUP(drive
)->rq
;
389 u8 stat
= hwif
->INB(IDE_STATUS_REG
);
391 /* new way for dealing with premature shared PCI interrupts */
392 if (!OK_STAT(stat
, DATA_READY
, BAD_R_STAT
)) {
393 if (stat
& (ERR_STAT
| DRQ_STAT
))
394 return task_error(drive
, rq
, __FUNCTION__
, stat
);
395 /* No data yet, so wait for another IRQ. */
396 ide_set_handler(drive
, &task_in_intr
, WAIT_WORSTCASE
, NULL
);
400 ide_pio_datablock(drive
, rq
, 0);
402 /* If it was the last datablock check status and finish transfer. */
404 stat
= wait_drive_not_busy(drive
);
405 if (!OK_STAT(stat
, 0, BAD_R_STAT
))
406 return task_error(drive
, rq
, __FUNCTION__
, stat
);
407 task_end_request(drive
, rq
, stat
);
411 /* Still data left to transfer. */
412 ide_set_handler(drive
, &task_in_intr
, WAIT_WORSTCASE
, NULL
);
416 EXPORT_SYMBOL(task_in_intr
);
419 * Handler for command with PIO data-out phase (Write/Write Multiple).
421 static ide_startstop_t
task_out_intr (ide_drive_t
*drive
)
423 ide_hwif_t
*hwif
= drive
->hwif
;
424 struct request
*rq
= HWGROUP(drive
)->rq
;
425 u8 stat
= hwif
->INB(IDE_STATUS_REG
);
427 if (!OK_STAT(stat
, DRIVE_READY
, drive
->bad_wstat
))
428 return task_error(drive
, rq
, __FUNCTION__
, stat
);
430 /* Deal with unexpected ATA data phase. */
431 if (((stat
& DRQ_STAT
) == 0) ^ !hwif
->nleft
)
432 return task_error(drive
, rq
, __FUNCTION__
, stat
);
435 task_end_request(drive
, rq
, stat
);
439 /* Still data left to transfer. */
440 ide_pio_datablock(drive
, rq
, 1);
441 ide_set_handler(drive
, &task_out_intr
, WAIT_WORSTCASE
, NULL
);
446 ide_startstop_t
pre_task_out_intr (ide_drive_t
*drive
, struct request
*rq
)
448 ide_startstop_t startstop
;
450 if (ide_wait_stat(&startstop
, drive
, DATA_READY
,
451 drive
->bad_wstat
, WAIT_DRQ
)) {
452 printk(KERN_ERR
"%s: no DRQ after issuing %sWRITE%s\n",
454 drive
->hwif
->data_phase
? "MULT" : "",
455 drive
->addressing
? "_EXT" : "");
462 ide_set_handler(drive
, &task_out_intr
, WAIT_WORSTCASE
, NULL
);
463 ide_pio_datablock(drive
, rq
, 1);
467 EXPORT_SYMBOL(pre_task_out_intr
);
469 static int ide_diag_taskfile(ide_drive_t
*drive
, ide_task_t
*args
, unsigned long data_size
, u8
*buf
)
473 memset(&rq
, 0, sizeof(rq
));
474 rq
.flags
= REQ_DRIVE_TASKFILE
;
478 * (ks) We transfer currently only whole sectors.
479 * This is suffient for now. But, it would be great,
480 * if we would find a solution to transfer any size.
481 * To support special commands like READ LONG.
483 if (args
->command_type
!= IDE_DRIVE_TASK_NO_DATA
) {
485 rq
.nr_sectors
= (args
->hobRegister
[IDE_NSECTOR_OFFSET
] << 8) | args
->tfRegister
[IDE_NSECTOR_OFFSET
];
487 rq
.nr_sectors
= data_size
/ SECTOR_SIZE
;
489 if (!rq
.nr_sectors
) {
490 printk(KERN_ERR
"%s: in/out command without data\n",
495 rq
.hard_nr_sectors
= rq
.nr_sectors
;
496 rq
.hard_cur_sectors
= rq
.current_nr_sectors
= rq
.nr_sectors
;
498 if (args
->command_type
== IDE_DRIVE_TASK_RAW_WRITE
)
503 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
506 int ide_raw_taskfile (ide_drive_t
*drive
, ide_task_t
*args
, u8
*buf
)
508 return ide_diag_taskfile(drive
, args
, 0, buf
);
511 EXPORT_SYMBOL(ide_raw_taskfile
);
513 int ide_taskfile_ioctl (ide_drive_t
*drive
, unsigned int cmd
, unsigned long arg
)
515 ide_task_request_t
*req_task
;
519 task_ioreg_t
*argsptr
= args
.tfRegister
;
520 task_ioreg_t
*hobsptr
= args
.hobRegister
;
522 int tasksize
= sizeof(struct ide_task_request_s
);
525 u8 io_32bit
= drive
->io_32bit
;
526 char __user
*buf
= (char __user
*)arg
;
528 // printk("IDE Taskfile ...\n");
530 req_task
= kmalloc(tasksize
, GFP_KERNEL
);
531 if (req_task
== NULL
) return -ENOMEM
;
532 memset(req_task
, 0, tasksize
);
533 if (copy_from_user(req_task
, buf
, tasksize
)) {
538 taskout
= (int) req_task
->out_size
;
539 taskin
= (int) req_task
->in_size
;
542 int outtotal
= tasksize
;
543 outbuf
= kmalloc(taskout
, GFP_KERNEL
);
544 if (outbuf
== NULL
) {
548 memset(outbuf
, 0, taskout
);
549 if (copy_from_user(outbuf
, buf
+ outtotal
, taskout
)) {
556 int intotal
= tasksize
+ taskout
;
557 inbuf
= kmalloc(taskin
, GFP_KERNEL
);
562 memset(inbuf
, 0, taskin
);
563 if (copy_from_user(inbuf
, buf
+ intotal
, taskin
)) {
569 memset(&args
, 0, sizeof(ide_task_t
));
570 memcpy(argsptr
, req_task
->io_ports
, HDIO_DRIVE_TASK_HDR_SIZE
);
571 memcpy(hobsptr
, req_task
->hob_ports
, HDIO_DRIVE_HOB_HDR_SIZE
);
573 args
.tf_in_flags
= req_task
->in_flags
;
574 args
.tf_out_flags
= req_task
->out_flags
;
575 args
.data_phase
= req_task
->data_phase
;
576 args
.command_type
= req_task
->req_cmd
;
579 switch(req_task
->data_phase
) {
580 case TASKFILE_OUT_DMAQ
:
581 case TASKFILE_OUT_DMA
:
582 err
= ide_diag_taskfile(drive
, &args
, taskout
, outbuf
);
584 case TASKFILE_IN_DMAQ
:
585 case TASKFILE_IN_DMA
:
586 err
= ide_diag_taskfile(drive
, &args
, taskin
, inbuf
);
588 case TASKFILE_MULTI_OUT
:
589 if (!drive
->mult_count
) {
590 /* (hs): give up if multcount is not set */
591 printk(KERN_ERR
"%s: %s Multimode Write " \
592 "multcount is not set\n",
593 drive
->name
, __FUNCTION__
);
599 args
.prehandler
= &pre_task_out_intr
;
600 args
.handler
= &task_out_intr
;
601 err
= ide_diag_taskfile(drive
, &args
, taskout
, outbuf
);
603 case TASKFILE_MULTI_IN
:
604 if (!drive
->mult_count
) {
605 /* (hs): give up if multcount is not set */
606 printk(KERN_ERR
"%s: %s Multimode Read failure " \
607 "multcount is not set\n",
608 drive
->name
, __FUNCTION__
);
614 args
.handler
= &task_in_intr
;
615 err
= ide_diag_taskfile(drive
, &args
, taskin
, inbuf
);
617 case TASKFILE_NO_DATA
:
618 args
.handler
= &task_no_data_intr
;
619 err
= ide_diag_taskfile(drive
, &args
, 0, NULL
);
626 memcpy(req_task
->io_ports
, &(args
.tfRegister
), HDIO_DRIVE_TASK_HDR_SIZE
);
627 memcpy(req_task
->hob_ports
, &(args
.hobRegister
), HDIO_DRIVE_HOB_HDR_SIZE
);
628 req_task
->in_flags
= args
.tf_in_flags
;
629 req_task
->out_flags
= args
.tf_out_flags
;
631 if (copy_to_user(buf
, req_task
, tasksize
)) {
636 int outtotal
= tasksize
;
637 if (copy_to_user(buf
+ outtotal
, outbuf
, taskout
)) {
643 int intotal
= tasksize
+ taskout
;
644 if (copy_to_user(buf
+ intotal
, inbuf
, taskin
)) {
656 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
658 drive
->io_32bit
= io_32bit
;
663 int ide_wait_cmd (ide_drive_t
*drive
, u8 cmd
, u8 nsect
, u8 feature
, u8 sectors
, u8
*buf
)
670 memset(buf
, 0, 4 + SECTOR_WORDS
* 4 * sectors
);
671 ide_init_drive_cmd(&rq
);
677 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
681 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
683 int ide_cmd_ioctl (ide_drive_t
*drive
, unsigned int cmd
, unsigned long arg
)
686 u8 args
[4], *argbuf
= args
;
691 if (NULL
== (void *) arg
) {
693 ide_init_drive_cmd(&rq
);
694 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
697 if (copy_from_user(args
, (void __user
*)arg
, 4))
700 memset(&tfargs
, 0, sizeof(ide_task_t
));
701 tfargs
.tfRegister
[IDE_FEATURE_OFFSET
] = args
[2];
702 tfargs
.tfRegister
[IDE_NSECTOR_OFFSET
] = args
[3];
703 tfargs
.tfRegister
[IDE_SECTOR_OFFSET
] = args
[1];
704 tfargs
.tfRegister
[IDE_LCYL_OFFSET
] = 0x00;
705 tfargs
.tfRegister
[IDE_HCYL_OFFSET
] = 0x00;
706 tfargs
.tfRegister
[IDE_SELECT_OFFSET
] = 0x00;
707 tfargs
.tfRegister
[IDE_COMMAND_OFFSET
] = args
[0];
710 argsize
= 4 + (SECTOR_WORDS
* 4 * args
[3]);
711 argbuf
= kmalloc(argsize
, GFP_KERNEL
);
714 memcpy(argbuf
, args
, 4);
716 if (set_transfer(drive
, &tfargs
)) {
718 if (ide_ata66_check(drive
, &tfargs
))
722 err
= ide_wait_cmd(drive
, args
[0], args
[1], args
[2], args
[3], argbuf
);
724 if (!err
&& xfer_rate
) {
725 /* active-retuning-calls future */
726 ide_set_xfer_rate(drive
, xfer_rate
);
727 ide_driveid_update(drive
);
730 if (copy_to_user((void __user
*)arg
, argbuf
, argsize
))
737 static int ide_wait_cmd_task(ide_drive_t
*drive
, u8
*buf
)
741 ide_init_drive_cmd(&rq
);
742 rq
.flags
= REQ_DRIVE_TASK
;
744 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
748 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
750 int ide_task_ioctl (ide_drive_t
*drive
, unsigned int cmd
, unsigned long arg
)
752 void __user
*p
= (void __user
*)arg
;
754 u8 args
[7], *argbuf
= args
;
757 if (copy_from_user(args
, p
, 7))
759 err
= ide_wait_cmd_task(drive
, argbuf
);
760 if (copy_to_user(p
, argbuf
, argsize
))
766 * NOTICE: This is additions from IBM to provide a discrete interface,
767 * for selective taskregister access operations. Nice JOB Klaus!!!
768 * Glad to be able to work and co-develop this with you and IBM.
770 ide_startstop_t
flagged_taskfile (ide_drive_t
*drive
, ide_task_t
*task
)
772 ide_hwif_t
*hwif
= HWIF(drive
);
773 task_struct_t
*taskfile
= (task_struct_t
*) task
->tfRegister
;
774 hob_struct_t
*hobfile
= (hob_struct_t
*) task
->hobRegister
;
779 if (task
->data_phase
== TASKFILE_MULTI_IN
||
780 task
->data_phase
== TASKFILE_MULTI_OUT
) {
781 if (!drive
->mult_count
) {
782 printk(KERN_ERR
"%s: multimode not set!\n", drive
->name
);
788 * (ks) Check taskfile in/out flags.
789 * If set, then execute as it is defined.
790 * If not set, then define default settings.
791 * The default values are:
792 * write and read all taskfile registers (except data)
793 * write and read the hob registers (sector,nsector,lcyl,hcyl)
795 if (task
->tf_out_flags
.all
== 0) {
796 task
->tf_out_flags
.all
= IDE_TASKFILE_STD_OUT_FLAGS
;
797 if (drive
->addressing
== 1)
798 task
->tf_out_flags
.all
|= (IDE_HOB_STD_OUT_FLAGS
<< 8);
801 if (task
->tf_in_flags
.all
== 0) {
802 task
->tf_in_flags
.all
= IDE_TASKFILE_STD_IN_FLAGS
;
803 if (drive
->addressing
== 1)
804 task
->tf_in_flags
.all
|= (IDE_HOB_STD_IN_FLAGS
<< 8);
807 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
810 hwif
->OUTB(drive
->ctl
, IDE_CONTROL_REG
);
811 SELECT_MASK(drive
, 0);
814 status
= hwif
->INB(IDE_STATUS_REG
);
816 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status
);
818 status
= hwif
->INB(IDE_STATUS_REG
);
819 printk("flagged_taskfile -> Status = %02x\n", status
);
823 if (task
->tf_out_flags
.b
.data
) {
824 u16 data
= taskfile
->data
+ (hobfile
->data
<< 8);
825 hwif
->OUTW(data
, IDE_DATA_REG
);
828 /* (ks) send hob registers first */
829 if (task
->tf_out_flags
.b
.nsector_hob
)
830 hwif
->OUTB(hobfile
->sector_count
, IDE_NSECTOR_REG
);
831 if (task
->tf_out_flags
.b
.sector_hob
)
832 hwif
->OUTB(hobfile
->sector_number
, IDE_SECTOR_REG
);
833 if (task
->tf_out_flags
.b
.lcyl_hob
)
834 hwif
->OUTB(hobfile
->low_cylinder
, IDE_LCYL_REG
);
835 if (task
->tf_out_flags
.b
.hcyl_hob
)
836 hwif
->OUTB(hobfile
->high_cylinder
, IDE_HCYL_REG
);
838 /* (ks) Send now the standard registers */
839 if (task
->tf_out_flags
.b
.error_feature
)
840 hwif
->OUTB(taskfile
->feature
, IDE_FEATURE_REG
);
841 /* refers to number of sectors to transfer */
842 if (task
->tf_out_flags
.b
.nsector
)
843 hwif
->OUTB(taskfile
->sector_count
, IDE_NSECTOR_REG
);
844 /* refers to sector offset or start sector */
845 if (task
->tf_out_flags
.b
.sector
)
846 hwif
->OUTB(taskfile
->sector_number
, IDE_SECTOR_REG
);
847 if (task
->tf_out_flags
.b
.lcyl
)
848 hwif
->OUTB(taskfile
->low_cylinder
, IDE_LCYL_REG
);
849 if (task
->tf_out_flags
.b
.hcyl
)
850 hwif
->OUTB(taskfile
->high_cylinder
, IDE_HCYL_REG
);
853 * (ks) In the flagged taskfile approch, we will use all specified
854 * registers and the register value will not be changed, except the
855 * select bit (master/slave) in the drive_head register. We must make
856 * sure that the desired drive is selected.
858 hwif
->OUTB(taskfile
->device_head
| drive
->select
.all
, IDE_SELECT_REG
);
859 switch(task
->data_phase
) {
861 case TASKFILE_OUT_DMAQ
:
862 case TASKFILE_OUT_DMA
:
863 case TASKFILE_IN_DMAQ
:
864 case TASKFILE_IN_DMA
:
865 hwif
->dma_setup(drive
);
866 hwif
->dma_exec_cmd(drive
, taskfile
->command
);
867 hwif
->dma_start(drive
);
871 if (task
->handler
== NULL
)
874 /* Issue the command */
875 if (task
->prehandler
) {
876 hwif
->OUTBSYNC(drive
, taskfile
->command
, IDE_COMMAND_REG
);
877 ndelay(400); /* FIXME */
878 return task
->prehandler(drive
, task
->rq
);
880 ide_execute_command(drive
, taskfile
->command
, task
->handler
, WAIT_WORSTCASE
, NULL
);