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 !!!
17 * General refers to the Controller and Driver "pair".
19 * Under the context of Linux it generally refers to an interrupt handler.
20 * However, it correctly describes the 'HOST'
22 * The amount of data needed to be transfered as predefined in the
23 * setup of the device.
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
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>
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>
50 #include <asm/uaccess.h>
52 #include <asm/bitops.h>
54 #define DEBUG_TASKFILE 0 /* unset when fixed */
57 #define DTF(x...) printk(x)
62 static void ata_bswap_data (void *buffer
, int 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
);
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
)
85 ata_bswap_data(buffer
, wcount
);
86 HWIF(drive
)->ata_output_data(drive
, buffer
, wcount
);
87 ata_bswap_data(buffer
, wcount
);
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
)
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
;
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
) {
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
);
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
);
186 if (!drive
->using_dma
)
189 switch (taskfile
->command
) {
190 case WIN_WRITEDMA_ONCE
:
192 case WIN_WRITEDMA_EXT
:
193 if (!hwif
->ide_dma_write(drive
))
196 case WIN_READDMA_ONCE
:
198 case WIN_READDMA_EXT
:
199 case WIN_IDENTIFY_DMA
:
200 if (!hwif
->ide_dma_read(drive
))
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
);
210 if (task
->handler
== NULL
)
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
);
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
];
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
);
264 /* taskfile_settings_update(drive, args, command); */
266 if (args
->posthandler
!= NULL
)
267 args
->posthandler(drive
, args
);
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
);
287 if (OK_STAT(stat
= hwif
->INB(IDE_STATUS_REG
),READY_STAT
,BAD_STAT
)) {
288 drive
->mult_count
= drive
->mult_req
;
290 drive
->mult_req
= drive
->mult_count
= 0;
291 drive
->special
.b
.recalibrate
= 1;
292 (void) ide_dump_status(drive
, "set_multmode", stat
);
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
);
308 while (((stat
= hwif
->INB(IDE_STATUS_REG
)) & BUSY_STAT
) && retries
--)
311 if (OK_STAT(stat
, READY_STAT
, BAD_STAT
))
314 if (stat
& (ERR_STAT
|DRQ_STAT
))
315 return DRIVER(drive
)->error(drive
, "set_geometry_intr", stat
);
317 if (HWGROUP(drive
)->handler
!= NULL
)
319 ide_set_handler(drive
, &set_geometry_intr
, WAIT_WORSTCASE
, NULL
);
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
);
333 if (!OK_STAT(stat
= hwif
->INB(IDE_STATUS_REG
), READY_STAT
, BAD_STAT
))
334 return DRIVER(drive
)->error(drive
, "recal_intr", stat
);
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
);
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 */
357 ide_end_drive_cmd(drive
, stat
, hwif
->INB(IDE_ERROR_REG
));
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
);
387 if (!OK_STAT(stat
= hwif
->INB(IDE_STATUS_REG
),DATA_READY
,BAD_R_STAT
)) {
388 if (stat
& (ERR_STAT
|DRQ_STAT
)) {
390 DTF("%s: attempting to recover last " \
391 "sector counter status=0x%02x\n",
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.
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
);
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",
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))
427 if (--rq
->current_nr_sectors
<= 0)
428 if (!DRIVER(drive
)->end_request(drive
, 1, 0))
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))
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
);
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
;
465 unsigned int msect
= drive
->mult_count
;
470 if (!OK_STAT(stat
= hwif
->INB(IDE_STATUS_REG
),DATA_READY
,BAD_R_STAT
)) {
471 if (stat
& (ERR_STAT
|DRQ_STAT
)) {
473 rq
->current_nr_sectors
+= drive
->mult_count
;
475 * NOTE: could rewind beyond beginning :-/
478 printk(KERN_ERR
"%s: MULTI-READ assume all data " \
479 "transfered is bad status=0x%02x\n",
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
);
491 nsect
= rq
->current_nr_sectors
;
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
);
501 rq
->current_nr_sectors
-= 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))
514 if (HWGROUP(drive
)->handler
== NULL
)
515 ide_set_handler(drive
, &task_mulin_intr
, WAIT_WORSTCASE
, NULL
);
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
)
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",
535 drive
->addressing
? "_EXT" : "");
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
);
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
;
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",
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))
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
);
583 rq
->current_nr_sectors
--;
585 if (HWGROUP(drive
)->handler
== NULL
)
586 ide_set_handler(drive
, &task_out_intr
, WAIT_WORSTCASE
, NULL
);
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
);
599 unsigned int nsect
= 0, msect
= drive
->mult_count
;
602 #endif /* ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
604 ide_task_t
*args
= rq
->special
;
605 ide_startstop_t startstop
;
609 * assign private copy for multi-write
611 memcpy(&HWGROUP(drive
)->wrq
, rq
, sizeof(struct request
));
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",
618 drive
->addressing
? "MULTWRITE_EXT" : "MULTWRITE");
621 #ifdef ALTERNATE_STATE_DIAGRAM_MULTI_OUT
624 nsect
= rq
->current_nr_sectors
;
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
);
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))
638 stat
= hwif
->INB(IDE_STATUS_REG
);
645 #else /* ! ALTERNATE_STATE_DIAGRAM_MULTI_OUT */
646 if (!(drive_is_ready(drive
))) {
648 for (i
=0; i
<100; i
++) {
649 if (drive_is_ready(drive
))
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
;
678 ide_startstop_t startstop
= ide_stopped
;
679 unsigned int msect
= drive
->mult_count
;
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
)) {
690 rq
->current_nr_sectors
+= drive
->mult_count
;
692 * NOTE: could rewind beyond beginning :-/
695 printk(KERN_ERR
"%s: MULTI-WRITE assume all data " \
696 "transfered is bad status=0x%02x\n",
699 return DRIVER(drive
)->error(drive
, "task_mulout_intr", stat
);
702 DRIVER(drive
)->end_request(drive
, 1, 0);
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
)) {
711 rq
->current_nr_sectors
+= drive
->mult_count
;
713 * NOTE: could rewind beyond beginning :-/
716 printk("%s: MULTI-WRITE assume all data " \
717 "transfered is bad status=0x%02x\n",
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
);
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 */
739 nsect
= rq
->current_nr_sectors
;
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
);
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))
763 if (HWGROUP(drive
)->handler
== NULL
)
764 ide_set_handler(drive
, &task_mulout_intr
, WAIT_WORSTCASE
, NULL
);
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
);
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
--)
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
;
794 good_stat
= DATA_READY
;
795 stat
= HWIF(drive
)->INB(IDE_STATUS_REG
);
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
);
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
)))
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
));
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
) {
824 stat
= wait_drive_not_busy(drive
);
828 /* Still data left to transfer. */
829 ide_set_handler(drive
, &task_in_intr
, WAIT_WORSTCASE
, NULL
);
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
;
845 good_stat
= DATA_READY
;
846 stat
= HWIF(drive
)->INB(IDE_STATUS_REG
);
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
);
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
)))
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
));
871 nsect
= rq
->current_nr_sectors
;
875 task_sectors(drive
, rq
, nsect
, IDE_PIO_IN
);
883 /* If it was the last datablock check status and finish transfer. */
884 if (!rq
->nr_sectors
) {
886 stat
= wait_drive_not_busy(drive
);
890 /* Still data left to transfer. */
891 ide_set_handler(drive
, &task_mulin_intr
, WAIT_WORSTCASE
, NULL
);
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
;
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
);
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
)))
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
));
935 /* Still data left to transfer. */
936 ide_set_handler(drive
, &task_out_intr
, WAIT_WORSTCASE
, NULL
);
939 task_sectors(drive
, rq
, 1, IDE_PIO_OUT
);
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" : "");
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
;
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
);
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
)))
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
));
1001 /* Still data left to transfer. */
1002 ide_set_handler(drive
, &task_mulout_intr
, WAIT_WORSTCASE
, NULL
);
1006 nsect
= rq
->current_nr_sectors
;
1010 task_sectors(drive
, rq
, nsect
, IDE_PIO_OUT
);
1012 if (!rq
->nr_sectors
)
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" : "");
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:
1049 case WIN_MULTWRITE_EXT
:
1050 return &pre_task_mulout_intr
;
1052 /* IDE_DRIVE_TASK_OUT */
1054 // case WIN_WRITE_ONCE:
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 */
1063 if (taskfile
->feature
== SMART_WRITE_LOG_SECTOR
)
1064 return &pre_task_out_intr
;
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 */
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
) {
1086 case CFA_TRANSLATE_SECTOR
:
1087 case WIN_READ_BUFFER
:
1089 // case WIN_READ_ONCE:
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
:
1101 // case WIN_WRITE_ONCE:
1103 return &task_out_intr
;
1104 // case WIN_READ_LONG:
1105 // case WIN_READ_LONG_ONCE:
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
:
1113 case WIN_MULTWRITE_EXT
:
1114 return &task_mulout_intr
;
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
;
1124 return &task_no_data_intr
;
1126 case CFA_REQ_EXT_ERROR_CODE
:
1127 case CFA_ERASE_SECTORS
:
1129 // case WIN_VERIFY_ONCE:
1130 case WIN_VERIFY_EXT
:
1132 return &task_no_data_intr
;
1134 return &set_geometry_intr
;
1136 // case WIN_RESTORE:
1140 case WIN_FLUSH_CACHE
:
1141 case WIN_FLUSH_CACHE_EXT
:
1142 case WIN_STANDBYNOW1
:
1143 case WIN_STANDBYNOW2
:
1147 case WIN_CHECKPOWERMODE1
:
1148 case WIN_CHECKPOWERMODE2
:
1149 case WIN_GETMEDIASTATUS
:
1150 case WIN_MEDIAEJECT
:
1151 return &task_no_data_intr
;
1153 return &set_multmode_intr
;
1154 case WIN_READ_NATIVE_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
:
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
;
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
:
1174 // case WIN_WRITEDMA_ONCE:
1175 case WIN_WRITEDMA_QUEUED
:
1176 case WIN_WRITEDMA_EXT
:
1177 case WIN_WRITEDMA_QUEUED_EXT
:
1180 case WIN_DEVICE_RESET
:
1181 case WIN_QUEUED_SERVICE
:
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 */
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
]) {
1217 return IDE_DRIVE_TASK_IN
;
1218 case CFA_TRANSLATE_SECTOR
:
1220 // case WIN_READ_ONCE:
1222 case WIN_READ_BUFFER
:
1223 return IDE_DRIVE_TASK_IN
;
1225 // case WIN_WRITE_ONCE:
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:
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
:
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
;
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
;
1259 return IDE_DRIVE_TASK_NO_DATA
;
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
;
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
:
1306 return IDE_DRIVE_TASK_NO_DATA
;
1309 case CFA_REQ_EXT_ERROR_CODE
:
1310 case CFA_ERASE_SECTORS
:
1312 // case WIN_VERIFY_ONCE:
1313 case WIN_VERIFY_EXT
:
1318 case WIN_FLUSH_CACHE
:
1319 case WIN_FLUSH_CACHE_EXT
:
1320 case WIN_STANDBYNOW1
:
1321 case WIN_STANDBYNOW2
:
1325 case DISABLE_SEAGATE
:
1326 case WIN_CHECKPOWERMODE1
:
1327 case WIN_CHECKPOWERMODE2
:
1328 case WIN_GETMEDIASTATUS
:
1329 case WIN_MEDIAEJECT
:
1331 case WIN_READ_NATIVE_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
:
1339 case WIN_DOORUNLOCK
:
1340 return IDE_DRIVE_TASK_NO_DATA
;
1343 case WIN_DEVICE_RESET
:
1344 case WIN_QUEUED_SERVICE
:
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
);
1366 int ide_diag_taskfile (ide_drive_t
*drive
, ide_task_t
*args
, unsigned long data_size
, u8
*buf
)
1370 ide_init_drive_taskfile(&rq
);
1371 rq
.flags
= REQ_DRIVE_TASKFILE
;
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
) {
1382 rq
.nr_sectors
= (args
->hobRegister
[IDE_NSECTOR_OFFSET_HOB
] << 8) | args
->tfRegister
[IDE_NSECTOR_OFFSET
];
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
);
1401 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
1406 int ide_diag_taskfile (ide_drive_t
*drive
, ide_task_t
*args
, unsigned long data_size
, u8
*buf
)
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
;
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
;
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
);
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 */
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
)
1482 char * ide_task_cmd_verbose (u8 task
)
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
;
1505 task_ioreg_t
*argsptr
= args
.tfRegister
;
1506 task_ioreg_t
*hobsptr
= args
.hobRegister
;
1508 int tasksize
= sizeof(struct ide_task_request_s
);
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
)) {
1523 taskout
= (int) req_task
->out_size
;
1524 taskin
= (int) req_task
->in_size
;
1527 int outtotal
= tasksize
;
1528 outbuf
= kmalloc(taskout
, GFP_KERNEL
);
1529 if (outbuf
== NULL
) {
1533 memset(outbuf
, 0, taskout
);
1534 if (copy_from_user(outbuf
, (void *)arg
+ outtotal
, taskout
)) {
1541 int intotal
= tasksize
+ taskout
;
1542 inbuf
= kmalloc(taskin
, GFP_KERNEL
);
1543 if (inbuf
== NULL
) {
1547 memset(inbuf
, 0, taskin
);
1548 if (copy_from_user(inbuf
, (void *)arg
+ intotal
, taskin
)) {
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",
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
);
1576 case TASKFILE_IN_DMAQ
:
1577 case TASKFILE_IN_DMA
:
1578 err
= ide_diag_taskfile(drive
, &args
, taskin
, inbuf
);
1580 case TASKFILE_IN_OUT
:
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
);
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__
);
1604 if (args
.tf_out_flags
.all
!= 0) {
1605 args
.prehandler
= &flagged_pre_task_mulout_intr
;
1606 args
.handler
= &flagged_task_mulout_intr
;
1608 args
.prehandler
= &pre_task_mulout_intr
;
1609 args
.handler
= &task_mulout_intr
;
1611 err
= ide_diag_taskfile(drive
, &args
, taskout
, outbuf
);
1614 if (args
.tf_out_flags
.all
!= 0) {
1615 args
.prehandler
= &flagged_pre_task_out_intr
;
1616 args
.handler
= &flagged_task_out_intr
;
1618 args
.prehandler
= &pre_task_out_intr
;
1619 args
.handler
= &task_out_intr
;
1621 err
= ide_diag_taskfile(drive
, &args
, taskout
, outbuf
);
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__
);
1632 if (args
.tf_out_flags
.all
!= 0) {
1633 args
.handler
= &flagged_task_mulin_intr
;
1635 args
.handler
= &task_mulin_intr
;
1637 err
= ide_diag_taskfile(drive
, &args
, taskin
, inbuf
);
1640 if (args
.tf_out_flags
.all
!= 0) {
1641 args
.handler
= &flagged_task_in_intr
;
1643 args
.handler
= &task_in_intr
;
1645 err
= ide_diag_taskfile(drive
, &args
, taskin
, inbuf
);
1647 case TASKFILE_NO_DATA
:
1648 if (args
.tf_out_flags
.all
!= 0) {
1649 args
.handler
= &flagged_task_no_data_intr
;
1651 args
.handler
= &task_no_data_intr
;
1653 err
= ide_diag_taskfile(drive
, &args
, 0, NULL
);
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
)) {
1670 int outtotal
= tasksize
;
1671 if (copy_to_user((void *)arg
+outtotal
, outbuf
, taskout
)) {
1677 int intotal
= tasksize
+ taskout
;
1678 if (copy_to_user((void *)arg
+intotal
, inbuf
, taskin
)) {
1690 // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
1692 drive
->io_32bit
= io_32bit
;
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
)
1706 memset(buf
, 0, 4 + SECTOR_WORDS
* 4 * sectors
);
1707 ide_init_drive_cmd(&rq
);
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
)
1725 u8 args
[4], *argbuf
= args
;
1730 if (NULL
== (void *) arg
) {
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))
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];
1749 argsize
= 4 + (SECTOR_WORDS
* 4 * args
[3]);
1750 argbuf
= kmalloc(argsize
, GFP_KERNEL
);
1753 memcpy(argbuf
, args
, 4);
1755 if (set_transfer(drive
, &tfargs
)) {
1756 xfer_rate
= args
[1];
1757 if (ide_ata66_check(drive
, &tfargs
))
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
);
1769 if (copy_to_user((void *)arg
, argbuf
, argsize
))
1778 u8 args
[4], *argbuf
= args
;
1783 if (NULL
== (void *) arg
) {
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))
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];
1802 argsize
= (SECTOR_WORDS
* 4 * args
[3]);
1803 argbuf
= kmalloc(argsize
, GFP_KERNEL
);
1808 if (set_transfer(drive
, &tfargs
)) {
1809 xfer_rate
= args
[1];
1810 if (ide_ata66_check(drive
, &tfargs
))
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
);
1823 args
[0] = tfargs
.tfRegister
[IDE_COMMAND_OFFSET
];
1824 args
[1] = tfargs
.tfRegister
[IDE_FEATURE_OFFSET
];
1825 args
[2] = tfargs
.tfRegister
[IDE_NSECTOR_OFFSET
];
1828 if (copy_to_user((void *)arg
, argbuf
, 4))
1830 if (argbuf
!= NULL
) {
1831 if (copy_to_user((void *)arg
, argbuf
+ 4, argsize
))
1840 EXPORT_SYMBOL(ide_cmd_ioctl
);
1842 int ide_wait_cmd_task (ide_drive_t
*drive
, u8
*buf
)
1846 ide_init_drive_cmd(&rq
);
1847 rq
.flags
= REQ_DRIVE_TASK
;
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
)
1860 u8 args
[7], *argbuf
= args
;
1863 if (copy_from_user(args
, (void *)arg
, 7))
1865 err
= ide_wait_cmd_task(drive
, argbuf
);
1866 if (copy_to_user((void *)arg
, argbuf
, argsize
))
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
;
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
)
1915 hwif
->OUTB(drive
->ctl
, IDE_CONTROL_REG
);
1916 SELECT_MASK(drive
, 0);
1919 status
= hwif
->INB(IDE_STATUS_REG
);
1920 if (status
& 0x80) {
1921 printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status
);
1923 status
= hwif
->INB(IDE_STATUS_REG
);
1924 printk("flagged_taskfile -> Status = %02x\n", status
);
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
);
1971 case TASKFILE_IN_DMAQ
:
1972 case TASKFILE_IN_DMA
:
1973 hwif
->ide_dma_read(drive
);
1977 if (task
->handler
== NULL
)
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
);
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
);
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
));
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
;
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
);
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
--)
2062 ide_end_drive_cmd (drive
, stat
, hwif
->INB(IDE_ERROR_REG
));
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
;
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
;
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
);
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
--)
2120 ide_end_drive_cmd (drive
, stat
, hwif
->INB(IDE_ERROR_REG
));
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
);
2144 taskfile_output_data(drive
, rq
->buffer
, SECTOR_WORDS
);
2145 --rq
->current_nr_sectors
;
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
;
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
));
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
);
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
);
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
;
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
);
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
;
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
;
2230 unsigned int msect
, nsect
;
2232 msect
= drive
->mult_count
;
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
));
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
);
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
)
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
:
2292 EXPORT_SYMBOL(pkt_taskfile_ioctl
);
2294 #endif /* CONFIG_PKT_TASK_IOCTL */