2 * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org>
3 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
4 * Copyright (C) 2001-2002 Klaus Smolin
5 * IBM Storage Technology Division
6 * Copyright (C) 2003-2004, 2007 Bartlomiej Zolnierkiewicz
8 * The big the bad and the ugly.
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/string.h>
14 #include <linux/kernel.h>
15 #include <linux/timer.h>
17 #include <linux/sched.h>
18 #include <linux/interrupt.h>
19 #include <linux/major.h>
20 #include <linux/errno.h>
21 #include <linux/genhd.h>
22 #include <linux/blkpg.h>
23 #include <linux/slab.h>
24 #include <linux/pci.h>
25 #include <linux/delay.h>
26 #include <linux/hdreg.h>
27 #include <linux/ide.h>
28 #include <linux/bitops.h>
29 #include <linux/scatterlist.h>
31 #include <asm/byteorder.h>
33 #include <asm/uaccess.h>
36 void ide_tf_load(ide_drive_t
*drive
, ide_task_t
*task
)
38 ide_hwif_t
*hwif
= drive
->hwif
;
39 struct ide_taskfile
*tf
= &task
->tf
;
40 u8 HIHI
= (task
->tf_flags
& IDE_TFLAG_LBA48
) ? 0xE0 : 0xEF;
42 if (task
->tf_flags
& IDE_TFLAG_FLAGGED
)
46 printk("%s: tf: feat 0x%02x nsect 0x%02x lbal 0x%02x "
47 "lbam 0x%02x lbah 0x%02x dev 0x%02x cmd 0x%02x\n",
48 drive
->name
, tf
->feature
, tf
->nsect
, tf
->lbal
,
49 tf
->lbam
, tf
->lbah
, tf
->device
, tf
->command
);
50 printk("%s: hob: nsect 0x%02x lbal 0x%02x "
51 "lbam 0x%02x lbah 0x%02x\n",
52 drive
->name
, tf
->hob_nsect
, tf
->hob_lbal
,
53 tf
->hob_lbam
, tf
->hob_lbah
);
56 ide_set_irq(drive
, 1);
58 if ((task
->tf_flags
& IDE_TFLAG_NO_SELECT_MASK
) == 0)
59 SELECT_MASK(drive
, 0);
61 if (task
->tf_flags
& IDE_TFLAG_OUT_DATA
)
62 hwif
->OUTW((tf
->hob_data
<< 8) | tf
->data
,
63 hwif
->io_ports
[IDE_DATA_OFFSET
]);
65 if (task
->tf_flags
& IDE_TFLAG_OUT_HOB_FEATURE
)
66 hwif
->OUTB(tf
->hob_feature
, hwif
->io_ports
[IDE_FEATURE_OFFSET
]);
67 if (task
->tf_flags
& IDE_TFLAG_OUT_HOB_NSECT
)
68 hwif
->OUTB(tf
->hob_nsect
, hwif
->io_ports
[IDE_NSECTOR_OFFSET
]);
69 if (task
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAL
)
70 hwif
->OUTB(tf
->hob_lbal
, hwif
->io_ports
[IDE_SECTOR_OFFSET
]);
71 if (task
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAM
)
72 hwif
->OUTB(tf
->hob_lbam
, hwif
->io_ports
[IDE_LCYL_OFFSET
]);
73 if (task
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAH
)
74 hwif
->OUTB(tf
->hob_lbah
, hwif
->io_ports
[IDE_HCYL_OFFSET
]);
76 if (task
->tf_flags
& IDE_TFLAG_OUT_FEATURE
)
77 hwif
->OUTB(tf
->feature
, hwif
->io_ports
[IDE_FEATURE_OFFSET
]);
78 if (task
->tf_flags
& IDE_TFLAG_OUT_NSECT
)
79 hwif
->OUTB(tf
->nsect
, hwif
->io_ports
[IDE_NSECTOR_OFFSET
]);
80 if (task
->tf_flags
& IDE_TFLAG_OUT_LBAL
)
81 hwif
->OUTB(tf
->lbal
, hwif
->io_ports
[IDE_SECTOR_OFFSET
]);
82 if (task
->tf_flags
& IDE_TFLAG_OUT_LBAM
)
83 hwif
->OUTB(tf
->lbam
, hwif
->io_ports
[IDE_LCYL_OFFSET
]);
84 if (task
->tf_flags
& IDE_TFLAG_OUT_LBAH
)
85 hwif
->OUTB(tf
->lbah
, hwif
->io_ports
[IDE_HCYL_OFFSET
]);
87 if (task
->tf_flags
& IDE_TFLAG_OUT_DEVICE
)
88 hwif
->OUTB((tf
->device
& HIHI
) | drive
->select
.all
,
89 hwif
->io_ports
[IDE_SELECT_OFFSET
]);
92 int taskfile_lib_get_identify (ide_drive_t
*drive
, u8
*buf
)
96 memset(&args
, 0, sizeof(ide_task_t
));
98 if (drive
->media
== ide_disk
)
99 args
.tf
.command
= WIN_IDENTIFY
;
101 args
.tf
.command
= WIN_PIDENTIFY
;
102 args
.tf_flags
= IDE_TFLAG_TF
| IDE_TFLAG_DEVICE
;
103 args
.data_phase
= TASKFILE_IN
;
104 return ide_raw_taskfile(drive
, &args
, buf
, 1);
107 static int inline task_dma_ok(ide_task_t
*task
)
109 if (blk_fs_request(task
->rq
) || (task
->tf_flags
& IDE_TFLAG_FLAGGED
))
112 switch (task
->tf
.command
) {
113 case WIN_WRITEDMA_ONCE
:
115 case WIN_WRITEDMA_EXT
:
116 case WIN_READDMA_ONCE
:
118 case WIN_READDMA_EXT
:
119 case WIN_IDENTIFY_DMA
:
126 static ide_startstop_t
task_no_data_intr(ide_drive_t
*);
127 static ide_startstop_t
set_geometry_intr(ide_drive_t
*);
128 static ide_startstop_t
recal_intr(ide_drive_t
*);
129 static ide_startstop_t
set_multmode_intr(ide_drive_t
*);
130 static ide_startstop_t
pre_task_out_intr(ide_drive_t
*, struct request
*);
131 static ide_startstop_t
task_in_intr(ide_drive_t
*);
133 ide_startstop_t
do_rw_taskfile (ide_drive_t
*drive
, ide_task_t
*task
)
135 ide_hwif_t
*hwif
= HWIF(drive
);
136 struct ide_taskfile
*tf
= &task
->tf
;
137 ide_handler_t
*handler
= NULL
;
138 const struct ide_dma_ops
*dma_ops
= hwif
->dma_ops
;
140 if (task
->data_phase
== TASKFILE_MULTI_IN
||
141 task
->data_phase
== TASKFILE_MULTI_OUT
) {
142 if (!drive
->mult_count
) {
143 printk(KERN_ERR
"%s: multimode not set!\n",
149 if (task
->tf_flags
& IDE_TFLAG_FLAGGED
)
150 task
->tf_flags
|= IDE_TFLAG_FLAGGED_SET_IN_FLAGS
;
152 if ((task
->tf_flags
& IDE_TFLAG_DMA_PIO_FALLBACK
) == 0)
153 ide_tf_load(drive
, task
);
155 switch (task
->data_phase
) {
156 case TASKFILE_MULTI_OUT
:
158 hwif
->OUTBSYNC(drive
, tf
->command
,
159 hwif
->io_ports
[IDE_COMMAND_OFFSET
]);
160 ndelay(400); /* FIXME */
161 return pre_task_out_intr(drive
, task
->rq
);
162 case TASKFILE_MULTI_IN
:
164 handler
= task_in_intr
;
166 case TASKFILE_NO_DATA
:
168 handler
= task_no_data_intr
;
169 /* WIN_{SPECIFY,RESTORE,SETMULT} use custom handlers */
170 if (task
->tf_flags
& IDE_TFLAG_CUSTOM_HANDLER
) {
171 switch (tf
->command
) {
172 case WIN_SPECIFY
: handler
= set_geometry_intr
; break;
173 case WIN_RESTORE
: handler
= recal_intr
; break;
174 case WIN_SETMULT
: handler
= set_multmode_intr
; break;
177 ide_execute_command(drive
, tf
->command
, handler
,
178 WAIT_WORSTCASE
, NULL
);
181 if (task_dma_ok(task
) == 0 || drive
->using_dma
== 0 ||
182 dma_ops
->dma_setup(drive
))
184 dma_ops
->dma_exec_cmd(drive
, tf
->command
);
185 dma_ops
->dma_start(drive
);
189 EXPORT_SYMBOL_GPL(do_rw_taskfile
);
192 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
194 static ide_startstop_t
set_multmode_intr(ide_drive_t
*drive
)
196 u8 stat
= ide_read_status(drive
);
198 if (OK_STAT(stat
, READY_STAT
, BAD_STAT
))
199 drive
->mult_count
= drive
->mult_req
;
201 drive
->mult_req
= drive
->mult_count
= 0;
202 drive
->special
.b
.recalibrate
= 1;
203 (void) ide_dump_status(drive
, "set_multmode", stat
);
209 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
211 static ide_startstop_t
set_geometry_intr(ide_drive_t
*drive
)
216 while (((stat
= ide_read_status(drive
)) & BUSY_STAT
) && retries
--)
219 if (OK_STAT(stat
, READY_STAT
, BAD_STAT
))
222 if (stat
& (ERR_STAT
|DRQ_STAT
))
223 return ide_error(drive
, "set_geometry_intr", stat
);
225 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
226 ide_set_handler(drive
, &set_geometry_intr
, WAIT_WORSTCASE
, NULL
);
231 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
233 static ide_startstop_t
recal_intr(ide_drive_t
*drive
)
235 u8 stat
= ide_read_status(drive
);
237 if (!OK_STAT(stat
, READY_STAT
, BAD_STAT
))
238 return ide_error(drive
, "recal_intr", stat
);
243 * Handler for commands without a data phase
245 static ide_startstop_t
task_no_data_intr(ide_drive_t
*drive
)
247 ide_task_t
*args
= HWGROUP(drive
)->rq
->special
;
250 local_irq_enable_in_hardirq();
251 stat
= ide_read_status(drive
);
253 if (!OK_STAT(stat
, READY_STAT
, BAD_STAT
))
254 return ide_error(drive
, "task_no_data_intr", stat
);
255 /* calls ide_end_drive_cmd */
258 ide_end_drive_cmd(drive
, stat
, ide_read_error(drive
));
263 static u8
wait_drive_not_busy(ide_drive_t
*drive
)
269 * Last sector was transfered, wait until drive is ready.
270 * This can take up to 10 usec, but we will wait max 1 ms.
272 for (retries
= 0; retries
< 100; retries
++) {
273 stat
= ide_read_status(drive
);
275 if (stat
& BUSY_STAT
)
281 if (stat
& BUSY_STAT
)
282 printk(KERN_ERR
"%s: drive still BUSY!\n", drive
->name
);
287 static void ide_pio_sector(ide_drive_t
*drive
, unsigned int write
)
289 ide_hwif_t
*hwif
= drive
->hwif
;
290 struct scatterlist
*sg
= hwif
->sg_table
;
291 struct scatterlist
*cursg
= hwif
->cursg
;
293 #ifdef CONFIG_HIGHMEM
305 page
= sg_page(cursg
);
306 offset
= cursg
->offset
+ hwif
->cursg_ofs
* SECTOR_SIZE
;
308 /* get the current page and offset */
309 page
= nth_page(page
, (offset
>> PAGE_SHIFT
));
312 #ifdef CONFIG_HIGHMEM
313 local_irq_save(flags
);
315 buf
= kmap_atomic(page
, KM_BIO_SRC_IRQ
) + offset
;
320 if ((hwif
->cursg_ofs
* SECTOR_SIZE
) == cursg
->length
) {
321 hwif
->cursg
= sg_next(hwif
->cursg
);
325 /* do the actual data transfer */
327 hwif
->ata_output_data(drive
, buf
, SECTOR_WORDS
);
329 hwif
->ata_input_data(drive
, buf
, SECTOR_WORDS
);
331 kunmap_atomic(buf
, KM_BIO_SRC_IRQ
);
332 #ifdef CONFIG_HIGHMEM
333 local_irq_restore(flags
);
337 static void ide_pio_multi(ide_drive_t
*drive
, unsigned int write
)
341 nsect
= min_t(unsigned int, drive
->hwif
->nleft
, drive
->mult_count
);
343 ide_pio_sector(drive
, write
);
346 static void ide_pio_datablock(ide_drive_t
*drive
, struct request
*rq
,
349 u8 saved_io_32bit
= drive
->io_32bit
;
351 if (rq
->bio
) /* fs request */
354 if (rq
->cmd_type
== REQ_TYPE_ATA_TASKFILE
) {
355 ide_task_t
*task
= rq
->special
;
357 if (task
->tf_flags
& IDE_TFLAG_IO_16BIT
)
361 touch_softlockup_watchdog();
363 switch (drive
->hwif
->data_phase
) {
364 case TASKFILE_MULTI_IN
:
365 case TASKFILE_MULTI_OUT
:
366 ide_pio_multi(drive
, write
);
369 ide_pio_sector(drive
, write
);
373 drive
->io_32bit
= saved_io_32bit
;
376 static ide_startstop_t
task_error(ide_drive_t
*drive
, struct request
*rq
,
377 const char *s
, u8 stat
)
380 ide_hwif_t
*hwif
= drive
->hwif
;
381 int sectors
= hwif
->nsect
- hwif
->nleft
;
383 switch (hwif
->data_phase
) {
391 case TASKFILE_MULTI_IN
:
395 case TASKFILE_MULTI_OUT
:
396 sectors
-= drive
->mult_count
;
404 drv
= *(ide_driver_t
**)rq
->rq_disk
->private_data
;
405 drv
->end_request(drive
, 1, sectors
);
408 return ide_error(drive
, s
, stat
);
411 void task_end_request(ide_drive_t
*drive
, struct request
*rq
, u8 stat
)
413 if (rq
->cmd_type
== REQ_TYPE_ATA_TASKFILE
) {
414 u8 err
= ide_read_error(drive
);
416 ide_end_drive_cmd(drive
, stat
, err
);
423 drv
= *(ide_driver_t
**)rq
->rq_disk
->private_data
;;
424 drv
->end_request(drive
, 1, rq
->nr_sectors
);
426 ide_end_request(drive
, 1, rq
->nr_sectors
);
430 * We got an interrupt on a task_in case, but no errors and no DRQ.
432 * It might be a spurious irq (shared irq), but it might be a
433 * command that had no output.
435 static ide_startstop_t
task_in_unexpected(ide_drive_t
*drive
, struct request
*rq
, u8 stat
)
437 /* Command all done? */
438 if (OK_STAT(stat
, READY_STAT
, BUSY_STAT
)) {
439 task_end_request(drive
, rq
, stat
);
443 /* Assume it was a spurious irq */
444 ide_set_handler(drive
, &task_in_intr
, WAIT_WORSTCASE
, NULL
);
449 * Handler for command with PIO data-in phase (Read/Read Multiple).
451 static ide_startstop_t
task_in_intr(ide_drive_t
*drive
)
453 ide_hwif_t
*hwif
= drive
->hwif
;
454 struct request
*rq
= HWGROUP(drive
)->rq
;
455 u8 stat
= ide_read_status(drive
);
459 return task_error(drive
, rq
, __func__
, stat
);
461 /* Didn't want any data? Odd. */
462 if (!(stat
& DRQ_STAT
))
463 return task_in_unexpected(drive
, rq
, stat
);
465 ide_pio_datablock(drive
, rq
, 0);
467 /* Are we done? Check status and finish transfer. */
469 stat
= wait_drive_not_busy(drive
);
470 if (!OK_STAT(stat
, 0, BAD_STAT
))
471 return task_error(drive
, rq
, __func__
, stat
);
472 task_end_request(drive
, rq
, stat
);
476 /* Still data left to transfer. */
477 ide_set_handler(drive
, &task_in_intr
, WAIT_WORSTCASE
, NULL
);
483 * Handler for command with PIO data-out phase (Write/Write Multiple).
485 static ide_startstop_t
task_out_intr (ide_drive_t
*drive
)
487 ide_hwif_t
*hwif
= drive
->hwif
;
488 struct request
*rq
= HWGROUP(drive
)->rq
;
489 u8 stat
= ide_read_status(drive
);
491 if (!OK_STAT(stat
, DRIVE_READY
, drive
->bad_wstat
))
492 return task_error(drive
, rq
, __func__
, stat
);
494 /* Deal with unexpected ATA data phase. */
495 if (((stat
& DRQ_STAT
) == 0) ^ !hwif
->nleft
)
496 return task_error(drive
, rq
, __func__
, stat
);
499 task_end_request(drive
, rq
, stat
);
503 /* Still data left to transfer. */
504 ide_pio_datablock(drive
, rq
, 1);
505 ide_set_handler(drive
, &task_out_intr
, WAIT_WORSTCASE
, NULL
);
510 static ide_startstop_t
pre_task_out_intr(ide_drive_t
*drive
, struct request
*rq
)
512 ide_startstop_t startstop
;
514 if (ide_wait_stat(&startstop
, drive
, DRQ_STAT
,
515 drive
->bad_wstat
, WAIT_DRQ
)) {
516 printk(KERN_ERR
"%s: no DRQ after issuing %sWRITE%s\n",
518 drive
->hwif
->data_phase
? "MULT" : "",
519 drive
->addressing
? "_EXT" : "");
526 ide_set_handler(drive
, &task_out_intr
, WAIT_WORSTCASE
, NULL
);
527 ide_pio_datablock(drive
, rq
, 1);
532 int ide_raw_taskfile(ide_drive_t
*drive
, ide_task_t
*task
, u8
*buf
, u16 nsect
)
536 memset(&rq
, 0, sizeof(rq
));
538 rq
.cmd_type
= REQ_TYPE_ATA_TASKFILE
;
542 * (ks) We transfer currently only whole sectors.
543 * This is suffient for now. But, it would be great,
544 * if we would find a solution to transfer any size.
545 * To support special commands like READ LONG.
547 rq
.hard_nr_sectors
= rq
.nr_sectors
= nsect
;
548 rq
.hard_cur_sectors
= rq
.current_nr_sectors
= nsect
;
550 if (task
->tf_flags
& IDE_TFLAG_WRITE
)
551 rq
.cmd_flags
|= REQ_RW
;
556 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
559 EXPORT_SYMBOL(ide_raw_taskfile
);
561 int ide_no_data_taskfile(ide_drive_t
*drive
, ide_task_t
*task
)
563 task
->data_phase
= TASKFILE_NO_DATA
;
565 return ide_raw_taskfile(drive
, task
, NULL
, 0);
567 EXPORT_SYMBOL_GPL(ide_no_data_taskfile
);
569 #ifdef CONFIG_IDE_TASK_IOCTL
570 int ide_taskfile_ioctl (ide_drive_t
*drive
, unsigned int cmd
, unsigned long arg
)
572 ide_task_request_t
*req_task
;
578 int tasksize
= sizeof(struct ide_task_request_s
);
579 unsigned int taskin
= 0;
580 unsigned int taskout
= 0;
582 char __user
*buf
= (char __user
*)arg
;
584 // printk("IDE Taskfile ...\n");
586 req_task
= kzalloc(tasksize
, GFP_KERNEL
);
587 if (req_task
== NULL
) return -ENOMEM
;
588 if (copy_from_user(req_task
, buf
, tasksize
)) {
593 taskout
= req_task
->out_size
;
594 taskin
= req_task
->in_size
;
596 if (taskin
> 65536 || taskout
> 65536) {
602 int outtotal
= tasksize
;
603 outbuf
= kzalloc(taskout
, GFP_KERNEL
);
604 if (outbuf
== NULL
) {
608 if (copy_from_user(outbuf
, buf
+ outtotal
, taskout
)) {
615 int intotal
= tasksize
+ taskout
;
616 inbuf
= kzalloc(taskin
, GFP_KERNEL
);
621 if (copy_from_user(inbuf
, buf
+ intotal
, taskin
)) {
627 memset(&args
, 0, sizeof(ide_task_t
));
629 memcpy(&args
.tf_array
[0], req_task
->hob_ports
, HDIO_DRIVE_HOB_HDR_SIZE
- 2);
630 memcpy(&args
.tf_array
[6], req_task
->io_ports
, HDIO_DRIVE_TASK_HDR_SIZE
);
632 args
.data_phase
= req_task
->data_phase
;
634 args
.tf_flags
= IDE_TFLAG_IO_16BIT
| IDE_TFLAG_DEVICE
|
636 if (drive
->addressing
== 1)
637 args
.tf_flags
|= (IDE_TFLAG_LBA48
| IDE_TFLAG_IN_HOB
);
639 if (req_task
->out_flags
.all
) {
640 args
.tf_flags
|= IDE_TFLAG_FLAGGED
;
642 if (req_task
->out_flags
.b
.data
)
643 args
.tf_flags
|= IDE_TFLAG_OUT_DATA
;
645 if (req_task
->out_flags
.b
.nsector_hob
)
646 args
.tf_flags
|= IDE_TFLAG_OUT_HOB_NSECT
;
647 if (req_task
->out_flags
.b
.sector_hob
)
648 args
.tf_flags
|= IDE_TFLAG_OUT_HOB_LBAL
;
649 if (req_task
->out_flags
.b
.lcyl_hob
)
650 args
.tf_flags
|= IDE_TFLAG_OUT_HOB_LBAM
;
651 if (req_task
->out_flags
.b
.hcyl_hob
)
652 args
.tf_flags
|= IDE_TFLAG_OUT_HOB_LBAH
;
654 if (req_task
->out_flags
.b
.error_feature
)
655 args
.tf_flags
|= IDE_TFLAG_OUT_FEATURE
;
656 if (req_task
->out_flags
.b
.nsector
)
657 args
.tf_flags
|= IDE_TFLAG_OUT_NSECT
;
658 if (req_task
->out_flags
.b
.sector
)
659 args
.tf_flags
|= IDE_TFLAG_OUT_LBAL
;
660 if (req_task
->out_flags
.b
.lcyl
)
661 args
.tf_flags
|= IDE_TFLAG_OUT_LBAM
;
662 if (req_task
->out_flags
.b
.hcyl
)
663 args
.tf_flags
|= IDE_TFLAG_OUT_LBAH
;
665 args
.tf_flags
|= IDE_TFLAG_OUT_TF
;
666 if (args
.tf_flags
& IDE_TFLAG_LBA48
)
667 args
.tf_flags
|= IDE_TFLAG_OUT_HOB
;
670 if (req_task
->in_flags
.b
.data
)
671 args
.tf_flags
|= IDE_TFLAG_IN_DATA
;
673 switch(req_task
->data_phase
) {
674 case TASKFILE_MULTI_OUT
:
675 if (!drive
->mult_count
) {
676 /* (hs): give up if multcount is not set */
677 printk(KERN_ERR
"%s: %s Multimode Write " \
678 "multcount is not set\n",
679 drive
->name
, __func__
);
686 case TASKFILE_OUT_DMAQ
:
687 case TASKFILE_OUT_DMA
:
688 nsect
= taskout
/ SECTOR_SIZE
;
691 case TASKFILE_MULTI_IN
:
692 if (!drive
->mult_count
) {
693 /* (hs): give up if multcount is not set */
694 printk(KERN_ERR
"%s: %s Multimode Read failure " \
695 "multcount is not set\n",
696 drive
->name
, __func__
);
703 case TASKFILE_IN_DMAQ
:
704 case TASKFILE_IN_DMA
:
705 nsect
= taskin
/ SECTOR_SIZE
;
708 case TASKFILE_NO_DATA
:
715 if (req_task
->req_cmd
== IDE_DRIVE_TASK_NO_DATA
)
718 nsect
= (args
.tf
.hob_nsect
<< 8) | args
.tf
.nsect
;
721 printk(KERN_ERR
"%s: in/out command without data\n",
728 if (req_task
->req_cmd
== IDE_DRIVE_TASK_RAW_WRITE
)
729 args
.tf_flags
|= IDE_TFLAG_WRITE
;
731 err
= ide_raw_taskfile(drive
, &args
, data_buf
, nsect
);
733 memcpy(req_task
->hob_ports
, &args
.tf_array
[0], HDIO_DRIVE_HOB_HDR_SIZE
- 2);
734 memcpy(req_task
->io_ports
, &args
.tf_array
[6], HDIO_DRIVE_TASK_HDR_SIZE
);
736 if ((args
.tf_flags
& IDE_TFLAG_FLAGGED_SET_IN_FLAGS
) &&
737 req_task
->in_flags
.all
== 0) {
738 req_task
->in_flags
.all
= IDE_TASKFILE_STD_IN_FLAGS
;
739 if (drive
->addressing
== 1)
740 req_task
->in_flags
.all
|= (IDE_HOB_STD_IN_FLAGS
<< 8);
743 if (copy_to_user(buf
, req_task
, tasksize
)) {
748 int outtotal
= tasksize
;
749 if (copy_to_user(buf
+ outtotal
, outbuf
, taskout
)) {
755 int intotal
= tasksize
+ taskout
;
756 if (copy_to_user(buf
+ intotal
, inbuf
, taskin
)) {
766 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
772 int ide_cmd_ioctl (ide_drive_t
*drive
, unsigned int cmd
, unsigned long arg
)
775 int bufsize
= 0, err
= 0;
776 u8 args
[4], xfer_rate
= 0;
778 struct ide_taskfile
*tf
= &tfargs
.tf
;
779 struct hd_driveid
*id
= drive
->id
;
781 if (NULL
== (void *) arg
) {
784 ide_init_drive_cmd(&rq
);
785 rq
.cmd_type
= REQ_TYPE_ATA_TASKFILE
;
787 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
790 if (copy_from_user(args
, (void __user
*)arg
, 4))
793 memset(&tfargs
, 0, sizeof(ide_task_t
));
794 tf
->feature
= args
[2];
795 if (args
[0] == WIN_SMART
) {
800 tfargs
.tf_flags
= IDE_TFLAG_OUT_TF
| IDE_TFLAG_IN_NSECT
;
803 tfargs
.tf_flags
= IDE_TFLAG_OUT_FEATURE
|
804 IDE_TFLAG_OUT_NSECT
| IDE_TFLAG_IN_NSECT
;
806 tf
->command
= args
[0];
807 tfargs
.data_phase
= args
[3] ? TASKFILE_IN
: TASKFILE_NO_DATA
;
810 tfargs
.tf_flags
|= IDE_TFLAG_IO_16BIT
;
811 bufsize
= SECTOR_WORDS
* 4 * args
[3];
812 buf
= kzalloc(bufsize
, GFP_KERNEL
);
817 if (tf
->command
== WIN_SETFEATURES
&&
818 tf
->feature
== SETFEATURES_XFER
&&
819 tf
->nsect
>= XFER_SW_DMA_0
&&
820 (id
->dma_ultra
|| id
->dma_mword
|| id
->dma_1word
)) {
822 if (tf
->nsect
> XFER_UDMA_2
&& !eighty_ninty_three(drive
)) {
823 printk(KERN_WARNING
"%s: UDMA speeds >UDMA33 cannot "
824 "be set\n", drive
->name
);
829 err
= ide_raw_taskfile(drive
, &tfargs
, buf
, args
[3]);
831 args
[0] = tf
->status
;
835 if (!err
&& xfer_rate
) {
836 /* active-retuning-calls future */
837 ide_set_xfer_rate(drive
, xfer_rate
);
838 ide_driveid_update(drive
);
841 if (copy_to_user((void __user
*)arg
, &args
, 4))
844 if (copy_to_user((void __user
*)(arg
+ 4), buf
, bufsize
))
851 int ide_task_ioctl (ide_drive_t
*drive
, unsigned int cmd
, unsigned long arg
)
853 void __user
*p
= (void __user
*)arg
;
858 if (copy_from_user(args
, p
, 7))
861 memset(&task
, 0, sizeof(task
));
862 memcpy(&task
.tf_array
[7], &args
[1], 6);
863 task
.tf
.command
= args
[0];
864 task
.tf_flags
= IDE_TFLAG_TF
| IDE_TFLAG_DEVICE
;
866 err
= ide_no_data_taskfile(drive
, &task
);
868 args
[0] = task
.tf
.command
;
869 memcpy(&args
[1], &task
.tf_array
[7], 6);
871 if (copy_to_user(p
, args
, 7))