]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
59bca8cc BZ |
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 | |
1da177e4 | 5 | * IBM Storage Technology Division |
59bca8cc | 6 | * Copyright (C) 2003-2004, 2007 Bartlomiej Zolnierkiewicz |
1da177e4 LT |
7 | * |
8 | * The big the bad and the ugly. | |
1da177e4 LT |
9 | */ |
10 | ||
1da177e4 LT |
11 | #include <linux/types.h> |
12 | #include <linux/string.h> | |
13 | #include <linux/kernel.h> | |
651c29a1 | 14 | #include <linux/sched.h> |
1da177e4 | 15 | #include <linux/interrupt.h> |
1da177e4 | 16 | #include <linux/errno.h> |
1da177e4 | 17 | #include <linux/slab.h> |
1da177e4 LT |
18 | #include <linux/delay.h> |
19 | #include <linux/hdreg.h> | |
20 | #include <linux/ide.h> | |
55c16a70 | 21 | #include <linux/scatterlist.h> |
1da177e4 | 22 | |
1da177e4 LT |
23 | #include <asm/uaccess.h> |
24 | #include <asm/io.h> | |
25 | ||
089c5c7e | 26 | void ide_tf_dump(const char *s, struct ide_taskfile *tf) |
9e42237f | 27 | { |
807e35d6 BZ |
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", | |
089c5c7e | 31 | s, tf->feature, tf->nsect, tf->lbal, |
807e35d6 | 32 | tf->lbam, tf->lbah, tf->device, tf->command); |
6dd9b837 BZ |
33 | printk("%s: hob: nsect 0x%02x lbal 0x%02x " |
34 | "lbam 0x%02x lbah 0x%02x\n", | |
089c5c7e | 35 | s, tf->hob_nsect, tf->hob_lbal, |
6dd9b837 | 36 | tf->hob_lbam, tf->hob_lbah); |
807e35d6 | 37 | #endif |
089c5c7e BZ |
38 | } |
39 | ||
1da177e4 LT |
40 | int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf) |
41 | { | |
22aa4b32 | 42 | struct ide_cmd cmd; |
650d841d | 43 | |
22aa4b32 BZ |
44 | memset(&cmd, 0, sizeof(cmd)); |
45 | cmd.tf.nsect = 0x01; | |
1da177e4 | 46 | if (drive->media == ide_disk) |
22aa4b32 | 47 | cmd.tf.command = ATA_CMD_ID_ATA; |
1da177e4 | 48 | else |
22aa4b32 BZ |
49 | 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); | |
1da177e4 LT |
54 | } |
55 | ||
1192e528 | 56 | static ide_startstop_t task_no_data_intr(ide_drive_t *); |
f6e29e35 BZ |
57 | static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *); |
58 | static ide_startstop_t task_in_intr(ide_drive_t *); | |
1192e528 | 59 | |
22aa4b32 | 60 | ide_startstop_t do_rw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd) |
1da177e4 | 61 | { |
898ec223 | 62 | ide_hwif_t *hwif = drive->hwif; |
22aa4b32 | 63 | struct ide_taskfile *tf = &cmd->tf; |
57d7366b | 64 | ide_handler_t *handler = NULL; |
374e042c | 65 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; |
f37afdac | 66 | const struct ide_dma_ops *dma_ops = hwif->dma_ops; |
1da177e4 | 67 | |
22aa4b32 BZ |
68 | if (cmd->data_phase == TASKFILE_MULTI_IN || |
69 | cmd->data_phase == TASKFILE_MULTI_OUT) { | |
1edee60e BZ |
70 | if (!drive->mult_count) { |
71 | printk(KERN_ERR "%s: multimode not set!\n", | |
72 | drive->name); | |
73 | return ide_stopped; | |
74 | } | |
75 | } | |
76 | ||
22aa4b32 BZ |
77 | if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) |
78 | cmd->ftf_flags |= IDE_FTFLAG_SET_IN_FLAGS; | |
1edee60e | 79 | |
22aa4b32 | 80 | memcpy(&hwif->cmd, cmd, sizeof(*cmd)); |
d6ff9f64 | 81 | |
22aa4b32 | 82 | if ((cmd->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) { |
089c5c7e | 83 | ide_tf_dump(drive->name, tf); |
374e042c | 84 | tp_ops->set_irq(hwif, 1); |
ed4af48f | 85 | SELECT_MASK(drive, 0); |
22aa4b32 | 86 | tp_ops->tf_load(drive, cmd); |
089c5c7e | 87 | } |
1da177e4 | 88 | |
22aa4b32 | 89 | switch (cmd->data_phase) { |
10d90157 BZ |
90 | case TASKFILE_MULTI_OUT: |
91 | case TASKFILE_OUT: | |
374e042c | 92 | tp_ops->exec_command(hwif, tf->command); |
10d90157 | 93 | ndelay(400); /* FIXME */ |
22aa4b32 | 94 | return pre_task_out_intr(drive, cmd->rq); |
10d90157 BZ |
95 | case TASKFILE_MULTI_IN: |
96 | case TASKFILE_IN: | |
57d7366b | 97 | handler = task_in_intr; |
1192e528 | 98 | /* fall-through */ |
10d90157 | 99 | case TASKFILE_NO_DATA: |
57d7366b BZ |
100 | if (handler == NULL) |
101 | handler = task_no_data_intr; | |
57d7366b BZ |
102 | ide_execute_command(drive, tf->command, handler, |
103 | WAIT_WORSTCASE, NULL); | |
1da177e4 | 104 | return ide_started; |
10d90157 | 105 | default: |
97100fc8 | 106 | if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 || |
e6830a86 | 107 | ide_build_sglist(drive, hwif->rq) == 0 || |
97100fc8 | 108 | dma_ops->dma_setup(drive)) |
10d90157 | 109 | return ide_stopped; |
5e37bdc0 BZ |
110 | dma_ops->dma_exec_cmd(drive, tf->command); |
111 | dma_ops->dma_start(drive); | |
74095a91 | 112 | return ide_started; |
1da177e4 | 113 | } |
1da177e4 | 114 | } |
f6e29e35 | 115 | EXPORT_SYMBOL_GPL(do_rw_taskfile); |
1da177e4 | 116 | |
1da177e4 | 117 | /* |
d6ff9f64 | 118 | * Handler for commands without a data phase |
1da177e4 | 119 | */ |
d6ff9f64 | 120 | static ide_startstop_t task_no_data_intr(ide_drive_t *drive) |
1da177e4 | 121 | { |
b73c7ee2 | 122 | ide_hwif_t *hwif = drive->hwif; |
22aa4b32 BZ |
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; | |
d6ff9f64 | 126 | int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1; |
1da177e4 LT |
127 | u8 stat; |
128 | ||
90d2c6bc BZ |
129 | local_irq_enable_in_hardirq(); |
130 | ||
374e042c BZ |
131 | while (1) { |
132 | stat = hwif->tp_ops->read_status(hwif); | |
3a7d2484 | 133 | if ((stat & ATA_BUSY) == 0 || retries-- == 0) |
374e042c | 134 | break; |
1da177e4 | 135 | udelay(10); |
374e042c | 136 | }; |
1da177e4 | 137 | |
d6ff9f64 BZ |
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, NULL); | |
148 | return ide_started; | |
149 | } | |
150 | } | |
1da177e4 | 151 | return ide_error(drive, "task_no_data_intr", stat); |
d6ff9f64 | 152 | } |
c47137a9 | 153 | |
a09485df | 154 | if (custom && tf->command == ATA_CMD_IDLEIMMEDIATE) { |
22aa4b32 | 155 | hwif->tp_ops->tf_read(drive, cmd); |
4abdc6ee EO |
156 | 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; | |
a09485df | 162 | } else if (custom && tf->command == ATA_CMD_SET_MULTI) |
d6ff9f64 | 163 | drive->mult_count = drive->mult_req; |
1da177e4 | 164 | |
a09485df BZ |
165 | 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) | |
22aa4b32 | 173 | ide_complete_cmd(drive, cmd, stat, err); |
a09485df BZ |
174 | ide_complete_rq(drive, err); |
175 | } | |
176 | } | |
177 | ||
1da177e4 LT |
178 | return ide_stopped; |
179 | } | |
180 | ||
da6f4c7f | 181 | static u8 wait_drive_not_busy(ide_drive_t *drive) |
1da177e4 | 182 | { |
b73c7ee2 | 183 | ide_hwif_t *hwif = drive->hwif; |
b42fa133 | 184 | int retries; |
1da177e4 LT |
185 | u8 stat; |
186 | ||
187 | /* | |
f54feafa BZ |
188 | * 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. | |
1da177e4 | 190 | */ |
f54feafa | 191 | for (retries = 0; retries < 1000; retries++) { |
374e042c | 192 | stat = hwif->tp_ops->read_status(hwif); |
c47137a9 | 193 | |
3a7d2484 | 194 | if (stat & ATA_BUSY) |
b42fa133 MY |
195 | udelay(10); |
196 | else | |
197 | break; | |
198 | } | |
1da177e4 | 199 | |
3a7d2484 | 200 | if (stat & ATA_BUSY) |
1da177e4 LT |
201 | printk(KERN_ERR "%s: drive still BUSY!\n", drive->name); |
202 | ||
203 | return stat; | |
204 | } | |
205 | ||
92d3ab27 BZ |
206 | static void ide_pio_sector(ide_drive_t *drive, struct request *rq, |
207 | unsigned int write) | |
1da177e4 LT |
208 | { |
209 | ide_hwif_t *hwif = drive->hwif; | |
210 | struct scatterlist *sg = hwif->sg_table; | |
55c16a70 | 211 | struct scatterlist *cursg = hwif->cursg; |
1da177e4 LT |
212 | struct page *page; |
213 | #ifdef CONFIG_HIGHMEM | |
214 | unsigned long flags; | |
215 | #endif | |
216 | unsigned int offset; | |
217 | u8 *buf; | |
218 | ||
55c16a70 JA |
219 | cursg = hwif->cursg; |
220 | if (!cursg) { | |
221 | cursg = sg; | |
222 | hwif->cursg = sg; | |
223 | } | |
224 | ||
45711f1a | 225 | page = sg_page(cursg); |
55c16a70 | 226 | offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE; |
1da177e4 LT |
227 | |
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 | ||
55c16a70 JA |
240 | if ((hwif->cursg_ofs * SECTOR_SIZE) == cursg->length) { |
241 | hwif->cursg = sg_next(hwif->cursg); | |
1da177e4 LT |
242 | hwif->cursg_ofs = 0; |
243 | } | |
244 | ||
245 | /* do the actual data transfer */ | |
246 | if (write) | |
374e042c | 247 | hwif->tp_ops->output_data(drive, rq, buf, SECTOR_SIZE); |
1da177e4 | 248 | else |
374e042c | 249 | hwif->tp_ops->input_data(drive, rq, buf, SECTOR_SIZE); |
1da177e4 LT |
250 | |
251 | kunmap_atomic(buf, KM_BIO_SRC_IRQ); | |
252 | #ifdef CONFIG_HIGHMEM | |
253 | local_irq_restore(flags); | |
254 | #endif | |
255 | } | |
256 | ||
92d3ab27 BZ |
257 | static void ide_pio_multi(ide_drive_t *drive, struct request *rq, |
258 | unsigned int write) | |
1da177e4 LT |
259 | { |
260 | unsigned int nsect; | |
261 | ||
262 | nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count); | |
263 | while (nsect--) | |
92d3ab27 | 264 | ide_pio_sector(drive, rq, write); |
1da177e4 LT |
265 | } |
266 | ||
858119e1 | 267 | static void ide_pio_datablock(ide_drive_t *drive, struct request *rq, |
1da177e4 LT |
268 | unsigned int write) |
269 | { | |
22aa4b32 | 270 | struct ide_cmd *cmd = &drive->hwif->cmd; |
35cf2b94 TH |
271 | u8 saved_io_32bit = drive->io_32bit; |
272 | ||
b109f526 | 273 | if (blk_fs_request(rq)) |
1da177e4 LT |
274 | rq->errors = 0; |
275 | ||
22aa4b32 | 276 | if (cmd->tf_flags & IDE_TFLAG_IO_16BIT) |
e3d9a73a | 277 | drive->io_32bit = 0; |
35cf2b94 | 278 | |
651c29a1 AM |
279 | touch_softlockup_watchdog(); |
280 | ||
22aa4b32 | 281 | switch (cmd->data_phase) { |
1da177e4 LT |
282 | case TASKFILE_MULTI_IN: |
283 | case TASKFILE_MULTI_OUT: | |
92d3ab27 | 284 | ide_pio_multi(drive, rq, write); |
1da177e4 LT |
285 | break; |
286 | default: | |
92d3ab27 | 287 | ide_pio_sector(drive, rq, write); |
1da177e4 LT |
288 | break; |
289 | } | |
35cf2b94 TH |
290 | |
291 | drive->io_32bit = saved_io_32bit; | |
1da177e4 LT |
292 | } |
293 | ||
294 | static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq, | |
295 | const char *s, u8 stat) | |
296 | { | |
b109f526 | 297 | if (blk_fs_request(rq)) { |
1da177e4 | 298 | ide_hwif_t *hwif = drive->hwif; |
22aa4b32 | 299 | struct ide_cmd *cmd = &hwif->cmd; |
1da177e4 LT |
300 | int sectors = hwif->nsect - hwif->nleft; |
301 | ||
22aa4b32 | 302 | switch (cmd->data_phase) { |
1da177e4 LT |
303 | 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 | ||
c152cc1a BZ |
320 | if (sectors > 0) |
321 | ide_end_request(drive, 1, sectors); | |
1da177e4 LT |
322 | } |
323 | return ide_error(drive, s, stat); | |
324 | } | |
325 | ||
4d7a984b | 326 | void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat) |
1da177e4 | 327 | { |
b109f526 | 328 | if (blk_fs_request(rq) == 0) { |
22aa4b32 | 329 | struct ide_cmd *cmd = rq->special; |
64a57fe4 | 330 | u8 err = ide_read_error(drive); |
1da177e4 | 331 | |
22aa4b32 BZ |
332 | if (cmd) |
333 | ide_complete_cmd(drive, cmd, stat, err); | |
a09485df | 334 | ide_complete_rq(drive, err); |
4d7a984b | 335 | return; |
1da177e4 LT |
336 | } |
337 | ||
c152cc1a | 338 | ide_end_request(drive, 1, rq->nr_sectors); |
1da177e4 LT |
339 | } |
340 | ||
6c3c3158 LT |
341 | /* |
342 | * 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 | */ | |
347 | static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat) | |
348 | { | |
349 | /* Command all done? */ | |
3a7d2484 | 350 | if (OK_STAT(stat, ATA_DRDY, ATA_BUSY)) { |
6c3c3158 LT |
351 | 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 | ||
1da177e4 LT |
360 | /* |
361 | * Handler for command with PIO data-in phase (Read/Read Multiple). | |
362 | */ | |
f6e29e35 | 363 | static ide_startstop_t task_in_intr(ide_drive_t *drive) |
1da177e4 LT |
364 | { |
365 | ide_hwif_t *hwif = drive->hwif; | |
b65fac32 | 366 | struct request *rq = hwif->rq; |
374e042c | 367 | u8 stat = hwif->tp_ops->read_status(hwif); |
1da177e4 | 368 | |
6c3c3158 | 369 | /* Error? */ |
3a7d2484 | 370 | if (stat & ATA_ERR) |
eb63963a | 371 | return task_error(drive, rq, __func__, stat); |
6c3c3158 LT |
372 | |
373 | /* Didn't want any data? Odd. */ | |
3a7d2484 | 374 | if ((stat & ATA_DRQ) == 0) |
6c3c3158 | 375 | return task_in_unexpected(drive, rq, stat); |
1da177e4 LT |
376 | |
377 | ide_pio_datablock(drive, rq, 0); | |
378 | ||
6c3c3158 | 379 | /* Are we done? Check status and finish transfer. */ |
1da177e4 LT |
380 | if (!hwif->nleft) { |
381 | stat = wait_drive_not_busy(drive); | |
73d7de0c | 382 | if (!OK_STAT(stat, 0, BAD_STAT)) |
eb63963a | 383 | return task_error(drive, rq, __func__, stat); |
1da177e4 LT |
384 | 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 | } | |
1da177e4 LT |
393 | |
394 | /* | |
395 | * Handler for command with PIO data-out phase (Write/Write Multiple). | |
396 | */ | |
397 | static ide_startstop_t task_out_intr (ide_drive_t *drive) | |
398 | { | |
399 | ide_hwif_t *hwif = drive->hwif; | |
b65fac32 | 400 | struct request *rq = hwif->rq; |
374e042c | 401 | u8 stat = hwif->tp_ops->read_status(hwif); |
1da177e4 LT |
402 | |
403 | if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) | |
eb63963a | 404 | return task_error(drive, rq, __func__, stat); |
1da177e4 LT |
405 | |
406 | /* Deal with unexpected ATA data phase. */ | |
3a7d2484 | 407 | if (((stat & ATA_DRQ) == 0) ^ !hwif->nleft) |
eb63963a | 408 | return task_error(drive, rq, __func__, stat); |
1da177e4 LT |
409 | |
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 | ||
f6e29e35 | 422 | static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq) |
1da177e4 | 423 | { |
22aa4b32 | 424 | struct ide_cmd *cmd = &drive->hwif->cmd; |
1da177e4 LT |
425 | ide_startstop_t startstop; |
426 | ||
3a7d2484 | 427 | if (ide_wait_stat(&startstop, drive, ATA_DRQ, |
1da177e4 LT |
428 | drive->bad_wstat, WAIT_DRQ)) { |
429 | printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", | |
c7db966b | 430 | drive->name, |
22aa4b32 | 431 | cmd->data_phase == TASKFILE_MULTI_OUT ? "MULT" : "", |
97100fc8 | 432 | (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : ""); |
1da177e4 LT |
433 | return startstop; |
434 | } | |
435 | ||
97100fc8 | 436 | if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0) |
1da177e4 LT |
437 | 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 | } | |
1da177e4 | 444 | |
22aa4b32 BZ |
445 | int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf, |
446 | u16 nsect) | |
1da177e4 | 447 | { |
154ed280 FT |
448 | struct request *rq; |
449 | int error; | |
1da177e4 | 450 | |
154ed280 FT |
451 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
452 | rq->cmd_type = REQ_TYPE_ATA_TASKFILE; | |
453 | rq->buffer = buf; | |
1da177e4 LT |
454 | |
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 | */ | |
154ed280 FT |
461 | rq->hard_nr_sectors = rq->nr_sectors = nsect; |
462 | rq->hard_cur_sectors = rq->current_nr_sectors = nsect; | |
1da177e4 | 463 | |
22aa4b32 | 464 | if (cmd->tf_flags & IDE_TFLAG_WRITE) |
154ed280 | 465 | rq->cmd_flags |= REQ_RW; |
1da177e4 | 466 | |
22aa4b32 BZ |
467 | rq->special = cmd; |
468 | cmd->rq = rq; | |
1da177e4 | 469 | |
154ed280 FT |
470 | error = blk_execute_rq(drive->queue, NULL, rq, 0); |
471 | blk_put_request(rq); | |
472 | ||
473 | return error; | |
1da177e4 LT |
474 | } |
475 | ||
1da177e4 LT |
476 | EXPORT_SYMBOL(ide_raw_taskfile); |
477 | ||
22aa4b32 | 478 | int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd) |
9a3c49be | 479 | { |
22aa4b32 | 480 | cmd->data_phase = TASKFILE_NO_DATA; |
9a3c49be | 481 | |
22aa4b32 | 482 | return ide_raw_taskfile(drive, cmd, NULL, 0); |
9a3c49be BZ |
483 | } |
484 | EXPORT_SYMBOL_GPL(ide_no_data_taskfile); | |
485 | ||
26a5b040 | 486 | #ifdef CONFIG_IDE_TASK_IOCTL |
22aa4b32 | 487 | int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg) |
1da177e4 LT |
488 | { |
489 | ide_task_request_t *req_task; | |
22aa4b32 | 490 | struct ide_cmd cmd; |
1da177e4 LT |
491 | u8 *outbuf = NULL; |
492 | u8 *inbuf = NULL; | |
ac026ff2 | 493 | u8 *data_buf = NULL; |
1da177e4 LT |
494 | int err = 0; |
495 | int tasksize = sizeof(struct ide_task_request_s); | |
3a42bb22 AC |
496 | unsigned int taskin = 0; |
497 | unsigned int taskout = 0; | |
ac026ff2 | 498 | u16 nsect = 0; |
1da177e4 LT |
499 | char __user *buf = (char __user *)arg; |
500 | ||
501 | // printk("IDE Taskfile ...\n"); | |
502 | ||
f5e3c2fa | 503 | req_task = kzalloc(tasksize, GFP_KERNEL); |
1da177e4 | 504 | if (req_task == NULL) return -ENOMEM; |
1da177e4 LT |
505 | if (copy_from_user(req_task, buf, tasksize)) { |
506 | kfree(req_task); | |
507 | return -EFAULT; | |
508 | } | |
509 | ||
3a42bb22 AC |
510 | 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 | } | |
1da177e4 LT |
517 | |
518 | if (taskout) { | |
519 | int outtotal = tasksize; | |
f5e3c2fa | 520 | outbuf = kzalloc(taskout, GFP_KERNEL); |
1da177e4 LT |
521 | if (outbuf == NULL) { |
522 | err = -ENOMEM; | |
523 | goto abort; | |
524 | } | |
1da177e4 LT |
525 | 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; | |
f5e3c2fa | 533 | inbuf = kzalloc(taskin, GFP_KERNEL); |
1da177e4 LT |
534 | if (inbuf == NULL) { |
535 | err = -ENOMEM; | |
536 | goto abort; | |
537 | } | |
1da177e4 LT |
538 | if (copy_from_user(inbuf, buf + intotal, taskin)) { |
539 | err = -EFAULT; | |
540 | goto abort; | |
541 | } | |
542 | } | |
543 | ||
22aa4b32 | 544 | memset(&cmd, 0, sizeof(cmd)); |
1da177e4 | 545 | |
22aa4b32 BZ |
546 | 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); | |
866e2ec9 | 550 | |
22aa4b32 BZ |
551 | cmd.data_phase = req_task->data_phase; |
552 | cmd.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE | | |
553 | IDE_TFLAG_IN_TF; | |
1da177e4 | 554 | |
97100fc8 | 555 | if (drive->dev_flags & IDE_DFLAG_LBA48) |
22aa4b32 | 556 | cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB); |
a3bbb9d8 | 557 | |
74095a91 | 558 | if (req_task->out_flags.all) { |
22aa4b32 | 559 | cmd.ftf_flags |= IDE_FTFLAG_FLAGGED; |
74095a91 BZ |
560 | |
561 | if (req_task->out_flags.b.data) | |
22aa4b32 | 562 | cmd.ftf_flags |= IDE_FTFLAG_OUT_DATA; |
74095a91 BZ |
563 | |
564 | if (req_task->out_flags.b.nsector_hob) | |
22aa4b32 | 565 | cmd.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT; |
74095a91 | 566 | if (req_task->out_flags.b.sector_hob) |
22aa4b32 | 567 | cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL; |
74095a91 | 568 | if (req_task->out_flags.b.lcyl_hob) |
22aa4b32 | 569 | cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM; |
74095a91 | 570 | if (req_task->out_flags.b.hcyl_hob) |
22aa4b32 | 571 | cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH; |
74095a91 BZ |
572 | |
573 | if (req_task->out_flags.b.error_feature) | |
22aa4b32 | 574 | cmd.tf_flags |= IDE_TFLAG_OUT_FEATURE; |
74095a91 | 575 | if (req_task->out_flags.b.nsector) |
22aa4b32 | 576 | cmd.tf_flags |= IDE_TFLAG_OUT_NSECT; |
74095a91 | 577 | if (req_task->out_flags.b.sector) |
22aa4b32 | 578 | cmd.tf_flags |= IDE_TFLAG_OUT_LBAL; |
74095a91 | 579 | if (req_task->out_flags.b.lcyl) |
22aa4b32 | 580 | cmd.tf_flags |= IDE_TFLAG_OUT_LBAM; |
74095a91 | 581 | if (req_task->out_flags.b.hcyl) |
22aa4b32 | 582 | cmd.tf_flags |= IDE_TFLAG_OUT_LBAH; |
a3bbb9d8 | 583 | } else { |
22aa4b32 BZ |
584 | cmd.tf_flags |= IDE_TFLAG_OUT_TF; |
585 | if (cmd.tf_flags & IDE_TFLAG_LBA48) | |
586 | cmd.tf_flags |= IDE_TFLAG_OUT_HOB; | |
74095a91 BZ |
587 | } |
588 | ||
866e2ec9 | 589 | if (req_task->in_flags.b.data) |
22aa4b32 | 590 | cmd.ftf_flags |= IDE_FTFLAG_IN_DATA; |
866e2ec9 | 591 | |
1da177e4 | 592 | switch(req_task->data_phase) { |
1da177e4 LT |
593 | 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", | |
eb63963a | 598 | drive->name, __func__); |
1da177e4 LT |
599 | err = -EPERM; |
600 | goto abort; | |
601 | } | |
602 | /* fall through */ | |
603 | case TASKFILE_OUT: | |
ac026ff2 BZ |
604 | /* fall through */ |
605 | case TASKFILE_OUT_DMAQ: | |
606 | case TASKFILE_OUT_DMA: | |
607 | nsect = taskout / SECTOR_SIZE; | |
608 | data_buf = outbuf; | |
1da177e4 LT |
609 | 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", | |
eb63963a | 615 | drive->name, __func__); |
1da177e4 LT |
616 | err = -EPERM; |
617 | goto abort; | |
618 | } | |
619 | /* fall through */ | |
620 | case TASKFILE_IN: | |
ac026ff2 BZ |
621 | /* fall through */ |
622 | case TASKFILE_IN_DMAQ: | |
623 | case TASKFILE_IN_DMA: | |
624 | nsect = taskin / SECTOR_SIZE; | |
625 | data_buf = inbuf; | |
1da177e4 LT |
626 | break; |
627 | case TASKFILE_NO_DATA: | |
1da177e4 LT |
628 | break; |
629 | default: | |
630 | err = -EFAULT; | |
631 | goto abort; | |
632 | } | |
633 | ||
ac026ff2 BZ |
634 | if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA) |
635 | nsect = 0; | |
636 | else if (!nsect) { | |
22aa4b32 | 637 | nsect = (cmd.tf.hob_nsect << 8) | cmd.tf.nsect; |
ac026ff2 BZ |
638 | |
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) | |
22aa4b32 | 648 | cmd.tf_flags |= IDE_TFLAG_WRITE; |
ac026ff2 | 649 | |
22aa4b32 | 650 | err = ide_raw_taskfile(drive, &cmd, data_buf, nsect); |
ac026ff2 | 651 | |
22aa4b32 BZ |
652 | 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); | |
866e2ec9 | 656 | |
22aa4b32 | 657 | if ((cmd.ftf_flags & IDE_FTFLAG_SET_IN_FLAGS) && |
866e2ec9 BZ |
658 | req_task->in_flags.all == 0) { |
659 | req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS; | |
97100fc8 | 660 | if (drive->dev_flags & IDE_DFLAG_LBA48) |
866e2ec9 BZ |
661 | req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8); |
662 | } | |
1da177e4 LT |
663 | |
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 | } | |
682 | abort: | |
683 | kfree(req_task); | |
6044ec88 JJ |
684 | kfree(outbuf); |
685 | kfree(inbuf); | |
1da177e4 LT |
686 | |
687 | // printk("IDE Taskfile ioctl ended. rc = %i\n", err); | |
688 | ||
1da177e4 LT |
689 | return err; |
690 | } | |
26a5b040 | 691 | #endif |