More meth updates.
[linux-2.6/linux-mips.git] / drivers / ide / ide-taskfile.c
blob1600030f6b0213cf12fa4d915638c18194da70a1
1 /*
2 * linux/drivers/ide/ide-taskfile.c Version 0.38 March 05, 2003
4 * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org>
5 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
6 * Copyright (C) 2001-2002 Klaus Smolin
7 * IBM Storage Technology Division
8 * Copyright (C) 2003 Bartlomiej Zolnierkiewicz
10 * The big the bad and the ugly.
12 * Problems to be fixed because of BH interface or the lack therefore.
14 * Fill me in stupid !!!
16 * HOST:
17 * General refers to the Controller and Driver "pair".
18 * DATA HANDLER:
19 * Under the context of Linux it generally refers to an interrupt handler.
20 * However, it correctly describes the 'HOST'
21 * DATA BLOCK:
22 * The amount of data needed to be transfered as predefined in the
23 * setup of the device.
24 * STORAGE ATOMIC:
25 * The 'DATA BLOCK' associated to the 'DATA HANDLER', and can be as
26 * small as a single sector or as large as the entire command block
27 * request.
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/string.h>
34 #include <linux/kernel.h>
35 #include <linux/timer.h>
36 #include <linux/mm.h>
37 #include <linux/interrupt.h>
38 #include <linux/major.h>
39 #include <linux/errno.h>
40 #include <linux/genhd.h>
41 #include <linux/blkpg.h>
42 #include <linux/slab.h>
43 #include <linux/pci.h>
44 #include <linux/delay.h>
45 #include <linux/hdreg.h>
46 #include <linux/ide.h>
48 #include <asm/byteorder.h>
49 #include <asm/irq.h>
50 #include <asm/uaccess.h>
51 #include <asm/io.h>
52 #include <asm/bitops.h>
54 #define DEBUG_TASKFILE 0 /* unset when fixed */
56 #if DEBUG_TASKFILE
57 #define DTF(x...) printk(x)
58 #else
59 #define DTF(x...)
60 #endif
62 static void ata_bswap_data (void *buffer, int wcount)
64 u16 *p = buffer;
66 while (wcount--) {
67 *p = *p << 8 | *p >> 8; p++;
68 *p = *p << 8 | *p >> 8; p++;
73 void taskfile_input_data (ide_drive_t *drive, void *buffer, u32 wcount)
75 HWIF(drive)->ata_input_data(drive, buffer, wcount);
76 if (drive->bswap)
77 ata_bswap_data(buffer, wcount);
80 EXPORT_SYMBOL(taskfile_input_data);
82 void taskfile_output_data (ide_drive_t *drive, void *buffer, u32 wcount)
84 if (drive->bswap) {
85 ata_bswap_data(buffer, wcount);
86 HWIF(drive)->ata_output_data(drive, buffer, wcount);
87 ata_bswap_data(buffer, wcount);
88 } else {
89 HWIF(drive)->ata_output_data(drive, buffer, wcount);
93 EXPORT_SYMBOL(taskfile_output_data);
95 int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
97 ide_task_t args;
98 memset(&args, 0, sizeof(ide_task_t));
99 args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01;
100 if (drive->media == ide_disk)
101 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_IDENTIFY;
102 else
103 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_PIDENTIFY;
104 args.command_type = ide_cmd_type_parser(&args);
105 return ide_raw_taskfile(drive, &args, buf);
108 EXPORT_SYMBOL(taskfile_lib_get_identify);
110 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
111 void debug_taskfile (ide_drive_t *drive, ide_task_t *args)
113 printk(KERN_INFO "%s: ", drive->name);
114 // printk("TF.0=x%02x ", args->tfRegister[IDE_DATA_OFFSET]);
115 printk("TF.1=x%02x ", args->tfRegister[IDE_FEATURE_OFFSET]);
116 printk("TF.2=x%02x ", args->tfRegister[IDE_NSECTOR_OFFSET]);
117 printk("TF.3=x%02x ", args->tfRegister[IDE_SECTOR_OFFSET]);
118 printk("TF.4=x%02x ", args->tfRegister[IDE_LCYL_OFFSET]);
119 printk("TF.5=x%02x ", args->tfRegister[IDE_HCYL_OFFSET]);
120 printk("TF.6=x%02x ", args->tfRegister[IDE_SELECT_OFFSET]);
121 printk("TF.7=x%02x\n", args->tfRegister[IDE_COMMAND_OFFSET]);
122 printk(KERN_INFO "%s: ", drive->name);
123 // printk("HTF.0=x%02x ", args->hobRegister[IDE_DATA_OFFSET_HOB]);
124 printk("HTF.1=x%02x ", args->hobRegister[IDE_FEATURE_OFFSET_HOB]);
125 printk("HTF.2=x%02x ", args->hobRegister[IDE_NSECTOR_OFFSET_HOB]);
126 printk("HTF.3=x%02x ", args->hobRegister[IDE_SECTOR_OFFSET_HOB]);
127 printk("HTF.4=x%02x ", args->hobRegister[IDE_LCYL_OFFSET_HOB]);
128 printk("HTF.5=x%02x ", args->hobRegister[IDE_HCYL_OFFSET_HOB]);
129 printk("HTF.6=x%02x ", args->hobRegister[IDE_SELECT_OFFSET_HOB]);
130 printk("HTF.7=x%02x\n", args->hobRegister[IDE_CONTROL_OFFSET_HOB]);
132 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
134 ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
136 ide_hwif_t *hwif = HWIF(drive);
137 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
138 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
139 u8 HIHI = (drive->addressing == 1) ? 0xE0 : 0xEF;
141 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
142 void debug_taskfile(drive, task);
143 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
145 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
146 if (IDE_CONTROL_REG) {
147 /* clear nIEN */
148 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
150 SELECT_MASK(drive, 0);
152 if (drive->addressing == 1) {
153 hwif->OUTB(hobfile->feature, IDE_FEATURE_REG);
154 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
155 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
156 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
157 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
160 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
161 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
162 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
163 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
164 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
166 hwif->OUTB((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG);
167 #ifdef CONFIG_IDE_TASKFILE_IO
168 if (task->handler != NULL) {
169 if (task->prehandler != NULL) {
170 hwif->OUTBSYNC(drive, taskfile->command, IDE_COMMAND_REG);
171 ndelay(400); /* FIXME */
172 return task->prehandler(drive, task->rq);
174 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
175 return ide_started;
177 #else
178 if (task->handler != NULL) {
179 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
180 if (task->prehandler != NULL)
181 return task->prehandler(drive, task->rq);
182 return ide_started;
184 #endif
186 if (!drive->using_dma)
187 return ide_stopped;
189 switch (taskfile->command) {
190 case WIN_WRITEDMA_ONCE:
191 case WIN_WRITEDMA:
192 case WIN_WRITEDMA_EXT:
193 if (!hwif->ide_dma_write(drive))
194 return ide_started;
195 break;
196 case WIN_READDMA_ONCE:
197 case WIN_READDMA:
198 case WIN_READDMA_EXT:
199 case WIN_IDENTIFY_DMA:
200 if (!hwif->ide_dma_read(drive))
201 return ide_started;
202 break;
203 case WIN_READDMA_QUEUED:
204 case WIN_READDMA_QUEUED_EXT:
205 return hwif->ide_dma_queued_read(drive);
206 case WIN_WRITEDMA_QUEUED:
207 case WIN_WRITEDMA_QUEUED_EXT:
208 return hwif->ide_dma_queued_write(drive);
209 default:
210 if (task->handler == NULL)
211 return ide_stopped;
214 return ide_stopped;
217 EXPORT_SYMBOL(do_rw_taskfile);
220 * Clean up after success/failure of an explicit taskfile operation.
222 void ide_end_taskfile (ide_drive_t *drive, u8 stat, u8 err)
224 ide_hwif_t *hwif = HWIF(drive);
225 unsigned long flags;
226 struct request *rq;
227 ide_task_t *args;
228 task_ioreg_t command;
230 spin_lock_irqsave(&ide_lock, flags);
231 rq = HWGROUP(drive)->rq;
232 spin_unlock_irqrestore(&ide_lock, flags);
233 args = (ide_task_t *) rq->special;
235 command = args->tfRegister[IDE_COMMAND_OFFSET];
237 if (rq->errors == 0)
238 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
240 if (args->tf_in_flags.b.data) {
241 u16 data = hwif->INW(IDE_DATA_REG);
242 args->tfRegister[IDE_DATA_OFFSET] = (data) & 0xFF;
243 args->hobRegister[IDE_DATA_OFFSET_HOB] = (data >> 8) & 0xFF;
245 args->tfRegister[IDE_ERROR_OFFSET] = err;
246 args->tfRegister[IDE_NSECTOR_OFFSET] = hwif->INB(IDE_NSECTOR_REG);
247 args->tfRegister[IDE_SECTOR_OFFSET] = hwif->INB(IDE_SECTOR_REG);
248 args->tfRegister[IDE_LCYL_OFFSET] = hwif->INB(IDE_LCYL_REG);
249 args->tfRegister[IDE_HCYL_OFFSET] = hwif->INB(IDE_HCYL_REG);
250 args->tfRegister[IDE_SELECT_OFFSET] = hwif->INB(IDE_SELECT_REG);
251 args->tfRegister[IDE_STATUS_OFFSET] = stat;
252 if ((drive->id->command_set_2 & 0x0400) &&
253 (drive->id->cfs_enable_2 & 0x0400) &&
254 (drive->addressing == 1)) {
255 hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG_HOB);
256 args->hobRegister[IDE_FEATURE_OFFSET_HOB] = hwif->INB(IDE_FEATURE_REG);
257 args->hobRegister[IDE_NSECTOR_OFFSET_HOB] = hwif->INB(IDE_NSECTOR_REG);
258 args->hobRegister[IDE_SECTOR_OFFSET_HOB] = hwif->INB(IDE_SECTOR_REG);
259 args->hobRegister[IDE_LCYL_OFFSET_HOB] = hwif->INB(IDE_LCYL_REG);
260 args->hobRegister[IDE_HCYL_OFFSET_HOB] = hwif->INB(IDE_HCYL_REG);
263 #if 0
264 /* taskfile_settings_update(drive, args, command); */
266 if (args->posthandler != NULL)
267 args->posthandler(drive, args);
268 #endif
270 spin_lock_irqsave(&ide_lock, flags);
271 blkdev_dequeue_request(rq);
272 HWGROUP(drive)->rq = NULL;
273 end_that_request_last(rq);
274 spin_unlock_irqrestore(&ide_lock, flags);
277 EXPORT_SYMBOL(ide_end_taskfile);
280 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
282 ide_startstop_t set_multmode_intr (ide_drive_t *drive)
284 ide_hwif_t *hwif = HWIF(drive);
285 u8 stat;
287 if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
288 drive->mult_count = drive->mult_req;
289 } else {
290 drive->mult_req = drive->mult_count = 0;
291 drive->special.b.recalibrate = 1;
292 (void) ide_dump_status(drive, "set_multmode", stat);
294 return ide_stopped;
297 EXPORT_SYMBOL(set_multmode_intr);
300 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
302 ide_startstop_t set_geometry_intr (ide_drive_t *drive)
304 ide_hwif_t *hwif = HWIF(drive);
305 int retries = 5;
306 u8 stat;
308 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
309 udelay(10);
311 if (OK_STAT(stat, READY_STAT, BAD_STAT))
312 return ide_stopped;
314 if (stat & (ERR_STAT|DRQ_STAT))
315 return DRIVER(drive)->error(drive, "set_geometry_intr", stat);
317 if (HWGROUP(drive)->handler != NULL)
318 BUG();
319 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
320 return ide_started;
323 EXPORT_SYMBOL(set_geometry_intr);
326 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
328 ide_startstop_t recal_intr (ide_drive_t *drive)
330 ide_hwif_t *hwif = HWIF(drive);
331 u8 stat;
333 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT))
334 return DRIVER(drive)->error(drive, "recal_intr", stat);
335 return ide_stopped;
338 EXPORT_SYMBOL(recal_intr);
341 * Handler for commands without a data phase
343 ide_startstop_t task_no_data_intr (ide_drive_t *drive)
345 ide_task_t *args = HWGROUP(drive)->rq->special;
346 ide_hwif_t *hwif = HWIF(drive);
347 u8 stat;
349 local_irq_enable();
350 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
351 DTF("%s: command opcode 0x%02x\n", drive->name,
352 args->tfRegister[IDE_COMMAND_OFFSET]);
353 return DRIVER(drive)->error(drive, "task_no_data_intr", stat);
354 /* calls ide_end_drive_cmd */
356 if (args)
357 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
359 return ide_stopped;
362 EXPORT_SYMBOL(task_no_data_intr);
365 * old taskfile PIO handlers, to be killed as soon as possible.
367 #ifndef CONFIG_IDE_TASKFILE_IO
369 #define task_map_rq(rq, flags) ide_map_buffer((rq), (flags))
370 #define task_unmap_rq(rq, buf, flags) ide_unmap_buffer((rq), (buf), (flags))
373 * Handler for command with PIO data-in phase, READ
376 * FIXME before 2.4 enable ...
377 * DATA integrity issue upon error. <andre@linux-ide.org>
379 ide_startstop_t task_in_intr (ide_drive_t *drive)
381 struct request *rq = HWGROUP(drive)->rq;
382 ide_hwif_t *hwif = HWIF(drive);
383 char *pBuf = NULL;
384 u8 stat;
385 unsigned long flags;
387 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
388 if (stat & (ERR_STAT|DRQ_STAT)) {
389 #if 0
390 DTF("%s: attempting to recover last " \
391 "sector counter status=0x%02x\n",
392 drive->name, stat);
394 * Expect a BUG BOMB if we attempt to rewind the
395 * offset in the BH aka PAGE in the current BLOCK
396 * segment. This is different than the HOST segment.
398 #endif
399 if (!rq->bio)
400 rq->current_nr_sectors++;
401 return DRIVER(drive)->error(drive, "task_in_intr", stat);
403 if (!(stat & BUSY_STAT)) {
404 DTF("task_in_intr to Soon wait for next interrupt\n");
405 if (HWGROUP(drive)->handler == NULL)
406 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
407 return ide_started;
410 #if 0
413 * Holding point for a brain dump of a thought :-/
416 if (!OK_STAT(stat,DRIVE_READY,drive->bad_wstat)) {
417 DTF("%s: READ attempting to recover last " \
418 "sector counter status=0x%02x\n",
419 drive->name, stat);
420 rq->current_nr_sectors++;
421 return DRIVER(drive)->error(drive, "task_in_intr", stat);
423 if (!rq->current_nr_sectors)
424 if (!DRIVER(drive)->end_request(drive, 1, 0))
425 return ide_stopped;
427 if (--rq->current_nr_sectors <= 0)
428 if (!DRIVER(drive)->end_request(drive, 1, 0))
429 return ide_stopped;
430 #endif
432 pBuf = task_map_rq(rq, &flags);
433 DTF("Read: %p, rq->current_nr_sectors: %d, stat: %02x\n",
434 pBuf, (int) rq->current_nr_sectors, stat);
435 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
436 task_unmap_rq(rq, pBuf, &flags);
438 * FIXME :: We really can not legally get a new page/bh
439 * regardless, if this is the end of our segment.
440 * BH walking or segment can only be updated after we have a good
441 * hwif->INB(IDE_STATUS_REG); return.
443 if (--rq->current_nr_sectors <= 0)
444 if (!DRIVER(drive)->end_request(drive, 1, 0))
445 return ide_stopped;
447 * ERM, it is techincally legal to leave/exit here but it makes
448 * a mess of the code ...
450 if (HWGROUP(drive)->handler == NULL)
451 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
452 return ide_started;
455 EXPORT_SYMBOL(task_in_intr);
458 * Handler for command with Read Multiple
460 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
462 ide_hwif_t *hwif = HWIF(drive);
463 struct request *rq = HWGROUP(drive)->rq;
464 char *pBuf = NULL;
465 unsigned int msect = drive->mult_count;
466 unsigned int nsect;
467 unsigned long flags;
468 u8 stat;
470 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),DATA_READY,BAD_R_STAT)) {
471 if (stat & (ERR_STAT|DRQ_STAT)) {
472 if (!rq->bio) {
473 rq->current_nr_sectors += drive->mult_count;
475 * NOTE: could rewind beyond beginning :-/
477 } else {
478 printk(KERN_ERR "%s: MULTI-READ assume all data " \
479 "transfered is bad status=0x%02x\n",
480 drive->name, stat);
482 return DRIVER(drive)->error(drive, "task_mulin_intr", stat);
484 /* no data yet, so wait for another interrupt */
485 if (HWGROUP(drive)->handler == NULL)
486 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
487 return ide_started;
490 do {
491 nsect = rq->current_nr_sectors;
492 if (nsect > msect)
493 nsect = msect;
494 pBuf = task_map_rq(rq, &flags);
495 DTF("Multiread: %p, nsect: %d, msect: %d, " \
496 " rq->current_nr_sectors: %d\n",
497 pBuf, nsect, msect, rq->current_nr_sectors);
498 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
499 task_unmap_rq(rq, pBuf, &flags);
500 rq->errors = 0;
501 rq->current_nr_sectors -= nsect;
502 msect -= nsect;
504 * FIXME :: We really can not legally get a new page/bh
505 * regardless, if this is the end of our segment.
506 * BH walking or segment can only be updated after we have a
507 * good hwif->INB(IDE_STATUS_REG); return.
509 if (!rq->current_nr_sectors) {
510 if (!DRIVER(drive)->end_request(drive, 1, 0))
511 return ide_stopped;
513 } while (msect);
514 if (HWGROUP(drive)->handler == NULL)
515 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
516 return ide_started;
519 EXPORT_SYMBOL(task_mulin_intr);
522 * VERIFY ME before 2.4 ... unexpected race is possible based on details
523 * RMK with 74LS245/373/374 TTL buffer logic because of passthrough.
525 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
527 char *pBuf = NULL;
528 unsigned long flags;
529 ide_startstop_t startstop;
531 if (ide_wait_stat(&startstop, drive, DATA_READY,
532 drive->bad_wstat, WAIT_DRQ)) {
533 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
534 drive->name,
535 drive->addressing ? "_EXT" : "");
536 return startstop;
538 /* For Write_sectors we need to stuff the first sector */
539 pBuf = task_map_rq(rq, &flags);
540 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
541 rq->current_nr_sectors--;
542 task_unmap_rq(rq, pBuf, &flags);
543 return ide_started;
546 EXPORT_SYMBOL(pre_task_out_intr);
549 * Handler for command with PIO data-out phase WRITE
551 * WOOHOO this is a CORRECT STATE DIAGRAM NOW, <andre@linux-ide.org>
553 ide_startstop_t task_out_intr (ide_drive_t *drive)
555 ide_hwif_t *hwif = HWIF(drive);
556 struct request *rq = HWGROUP(drive)->rq;
557 char *pBuf = NULL;
558 unsigned long flags;
559 u8 stat;
561 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), DRIVE_READY, drive->bad_wstat)) {
562 DTF("%s: WRITE attempting to recover last " \
563 "sector counter status=0x%02x\n",
564 drive->name, stat);
565 rq->current_nr_sectors++;
566 return DRIVER(drive)->error(drive, "task_out_intr", stat);
569 * Safe to update request for partial completions.
570 * We have a good STATUS CHECK!!!
572 if (!rq->current_nr_sectors)
573 if (!DRIVER(drive)->end_request(drive, 1, 0))
574 return ide_stopped;
575 if ((rq->current_nr_sectors==1) ^ (stat & DRQ_STAT)) {
576 rq = HWGROUP(drive)->rq;
577 pBuf = task_map_rq(rq, &flags);
578 DTF("write: %p, rq->current_nr_sectors: %d\n",
579 pBuf, (int) rq->current_nr_sectors);
580 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
581 task_unmap_rq(rq, pBuf, &flags);
582 rq->errors = 0;
583 rq->current_nr_sectors--;
585 if (HWGROUP(drive)->handler == NULL)
586 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
587 return ide_started;
590 EXPORT_SYMBOL(task_out_intr);
592 #undef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
594 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
596 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
597 ide_hwif_t *hwif = HWIF(drive);
598 char *pBuf = NULL;
599 unsigned int nsect = 0, msect = drive->mult_count;
600 u8 stat;
601 unsigned long flags;
602 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
604 ide_task_t *args = rq->special;
605 ide_startstop_t startstop;
607 #if 0
609 * assign private copy for multi-write
611 memcpy(&HWGROUP(drive)->wrq, rq, sizeof(struct request));
612 #endif
614 if (ide_wait_stat(&startstop, drive, DATA_READY,
615 drive->bad_wstat, WAIT_DRQ)) {
616 printk(KERN_ERR "%s: no DRQ after issuing %s\n",
617 drive->name,
618 drive->addressing ? "MULTWRITE_EXT" : "MULTWRITE");
619 return startstop;
621 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
623 do {
624 nsect = rq->current_nr_sectors;
625 if (nsect > msect)
626 nsect = msect;
627 pBuf = task_map_rq(rq, &flags);
628 DTF("Pre-Multiwrite: %p, nsect: %d, msect: %d, " \
629 "rq->current_nr_sectors: %ld\n",
630 pBuf, nsect, msect, rq->current_nr_sectors);
631 msect -= nsect;
632 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
633 task_unmap_rq(rq, pBuf, &flags);
634 rq->current_nr_sectors -= nsect;
635 if (!rq->current_nr_sectors) {
636 if (!DRIVER(drive)->end_request(drive, 1, 0))
637 if (!rq->bio) {
638 stat = hwif->INB(IDE_STATUS_REG);
639 return ide_stopped;
642 } while (msect);
643 rq->errors = 0;
644 return ide_started;
645 #else /* ! ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
646 if (!(drive_is_ready(drive))) {
647 int i;
648 for (i=0; i<100; i++) {
649 if (drive_is_ready(drive))
650 break;
655 * WARNING :: if the drive as not acked good status we may not
656 * move the DATA-TRANSFER T-Bar as BSY != 0. <andre@linux-ide.org>
658 return args->handler(drive);
659 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
662 EXPORT_SYMBOL(pre_task_mulout_intr);
665 * FIXME before enabling in 2.4 ... DATA integrity issue upon error.
668 * Handler for command write multiple
669 * Called directly from execute_drive_cmd for the first bunch of sectors,
670 * afterwards only by the ISR
672 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
674 ide_hwif_t *hwif = HWIF(drive);
675 u8 stat = hwif->INB(IDE_STATUS_REG);
676 struct request *rq = HWGROUP(drive)->rq;
677 char *pBuf = NULL;
678 ide_startstop_t startstop = ide_stopped;
679 unsigned int msect = drive->mult_count;
680 unsigned int nsect;
681 unsigned long flags;
684 * (ks/hs): Handle last IRQ on multi-sector transfer,
685 * occurs after all data was sent in this chunk
687 if (rq->current_nr_sectors == 0) {
688 if (stat & (ERR_STAT|DRQ_STAT)) {
689 if (!rq->bio) {
690 rq->current_nr_sectors += drive->mult_count;
692 * NOTE: could rewind beyond beginning :-/
694 } else {
695 printk(KERN_ERR "%s: MULTI-WRITE assume all data " \
696 "transfered is bad status=0x%02x\n",
697 drive->name, stat);
699 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
701 if (!rq->bio)
702 DRIVER(drive)->end_request(drive, 1, 0);
703 return startstop;
706 * DON'T be lazy code the above and below togather !!!
708 if (!OK_STAT(stat,DATA_READY,BAD_R_STAT)) {
709 if (stat & (ERR_STAT|DRQ_STAT)) {
710 if (!rq->bio) {
711 rq->current_nr_sectors += drive->mult_count;
713 * NOTE: could rewind beyond beginning :-/
715 } else {
716 printk("%s: MULTI-WRITE assume all data " \
717 "transfered is bad status=0x%02x\n",
718 drive->name, stat);
720 return DRIVER(drive)->error(drive, "task_mulout_intr", stat);
722 /* no data yet, so wait for another interrupt */
723 if (HWGROUP(drive)->handler == NULL)
724 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
725 return ide_started;
728 #ifndef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
729 if (HWGROUP(drive)->handler != NULL) {
730 unsigned long lflags;
731 spin_lock_irqsave(&ide_lock, lflags);
732 HWGROUP(drive)->handler = NULL;
733 del_timer(&HWGROUP(drive)->timer);
734 spin_unlock_irqrestore(&ide_lock, lflags);
736 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
738 do {
739 nsect = rq->current_nr_sectors;
740 if (nsect > msect)
741 nsect = msect;
742 pBuf = task_map_rq(rq, &flags);
743 DTF("Multiwrite: %p, nsect: %d, msect: %d, " \
744 "rq->current_nr_sectors: %ld\n",
745 pBuf, nsect, msect, rq->current_nr_sectors);
746 msect -= nsect;
747 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
748 task_unmap_rq(rq, pBuf, &flags);
749 rq->current_nr_sectors -= nsect;
751 * FIXME :: We really can not legally get a new page/bh
752 * regardless, if this is the end of our segment.
753 * BH walking or segment can only be updated after we
754 * have a good hwif->INB(IDE_STATUS_REG); return.
756 if (!rq->current_nr_sectors) {
757 if (!DRIVER(drive)->end_request(drive, 1, 0))
758 if (!rq->bio)
759 return ide_stopped;
761 } while (msect);
762 rq->errors = 0;
763 if (HWGROUP(drive)->handler == NULL)
764 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
765 return ide_started;
768 EXPORT_SYMBOL(task_mulout_intr);
770 #else /* !CONFIG_IDE_TASKFILE_IO */
772 static u8 wait_drive_not_busy(ide_drive_t *drive)
774 ide_hwif_t *hwif = HWIF(drive);
775 int retries = 5;
776 u8 stat;
778 * (ks) Last sector was transfered, wait until drive is ready.
779 * This can take up to 10 usec. We willl wait max 50 us.
781 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
782 udelay(10);
783 return stat;
787 * Handler for command with PIO data-in phase (Read).
789 ide_startstop_t task_in_intr (ide_drive_t *drive)
791 struct request *rq = HWGROUP(drive)->rq;
792 u8 stat, good_stat;
794 good_stat = DATA_READY;
795 stat = HWIF(drive)->INB(IDE_STATUS_REG);
796 check_status:
797 if (!OK_STAT(stat, good_stat, BAD_R_STAT)) {
798 if (stat & (ERR_STAT | DRQ_STAT))
799 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
800 /* BUSY_STAT: No data yet, so wait for another IRQ. */
801 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
802 return ide_started;
806 * Complete previously submitted bios (if any).
807 * Status was already verifyied.
809 while (rq->bio != rq->cbio)
810 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
811 return ide_stopped;
812 /* Complete rq->buffer based request (ioctls). */
813 if (!rq->bio && !rq->nr_sectors) {
814 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
815 return ide_stopped;
818 rq->errors = 0;
819 task_sectors(drive, rq, 1, IDE_PIO_IN);
821 /* If it was the last datablock check status and finish transfer. */
822 if (!rq->nr_sectors) {
823 good_stat = 0;
824 stat = wait_drive_not_busy(drive);
825 goto check_status;
828 /* Still data left to transfer. */
829 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
831 return ide_started;
833 EXPORT_SYMBOL(task_in_intr);
836 * Handler for command with PIO data-in phase (Read Multiple).
838 ide_startstop_t task_mulin_intr (ide_drive_t *drive)
840 struct request *rq = HWGROUP(drive)->rq;
841 unsigned int msect = drive->mult_count;
842 unsigned int nsect;
843 u8 stat, good_stat;
845 good_stat = DATA_READY;
846 stat = HWIF(drive)->INB(IDE_STATUS_REG);
847 check_status:
848 if (!OK_STAT(stat, good_stat, BAD_R_STAT)) {
849 if (stat & (ERR_STAT | DRQ_STAT))
850 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
851 /* BUSY_STAT: No data yet, so wait for another IRQ. */
852 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
853 return ide_started;
857 * Complete previously submitted bios (if any).
858 * Status was already verifyied.
860 while (rq->bio != rq->cbio)
861 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
862 return ide_stopped;
863 /* Complete rq->buffer based request (ioctls). */
864 if (!rq->bio && !rq->nr_sectors) {
865 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
866 return ide_stopped;
869 rq->errors = 0;
870 do {
871 nsect = rq->current_nr_sectors;
872 if (nsect > msect)
873 nsect = msect;
875 task_sectors(drive, rq, nsect, IDE_PIO_IN);
877 if (!rq->nr_sectors)
878 msect = 0;
879 else
880 msect -= nsect;
881 } while (msect);
883 /* If it was the last datablock check status and finish transfer. */
884 if (!rq->nr_sectors) {
885 good_stat = 0;
886 stat = wait_drive_not_busy(drive);
887 goto check_status;
890 /* Still data left to transfer. */
891 ide_set_handler(drive, &task_mulin_intr, WAIT_WORSTCASE, NULL);
893 return ide_started;
895 EXPORT_SYMBOL(task_mulin_intr);
898 * Handler for command with PIO data-out phase (Write).
900 ide_startstop_t task_out_intr (ide_drive_t *drive)
902 struct request *rq = HWGROUP(drive)->rq;
903 u8 stat;
905 stat = HWIF(drive)->INB(IDE_STATUS_REG);
906 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) {
907 if ((stat & (ERR_STAT | DRQ_STAT)) ||
908 ((stat & WRERR_STAT) && !drive->nowerr))
909 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
910 if (stat & BUSY_STAT) {
911 /* Not ready yet, so wait for another IRQ. */
912 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
913 return ide_started;
917 /* Deal with unexpected ATA data phase. */
918 if ((!(stat & DATA_READY) && rq->nr_sectors) ||
919 ((stat & DATA_READY) && !rq->nr_sectors))
920 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
923 * Complete previously submitted bios (if any).
924 * Status was already verifyied.
926 while (rq->bio != rq->cbio)
927 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
928 return ide_stopped;
929 /* Complete rq->buffer based request (ioctls). */
930 if (!rq->bio && !rq->nr_sectors) {
931 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
932 return ide_stopped;
935 /* Still data left to transfer. */
936 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
938 rq->errors = 0;
939 task_sectors(drive, rq, 1, IDE_PIO_OUT);
941 return ide_started;
944 EXPORT_SYMBOL(task_out_intr);
946 ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq)
948 ide_startstop_t startstop;
950 if (ide_wait_stat(&startstop, drive, DATA_READY,
951 drive->bad_wstat, WAIT_DRQ)) {
952 printk(KERN_ERR "%s: no DRQ after issuing WRITE%s\n",
953 drive->name, drive->addressing ? "_EXT" : "");
954 return startstop;
957 return task_out_intr(drive);
959 EXPORT_SYMBOL(pre_task_out_intr);
962 * Handler for command with PIO data-out phase (Write Multiple).
964 ide_startstop_t task_mulout_intr (ide_drive_t *drive)
966 struct request *rq = HWGROUP(drive)->rq;
967 unsigned int msect = drive->mult_count;
968 unsigned int nsect;
969 u8 stat;
971 stat = HWIF(drive)->INB(IDE_STATUS_REG);
972 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) {
973 if ((stat & (ERR_STAT | DRQ_STAT)) ||
974 ((stat & WRERR_STAT) && !drive->nowerr))
975 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
976 if (stat & BUSY_STAT) {
977 /* Not ready yet, so wait for another IRQ. */
978 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
979 return ide_started;
983 /* Deal with unexpected ATA data phase. */
984 if ((!(stat & DATA_READY) && rq->nr_sectors) ||
985 ((stat & DATA_READY) && !rq->nr_sectors))
986 return DRIVER(drive)->error(drive, __FUNCTION__, stat);
989 * Complete previously submitted bios (if any).
990 * Status was already verifyied.
992 while (rq->bio != rq->cbio)
993 if (!DRIVER(drive)->end_request(drive, 1, bio_sectors(rq->bio)))
994 return ide_stopped;
995 /* Complete rq->buffer based request (ioctls). */
996 if (!rq->bio && !rq->nr_sectors) {
997 ide_end_drive_cmd(drive, stat, HWIF(drive)->INB(IDE_ERROR_REG));
998 return ide_stopped;
1001 /* Still data left to transfer. */
1002 ide_set_handler(drive, &task_mulout_intr, WAIT_WORSTCASE, NULL);
1004 rq->errors = 0;
1005 do {
1006 nsect = rq->current_nr_sectors;
1007 if (nsect > msect)
1008 nsect = msect;
1010 task_sectors(drive, rq, nsect, IDE_PIO_OUT);
1012 if (!rq->nr_sectors)
1013 msect = 0;
1014 else
1015 msect -= nsect;
1016 } while (msect);
1018 return ide_started;
1020 EXPORT_SYMBOL(task_mulout_intr);
1022 ide_startstop_t pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
1024 ide_startstop_t startstop;
1026 if (ide_wait_stat(&startstop, drive, DATA_READY,
1027 drive->bad_wstat, WAIT_DRQ)) {
1028 printk(KERN_ERR "%s: no DRQ after issuing MULTWRITE%s\n",
1029 drive->name, drive->addressing ? "_EXT" : "");
1030 return startstop;
1033 return task_mulout_intr(drive);
1035 EXPORT_SYMBOL(pre_task_mulout_intr);
1037 #endif /* !CONFIG_IDE_TASKFILE_IO */
1039 /* Called by internal to feature out type of command being called */
1040 //ide_pre_handler_t * ide_pre_handler_parser (task_struct_t *taskfile, hob_struct_t *hobfile)
1041 ide_pre_handler_t * ide_pre_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
1043 switch(taskfile->command) {
1044 /* IDE_DRIVE_TASK_RAW_WRITE */
1045 case CFA_WRITE_MULTI_WO_ERASE:
1046 // case WIN_WRITE_LONG:
1047 // case WIN_WRITE_LONG_ONCE:
1048 case WIN_MULTWRITE:
1049 case WIN_MULTWRITE_EXT:
1050 return &pre_task_mulout_intr;
1052 /* IDE_DRIVE_TASK_OUT */
1053 case WIN_WRITE:
1054 // case WIN_WRITE_ONCE:
1055 case WIN_WRITE_EXT:
1056 case WIN_WRITE_VERIFY:
1057 case WIN_WRITE_BUFFER:
1058 case CFA_WRITE_SECT_WO_ERASE:
1059 case WIN_DOWNLOAD_MICROCODE:
1060 return &pre_task_out_intr;
1061 /* IDE_DRIVE_TASK_OUT */
1062 case WIN_SMART:
1063 if (taskfile->feature == SMART_WRITE_LOG_SECTOR)
1064 return &pre_task_out_intr;
1065 case WIN_WRITEDMA:
1066 // case WIN_WRITEDMA_ONCE:
1067 case WIN_WRITEDMA_QUEUED:
1068 case WIN_WRITEDMA_EXT:
1069 case WIN_WRITEDMA_QUEUED_EXT:
1070 /* IDE_DRIVE_TASK_OUT */
1071 default:
1072 break;
1074 return(NULL);
1077 EXPORT_SYMBOL(ide_pre_handler_parser);
1079 /* Called by internal to feature out type of command being called */
1080 //ide_handler_t * ide_handler_parser (task_struct_t *taskfile, hob_struct_t *hobfile)
1081 ide_handler_t * ide_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
1083 switch(taskfile->command) {
1084 case WIN_IDENTIFY:
1085 case WIN_PIDENTIFY:
1086 case CFA_TRANSLATE_SECTOR:
1087 case WIN_READ_BUFFER:
1088 case WIN_READ:
1089 // case WIN_READ_ONCE:
1090 case WIN_READ_EXT:
1091 return &task_in_intr;
1092 case WIN_SECURITY_DISABLE:
1093 case WIN_SECURITY_ERASE_UNIT:
1094 case WIN_SECURITY_SET_PASS:
1095 case WIN_SECURITY_UNLOCK:
1096 case WIN_DOWNLOAD_MICROCODE:
1097 case CFA_WRITE_SECT_WO_ERASE:
1098 case WIN_WRITE_BUFFER:
1099 case WIN_WRITE_VERIFY:
1100 case WIN_WRITE:
1101 // case WIN_WRITE_ONCE:
1102 case WIN_WRITE_EXT:
1103 return &task_out_intr;
1104 // case WIN_READ_LONG:
1105 // case WIN_READ_LONG_ONCE:
1106 case WIN_MULTREAD:
1107 case WIN_MULTREAD_EXT:
1108 return &task_mulin_intr;
1109 // case WIN_WRITE_LONG:
1110 // case WIN_WRITE_LONG_ONCE:
1111 case CFA_WRITE_MULTI_WO_ERASE:
1112 case WIN_MULTWRITE:
1113 case WIN_MULTWRITE_EXT:
1114 return &task_mulout_intr;
1115 case WIN_SMART:
1116 switch(taskfile->feature) {
1117 case SMART_READ_VALUES:
1118 case SMART_READ_THRESHOLDS:
1119 case SMART_READ_LOG_SECTOR:
1120 return &task_in_intr;
1121 case SMART_WRITE_LOG_SECTOR:
1122 return &task_out_intr;
1123 default:
1124 return &task_no_data_intr;
1126 case CFA_REQ_EXT_ERROR_CODE:
1127 case CFA_ERASE_SECTORS:
1128 case WIN_VERIFY:
1129 // case WIN_VERIFY_ONCE:
1130 case WIN_VERIFY_EXT:
1131 case WIN_SEEK:
1132 return &task_no_data_intr;
1133 case WIN_SPECIFY:
1134 return &set_geometry_intr;
1135 case WIN_RECAL:
1136 // case WIN_RESTORE:
1137 return &recal_intr;
1138 case WIN_NOP:
1139 case WIN_DIAGNOSE:
1140 case WIN_FLUSH_CACHE:
1141 case WIN_FLUSH_CACHE_EXT:
1142 case WIN_STANDBYNOW1:
1143 case WIN_STANDBYNOW2:
1144 case WIN_SLEEPNOW1:
1145 case WIN_SLEEPNOW2:
1146 case WIN_SETIDLE1:
1147 case WIN_CHECKPOWERMODE1:
1148 case WIN_CHECKPOWERMODE2:
1149 case WIN_GETMEDIASTATUS:
1150 case WIN_MEDIAEJECT:
1151 return &task_no_data_intr;
1152 case WIN_SETMULT:
1153 return &set_multmode_intr;
1154 case WIN_READ_NATIVE_MAX:
1155 case WIN_SET_MAX:
1156 case WIN_READ_NATIVE_MAX_EXT:
1157 case WIN_SET_MAX_EXT:
1158 case WIN_SECURITY_ERASE_PREPARE:
1159 case WIN_SECURITY_FREEZE_LOCK:
1160 case WIN_DOORLOCK:
1161 case WIN_DOORUNLOCK:
1162 case WIN_SETFEATURES:
1163 return &task_no_data_intr;
1164 case DISABLE_SEAGATE:
1165 case EXABYTE_ENABLE_NEST:
1166 return &task_no_data_intr;
1167 case WIN_READDMA:
1168 // case WIN_READDMA_ONCE:
1169 case WIN_IDENTIFY_DMA:
1170 case WIN_READDMA_QUEUED:
1171 case WIN_READDMA_EXT:
1172 case WIN_READDMA_QUEUED_EXT:
1173 case WIN_WRITEDMA:
1174 // case WIN_WRITEDMA_ONCE:
1175 case WIN_WRITEDMA_QUEUED:
1176 case WIN_WRITEDMA_EXT:
1177 case WIN_WRITEDMA_QUEUED_EXT:
1178 case WIN_FORMAT:
1179 case WIN_INIT:
1180 case WIN_DEVICE_RESET:
1181 case WIN_QUEUED_SERVICE:
1182 case WIN_PACKETCMD:
1183 default:
1184 return(NULL);
1188 EXPORT_SYMBOL(ide_handler_parser);
1190 ide_post_handler_t * ide_post_handler_parser (struct hd_drive_task_hdr *taskfile, struct hd_drive_hob_hdr *hobfile)
1192 switch(taskfile->command) {
1193 case WIN_SPECIFY: /* set_geometry_intr */
1194 case WIN_RESTORE: /* recal_intr */
1195 case WIN_SETMULT: /* set_multmode_intr */
1196 default:
1197 return(NULL);
1201 EXPORT_SYMBOL(ide_post_handler_parser);
1203 /* Called by ioctl to feature out type of command being called */
1204 int ide_cmd_type_parser (ide_task_t *args)
1207 task_struct_t *taskfile = (task_struct_t *) args->tfRegister;
1208 hob_struct_t *hobfile = (hob_struct_t *) args->hobRegister;
1210 args->prehandler = ide_pre_handler_parser(taskfile, hobfile);
1211 args->handler = ide_handler_parser(taskfile, hobfile);
1212 args->posthandler = ide_post_handler_parser(taskfile, hobfile);
1214 switch(args->tfRegister[IDE_COMMAND_OFFSET]) {
1215 case WIN_IDENTIFY:
1216 case WIN_PIDENTIFY:
1217 return IDE_DRIVE_TASK_IN;
1218 case CFA_TRANSLATE_SECTOR:
1219 case WIN_READ:
1220 // case WIN_READ_ONCE:
1221 case WIN_READ_EXT:
1222 case WIN_READ_BUFFER:
1223 return IDE_DRIVE_TASK_IN;
1224 case WIN_WRITE:
1225 // case WIN_WRITE_ONCE:
1226 case WIN_WRITE_EXT:
1227 case WIN_WRITE_VERIFY:
1228 case WIN_WRITE_BUFFER:
1229 case CFA_WRITE_SECT_WO_ERASE:
1230 case WIN_DOWNLOAD_MICROCODE:
1231 return IDE_DRIVE_TASK_RAW_WRITE;
1232 // case WIN_READ_LONG:
1233 // case WIN_READ_LONG_ONCE:
1234 case WIN_MULTREAD:
1235 case WIN_MULTREAD_EXT:
1236 return IDE_DRIVE_TASK_IN;
1237 // case WIN_WRITE_LONG:
1238 // case WIN_WRITE_LONG_ONCE:
1239 case CFA_WRITE_MULTI_WO_ERASE:
1240 case WIN_MULTWRITE:
1241 case WIN_MULTWRITE_EXT:
1242 return IDE_DRIVE_TASK_RAW_WRITE;
1243 case WIN_SECURITY_DISABLE:
1244 case WIN_SECURITY_ERASE_UNIT:
1245 case WIN_SECURITY_SET_PASS:
1246 case WIN_SECURITY_UNLOCK:
1247 return IDE_DRIVE_TASK_OUT;
1248 case WIN_SMART:
1249 args->tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS;
1250 args->tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS;
1251 switch(args->tfRegister[IDE_FEATURE_OFFSET]) {
1252 case SMART_READ_VALUES:
1253 case SMART_READ_THRESHOLDS:
1254 case SMART_READ_LOG_SECTOR:
1255 return IDE_DRIVE_TASK_IN;
1256 case SMART_WRITE_LOG_SECTOR:
1257 return IDE_DRIVE_TASK_OUT;
1258 default:
1259 return IDE_DRIVE_TASK_NO_DATA;
1261 case WIN_READDMA:
1262 // case WIN_READDMA_ONCE:
1263 case WIN_IDENTIFY_DMA:
1264 case WIN_READDMA_QUEUED:
1265 case WIN_READDMA_EXT:
1266 case WIN_READDMA_QUEUED_EXT:
1267 return IDE_DRIVE_TASK_IN;
1268 case WIN_WRITEDMA:
1269 // case WIN_WRITEDMA_ONCE:
1270 case WIN_WRITEDMA_QUEUED:
1271 case WIN_WRITEDMA_EXT:
1272 case WIN_WRITEDMA_QUEUED_EXT:
1273 return IDE_DRIVE_TASK_RAW_WRITE;
1274 case WIN_SETFEATURES:
1275 switch(args->tfRegister[IDE_FEATURE_OFFSET]) {
1276 case SETFEATURES_EN_8BIT:
1277 case SETFEATURES_EN_WCACHE:
1278 return IDE_DRIVE_TASK_NO_DATA;
1279 case SETFEATURES_XFER:
1280 return IDE_DRIVE_TASK_SET_XFER;
1281 case SETFEATURES_DIS_DEFECT:
1282 case SETFEATURES_EN_APM:
1283 case SETFEATURES_DIS_MSN:
1284 case SETFEATURES_DIS_RETRY:
1285 case SETFEATURES_EN_AAM:
1286 case SETFEATURES_RW_LONG:
1287 case SETFEATURES_SET_CACHE:
1288 case SETFEATURES_DIS_RLA:
1289 case SETFEATURES_EN_RI:
1290 case SETFEATURES_EN_SI:
1291 case SETFEATURES_DIS_RPOD:
1292 case SETFEATURES_DIS_WCACHE:
1293 case SETFEATURES_EN_DEFECT:
1294 case SETFEATURES_DIS_APM:
1295 case SETFEATURES_EN_ECC:
1296 case SETFEATURES_EN_MSN:
1297 case SETFEATURES_EN_RETRY:
1298 case SETFEATURES_EN_RLA:
1299 case SETFEATURES_PREFETCH:
1300 case SETFEATURES_4B_RW_LONG:
1301 case SETFEATURES_DIS_AAM:
1302 case SETFEATURES_EN_RPOD:
1303 case SETFEATURES_DIS_RI:
1304 case SETFEATURES_DIS_SI:
1305 default:
1306 return IDE_DRIVE_TASK_NO_DATA;
1308 case WIN_NOP:
1309 case CFA_REQ_EXT_ERROR_CODE:
1310 case CFA_ERASE_SECTORS:
1311 case WIN_VERIFY:
1312 // case WIN_VERIFY_ONCE:
1313 case WIN_VERIFY_EXT:
1314 case WIN_SEEK:
1315 case WIN_SPECIFY:
1316 case WIN_RESTORE:
1317 case WIN_DIAGNOSE:
1318 case WIN_FLUSH_CACHE:
1319 case WIN_FLUSH_CACHE_EXT:
1320 case WIN_STANDBYNOW1:
1321 case WIN_STANDBYNOW2:
1322 case WIN_SLEEPNOW1:
1323 case WIN_SLEEPNOW2:
1324 case WIN_SETIDLE1:
1325 case DISABLE_SEAGATE:
1326 case WIN_CHECKPOWERMODE1:
1327 case WIN_CHECKPOWERMODE2:
1328 case WIN_GETMEDIASTATUS:
1329 case WIN_MEDIAEJECT:
1330 case WIN_SETMULT:
1331 case WIN_READ_NATIVE_MAX:
1332 case WIN_SET_MAX:
1333 case WIN_READ_NATIVE_MAX_EXT:
1334 case WIN_SET_MAX_EXT:
1335 case WIN_SECURITY_ERASE_PREPARE:
1336 case WIN_SECURITY_FREEZE_LOCK:
1337 case EXABYTE_ENABLE_NEST:
1338 case WIN_DOORLOCK:
1339 case WIN_DOORUNLOCK:
1340 return IDE_DRIVE_TASK_NO_DATA;
1341 case WIN_FORMAT:
1342 case WIN_INIT:
1343 case WIN_DEVICE_RESET:
1344 case WIN_QUEUED_SERVICE:
1345 case WIN_PACKETCMD:
1346 default:
1347 return IDE_DRIVE_TASK_INVALID;
1351 EXPORT_SYMBOL(ide_cmd_type_parser);
1354 * This function is intended to be used prior to invoking ide_do_drive_cmd().
1356 void ide_init_drive_taskfile (struct request *rq)
1358 memset(rq, 0, sizeof(*rq));
1359 rq->flags = REQ_DRIVE_TASKFILE;
1362 EXPORT_SYMBOL(ide_init_drive_taskfile);
1364 #if 1
1366 int ide_diag_taskfile (ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf)
1368 struct request rq;
1370 ide_init_drive_taskfile(&rq);
1371 rq.flags = REQ_DRIVE_TASKFILE;
1372 rq.buffer = buf;
1375 * (ks) We transfer currently only whole sectors.
1376 * This is suffient for now. But, it would be great,
1377 * if we would find a solution to transfer any size.
1378 * To support special commands like READ LONG.
1380 if (args->command_type != IDE_DRIVE_TASK_NO_DATA) {
1381 if (data_size == 0)
1382 rq.nr_sectors = (args->hobRegister[IDE_NSECTOR_OFFSET_HOB] << 8) | args->tfRegister[IDE_NSECTOR_OFFSET];
1383 else
1384 rq.nr_sectors = data_size / SECTOR_SIZE;
1386 rq.hard_nr_sectors = rq.nr_sectors;
1387 rq.hard_cur_sectors = rq.current_nr_sectors = rq.nr_sectors;
1390 if (args->tf_out_flags.all == 0) {
1392 * clean up kernel settings for driver sanity, regardless.
1393 * except for discrete diag services.
1395 args->posthandler = ide_post_handler_parser(
1396 (struct hd_drive_task_hdr *) args->tfRegister,
1397 (struct hd_drive_hob_hdr *) args->hobRegister);
1400 rq.special = args;
1401 return ide_do_drive_cmd(drive, &rq, ide_wait);
1404 #else
1406 int ide_diag_taskfile (ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf)
1408 struct request *rq;
1409 unsigned long flags;
1410 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1411 struct list_head *queue_head = &drive->queue.queue_head;
1412 DECLARE_COMPLETION(wait);
1414 if (HWIF(drive)->chipset == ide_pdc4030 && buf != NULL)
1415 return -ENOSYS; /* special drive cmds not supported */
1417 memset(rq, 0, sizeof(*rq));
1418 rq->flags = REQ_DRIVE_TASKFILE;
1419 rq->buffer = buf;
1422 * (ks) We transfer currently only whole sectors.
1423 * This is suffient for now. But, it would be great,
1424 * if we would find a solution to transfer any size.
1425 * To support special commands like READ LONG.
1427 if (args->command_type != IDE_DRIVE_TASK_NO_DATA) {
1428 if (data_size == 0) {
1429 ata_nsector_t nsector;
1430 nsector.b.low = args->hobRegister[IDE_NSECTOR_OFFSET_HOB];
1431 nsector.b.high = args->tfRegister[IDE_NSECTOR_OFFSET];
1432 rq.nr_sectors = nsector.all;
1433 } else {
1434 rq.nr_sectors = data_size / SECTOR_SIZE;
1436 rq.current_nr_sectors = rq.nr_sectors;
1437 // rq.hard_cur_sectors = rq.nr_sectors;
1440 if (args->tf_out_flags.all == 0) {
1442 * clean up kernel settings for driver sanity, regardless.
1443 * except for discrete diag services.
1445 args->posthandler = ide_post_handler_parser(
1446 (struct hd_drive_task_hdr *) args->tfRegister,
1447 (struct hd_drive_hob_hdr *) args->hobRegister);
1449 rq->special = args;
1450 rq->errors = 0;
1451 rq->rq_status = RQ_ACTIVE;
1452 rq->rq_disk = drive->disk;
1453 rq->waiting = &wait;
1455 spin_lock_irqsave(&ide_lock, flags);
1456 queue_head = queue_head->prev;
1457 list_add(&rq->queue, queue_head);
1458 ide_do_request(hwgroup, 0);
1459 spin_unlock_irqrestore(&ide_lock, flags);
1461 wait_for_completion(&wait); /* wait for it to be serviced */
1462 return rq->errors ? -EIO : 0; /* return -EIO if errors */
1465 #endif
1467 EXPORT_SYMBOL(ide_diag_taskfile);
1469 int ide_raw_taskfile (ide_drive_t *drive, ide_task_t *args, u8 *buf)
1471 return ide_diag_taskfile(drive, args, 0, buf);
1474 EXPORT_SYMBOL(ide_raw_taskfile);
1476 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1477 char * ide_ioctl_verbose (unsigned int cmd)
1479 return("unknown");
1482 char * ide_task_cmd_verbose (u8 task)
1484 return("unknown");
1486 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1488 #define MAX_DMA (256*SECTOR_WORDS)
1490 ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
1491 ide_startstop_t flagged_task_no_data_intr(ide_drive_t *);
1492 ide_startstop_t flagged_task_in_intr(ide_drive_t *);
1493 ide_startstop_t flagged_task_mulin_intr(ide_drive_t *);
1494 ide_startstop_t flagged_pre_task_out_intr(ide_drive_t *, struct request *);
1495 ide_startstop_t flagged_task_out_intr(ide_drive_t *);
1496 ide_startstop_t flagged_pre_task_mulout_intr(ide_drive_t *, struct request *);
1497 ide_startstop_t flagged_task_mulout_intr(ide_drive_t *);
1499 int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1501 ide_task_request_t *req_task;
1502 ide_task_t args;
1503 u8 *outbuf = NULL;
1504 u8 *inbuf = NULL;
1505 task_ioreg_t *argsptr = args.tfRegister;
1506 task_ioreg_t *hobsptr = args.hobRegister;
1507 int err = 0;
1508 int tasksize = sizeof(struct ide_task_request_s);
1509 int taskin = 0;
1510 int taskout = 0;
1511 u8 io_32bit = drive->io_32bit;
1513 // printk("IDE Taskfile ...\n");
1515 req_task = kmalloc(tasksize, GFP_KERNEL);
1516 if (req_task == NULL) return -ENOMEM;
1517 memset(req_task, 0, tasksize);
1518 if (copy_from_user(req_task, (void *) arg, tasksize)) {
1519 kfree(req_task);
1520 return -EFAULT;
1523 taskout = (int) req_task->out_size;
1524 taskin = (int) req_task->in_size;
1526 if (taskout) {
1527 int outtotal = tasksize;
1528 outbuf = kmalloc(taskout, GFP_KERNEL);
1529 if (outbuf == NULL) {
1530 err = -ENOMEM;
1531 goto abort;
1533 memset(outbuf, 0, taskout);
1534 if (copy_from_user(outbuf, (void *)arg + outtotal, taskout)) {
1535 err = -EFAULT;
1536 goto abort;
1540 if (taskin) {
1541 int intotal = tasksize + taskout;
1542 inbuf = kmalloc(taskin, GFP_KERNEL);
1543 if (inbuf == NULL) {
1544 err = -ENOMEM;
1545 goto abort;
1547 memset(inbuf, 0, taskin);
1548 if (copy_from_user(inbuf, (void *)arg + intotal , taskin)) {
1549 err = -EFAULT;
1550 goto abort;
1554 memset(&args, 0, sizeof(ide_task_t));
1555 memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
1556 memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE);
1558 args.tf_in_flags = req_task->in_flags;
1559 args.tf_out_flags = req_task->out_flags;
1560 args.data_phase = req_task->data_phase;
1561 args.command_type = req_task->req_cmd;
1563 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1564 DTF("%s: ide_ioctl_cmd %s: ide_task_cmd %s\n",
1565 drive->name,
1566 ide_ioctl_verbose(cmd),
1567 ide_task_cmd_verbose(args.tfRegister[IDE_COMMAND_OFFSET]));
1568 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1570 drive->io_32bit = 0;
1571 switch(req_task->data_phase) {
1572 case TASKFILE_OUT_DMAQ:
1573 case TASKFILE_OUT_DMA:
1574 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1575 break;
1576 case TASKFILE_IN_DMAQ:
1577 case TASKFILE_IN_DMA:
1578 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1579 break;
1580 case TASKFILE_IN_OUT:
1581 #if 0
1582 args.prehandler = &pre_task_out_intr;
1583 args.handler = &task_out_intr;
1584 args.posthandler = NULL;
1585 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1586 args.prehandler = NULL;
1587 args.handler = &task_in_intr;
1588 args.posthandler = NULL;
1589 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1590 break;
1591 #else
1592 err = -EFAULT;
1593 goto abort;
1594 #endif
1595 case TASKFILE_MULTI_OUT:
1596 if (!drive->mult_count) {
1597 /* (hs): give up if multcount is not set */
1598 printk(KERN_ERR "%s: %s Multimode Write " \
1599 "multcount is not set\n",
1600 drive->name, __FUNCTION__);
1601 err = -EPERM;
1602 goto abort;
1604 if (args.tf_out_flags.all != 0) {
1605 args.prehandler = &flagged_pre_task_mulout_intr;
1606 args.handler = &flagged_task_mulout_intr;
1607 } else {
1608 args.prehandler = &pre_task_mulout_intr;
1609 args.handler = &task_mulout_intr;
1611 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1612 break;
1613 case TASKFILE_OUT:
1614 if (args.tf_out_flags.all != 0) {
1615 args.prehandler = &flagged_pre_task_out_intr;
1616 args.handler = &flagged_task_out_intr;
1617 } else {
1618 args.prehandler = &pre_task_out_intr;
1619 args.handler = &task_out_intr;
1621 err = ide_diag_taskfile(drive, &args, taskout, outbuf);
1622 break;
1623 case TASKFILE_MULTI_IN:
1624 if (!drive->mult_count) {
1625 /* (hs): give up if multcount is not set */
1626 printk(KERN_ERR "%s: %s Multimode Read failure " \
1627 "multcount is not set\n",
1628 drive->name, __FUNCTION__);
1629 err = -EPERM;
1630 goto abort;
1632 if (args.tf_out_flags.all != 0) {
1633 args.handler = &flagged_task_mulin_intr;
1634 } else {
1635 args.handler = &task_mulin_intr;
1637 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1638 break;
1639 case TASKFILE_IN:
1640 if (args.tf_out_flags.all != 0) {
1641 args.handler = &flagged_task_in_intr;
1642 } else {
1643 args.handler = &task_in_intr;
1645 err = ide_diag_taskfile(drive, &args, taskin, inbuf);
1646 break;
1647 case TASKFILE_NO_DATA:
1648 if (args.tf_out_flags.all != 0) {
1649 args.handler = &flagged_task_no_data_intr;
1650 } else {
1651 args.handler = &task_no_data_intr;
1653 err = ide_diag_taskfile(drive, &args, 0, NULL);
1654 break;
1655 default:
1656 err = -EFAULT;
1657 goto abort;
1660 memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE);
1661 memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE);
1662 req_task->in_flags = args.tf_in_flags;
1663 req_task->out_flags = args.tf_out_flags;
1665 if (copy_to_user((void *)arg, req_task, tasksize)) {
1666 err = -EFAULT;
1667 goto abort;
1669 if (taskout) {
1670 int outtotal = tasksize;
1671 if (copy_to_user((void *)arg+outtotal, outbuf, taskout)) {
1672 err = -EFAULT;
1673 goto abort;
1676 if (taskin) {
1677 int intotal = tasksize + taskout;
1678 if (copy_to_user((void *)arg+intotal, inbuf, taskin)) {
1679 err = -EFAULT;
1680 goto abort;
1683 abort:
1684 kfree(req_task);
1685 if (outbuf != NULL)
1686 kfree(outbuf);
1687 if (inbuf != NULL)
1688 kfree(inbuf);
1690 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
1692 drive->io_32bit = io_32bit;
1694 return err;
1697 EXPORT_SYMBOL(ide_taskfile_ioctl);
1699 int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1701 struct request rq;
1702 u8 buffer[4];
1704 if (!buf)
1705 buf = buffer;
1706 memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors);
1707 ide_init_drive_cmd(&rq);
1708 rq.buffer = buf;
1709 *buf++ = cmd;
1710 *buf++ = nsect;
1711 *buf++ = feature;
1712 *buf++ = sectors;
1713 return ide_do_drive_cmd(drive, &rq, ide_wait);
1716 EXPORT_SYMBOL(ide_wait_cmd);
1719 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1721 int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1723 #if 1
1724 int err = 0;
1725 u8 args[4], *argbuf = args;
1726 u8 xfer_rate = 0;
1727 int argsize = 4;
1728 ide_task_t tfargs;
1730 if (NULL == (void *) arg) {
1731 struct request rq;
1732 ide_init_drive_cmd(&rq);
1733 return ide_do_drive_cmd(drive, &rq, ide_wait);
1736 if (copy_from_user(args, (void *)arg, 4))
1737 return -EFAULT;
1739 memset(&tfargs, 0, sizeof(ide_task_t));
1740 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
1741 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
1742 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
1743 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
1744 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
1745 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
1746 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
1748 if (args[3]) {
1749 argsize = 4 + (SECTOR_WORDS * 4 * args[3]);
1750 argbuf = kmalloc(argsize, GFP_KERNEL);
1751 if (argbuf == NULL)
1752 return -ENOMEM;
1753 memcpy(argbuf, args, 4);
1755 if (set_transfer(drive, &tfargs)) {
1756 xfer_rate = args[1];
1757 if (ide_ata66_check(drive, &tfargs))
1758 goto abort;
1761 err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf);
1763 if (!err && xfer_rate) {
1764 /* active-retuning-calls future */
1765 ide_set_xfer_rate(drive, xfer_rate);
1766 ide_driveid_update(drive);
1768 abort:
1769 if (copy_to_user((void *)arg, argbuf, argsize))
1770 err = -EFAULT;
1771 if (argsize > 4)
1772 kfree(argbuf);
1773 return err;
1775 #else
1777 int err = -EIO;
1778 u8 args[4], *argbuf = args;
1779 u8 xfer_rate = 0;
1780 int argsize = 0;
1781 ide_task_t tfargs;
1783 if (NULL == (void *) arg) {
1784 struct request rq;
1785 ide_init_drive_cmd(&rq);
1786 return ide_do_drive_cmd(drive, &rq, ide_wait);
1789 if (copy_from_user(args, (void *)arg, 4))
1790 return -EFAULT;
1792 memset(&tfargs, 0, sizeof(ide_task_t));
1793 tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2];
1794 tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3];
1795 tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1];
1796 tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00;
1797 tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00;
1798 tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00;
1799 tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0];
1801 if (args[3]) {
1802 argsize = (SECTOR_WORDS * 4 * args[3]);
1803 argbuf = kmalloc(argsize, GFP_KERNEL);
1804 if (argbuf == NULL)
1805 return -ENOMEM;
1808 if (set_transfer(drive, &tfargs)) {
1809 xfer_rate = args[1];
1810 if (ide_ata66_check(drive, &tfargs))
1811 goto abort;
1814 tfargs.command_type = ide_cmd_type_parser(&tfargs);
1815 err = ide_raw_taskfile(drive, &tfargs, argbuf);
1817 if (!err && xfer_rate) {
1818 /* active-retuning-calls future */
1819 ide_set_xfer_rate(driver, xfer_rate);
1820 ide_driveid_update(drive);
1822 abort:
1823 args[0] = tfargs.tfRegister[IDE_COMMAND_OFFSET];
1824 args[1] = tfargs.tfRegister[IDE_FEATURE_OFFSET];
1825 args[2] = tfargs.tfRegister[IDE_NSECTOR_OFFSET];
1826 args[3] = 0;
1828 if (copy_to_user((void *)arg, argbuf, 4))
1829 err = -EFAULT;
1830 if (argbuf != NULL) {
1831 if (copy_to_user((void *)arg, argbuf + 4, argsize))
1832 err = -EFAULT;
1833 kfree(argbuf);
1835 return err;
1837 #endif
1840 EXPORT_SYMBOL(ide_cmd_ioctl);
1842 int ide_wait_cmd_task (ide_drive_t *drive, u8 *buf)
1844 struct request rq;
1846 ide_init_drive_cmd(&rq);
1847 rq.flags = REQ_DRIVE_TASK;
1848 rq.buffer = buf;
1849 return ide_do_drive_cmd(drive, &rq, ide_wait);
1852 EXPORT_SYMBOL(ide_wait_cmd_task);
1855 * FIXME : this needs to map into at taskfile. <andre@linux-ide.org>
1857 int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
1859 int err = 0;
1860 u8 args[7], *argbuf = args;
1861 int argsize = 7;
1863 if (copy_from_user(args, (void *)arg, 7))
1864 return -EFAULT;
1865 err = ide_wait_cmd_task(drive, argbuf);
1866 if (copy_to_user((void *)arg, argbuf, argsize))
1867 err = -EFAULT;
1868 return err;
1871 EXPORT_SYMBOL(ide_task_ioctl);
1874 * NOTICE: This is additions from IBM to provide a discrete interface,
1875 * for selective taskregister access operations. Nice JOB Klaus!!!
1876 * Glad to be able to work and co-develop this with you and IBM.
1878 ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task)
1880 ide_hwif_t *hwif = HWIF(drive);
1881 task_struct_t *taskfile = (task_struct_t *) task->tfRegister;
1882 hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister;
1883 #if DEBUG_TASKFILE
1884 u8 status;
1885 #endif
1888 #ifdef CONFIG_IDE_TASK_IOCTL_DEBUG
1889 void debug_taskfile(drive, task);
1890 #endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */
1893 * (ks) Check taskfile in/out flags.
1894 * If set, then execute as it is defined.
1895 * If not set, then define default settings.
1896 * The default values are:
1897 * write and read all taskfile registers (except data)
1898 * write and read the hob registers (sector,nsector,lcyl,hcyl)
1900 if (task->tf_out_flags.all == 0) {
1901 task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS;
1902 if (drive->addressing == 1)
1903 task->tf_out_flags.all |= (IDE_HOB_STD_OUT_FLAGS << 8);
1906 if (task->tf_in_flags.all == 0) {
1907 task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
1908 if (drive->addressing == 1)
1909 task->tf_in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
1912 /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */
1913 if (IDE_CONTROL_REG)
1914 /* clear nIEN */
1915 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
1916 SELECT_MASK(drive, 0);
1918 #if DEBUG_TASKFILE
1919 status = hwif->INB(IDE_STATUS_REG);
1920 if (status & 0x80) {
1921 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status);
1922 udelay(100);
1923 status = hwif->INB(IDE_STATUS_REG);
1924 printk("flagged_taskfile -> Status = %02x\n", status);
1926 #endif
1928 if (task->tf_out_flags.b.data) {
1929 u16 data = taskfile->data + (hobfile->data << 8);
1930 hwif->OUTW(data, IDE_DATA_REG);
1933 /* (ks) send hob registers first */
1934 if (task->tf_out_flags.b.nsector_hob)
1935 hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG);
1936 if (task->tf_out_flags.b.sector_hob)
1937 hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG);
1938 if (task->tf_out_flags.b.lcyl_hob)
1939 hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG);
1940 if (task->tf_out_flags.b.hcyl_hob)
1941 hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG);
1943 /* (ks) Send now the standard registers */
1944 if (task->tf_out_flags.b.error_feature)
1945 hwif->OUTB(taskfile->feature, IDE_FEATURE_REG);
1946 /* refers to number of sectors to transfer */
1947 if (task->tf_out_flags.b.nsector)
1948 hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG);
1949 /* refers to sector offset or start sector */
1950 if (task->tf_out_flags.b.sector)
1951 hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG);
1952 if (task->tf_out_flags.b.lcyl)
1953 hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG);
1954 if (task->tf_out_flags.b.hcyl)
1955 hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG);
1958 * (ks) In the flagged taskfile approch, we will used all specified
1959 * registers and the register value will not be changed. Except the
1960 * select bit (master/slave) in the drive_head register. We must make
1961 * sure that the desired drive is selected.
1963 hwif->OUTB(taskfile->device_head | drive->select.all, IDE_SELECT_REG);
1964 switch(task->data_phase) {
1966 case TASKFILE_OUT_DMAQ:
1967 case TASKFILE_OUT_DMA:
1968 hwif->ide_dma_write(drive);
1969 break;
1971 case TASKFILE_IN_DMAQ:
1972 case TASKFILE_IN_DMA:
1973 hwif->ide_dma_read(drive);
1974 break;
1976 default:
1977 if (task->handler == NULL)
1978 return ide_stopped;
1980 /* Issue the command */
1981 ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL);
1982 if (task->prehandler != NULL)
1983 return task->prehandler(drive, HWGROUP(drive)->rq);
1986 return ide_started;
1989 EXPORT_SYMBOL(flagged_taskfile);
1991 ide_startstop_t flagged_task_no_data_intr (ide_drive_t *drive)
1993 ide_hwif_t *hwif = HWIF(drive);
1994 u8 stat;
1996 local_irq_enable();
1998 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) {
1999 if (stat & ERR_STAT) {
2000 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr", stat);
2003 * (ks) Unexpected ATA data phase detected.
2004 * This should not happen. But, it can !
2005 * I am not sure, which function is best to clean up
2006 * this situation. I choose: ide_error(...)
2008 return DRIVER(drive)->error(drive, "flagged_task_no_data_intr (unexpected phase)", stat);
2011 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
2013 return ide_stopped;
2017 * Handler for command with PIO data-in phase
2019 ide_startstop_t flagged_task_in_intr (ide_drive_t *drive)
2021 ide_hwif_t *hwif = HWIF(drive);
2022 u8 stat = hwif->INB(IDE_STATUS_REG);
2023 struct request *rq = HWGROUP(drive)->rq;
2024 char *pBuf = NULL;
2025 int retries = 5;
2027 if (rq->current_nr_sectors == 0)
2028 return DRIVER(drive)->error(drive, "flagged_task_in_intr (no data requested)", stat);
2030 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
2031 if (stat & ERR_STAT) {
2032 return DRIVER(drive)->error(drive, "flagged_task_in_intr", stat);
2035 * (ks) Unexpected ATA data phase detected.
2036 * This should not happen. But, it can !
2037 * I am not sure, which function is best to clean up
2038 * this situation. I choose: ide_error(...)
2040 return DRIVER(drive)->error(drive, "flagged_task_in_intr (unexpected data phase)", stat);
2043 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2044 DTF("Read - rq->current_nr_sectors: %d, status: %02x\n", (int) rq->current_nr_sectors, stat);
2046 taskfile_input_data(drive, pBuf, SECTOR_WORDS);
2048 if (--rq->current_nr_sectors != 0) {
2050 * (ks) We don't know which command was executed.
2051 * So, we wait the 'WORSTCASE' value.
2053 ide_set_handler(drive, &flagged_task_in_intr, WAIT_WORSTCASE, NULL);
2054 return ide_started;
2057 * (ks) Last sector was transfered, wait until drive is ready.
2058 * This can take up to 10 usec. We willl wait max 50 us.
2060 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
2061 udelay(10);
2062 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2064 return ide_stopped;
2067 ide_startstop_t flagged_task_mulin_intr (ide_drive_t *drive)
2069 ide_hwif_t *hwif = HWIF(drive);
2070 u8 stat = hwif->INB(IDE_STATUS_REG);
2071 struct request *rq = HWGROUP(drive)->rq;
2072 char *pBuf = NULL;
2073 int retries = 5;
2074 unsigned int msect, nsect;
2076 if (rq->current_nr_sectors == 0)
2077 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (no data requested)", stat);
2079 msect = drive->mult_count;
2080 if (msect == 0)
2081 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (multimode not set)", stat);
2083 if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) {
2084 if (stat & ERR_STAT) {
2085 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr", stat);
2088 * (ks) Unexpected ATA data phase detected.
2089 * This should not happen. But, it can !
2090 * I am not sure, which function is best to clean up
2091 * this situation. I choose: ide_error(...)
2093 return DRIVER(drive)->error(drive, "flagged_task_mulin_intr (unexpected data phase)", stat);
2096 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
2097 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2099 DTF("Multiread: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
2100 pBuf, nsect, rq->current_nr_sectors);
2102 taskfile_input_data(drive, pBuf, nsect * SECTOR_WORDS);
2104 rq->current_nr_sectors -= nsect;
2105 if (rq->current_nr_sectors != 0) {
2107 * (ks) We don't know which command was executed.
2108 * So, we wait the 'WORSTCASE' value.
2110 ide_set_handler(drive, &flagged_task_mulin_intr, WAIT_WORSTCASE, NULL);
2111 return ide_started;
2115 * (ks) Last sector was transfered, wait until drive is ready.
2116 * This can take up to 10 usec. We willl wait max 50 us.
2118 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
2119 udelay(10);
2120 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2122 return ide_stopped;
2126 * Pre handler for command with PIO data-out phase
2128 ide_startstop_t flagged_pre_task_out_intr (ide_drive_t *drive, struct request *rq)
2130 ide_hwif_t *hwif = HWIF(drive);
2131 u8 stat = hwif->INB(IDE_STATUS_REG);
2132 ide_startstop_t startstop;
2134 if (!rq->current_nr_sectors) {
2135 return DRIVER(drive)->error(drive, "flagged_pre_task_out_intr (write data not specified)", stat);
2138 if (ide_wait_stat(&startstop, drive, DATA_READY,
2139 BAD_W_STAT, WAIT_DRQ)) {
2140 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
2141 return startstop;
2144 taskfile_output_data(drive, rq->buffer, SECTOR_WORDS);
2145 --rq->current_nr_sectors;
2147 return ide_started;
2150 ide_startstop_t flagged_task_out_intr (ide_drive_t *drive)
2152 ide_hwif_t *hwif = HWIF(drive);
2153 u8 stat = hwif->INB(IDE_STATUS_REG);
2154 struct request *rq = HWGROUP(drive)->rq;
2155 char *pBuf = NULL;
2157 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
2158 return DRIVER(drive)->error(drive, "flagged_task_out_intr", stat);
2160 if (!rq->current_nr_sectors) {
2161 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2162 return ide_stopped;
2165 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
2167 * (ks) Unexpected ATA data phase detected.
2168 * This should not happen. But, it can !
2169 * I am not sure, which function is best to clean up
2170 * this situation. I choose: ide_error(...)
2172 return DRIVER(drive)->error(drive, "flagged_task_out_intr (unexpected data phase)", stat);
2175 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2176 DTF("Write - rq->current_nr_sectors: %d, status: %02x\n",
2177 (int) rq->current_nr_sectors, stat);
2179 taskfile_output_data(drive, pBuf, SECTOR_WORDS);
2180 --rq->current_nr_sectors;
2183 * (ks) We don't know which command was executed.
2184 * So, we wait the 'WORSTCASE' value.
2186 ide_set_handler(drive, &flagged_task_out_intr, WAIT_WORSTCASE, NULL);
2188 return ide_started;
2191 ide_startstop_t flagged_pre_task_mulout_intr (ide_drive_t *drive, struct request *rq)
2193 ide_hwif_t *hwif = HWIF(drive);
2194 u8 stat = hwif->INB(IDE_STATUS_REG);
2195 char *pBuf = NULL;
2196 ide_startstop_t startstop;
2197 unsigned int msect, nsect;
2199 if (!rq->current_nr_sectors)
2200 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (write data not specified)", stat);
2202 msect = drive->mult_count;
2203 if (msect == 0)
2204 return DRIVER(drive)->error(drive, "flagged_pre_task_mulout_intr (multimode not set)", stat);
2206 if (ide_wait_stat(&startstop, drive, DATA_READY,
2207 BAD_W_STAT, WAIT_DRQ)) {
2208 printk(KERN_ERR "%s: No DRQ bit after issuing write command.\n", drive->name);
2209 return startstop;
2212 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
2213 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2214 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
2215 pBuf, nsect, rq->current_nr_sectors);
2217 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
2219 rq->current_nr_sectors -= nsect;
2221 return ide_started;
2224 ide_startstop_t flagged_task_mulout_intr (ide_drive_t *drive)
2226 ide_hwif_t *hwif = HWIF(drive);
2227 u8 stat = hwif->INB(IDE_STATUS_REG);
2228 struct request *rq = HWGROUP(drive)->rq;
2229 char *pBuf = NULL;
2230 unsigned int msect, nsect;
2232 msect = drive->mult_count;
2233 if (msect == 0)
2234 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (multimode not set)", stat);
2236 if (!OK_STAT(stat, DRIVE_READY, BAD_W_STAT))
2237 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr", stat);
2239 if (!rq->current_nr_sectors) {
2240 ide_end_drive_cmd (drive, stat, hwif->INB(IDE_ERROR_REG));
2241 return ide_stopped;
2244 if (!OK_STAT(stat, DATA_READY, BAD_W_STAT)) {
2246 * (ks) Unexpected ATA data phase detected.
2247 * This should not happen. But, it can !
2248 * I am not sure, which function is best to clean up
2249 * this situation. I choose: ide_error(...)
2251 return DRIVER(drive)->error(drive, "flagged_task_mulout_intr (unexpected data phase)", stat);
2254 nsect = (rq->current_nr_sectors > msect) ? msect : rq->current_nr_sectors;
2255 pBuf = rq->buffer + ((rq->nr_sectors - rq->current_nr_sectors) * SECTOR_SIZE);
2256 DTF("Multiwrite: %p, nsect: %d , rq->current_nr_sectors: %ld\n",
2257 pBuf, nsect, rq->current_nr_sectors);
2259 taskfile_output_data(drive, pBuf, nsect * SECTOR_WORDS);
2260 rq->current_nr_sectors -= nsect;
2263 * (ks) We don't know which command was executed.
2264 * So, we wait the 'WORSTCASE' value.
2266 ide_set_handler(drive, &flagged_task_mulout_intr, WAIT_WORSTCASE, NULL);
2268 return ide_started;
2272 * Beginning of Taskfile OPCODE Library and feature sets.
2275 #ifdef CONFIG_PKT_TASK_IOCTL
2277 int pkt_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
2279 #if 0
2280 switch(req_task->data_phase) {
2281 case TASKFILE_P_OUT_DMAQ:
2282 case TASKFILE_P_IN_DMAQ:
2283 case TASKFILE_P_OUT_DMA:
2284 case TASKFILE_P_IN_DMA:
2285 case TASKFILE_P_OUT:
2286 case TASKFILE_P_IN:
2288 #endif
2289 return -ENOMSG;
2292 EXPORT_SYMBOL(pkt_taskfile_ioctl);
2294 #endif /* CONFIG_PKT_TASK_IOCTL */