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;
139 if (task->data_phase == TASKFILE_MULTI_IN ||
140 task->data_phase == TASKFILE_MULTI_OUT) {
141 if (!drive->mult_count) {
142 printk(KERN_ERR "%s: multimode not set!\n",
148 if (task->tf_flags & IDE_TFLAG_FLAGGED)
149 task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS;
151 if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0)
152 ide_tf_load(drive, task);
154 switch (task->data_phase) {
155 case TASKFILE_MULTI_OUT:
157 hwif->OUTBSYNC(drive, tf->command,
158 hwif->io_ports[IDE_COMMAND_OFFSET]);
159 ndelay(400); /* FIXME */
160 return pre_task_out_intr(drive, task->rq);
161 case TASKFILE_MULTI_IN:
163 handler = task_in_intr;
165 case TASKFILE_NO_DATA:
167 handler = task_no_data_intr;
168 /* WIN_{SPECIFY,RESTORE,SETMULT} use custom handlers */
169 if (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) {
170 switch (tf->command) {
171 case WIN_SPECIFY: handler = set_geometry_intr; break;
172 case WIN_RESTORE: handler = recal_intr; break;
173 case WIN_SETMULT: handler = set_multmode_intr; break;
176 ide_execute_command(drive, tf->command, handler,
177 WAIT_WORSTCASE, NULL);
180 if (task_dma_ok(task) == 0 || drive->using_dma == 0 ||
181 hwif->dma_setup(drive))
183 hwif->dma_exec_cmd(drive, tf->command);
184 hwif->dma_start(drive);
188 EXPORT_SYMBOL_GPL(do_rw_taskfile);
191 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
193 static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
195 u8 stat = ide_read_status(drive);
197 if (OK_STAT(stat, READY_STAT, BAD_STAT))
198 drive->mult_count = drive->mult_req;
200 drive->mult_req = drive->mult_count = 0;
201 drive->special.b.recalibrate = 1;
202 (void) ide_dump_status(drive, "set_multmode", stat);
208 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
210 static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
215 while (((stat = ide_read_status(drive)) & BUSY_STAT) && retries--)
218 if (OK_STAT(stat, READY_STAT, BAD_STAT))
221 if (stat & (ERR_STAT|DRQ_STAT))
222 return ide_error(drive, "set_geometry_intr", stat);
224 BUG_ON(HWGROUP(drive)->handler != NULL);
225 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
230 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
232 static ide_startstop_t recal_intr(ide_drive_t *drive)
234 u8 stat = ide_read_status(drive);
236 if (!OK_STAT(stat, READY_STAT, BAD_STAT))
237 return ide_error(drive, "recal_intr", stat);
242 * Handler for commands without a data phase
244 static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
246 ide_task_t *args = HWGROUP(drive)->rq->special;
249 local_irq_enable_in_hardirq();
250 stat = ide_read_status(drive);
252 if (!OK_STAT(stat, READY_STAT, BAD_STAT))
253 return ide_error(drive, "task_no_data_intr", stat);
254 /* calls ide_end_drive_cmd */
257 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
262 static u8 wait_drive_not_busy(ide_drive_t *drive)
268 * Last sector was transfered, wait until drive is ready.
269 * This can take up to 10 usec, but we will wait max 1 ms.
271 for (retries = 0; retries < 100; retries++) {
272 stat = ide_read_status(drive);
274 if (stat & BUSY_STAT)
280 if (stat & BUSY_STAT)
281 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
286 static void ide_pio_sector(ide_drive_t *drive, unsigned int write)
288 ide_hwif_t *hwif = drive->hwif;
289 struct scatterlist *sg = hwif->sg_table;
290 struct scatterlist *cursg = hwif->cursg;
292 #ifdef CONFIG_HIGHMEM
304 page = sg_page(cursg);
305 offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE;
307 /* get the current page and offset */
308 page = nth_page(page, (offset >> PAGE_SHIFT));
311 #ifdef CONFIG_HIGHMEM
312 local_irq_save(flags);
314 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
319 if ((hwif->cursg_ofs * SECTOR_SIZE) == cursg->length) {
320 hwif->cursg = sg_next(hwif->cursg);
324 /* do the actual data transfer */
326 hwif->ata_output_data(drive, buf, SECTOR_WORDS);
328 hwif->ata_input_data(drive, buf, SECTOR_WORDS);
330 kunmap_atomic(buf, KM_BIO_SRC_IRQ);
331 #ifdef CONFIG_HIGHMEM
332 local_irq_restore(flags);
336 static void ide_pio_multi(ide_drive_t *drive, unsigned int write)
340 nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count);
342 ide_pio_sector(drive, write);
345 static void ide_pio_datablock(ide_drive_t *drive, struct request *rq,
348 u8 saved_io_32bit = drive->io_32bit;
350 if (rq->bio) /* fs request */
353 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
354 ide_task_t *task = rq->special;
356 if (task->tf_flags & IDE_TFLAG_IO_16BIT)
360 touch_softlockup_watchdog();
362 switch (drive->hwif->data_phase) {
363 case TASKFILE_MULTI_IN:
364 case TASKFILE_MULTI_OUT:
365 ide_pio_multi(drive, write);
368 ide_pio_sector(drive, write);
372 drive->io_32bit = saved_io_32bit;
375 static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
376 const char *s, u8 stat)
379 ide_hwif_t *hwif = drive->hwif;
380 int sectors = hwif->nsect - hwif->nleft;
382 switch (hwif->data_phase) {
390 case TASKFILE_MULTI_IN:
394 case TASKFILE_MULTI_OUT:
395 sectors -= drive->mult_count;
403 drv = *(ide_driver_t **)rq->rq_disk->private_data;
404 drv->end_request(drive, 1, sectors);
407 return ide_error(drive, s, stat);
410 void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
412 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
413 u8 err = ide_read_error(drive);
415 ide_end_drive_cmd(drive, stat, err);
422 drv = *(ide_driver_t **)rq->rq_disk->private_data;;
423 drv->end_request(drive, 1, rq->nr_sectors);
425 ide_end_request(drive, 1, rq->nr_sectors);
429 * We got an interrupt on a task_in case, but no errors and no DRQ.
431 * It might be a spurious irq (shared irq), but it might be a
432 * command that had no output.
434 static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
436 /* Command all done? */
437 if (OK_STAT(stat, READY_STAT, BUSY_STAT)) {
438 task_end_request(drive, rq, stat);
442 /* Assume it was a spurious irq */
443 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
448 * Handler for command with PIO data-in phase (Read/Read Multiple).
450 static ide_startstop_t task_in_intr(ide_drive_t *drive)
452 ide_hwif_t *hwif = drive->hwif;
453 struct request *rq = HWGROUP(drive)->rq;
454 u8 stat = ide_read_status(drive);
458 return task_error(drive, rq, __func__, stat);
460 /* Didn't want any data? Odd. */
461 if (!(stat & DRQ_STAT))
462 return task_in_unexpected(drive, rq, stat);
464 ide_pio_datablock(drive, rq, 0);
466 /* Are we done? Check status and finish transfer. */
468 stat = wait_drive_not_busy(drive);
469 if (!OK_STAT(stat, 0, BAD_STAT))
470 return task_error(drive, rq, __func__, stat);
471 task_end_request(drive, rq, stat);
475 /* Still data left to transfer. */
476 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
482 * Handler for command with PIO data-out phase (Write/Write Multiple).
484 static ide_startstop_t task_out_intr (ide_drive_t *drive)
486 ide_hwif_t *hwif = drive->hwif;
487 struct request *rq = HWGROUP(drive)->rq;
488 u8 stat = ide_read_status(drive);
490 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
491 return task_error(drive, rq, __func__, stat);
493 /* Deal with unexpected ATA data phase. */
494 if (((stat & DRQ_STAT) == 0) ^ !hwif->nleft)
495 return task_error(drive, rq, __func__, stat);
498 task_end_request(drive, rq, stat);
502 /* Still data left to transfer. */
503 ide_pio_datablock(drive, rq, 1);
504 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
509 static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
511 ide_startstop_t startstop;
513 if (ide_wait_stat(&startstop, drive, DRQ_STAT,
514 drive->bad_wstat, WAIT_DRQ)) {
515 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
517 drive->hwif->data_phase ? "MULT" : "",
518 drive->addressing ? "_EXT" : "");
525 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
526 ide_pio_datablock(drive, rq, 1);
531 int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect)
535 memset(&rq, 0, sizeof(rq));
537 rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
541 * (ks) We transfer currently only whole sectors.
542 * This is suffient for now. But, it would be great,
543 * if we would find a solution to transfer any size.
544 * To support special commands like READ LONG.
546 rq.hard_nr_sectors = rq.nr_sectors = nsect;
547 rq.hard_cur_sectors = rq.current_nr_sectors = nsect;
549 if (task->tf_flags & IDE_TFLAG_WRITE)
550 rq.cmd_flags |= REQ_RW;
555 return ide_do_drive_cmd(drive, &rq, ide_wait);
558 EXPORT_SYMBOL(ide_raw_taskfile);
560 int ide_no_data_taskfile(ide_drive_t *drive, ide_task_t *task)
562 task->data_phase = TASKFILE_NO_DATA;
564 return ide_raw_taskfile(drive, task, NULL, 0);
566 EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
568 #ifdef CONFIG_IDE_TASK_IOCTL
569 int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
571 ide_task_request_t *req_task;
577 int tasksize = sizeof(struct ide_task_request_s);
578 unsigned int taskin = 0;
579 unsigned int taskout = 0;
581 char __user *buf = (char __user *)arg;
583 // printk("IDE Taskfile ...\n");
585 req_task = kzalloc(tasksize, GFP_KERNEL);
586 if (req_task == NULL) return -ENOMEM;
587 if (copy_from_user(req_task, buf, tasksize)) {
592 taskout = req_task->out_size;
593 taskin = req_task->in_size;
595 if (taskin > 65536 || taskout > 65536) {
601 int outtotal = tasksize;
602 outbuf = kzalloc(taskout, GFP_KERNEL);
603 if (outbuf == NULL) {
607 if (copy_from_user(outbuf, buf + outtotal, taskout)) {
614 int intotal = tasksize + taskout;
615 inbuf = kzalloc(taskin, GFP_KERNEL);
620 if (copy_from_user(inbuf, buf + intotal, taskin)) {
626 memset(&args, 0, sizeof(ide_task_t));
628 memcpy(&args.tf_array[0], req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE - 2);
629 memcpy(&args.tf_array[6], req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
631 args.data_phase = req_task->data_phase;
633 args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
635 if (drive->addressing == 1)
636 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
638 if (req_task->out_flags.all) {
639 args.tf_flags |= IDE_TFLAG_FLAGGED;
641 if (req_task->out_flags.b.data)
642 args.tf_flags |= IDE_TFLAG_OUT_DATA;
644 if (req_task->out_flags.b.nsector_hob)
645 args.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT;
646 if (req_task->out_flags.b.sector_hob)
647 args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL;
648 if (req_task->out_flags.b.lcyl_hob)
649 args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM;
650 if (req_task->out_flags.b.hcyl_hob)
651 args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH;
653 if (req_task->out_flags.b.error_feature)
654 args.tf_flags |= IDE_TFLAG_OUT_FEATURE;
655 if (req_task->out_flags.b.nsector)
656 args.tf_flags |= IDE_TFLAG_OUT_NSECT;
657 if (req_task->out_flags.b.sector)
658 args.tf_flags |= IDE_TFLAG_OUT_LBAL;
659 if (req_task->out_flags.b.lcyl)
660 args.tf_flags |= IDE_TFLAG_OUT_LBAM;
661 if (req_task->out_flags.b.hcyl)
662 args.tf_flags |= IDE_TFLAG_OUT_LBAH;
664 args.tf_flags |= IDE_TFLAG_OUT_TF;
665 if (args.tf_flags & IDE_TFLAG_LBA48)
666 args.tf_flags |= IDE_TFLAG_OUT_HOB;
669 if (req_task->in_flags.b.data)
670 args.tf_flags |= IDE_TFLAG_IN_DATA;
672 switch(req_task->data_phase) {
673 case TASKFILE_MULTI_OUT:
674 if (!drive->mult_count) {
675 /* (hs): give up if multcount is not set */
676 printk(KERN_ERR "%s: %s Multimode Write " \
677 "multcount is not set\n",
678 drive->name, __func__);
685 case TASKFILE_OUT_DMAQ:
686 case TASKFILE_OUT_DMA:
687 nsect = taskout / SECTOR_SIZE;
690 case TASKFILE_MULTI_IN:
691 if (!drive->mult_count) {
692 /* (hs): give up if multcount is not set */
693 printk(KERN_ERR "%s: %s Multimode Read failure " \
694 "multcount is not set\n",
695 drive->name, __func__);
702 case TASKFILE_IN_DMAQ:
703 case TASKFILE_IN_DMA:
704 nsect = taskin / SECTOR_SIZE;
707 case TASKFILE_NO_DATA:
714 if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
717 nsect = (args.tf.hob_nsect << 8) | args.tf.nsect;
720 printk(KERN_ERR "%s: in/out command without data\n",
727 if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE)
728 args.tf_flags |= IDE_TFLAG_WRITE;
730 err = ide_raw_taskfile(drive, &args, data_buf, nsect);
732 memcpy(req_task->hob_ports, &args.tf_array[0], HDIO_DRIVE_HOB_HDR_SIZE - 2);
733 memcpy(req_task->io_ports, &args.tf_array[6], HDIO_DRIVE_TASK_HDR_SIZE);
735 if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) &&
736 req_task->in_flags.all == 0) {
737 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
738 if (drive->addressing == 1)
739 req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
742 if (copy_to_user(buf, req_task, tasksize)) {
747 int outtotal = tasksize;
748 if (copy_to_user(buf + outtotal, outbuf, taskout)) {
754 int intotal = tasksize + taskout;
755 if (copy_to_user(buf + intotal, inbuf, taskin)) {
765 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
771 int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
774 int bufsize = 0, err = 0;
775 u8 args[4], xfer_rate = 0;
777 struct ide_taskfile *tf = &tfargs.tf;
778 struct hd_driveid *id = drive->id;
780 if (NULL == (void *) arg) {
783 ide_init_drive_cmd(&rq);
784 rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
786 return ide_do_drive_cmd(drive, &rq, ide_wait);
789 if (copy_from_user(args, (void __user *)arg, 4))
792 memset(&tfargs, 0, sizeof(ide_task_t));
793 tf->feature = args[2];
794 if (args[0] == WIN_SMART) {
799 tfargs.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_IN_NSECT;
802 tfargs.tf_flags = IDE_TFLAG_OUT_FEATURE |
803 IDE_TFLAG_OUT_NSECT | IDE_TFLAG_IN_NSECT;
805 tf->command = args[0];
806 tfargs.data_phase = args[3] ? TASKFILE_IN : TASKFILE_NO_DATA;
809 tfargs.tf_flags |= IDE_TFLAG_IO_16BIT;
810 bufsize = SECTOR_WORDS * 4 * args[3];
811 buf = kzalloc(bufsize, GFP_KERNEL);
816 if (tf->command == WIN_SETFEATURES &&
817 tf->feature == SETFEATURES_XFER &&
818 tf->nsect >= XFER_SW_DMA_0 &&
819 (id->dma_ultra || id->dma_mword || id->dma_1word)) {
821 if (tf->nsect > XFER_UDMA_2 && !eighty_ninty_three(drive)) {
822 printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
823 "be set\n", drive->name);
828 err = ide_raw_taskfile(drive, &tfargs, buf, args[3]);
830 args[0] = tf->status;
834 if (!err && xfer_rate) {
835 /* active-retuning-calls future */
836 ide_set_xfer_rate(drive, xfer_rate);
837 ide_driveid_update(drive);
840 if (copy_to_user((void __user *)arg, &args, 4))
843 if (copy_to_user((void __user *)(arg + 4), buf, bufsize))
850 int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
852 void __user *p = (void __user *)arg;
857 if (copy_from_user(args, p, 7))
860 memset(&task, 0, sizeof(task));
861 memcpy(&task.tf_array[7], &args[1], 6);
862 task.tf.command = args[0];
863 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
865 err = ide_no_data_taskfile(drive, &task);
867 args[0] = task.tf.command;
868 memcpy(&args[1], &task.tf_array[7], 6);
870 if (copy_to_user(p, args, 7))