47f13cd11031a36dfec07a84e05836437d475319
[linux-3.10.git] / drivers / ide / ide-taskfile.c
1 /*
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
7  *
8  *  The big the bad and the ugly.
9  */
10
11 #include <linux/types.h>
12 #include <linux/string.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/interrupt.h>
16 #include <linux/errno.h>
17 #include <linux/slab.h>
18 #include <linux/delay.h>
19 #include <linux/hdreg.h>
20 #include <linux/ide.h>
21 #include <linux/scatterlist.h>
22
23 #include <asm/uaccess.h>
24 #include <asm/io.h>
25
26 void ide_tf_dump(const char *s, struct ide_taskfile *tf)
27 {
28 #ifdef DEBUG
29         printk("%s: tf: feat 0x%02x nsect 0x%02x lbal 0x%02x "
30                 "lbam 0x%02x lbah 0x%02x dev 0x%02x cmd 0x%02x\n",
31                 s, tf->feature, tf->nsect, tf->lbal,
32                 tf->lbam, tf->lbah, tf->device, tf->command);
33         printk("%s: hob: nsect 0x%02x lbal 0x%02x "
34                 "lbam 0x%02x lbah 0x%02x\n",
35                 s, tf->hob_nsect, tf->hob_lbal,
36                 tf->hob_lbam, tf->hob_lbah);
37 #endif
38 }
39
40 int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
41 {
42         struct ide_cmd cmd;
43
44         memset(&cmd, 0, sizeof(cmd));
45         cmd.tf.nsect = 0x01;
46         if (drive->media == ide_disk)
47                 cmd.tf.command = ATA_CMD_ID_ATA;
48         else
49                 cmd.tf.command = ATA_CMD_ID_ATAPI;
50         cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
51         cmd.protocol = ATA_PROT_PIO;
52
53         return ide_raw_taskfile(drive, &cmd, buf, 1);
54 }
55
56 static ide_startstop_t task_no_data_intr(ide_drive_t *);
57 static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct ide_cmd *);
58 static ide_startstop_t task_pio_intr(ide_drive_t *);
59
60 ide_startstop_t do_rw_taskfile(ide_drive_t *drive, struct ide_cmd *orig_cmd)
61 {
62         ide_hwif_t *hwif = drive->hwif;
63         struct ide_cmd *cmd = &hwif->cmd;
64         struct ide_taskfile *tf = &cmd->tf;
65         ide_handler_t *handler = NULL;
66         const struct ide_tp_ops *tp_ops = hwif->tp_ops;
67         const struct ide_dma_ops *dma_ops = hwif->dma_ops;
68
69         if (orig_cmd->protocol == ATA_PROT_PIO &&
70             (orig_cmd->tf_flags & IDE_TFLAG_MULTI_PIO) &&
71             drive->mult_count == 0) {
72                 printk(KERN_ERR "%s: multimode not set!\n", drive->name);
73                 return ide_stopped;
74         }
75
76         if (orig_cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
77                 orig_cmd->ftf_flags |= IDE_FTFLAG_SET_IN_FLAGS;
78
79         memcpy(cmd, orig_cmd, sizeof(*cmd));
80
81         if ((cmd->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
82                 ide_tf_dump(drive->name, tf);
83                 tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
84                 SELECT_MASK(drive, 0);
85                 tp_ops->tf_load(drive, cmd);
86         }
87
88         switch (cmd->protocol) {
89         case ATA_PROT_PIO:
90                 if (cmd->tf_flags & IDE_TFLAG_WRITE) {
91                         tp_ops->exec_command(hwif, tf->command);
92                         ndelay(400);    /* FIXME */
93                         return pre_task_out_intr(drive, cmd);
94                 }
95                 handler = task_pio_intr;
96                 /* fall-through */
97         case ATA_PROT_NODATA:
98                 if (handler == NULL)
99                         handler = task_no_data_intr;
100                 ide_execute_command(drive, cmd, handler, WAIT_WORSTCASE);
101                 return ide_started;
102         case ATA_PROT_DMA:
103                 if (ide_dma_prepare(drive, cmd))
104                         return ide_stopped;
105                 hwif->expiry = dma_ops->dma_timer_expiry;
106                 ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD);
107                 dma_ops->dma_start(drive);
108         default:
109                 return ide_started;
110         }
111 }
112 EXPORT_SYMBOL_GPL(do_rw_taskfile);
113
114 static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
115 {
116         ide_hwif_t *hwif = drive->hwif;
117         struct ide_cmd *cmd = &hwif->cmd;
118         struct ide_taskfile *tf = &cmd->tf;
119         int custom = (cmd->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0;
120         int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
121         u8 stat;
122
123         local_irq_enable_in_hardirq();
124
125         while (1) {
126                 stat = hwif->tp_ops->read_status(hwif);
127                 if ((stat & ATA_BUSY) == 0 || retries-- == 0)
128                         break;
129                 udelay(10);
130         };
131
132         if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
133                 if (custom && tf->command == ATA_CMD_SET_MULTI) {
134                         drive->mult_req = drive->mult_count = 0;
135                         drive->special.b.recalibrate = 1;
136                         (void)ide_dump_status(drive, __func__, stat);
137                         return ide_stopped;
138                 } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) {
139                         if ((stat & (ATA_ERR | ATA_DRQ)) == 0) {
140                                 ide_set_handler(drive, &task_no_data_intr,
141                                                 WAIT_WORSTCASE);
142                                 return ide_started;
143                         }
144                 }
145                 return ide_error(drive, "task_no_data_intr", stat);
146         }
147
148         if (custom && tf->command == ATA_CMD_SET_MULTI)
149                 drive->mult_count = drive->mult_req;
150
151         if (custom == 0 || tf->command == ATA_CMD_IDLEIMMEDIATE ||
152             tf->command == ATA_CMD_CHK_POWER) {
153                 struct request *rq = hwif->rq;
154
155                 if (blk_pm_request(rq))
156                         ide_complete_pm_rq(drive, rq);
157                 else
158                         ide_finish_cmd(drive, cmd, stat);
159         }
160
161         return ide_stopped;
162 }
163
164 static u8 wait_drive_not_busy(ide_drive_t *drive)
165 {
166         ide_hwif_t *hwif = drive->hwif;
167         int retries;
168         u8 stat;
169
170         /*
171          * Last sector was transfered, wait until device is ready.  This can
172          * take up to 6 ms on some ATAPI devices, so we will wait max 10 ms.
173          */
174         for (retries = 0; retries < 1000; retries++) {
175                 stat = hwif->tp_ops->read_status(hwif);
176
177                 if (stat & ATA_BUSY)
178                         udelay(10);
179                 else
180                         break;
181         }
182
183         if (stat & ATA_BUSY)
184                 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
185
186         return stat;
187 }
188
189 void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
190                    unsigned int write, unsigned int len)
191 {
192         ide_hwif_t *hwif = drive->hwif;
193         struct scatterlist *sg = hwif->sg_table;
194         struct scatterlist *cursg = cmd->cursg;
195         struct page *page;
196         unsigned long flags;
197         unsigned int offset;
198         u8 *buf;
199
200         cursg = cmd->cursg;
201         if (cursg == NULL)
202                 cursg = cmd->cursg = sg;
203
204         while (len) {
205                 unsigned nr_bytes = min(len, cursg->length - cmd->cursg_ofs);
206
207                 if (nr_bytes > PAGE_SIZE)
208                         nr_bytes = PAGE_SIZE;
209
210                 page = sg_page(cursg);
211                 offset = cursg->offset + cmd->cursg_ofs;
212
213                 /* get the current page and offset */
214                 page = nth_page(page, (offset >> PAGE_SHIFT));
215                 offset %= PAGE_SIZE;
216
217                 if (PageHighMem(page))
218                         local_irq_save(flags);
219
220                 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
221
222                 cmd->nleft -= nr_bytes;
223                 cmd->cursg_ofs += nr_bytes;
224
225                 if (cmd->cursg_ofs == cursg->length) {
226                         cursg = cmd->cursg = sg_next(cmd->cursg);
227                         cmd->cursg_ofs = 0;
228                 }
229
230                 /* do the actual data transfer */
231                 if (write)
232                         hwif->tp_ops->output_data(drive, cmd, buf, nr_bytes);
233                 else
234                         hwif->tp_ops->input_data(drive, cmd, buf, nr_bytes);
235
236                 kunmap_atomic(buf, KM_BIO_SRC_IRQ);
237
238                 if (PageHighMem(page))
239                         local_irq_restore(flags);
240
241                 len -= nr_bytes;
242         }
243 }
244 EXPORT_SYMBOL_GPL(ide_pio_bytes);
245
246 static void ide_pio_datablock(ide_drive_t *drive, struct ide_cmd *cmd,
247                               unsigned int write)
248 {
249         unsigned int nr_bytes;
250
251         u8 saved_io_32bit = drive->io_32bit;
252
253         if (cmd->tf_flags & IDE_TFLAG_FS)
254                 cmd->rq->errors = 0;
255
256         if (cmd->tf_flags & IDE_TFLAG_IO_16BIT)
257                 drive->io_32bit = 0;
258
259         touch_softlockup_watchdog();
260
261         if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
262                 nr_bytes = min_t(unsigned, cmd->nleft, drive->mult_count << 9);
263         else
264                 nr_bytes = SECTOR_SIZE;
265
266         ide_pio_bytes(drive, cmd, write, nr_bytes);
267
268         drive->io_32bit = saved_io_32bit;
269 }
270
271 static void ide_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
272 {
273         if (cmd->tf_flags & IDE_TFLAG_FS) {
274                 int nr_bytes = cmd->nbytes - cmd->nleft;
275
276                 if (cmd->protocol == ATA_PROT_PIO &&
277                     ((cmd->tf_flags & IDE_TFLAG_WRITE) || cmd->nleft == 0)) {
278                         if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
279                                 nr_bytes -= drive->mult_count << 9;
280                         else
281                                 nr_bytes -= SECTOR_SIZE;
282                 }
283
284                 if (nr_bytes > 0)
285                         ide_complete_rq(drive, 0, nr_bytes);
286         }
287 }
288
289 void ide_finish_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat)
290 {
291         struct request *rq = drive->hwif->rq;
292         u8 err = ide_read_error(drive);
293
294         ide_complete_cmd(drive, cmd, stat, err);
295         rq->errors = err;
296         ide_complete_rq(drive, err ? -EIO : 0, blk_rq_bytes(rq));
297 }
298
299 /*
300  * Handler for command with PIO data phase.
301  */
302 static ide_startstop_t task_pio_intr(ide_drive_t *drive)
303 {
304         ide_hwif_t *hwif = drive->hwif;
305         struct ide_cmd *cmd = &drive->hwif->cmd;
306         u8 stat = hwif->tp_ops->read_status(hwif);
307         u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
308
309         if (write == 0) {
310                 /* Error? */
311                 if (stat & ATA_ERR)
312                         goto out_err;
313
314                 /* Didn't want any data? Odd. */
315                 if ((stat & ATA_DRQ) == 0) {
316                         /* Command all done? */
317                         if (OK_STAT(stat, ATA_DRDY, ATA_BUSY))
318                                 goto out_end;
319
320                         /* Assume it was a spurious irq */
321                         goto out_wait;
322                 }
323         } else {
324                 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
325                         goto out_err;
326
327                 /* Deal with unexpected ATA data phase. */
328                 if (((stat & ATA_DRQ) == 0) ^ (cmd->nleft == 0))
329                         goto out_err;
330         }
331
332         if (write && cmd->nleft == 0)
333                 goto out_end;
334
335         /* Still data left to transfer. */
336         ide_pio_datablock(drive, cmd, write);
337
338         /* Are we done? Check status and finish transfer. */
339         if (write == 0 && cmd->nleft == 0) {
340                 stat = wait_drive_not_busy(drive);
341                 if (!OK_STAT(stat, 0, BAD_STAT))
342                         goto out_err;
343
344                 goto out_end;
345         }
346 out_wait:
347         /* Still data left to transfer. */
348         ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
349         return ide_started;
350 out_end:
351         if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
352                 ide_finish_cmd(drive, cmd, stat);
353         else
354                 ide_complete_rq(drive, 0, cmd->rq->nr_sectors << 9);
355         return ide_stopped;
356 out_err:
357         ide_error_cmd(drive, cmd);
358         return ide_error(drive, __func__, stat);
359 }
360
361 static ide_startstop_t pre_task_out_intr(ide_drive_t *drive,
362                                          struct ide_cmd *cmd)
363 {
364         ide_startstop_t startstop;
365
366         if (ide_wait_stat(&startstop, drive, ATA_DRQ,
367                           drive->bad_wstat, WAIT_DRQ)) {
368                 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
369                         drive->name,
370                         (cmd->tf_flags & IDE_TFLAG_MULTI_PIO) ? "MULT" : "",
371                         (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
372                 return startstop;
373         }
374
375         if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
376                 local_irq_disable();
377
378         ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
379
380         ide_pio_datablock(drive, cmd, 1);
381
382         return ide_started;
383 }
384
385 int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
386                      u16 nsect)
387 {
388         struct request *rq;
389         int error;
390
391         rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
392         rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
393         rq->buffer = buf;
394
395         /*
396          * (ks) We transfer currently only whole sectors.
397          * This is suffient for now.  But, it would be great,
398          * if we would find a solution to transfer any size.
399          * To support special commands like READ LONG.
400          */
401         rq->hard_nr_sectors = rq->nr_sectors = nsect;
402         rq->hard_cur_sectors = rq->current_nr_sectors = nsect;
403
404         if (cmd->tf_flags & IDE_TFLAG_WRITE)
405                 rq->cmd_flags |= REQ_RW;
406
407         rq->special = cmd;
408         cmd->rq = rq;
409
410         error = blk_execute_rq(drive->queue, NULL, rq, 0);
411         blk_put_request(rq);
412
413         return error;
414 }
415
416 EXPORT_SYMBOL(ide_raw_taskfile);
417
418 int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd)
419 {
420         cmd->protocol = ATA_PROT_NODATA;
421
422         return ide_raw_taskfile(drive, cmd, NULL, 0);
423 }
424 EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
425
426 #ifdef CONFIG_IDE_TASK_IOCTL
427 int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
428 {
429         ide_task_request_t      *req_task;
430         struct ide_cmd          cmd;
431         u8 *outbuf              = NULL;
432         u8 *inbuf               = NULL;
433         u8 *data_buf            = NULL;
434         int err                 = 0;
435         int tasksize            = sizeof(struct ide_task_request_s);
436         unsigned int taskin     = 0;
437         unsigned int taskout    = 0;
438         u16 nsect               = 0;
439         char __user *buf = (char __user *)arg;
440
441 //      printk("IDE Taskfile ...\n");
442
443         req_task = kzalloc(tasksize, GFP_KERNEL);
444         if (req_task == NULL) return -ENOMEM;
445         if (copy_from_user(req_task, buf, tasksize)) {
446                 kfree(req_task);
447                 return -EFAULT;
448         }
449
450         taskout = req_task->out_size;
451         taskin  = req_task->in_size;
452         
453         if (taskin > 65536 || taskout > 65536) {
454                 err = -EINVAL;
455                 goto abort;
456         }
457
458         if (taskout) {
459                 int outtotal = tasksize;
460                 outbuf = kzalloc(taskout, GFP_KERNEL);
461                 if (outbuf == NULL) {
462                         err = -ENOMEM;
463                         goto abort;
464                 }
465                 if (copy_from_user(outbuf, buf + outtotal, taskout)) {
466                         err = -EFAULT;
467                         goto abort;
468                 }
469         }
470
471         if (taskin) {
472                 int intotal = tasksize + taskout;
473                 inbuf = kzalloc(taskin, GFP_KERNEL);
474                 if (inbuf == NULL) {
475                         err = -ENOMEM;
476                         goto abort;
477                 }
478                 if (copy_from_user(inbuf, buf + intotal, taskin)) {
479                         err = -EFAULT;
480                         goto abort;
481                 }
482         }
483
484         memset(&cmd, 0, sizeof(cmd));
485
486         memcpy(&cmd.tf_array[0], req_task->hob_ports,
487                HDIO_DRIVE_HOB_HDR_SIZE - 2);
488         memcpy(&cmd.tf_array[6], req_task->io_ports,
489                HDIO_DRIVE_TASK_HDR_SIZE);
490
491         cmd.tf_flags   = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
492                          IDE_TFLAG_IN_TF;
493
494         if (drive->dev_flags & IDE_DFLAG_LBA48)
495                 cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
496
497         if (req_task->out_flags.all) {
498                 cmd.ftf_flags |= IDE_FTFLAG_FLAGGED;
499
500                 if (req_task->out_flags.b.data)
501                         cmd.ftf_flags |= IDE_FTFLAG_OUT_DATA;
502
503                 if (req_task->out_flags.b.nsector_hob)
504                         cmd.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT;
505                 if (req_task->out_flags.b.sector_hob)
506                         cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL;
507                 if (req_task->out_flags.b.lcyl_hob)
508                         cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM;
509                 if (req_task->out_flags.b.hcyl_hob)
510                         cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH;
511
512                 if (req_task->out_flags.b.error_feature)
513                         cmd.tf_flags |= IDE_TFLAG_OUT_FEATURE;
514                 if (req_task->out_flags.b.nsector)
515                         cmd.tf_flags |= IDE_TFLAG_OUT_NSECT;
516                 if (req_task->out_flags.b.sector)
517                         cmd.tf_flags |= IDE_TFLAG_OUT_LBAL;
518                 if (req_task->out_flags.b.lcyl)
519                         cmd.tf_flags |= IDE_TFLAG_OUT_LBAM;
520                 if (req_task->out_flags.b.hcyl)
521                         cmd.tf_flags |= IDE_TFLAG_OUT_LBAH;
522         } else {
523                 cmd.tf_flags |= IDE_TFLAG_OUT_TF;
524                 if (cmd.tf_flags & IDE_TFLAG_LBA48)
525                         cmd.tf_flags |= IDE_TFLAG_OUT_HOB;
526         }
527
528         if (req_task->in_flags.b.data)
529                 cmd.ftf_flags |= IDE_FTFLAG_IN_DATA;
530
531         if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE) {
532                 /* fixup data phase if needed */
533                 if (req_task->data_phase == TASKFILE_IN_DMAQ ||
534                     req_task->data_phase == TASKFILE_IN_DMA)
535                         cmd.tf_flags |= IDE_TFLAG_WRITE;
536         }
537
538         cmd.protocol = ATA_PROT_DMA;
539
540         switch (req_task->data_phase) {
541                 case TASKFILE_MULTI_OUT:
542                         if (!drive->mult_count) {
543                                 /* (hs): give up if multcount is not set */
544                                 printk(KERN_ERR "%s: %s Multimode Write " \
545                                         "multcount is not set\n",
546                                         drive->name, __func__);
547                                 err = -EPERM;
548                                 goto abort;
549                         }
550                         cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
551                         /* fall through */
552                 case TASKFILE_OUT:
553                         cmd.protocol = ATA_PROT_PIO;
554                         /* fall through */
555                 case TASKFILE_OUT_DMAQ:
556                 case TASKFILE_OUT_DMA:
557                         cmd.tf_flags |= IDE_TFLAG_WRITE;
558                         nsect = taskout / SECTOR_SIZE;
559                         data_buf = outbuf;
560                         break;
561                 case TASKFILE_MULTI_IN:
562                         if (!drive->mult_count) {
563                                 /* (hs): give up if multcount is not set */
564                                 printk(KERN_ERR "%s: %s Multimode Read failure " \
565                                         "multcount is not set\n",
566                                         drive->name, __func__);
567                                 err = -EPERM;
568                                 goto abort;
569                         }
570                         cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
571                         /* fall through */
572                 case TASKFILE_IN:
573                         cmd.protocol = ATA_PROT_PIO;
574                         /* fall through */
575                 case TASKFILE_IN_DMAQ:
576                 case TASKFILE_IN_DMA:
577                         nsect = taskin / SECTOR_SIZE;
578                         data_buf = inbuf;
579                         break;
580                 case TASKFILE_NO_DATA:
581                         cmd.protocol = ATA_PROT_NODATA;
582                         break;
583                 default:
584                         err = -EFAULT;
585                         goto abort;
586         }
587
588         if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
589                 nsect = 0;
590         else if (!nsect) {
591                 nsect = (cmd.tf.hob_nsect << 8) | cmd.tf.nsect;
592
593                 if (!nsect) {
594                         printk(KERN_ERR "%s: in/out command without data\n",
595                                         drive->name);
596                         err = -EFAULT;
597                         goto abort;
598                 }
599         }
600
601         err = ide_raw_taskfile(drive, &cmd, data_buf, nsect);
602
603         memcpy(req_task->hob_ports, &cmd.tf_array[0],
604                HDIO_DRIVE_HOB_HDR_SIZE - 2);
605         memcpy(req_task->io_ports, &cmd.tf_array[6],
606                HDIO_DRIVE_TASK_HDR_SIZE);
607
608         if ((cmd.ftf_flags & IDE_FTFLAG_SET_IN_FLAGS) &&
609             req_task->in_flags.all == 0) {
610                 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
611                 if (drive->dev_flags & IDE_DFLAG_LBA48)
612                         req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
613         }
614
615         if (copy_to_user(buf, req_task, tasksize)) {
616                 err = -EFAULT;
617                 goto abort;
618         }
619         if (taskout) {
620                 int outtotal = tasksize;
621                 if (copy_to_user(buf + outtotal, outbuf, taskout)) {
622                         err = -EFAULT;
623                         goto abort;
624                 }
625         }
626         if (taskin) {
627                 int intotal = tasksize + taskout;
628                 if (copy_to_user(buf + intotal, inbuf, taskin)) {
629                         err = -EFAULT;
630                         goto abort;
631                 }
632         }
633 abort:
634         kfree(req_task);
635         kfree(outbuf);
636         kfree(inbuf);
637
638 //      printk("IDE Taskfile ioctl ended. rc = %i\n", err);
639
640         return err;
641 }
642 #endif