blob: 2b85c137764a37e80395ee74f526d20017a3e1c0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Bartlomiej Zolnierkiewicz59bca8c2008-02-01 23:09:33 +01002 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * IBM Storage Technology Division
Bartlomiej Zolnierkiewicz59bca8c2008-02-01 23:09:33 +01006 * Copyright (C) 2003-2004, 2007 Bartlomiej Zolnierkiewicz
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * The big the bad and the ugly.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/types.h>
12#include <linux/string.h>
13#include <linux/kernel.h>
Andrew Morton651c29a2006-02-15 15:17:37 -080014#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/delay.h>
19#include <linux/hdreg.h>
20#include <linux/ide.h>
Jens Axboe55c16a72007-07-25 08:13:56 +020021#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/uaccess.h>
24#include <asm/io.h>
25
Bartlomiej Zolnierkiewicz089c5c72008-04-28 23:44:39 +020026void 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070040int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
41{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010042 struct ide_cmd cmd;
Bartlomiej Zolnierkiewicz650d8412008-01-25 22:17:06 +010043
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010044 memset(&cmd, 0, sizeof(cmd));
45 cmd.tf.nsect = 0x01;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 if (drive->media == ide_disk)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010047 cmd.tf.command = ATA_CMD_ID_ATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 else
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010049 cmd.tf.command = ATA_CMD_ID_ATAPI;
50 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
51 cmd.data_phase = TASKFILE_IN;
52
53 return ide_raw_taskfile(drive, &cmd, buf, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
Bartlomiej Zolnierkiewicz1192e522008-01-25 22:17:16 +010056static ide_startstop_t task_no_data_intr(ide_drive_t *);
Bartlomiej Zolnierkiewiczf6e29e32008-01-25 22:17:16 +010057static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
58static ide_startstop_t task_in_intr(ide_drive_t *);
Bartlomiej Zolnierkiewicz1192e522008-01-25 22:17:16 +010059
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010060ide_startstop_t do_rw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Bartlomiej Zolnierkiewicz898ec222009-01-06 17:20:52 +010062 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010063 struct ide_taskfile *tf = &cmd->tf;
Bartlomiej Zolnierkiewicz57d73662008-01-25 22:17:16 +010064 ide_handler_t *handler = NULL;
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +020065 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
Bartlomiej Zolnierkiewiczf37afda2008-04-26 22:25:24 +020066 const struct ide_dma_ops *dma_ops = hwif->dma_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010068 if (cmd->data_phase == TASKFILE_MULTI_IN ||
69 cmd->data_phase == TASKFILE_MULTI_OUT) {
Bartlomiej Zolnierkiewicz1edee602008-01-25 22:17:15 +010070 if (!drive->mult_count) {
71 printk(KERN_ERR "%s: multimode not set!\n",
72 drive->name);
73 return ide_stopped;
74 }
75 }
76
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010077 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
78 cmd->ftf_flags |= IDE_FTFLAG_SET_IN_FLAGS;
Bartlomiej Zolnierkiewicz1edee602008-01-25 22:17:15 +010079
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010080 memcpy(&hwif->cmd, cmd, sizeof(*cmd));
Bartlomiej Zolnierkiewiczd6ff9f62008-10-13 21:39:41 +020081
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010082 if ((cmd->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
Bartlomiej Zolnierkiewicz089c5c72008-04-28 23:44:39 +020083 ide_tf_dump(drive->name, tf);
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +020084 tp_ops->set_irq(hwif, 1);
Bartlomiej Zolnierkiewiczed4af482008-07-15 21:21:48 +020085 SELECT_MASK(drive, 0);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010086 tp_ops->tf_load(drive, cmd);
Bartlomiej Zolnierkiewicz089c5c72008-04-28 23:44:39 +020087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010089 switch (cmd->data_phase) {
Bartlomiej Zolnierkiewicz10d90152008-01-25 22:17:16 +010090 case TASKFILE_MULTI_OUT:
91 case TASKFILE_OUT:
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +020092 tp_ops->exec_command(hwif, tf->command);
Bartlomiej Zolnierkiewicz10d90152008-01-25 22:17:16 +010093 ndelay(400); /* FIXME */
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010094 return pre_task_out_intr(drive, cmd->rq);
Bartlomiej Zolnierkiewicz10d90152008-01-25 22:17:16 +010095 case TASKFILE_MULTI_IN:
96 case TASKFILE_IN:
Bartlomiej Zolnierkiewicz57d73662008-01-25 22:17:16 +010097 handler = task_in_intr;
Bartlomiej Zolnierkiewicz1192e522008-01-25 22:17:16 +010098 /* fall-through */
Bartlomiej Zolnierkiewicz10d90152008-01-25 22:17:16 +010099 case TASKFILE_NO_DATA:
Bartlomiej Zolnierkiewicz57d73662008-01-25 22:17:16 +0100100 if (handler == NULL)
101 handler = task_no_data_intr;
Bartlomiej Zolnierkiewicz57d73662008-01-25 22:17:16 +0100102 ide_execute_command(drive, tf->command, handler,
103 WAIT_WORSTCASE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 return ide_started;
Bartlomiej Zolnierkiewicz10d90152008-01-25 22:17:16 +0100105 default:
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200106 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
Bartlomiej Zolnierkiewicze6830a82009-03-27 12:46:37 +0100107 ide_build_sglist(drive, hwif->rq) == 0 ||
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200108 dma_ops->dma_setup(drive))
Bartlomiej Zolnierkiewicz10d90152008-01-25 22:17:16 +0100109 return ide_stopped;
Bartlomiej Zolnierkiewicz5e37bdc2008-04-26 22:25:24 +0200110 dma_ops->dma_exec_cmd(drive, tf->command);
111 dma_ops->dma_start(drive);
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100112 return ide_started;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
Bartlomiej Zolnierkiewiczf6e29e32008-01-25 22:17:16 +0100115EXPORT_SYMBOL_GPL(do_rw_taskfile);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/*
Bartlomiej Zolnierkiewiczd6ff9f62008-10-13 21:39:41 +0200118 * Handler for commands without a data phase
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 */
Bartlomiej Zolnierkiewiczd6ff9f62008-10-13 21:39:41 +0200120static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Bartlomiej Zolnierkiewiczb73c7ee2008-07-23 19:55:52 +0200122 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100123 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;
Bartlomiej Zolnierkiewiczd6ff9f62008-10-13 21:39:41 +0200126 int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 u8 stat;
128
Bartlomiej Zolnierkiewicz90d2c6b2008-07-24 22:53:36 +0200129 local_irq_enable_in_hardirq();
130
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200131 while (1) {
132 stat = hwif->tp_ops->read_status(hwif);
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200133 if ((stat & ATA_BUSY) == 0 || retries-- == 0)
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200134 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 udelay(10);
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200136 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Bartlomiej Zolnierkiewiczd6ff9f62008-10-13 21:39:41 +0200138 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, NULL);
148 return ide_started;
149 }
150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 return ide_error(drive, "task_no_data_intr", stat);
Bartlomiej Zolnierkiewiczd6ff9f62008-10-13 21:39:41 +0200152 }
Bartlomiej Zolnierkiewiczc47137a2008-02-06 02:57:51 +0100153
Bartlomiej Zolnierkiewicza09485d2009-03-27 12:46:31 +0100154 if (custom && tf->command == ATA_CMD_IDLEIMMEDIATE) {
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100155 hwif->tp_ops->tf_read(drive, cmd);
Elias Oltmanns4abdc6e2008-10-13 21:39:50 +0200156 if (tf->lbal != 0xc4) {
157 printk(KERN_ERR "%s: head unload failed!\n",
158 drive->name);
159 ide_tf_dump(drive->name, tf);
160 } else
161 drive->dev_flags |= IDE_DFLAG_PARKED;
Bartlomiej Zolnierkiewicza09485d2009-03-27 12:46:31 +0100162 } else if (custom && tf->command == ATA_CMD_SET_MULTI)
Bartlomiej Zolnierkiewiczd6ff9f62008-10-13 21:39:41 +0200163 drive->mult_count = drive->mult_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Bartlomiej Zolnierkiewicza09485d2009-03-27 12:46:31 +0100165 if (custom == 0 || tf->command == ATA_CMD_IDLEIMMEDIATE) {
166 struct request *rq = hwif->rq;
167 u8 err = ide_read_error(drive);
168
169 if (blk_pm_request(rq))
170 ide_complete_pm_rq(drive, rq);
171 else {
172 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100173 ide_complete_cmd(drive, cmd, stat, err);
Bartlomiej Zolnierkiewicza09485d2009-03-27 12:46:31 +0100174 ide_complete_rq(drive, err);
175 }
176 }
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return ide_stopped;
179}
180
Adrian Bunkda6f4c72008-02-01 23:09:16 +0100181static u8 wait_drive_not_busy(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Bartlomiej Zolnierkiewiczb73c7ee2008-07-23 19:55:52 +0200183 ide_hwif_t *hwif = drive->hwif;
Masatake YAMATOb42fa132007-07-03 22:28:34 +0200184 int retries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 u8 stat;
186
187 /*
Bartlomiej Zolnierkiewiczf54feaf2008-06-20 20:53:33 +0200188 * Last sector was transfered, wait until device is ready. This can
189 * take up to 6 ms on some ATAPI devices, so we will wait max 10 ms.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 */
Bartlomiej Zolnierkiewiczf54feaf2008-06-20 20:53:33 +0200191 for (retries = 0; retries < 1000; retries++) {
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200192 stat = hwif->tp_ops->read_status(hwif);
Bartlomiej Zolnierkiewiczc47137a2008-02-06 02:57:51 +0100193
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200194 if (stat & ATA_BUSY)
Masatake YAMATOb42fa132007-07-03 22:28:34 +0200195 udelay(10);
196 else
197 break;
198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200200 if (stat & ATA_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
202
203 return stat;
204}
205
Bartlomiej Zolnierkiewicz92d3ab22008-04-28 23:44:36 +0200206static void ide_pio_sector(ide_drive_t *drive, struct request *rq,
207 unsigned int write)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
209 ide_hwif_t *hwif = drive->hwif;
210 struct scatterlist *sg = hwif->sg_table;
Jens Axboe55c16a72007-07-25 08:13:56 +0200211 struct scatterlist *cursg = hwif->cursg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 struct page *page;
213#ifdef CONFIG_HIGHMEM
214 unsigned long flags;
215#endif
216 unsigned int offset;
217 u8 *buf;
218
Jens Axboe55c16a72007-07-25 08:13:56 +0200219 cursg = hwif->cursg;
220 if (!cursg) {
221 cursg = sg;
222 hwif->cursg = sg;
223 }
224
Jens Axboe45711f12007-10-22 21:19:53 +0200225 page = sg_page(cursg);
Jens Axboe55c16a72007-07-25 08:13:56 +0200226 offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /* get the current page and offset */
229 page = nth_page(page, (offset >> PAGE_SHIFT));
230 offset %= PAGE_SIZE;
231
232#ifdef CONFIG_HIGHMEM
233 local_irq_save(flags);
234#endif
235 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
236
237 hwif->nleft--;
238 hwif->cursg_ofs++;
239
Jens Axboe55c16a72007-07-25 08:13:56 +0200240 if ((hwif->cursg_ofs * SECTOR_SIZE) == cursg->length) {
241 hwif->cursg = sg_next(hwif->cursg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 hwif->cursg_ofs = 0;
243 }
244
245 /* do the actual data transfer */
246 if (write)
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200247 hwif->tp_ops->output_data(drive, rq, buf, SECTOR_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 else
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200249 hwif->tp_ops->input_data(drive, rq, buf, SECTOR_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 kunmap_atomic(buf, KM_BIO_SRC_IRQ);
252#ifdef CONFIG_HIGHMEM
253 local_irq_restore(flags);
254#endif
255}
256
Bartlomiej Zolnierkiewicz92d3ab22008-04-28 23:44:36 +0200257static void ide_pio_multi(ide_drive_t *drive, struct request *rq,
258 unsigned int write)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 unsigned int nsect;
261
262 nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count);
263 while (nsect--)
Bartlomiej Zolnierkiewicz92d3ab22008-04-28 23:44:36 +0200264 ide_pio_sector(drive, rq, write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265}
266
Arjan van de Ven858119e2006-01-14 13:20:43 -0800267static void ide_pio_datablock(ide_drive_t *drive, struct request *rq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 unsigned int write)
269{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100270 struct ide_cmd *cmd = &drive->hwif->cmd;
Tejun Heo35cf2b92008-01-26 20:13:10 +0100271 u8 saved_io_32bit = drive->io_32bit;
272
Bartlomiej Zolnierkiewiczb109f522009-03-27 12:46:37 +0100273 if (blk_fs_request(rq))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 rq->errors = 0;
275
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100276 if (cmd->tf_flags & IDE_TFLAG_IO_16BIT)
Bartlomiej Zolnierkiewicze3d9a732009-03-27 12:46:32 +0100277 drive->io_32bit = 0;
Tejun Heo35cf2b92008-01-26 20:13:10 +0100278
Andrew Morton651c29a2006-02-15 15:17:37 -0800279 touch_softlockup_watchdog();
280
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100281 switch (cmd->data_phase) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 case TASKFILE_MULTI_IN:
283 case TASKFILE_MULTI_OUT:
Bartlomiej Zolnierkiewicz92d3ab22008-04-28 23:44:36 +0200284 ide_pio_multi(drive, rq, write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 break;
286 default:
Bartlomiej Zolnierkiewicz92d3ab22008-04-28 23:44:36 +0200287 ide_pio_sector(drive, rq, write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 break;
289 }
Tejun Heo35cf2b92008-01-26 20:13:10 +0100290
291 drive->io_32bit = saved_io_32bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
294static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
295 const char *s, u8 stat)
296{
Bartlomiej Zolnierkiewiczb109f522009-03-27 12:46:37 +0100297 if (blk_fs_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100299 struct ide_cmd *cmd = &hwif->cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 int sectors = hwif->nsect - hwif->nleft;
301
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100302 switch (cmd->data_phase) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 case TASKFILE_IN:
304 if (hwif->nleft)
305 break;
306 /* fall through */
307 case TASKFILE_OUT:
308 sectors--;
309 break;
310 case TASKFILE_MULTI_IN:
311 if (hwif->nleft)
312 break;
313 /* fall through */
314 case TASKFILE_MULTI_OUT:
315 sectors -= drive->mult_count;
316 default:
317 break;
318 }
319
Bartlomiej Zolnierkiewiczc152cc12009-03-27 12:46:34 +0100320 if (sectors > 0)
321 ide_end_request(drive, 1, sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323 return ide_error(drive, s, stat);
324}
325
Tejun Heo4d7a9842008-01-26 20:13:11 +0100326void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Bartlomiej Zolnierkiewiczb109f522009-03-27 12:46:37 +0100328 if (blk_fs_request(rq) == 0) {
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100329 struct ide_cmd *cmd = rq->special;
Bartlomiej Zolnierkiewicz64a57fe2008-02-06 02:57:51 +0100330 u8 err = ide_read_error(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100332 if (cmd)
333 ide_complete_cmd(drive, cmd, stat, err);
Bartlomiej Zolnierkiewicza09485d2009-03-27 12:46:31 +0100334 ide_complete_rq(drive, err);
Tejun Heo4d7a9842008-01-26 20:13:11 +0100335 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 }
337
Bartlomiej Zolnierkiewiczc152cc12009-03-27 12:46:34 +0100338 ide_end_request(drive, 1, rq->nr_sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
340
341/*
Linus Torvalds6c3c3152008-03-18 21:26:24 -0700342 * We got an interrupt on a task_in case, but no errors and no DRQ.
343 *
344 * It might be a spurious irq (shared irq), but it might be a
345 * command that had no output.
346 */
347static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
348{
349 /* Command all done? */
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200350 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY)) {
Linus Torvalds6c3c3152008-03-18 21:26:24 -0700351 task_end_request(drive, rq, stat);
352 return ide_stopped;
353 }
354
355 /* Assume it was a spurious irq */
356 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
357 return ide_started;
358}
359
360/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 * Handler for command with PIO data-in phase (Read/Read Multiple).
362 */
Bartlomiej Zolnierkiewiczf6e29e32008-01-25 22:17:16 +0100363static ide_startstop_t task_in_intr(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczb65fac32009-01-06 17:20:50 +0100366 struct request *rq = hwif->rq;
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200367 u8 stat = hwif->tp_ops->read_status(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Linus Torvalds6c3c3152008-03-18 21:26:24 -0700369 /* Error? */
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200370 if (stat & ATA_ERR)
Harvey Harrisoneb639632008-04-26 22:25:20 +0200371 return task_error(drive, rq, __func__, stat);
Linus Torvalds6c3c3152008-03-18 21:26:24 -0700372
373 /* Didn't want any data? Odd. */
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200374 if ((stat & ATA_DRQ) == 0)
Linus Torvalds6c3c3152008-03-18 21:26:24 -0700375 return task_in_unexpected(drive, rq, stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 ide_pio_datablock(drive, rq, 0);
378
Linus Torvalds6c3c3152008-03-18 21:26:24 -0700379 /* Are we done? Check status and finish transfer. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 if (!hwif->nleft) {
381 stat = wait_drive_not_busy(drive);
Bartlomiej Zolnierkiewicz73d7de02008-01-26 20:13:10 +0100382 if (!OK_STAT(stat, 0, BAD_STAT))
Harvey Harrisoneb639632008-04-26 22:25:20 +0200383 return task_error(drive, rq, __func__, stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 task_end_request(drive, rq, stat);
385 return ide_stopped;
386 }
387
388 /* Still data left to transfer. */
389 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
390
391 return ide_started;
392}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394/*
395 * Handler for command with PIO data-out phase (Write/Write Multiple).
396 */
397static ide_startstop_t task_out_intr (ide_drive_t *drive)
398{
399 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczb65fac32009-01-06 17:20:50 +0100400 struct request *rq = hwif->rq;
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200401 u8 stat = hwif->tp_ops->read_status(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
Harvey Harrisoneb639632008-04-26 22:25:20 +0200404 return task_error(drive, rq, __func__, stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 /* Deal with unexpected ATA data phase. */
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200407 if (((stat & ATA_DRQ) == 0) ^ !hwif->nleft)
Harvey Harrisoneb639632008-04-26 22:25:20 +0200408 return task_error(drive, rq, __func__, stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 if (!hwif->nleft) {
411 task_end_request(drive, rq, stat);
412 return ide_stopped;
413 }
414
415 /* Still data left to transfer. */
416 ide_pio_datablock(drive, rq, 1);
417 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
418
419 return ide_started;
420}
421
Bartlomiej Zolnierkiewiczf6e29e32008-01-25 22:17:16 +0100422static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100424 struct ide_cmd *cmd = &drive->hwif->cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 ide_startstop_t startstop;
426
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200427 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 drive->bad_wstat, WAIT_DRQ)) {
429 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
Bartlomiej Zolnierkiewiczc7db9662009-03-27 12:46:27 +0100430 drive->name,
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100431 cmd->data_phase == TASKFILE_MULTI_OUT ? "MULT" : "",
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200432 (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 return startstop;
434 }
435
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200436 if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 local_irq_disable();
438
439 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
440 ide_pio_datablock(drive, rq, 1);
441
442 return ide_started;
443}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100445int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
446 u16 nsect)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
FUJITA Tomonori154ed282008-07-15 21:21:43 +0200448 struct request *rq;
449 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
FUJITA Tomonori154ed282008-07-15 21:21:43 +0200451 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
452 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
453 rq->buffer = buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 /*
456 * (ks) We transfer currently only whole sectors.
457 * This is suffient for now. But, it would be great,
458 * if we would find a solution to transfer any size.
459 * To support special commands like READ LONG.
460 */
FUJITA Tomonori154ed282008-07-15 21:21:43 +0200461 rq->hard_nr_sectors = rq->nr_sectors = nsect;
462 rq->hard_cur_sectors = rq->current_nr_sectors = nsect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100464 if (cmd->tf_flags & IDE_TFLAG_WRITE)
FUJITA Tomonori154ed282008-07-15 21:21:43 +0200465 rq->cmd_flags |= REQ_RW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100467 rq->special = cmd;
468 cmd->rq = rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
FUJITA Tomonori154ed282008-07-15 21:21:43 +0200470 error = blk_execute_rq(drive->queue, NULL, rq, 0);
471 blk_put_request(rq);
472
473 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476EXPORT_SYMBOL(ide_raw_taskfile);
477
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100478int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd)
Bartlomiej Zolnierkiewicz9a3c49b2008-01-25 22:17:07 +0100479{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100480 cmd->data_phase = TASKFILE_NO_DATA;
Bartlomiej Zolnierkiewicz9a3c49b2008-01-25 22:17:07 +0100481
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100482 return ide_raw_taskfile(drive, cmd, NULL, 0);
Bartlomiej Zolnierkiewicz9a3c49b2008-01-25 22:17:07 +0100483}
484EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
485
Bartlomiej Zolnierkiewicz26a5b042007-11-05 21:42:27 +0100486#ifdef CONFIG_IDE_TASK_IOCTL
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100487int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489 ide_task_request_t *req_task;
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100490 struct ide_cmd cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 u8 *outbuf = NULL;
492 u8 *inbuf = NULL;
Bartlomiej Zolnierkiewiczac026ff2008-01-25 22:17:14 +0100493 u8 *data_buf = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 int err = 0;
495 int tasksize = sizeof(struct ide_task_request_s);
Alan Cox3a42bb22006-10-16 16:31:02 +0100496 unsigned int taskin = 0;
497 unsigned int taskout = 0;
Bartlomiej Zolnierkiewiczac026ff2008-01-25 22:17:14 +0100498 u16 nsect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 char __user *buf = (char __user *)arg;
500
501// printk("IDE Taskfile ...\n");
502
Deepak Saxenaf5e3c2f2005-11-07 01:01:25 -0800503 req_task = kzalloc(tasksize, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (req_task == NULL) return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (copy_from_user(req_task, buf, tasksize)) {
506 kfree(req_task);
507 return -EFAULT;
508 }
509
Alan Cox3a42bb22006-10-16 16:31:02 +0100510 taskout = req_task->out_size;
511 taskin = req_task->in_size;
512
513 if (taskin > 65536 || taskout > 65536) {
514 err = -EINVAL;
515 goto abort;
516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 if (taskout) {
519 int outtotal = tasksize;
Deepak Saxenaf5e3c2f2005-11-07 01:01:25 -0800520 outbuf = kzalloc(taskout, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 if (outbuf == NULL) {
522 err = -ENOMEM;
523 goto abort;
524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 if (copy_from_user(outbuf, buf + outtotal, taskout)) {
526 err = -EFAULT;
527 goto abort;
528 }
529 }
530
531 if (taskin) {
532 int intotal = tasksize + taskout;
Deepak Saxenaf5e3c2f2005-11-07 01:01:25 -0800533 inbuf = kzalloc(taskin, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (inbuf == NULL) {
535 err = -ENOMEM;
536 goto abort;
537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (copy_from_user(inbuf, buf + intotal, taskin)) {
539 err = -EFAULT;
540 goto abort;
541 }
542 }
543
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100544 memset(&cmd, 0, sizeof(cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100546 memcpy(&cmd.tf_array[0], req_task->hob_ports,
547 HDIO_DRIVE_HOB_HDR_SIZE - 2);
548 memcpy(&cmd.tf_array[6], req_task->io_ports,
549 HDIO_DRIVE_TASK_HDR_SIZE);
Bartlomiej Zolnierkiewicz866e2ec2008-01-25 22:17:14 +0100550
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100551 cmd.data_phase = req_task->data_phase;
552 cmd.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
553 IDE_TFLAG_IN_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200555 if (drive->dev_flags & IDE_DFLAG_LBA48)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100556 cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
Bartlomiej Zolnierkiewicza3bbb9d2008-01-25 22:17:10 +0100557
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100558 if (req_task->out_flags.all) {
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100559 cmd.ftf_flags |= IDE_FTFLAG_FLAGGED;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100560
561 if (req_task->out_flags.b.data)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100562 cmd.ftf_flags |= IDE_FTFLAG_OUT_DATA;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100563
564 if (req_task->out_flags.b.nsector_hob)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100565 cmd.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100566 if (req_task->out_flags.b.sector_hob)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100567 cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100568 if (req_task->out_flags.b.lcyl_hob)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100569 cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100570 if (req_task->out_flags.b.hcyl_hob)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100571 cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100572
573 if (req_task->out_flags.b.error_feature)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100574 cmd.tf_flags |= IDE_TFLAG_OUT_FEATURE;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100575 if (req_task->out_flags.b.nsector)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100576 cmd.tf_flags |= IDE_TFLAG_OUT_NSECT;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100577 if (req_task->out_flags.b.sector)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100578 cmd.tf_flags |= IDE_TFLAG_OUT_LBAL;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100579 if (req_task->out_flags.b.lcyl)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100580 cmd.tf_flags |= IDE_TFLAG_OUT_LBAM;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100581 if (req_task->out_flags.b.hcyl)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100582 cmd.tf_flags |= IDE_TFLAG_OUT_LBAH;
Bartlomiej Zolnierkiewicza3bbb9d2008-01-25 22:17:10 +0100583 } else {
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100584 cmd.tf_flags |= IDE_TFLAG_OUT_TF;
585 if (cmd.tf_flags & IDE_TFLAG_LBA48)
586 cmd.tf_flags |= IDE_TFLAG_OUT_HOB;
Bartlomiej Zolnierkiewicz74095a92008-01-25 22:17:07 +0100587 }
588
Bartlomiej Zolnierkiewicz866e2ec2008-01-25 22:17:14 +0100589 if (req_task->in_flags.b.data)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100590 cmd.ftf_flags |= IDE_FTFLAG_IN_DATA;
Bartlomiej Zolnierkiewicz866e2ec2008-01-25 22:17:14 +0100591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 switch(req_task->data_phase) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 case TASKFILE_MULTI_OUT:
594 if (!drive->mult_count) {
595 /* (hs): give up if multcount is not set */
596 printk(KERN_ERR "%s: %s Multimode Write " \
597 "multcount is not set\n",
Harvey Harrisoneb639632008-04-26 22:25:20 +0200598 drive->name, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 err = -EPERM;
600 goto abort;
601 }
602 /* fall through */
603 case TASKFILE_OUT:
Bartlomiej Zolnierkiewiczac026ff2008-01-25 22:17:14 +0100604 /* fall through */
605 case TASKFILE_OUT_DMAQ:
606 case TASKFILE_OUT_DMA:
607 nsect = taskout / SECTOR_SIZE;
608 data_buf = outbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 break;
610 case TASKFILE_MULTI_IN:
611 if (!drive->mult_count) {
612 /* (hs): give up if multcount is not set */
613 printk(KERN_ERR "%s: %s Multimode Read failure " \
614 "multcount is not set\n",
Harvey Harrisoneb639632008-04-26 22:25:20 +0200615 drive->name, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 err = -EPERM;
617 goto abort;
618 }
619 /* fall through */
620 case TASKFILE_IN:
Bartlomiej Zolnierkiewiczac026ff2008-01-25 22:17:14 +0100621 /* fall through */
622 case TASKFILE_IN_DMAQ:
623 case TASKFILE_IN_DMA:
624 nsect = taskin / SECTOR_SIZE;
625 data_buf = inbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 break;
627 case TASKFILE_NO_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 break;
629 default:
630 err = -EFAULT;
631 goto abort;
632 }
633
Bartlomiej Zolnierkiewiczac026ff2008-01-25 22:17:14 +0100634 if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
635 nsect = 0;
636 else if (!nsect) {
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100637 nsect = (cmd.tf.hob_nsect << 8) | cmd.tf.nsect;
Bartlomiej Zolnierkiewiczac026ff2008-01-25 22:17:14 +0100638
639 if (!nsect) {
640 printk(KERN_ERR "%s: in/out command without data\n",
641 drive->name);
642 err = -EFAULT;
643 goto abort;
644 }
645 }
646
647 if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE)
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100648 cmd.tf_flags |= IDE_TFLAG_WRITE;
Bartlomiej Zolnierkiewiczac026ff2008-01-25 22:17:14 +0100649
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100650 err = ide_raw_taskfile(drive, &cmd, data_buf, nsect);
Bartlomiej Zolnierkiewiczac026ff2008-01-25 22:17:14 +0100651
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100652 memcpy(req_task->hob_ports, &cmd.tf_array[0],
653 HDIO_DRIVE_HOB_HDR_SIZE - 2);
654 memcpy(req_task->io_ports, &cmd.tf_array[6],
655 HDIO_DRIVE_TASK_HDR_SIZE);
Bartlomiej Zolnierkiewicz866e2ec2008-01-25 22:17:14 +0100656
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100657 if ((cmd.ftf_flags & IDE_FTFLAG_SET_IN_FLAGS) &&
Bartlomiej Zolnierkiewicz866e2ec2008-01-25 22:17:14 +0100658 req_task->in_flags.all == 0) {
659 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200660 if (drive->dev_flags & IDE_DFLAG_LBA48)
Bartlomiej Zolnierkiewicz866e2ec2008-01-25 22:17:14 +0100661 req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 if (copy_to_user(buf, req_task, tasksize)) {
665 err = -EFAULT;
666 goto abort;
667 }
668 if (taskout) {
669 int outtotal = tasksize;
670 if (copy_to_user(buf + outtotal, outbuf, taskout)) {
671 err = -EFAULT;
672 goto abort;
673 }
674 }
675 if (taskin) {
676 int intotal = tasksize + taskout;
677 if (copy_to_user(buf + intotal, inbuf, taskin)) {
678 err = -EFAULT;
679 goto abort;
680 }
681 }
682abort:
683 kfree(req_task);
Jesper Juhl6044ec82005-11-07 01:01:32 -0800684 kfree(outbuf);
685 kfree(inbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687// printk("IDE Taskfile ioctl ended. rc = %i\n", err);
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 return err;
690}
Bartlomiej Zolnierkiewicz26a5b042007-11-05 21:42:27 +0100691#endif