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