Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/ide/ide-taskfile.c Version 0.38 March 05, 2003 |
| 3 | * |
| 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-2004 Bartlomiej Zolnierkiewicz |
| 9 | * |
| 10 | * The big the bad and the ugly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/timer.h> |
| 18 | #include <linux/mm.h> |
Andrew Morton | 651c29a | 2006-02-15 15:17:37 -0800 | [diff] [blame] | 19 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/major.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/genhd.h> |
| 24 | #include <linux/blkpg.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/pci.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/hdreg.h> |
| 29 | #include <linux/ide.h> |
| 30 | #include <linux/bitops.h> |
Jens Axboe | 55c16a7 | 2007-07-25 08:13:56 +0200 | [diff] [blame] | 31 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | #include <asm/byteorder.h> |
| 34 | #include <asm/irq.h> |
| 35 | #include <asm/uaccess.h> |
| 36 | #include <asm/io.h> |
| 37 | |
Bartlomiej Zolnierkiewicz | 9e42237 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 38 | void ide_tf_load(ide_drive_t *drive, ide_task_t *task) |
| 39 | { |
| 40 | ide_hwif_t *hwif = drive->hwif; |
| 41 | struct ide_taskfile *tf = &task->tf; |
| 42 | u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; |
| 43 | |
Bartlomiej Zolnierkiewicz | 74095a9 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 44 | if (task->tf_flags & IDE_TFLAG_FLAGGED) |
| 45 | HIHI = 0xFF; |
| 46 | |
Bartlomiej Zolnierkiewicz | 807e35d | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 47 | #ifdef DEBUG |
| 48 | printk("%s: tf: feat 0x%02x nsect 0x%02x lbal 0x%02x " |
| 49 | "lbam 0x%02x lbah 0x%02x dev 0x%02x cmd 0x%02x\n", |
| 50 | drive->name, tf->feature, tf->nsect, tf->lbal, |
| 51 | tf->lbam, tf->lbah, tf->device, tf->command); |
Bartlomiej Zolnierkiewicz | 6dd9b83 | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 52 | printk("%s: hob: nsect 0x%02x lbal 0x%02x " |
| 53 | "lbam 0x%02x lbah 0x%02x\n", |
| 54 | drive->name, tf->hob_nsect, tf->hob_lbal, |
| 55 | tf->hob_lbam, tf->hob_lbah); |
Bartlomiej Zolnierkiewicz | 807e35d | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 56 | #endif |
| 57 | |
Bartlomiej Zolnierkiewicz | 81ca691 | 2008-01-26 20:13:08 +0100 | [diff] [blame] | 58 | ide_set_irq(drive, 1); |
Bartlomiej Zolnierkiewicz | 9e42237 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 59 | |
| 60 | if ((task->tf_flags & IDE_TFLAG_NO_SELECT_MASK) == 0) |
| 61 | SELECT_MASK(drive, 0); |
| 62 | |
Bartlomiej Zolnierkiewicz | 74095a9 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 63 | if (task->tf_flags & IDE_TFLAG_OUT_DATA) |
| 64 | hwif->OUTW((tf->hob_data << 8) | tf->data, IDE_DATA_REG); |
Bartlomiej Zolnierkiewicz | 9e42237 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 65 | |
Bartlomiej Zolnierkiewicz | 74095a9 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 66 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) |
| 67 | hwif->OUTB(tf->hob_feature, IDE_FEATURE_REG); |
| 68 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) |
| 69 | hwif->OUTB(tf->hob_nsect, IDE_NSECTOR_REG); |
| 70 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) |
| 71 | hwif->OUTB(tf->hob_lbal, IDE_SECTOR_REG); |
| 72 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) |
| 73 | hwif->OUTB(tf->hob_lbam, IDE_LCYL_REG); |
| 74 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) |
| 75 | hwif->OUTB(tf->hob_lbah, IDE_HCYL_REG); |
| 76 | |
| 77 | if (task->tf_flags & IDE_TFLAG_OUT_FEATURE) |
| 78 | hwif->OUTB(tf->feature, IDE_FEATURE_REG); |
| 79 | if (task->tf_flags & IDE_TFLAG_OUT_NSECT) |
| 80 | hwif->OUTB(tf->nsect, IDE_NSECTOR_REG); |
| 81 | if (task->tf_flags & IDE_TFLAG_OUT_LBAL) |
| 82 | hwif->OUTB(tf->lbal, IDE_SECTOR_REG); |
| 83 | if (task->tf_flags & IDE_TFLAG_OUT_LBAM) |
| 84 | hwif->OUTB(tf->lbam, IDE_LCYL_REG); |
| 85 | if (task->tf_flags & IDE_TFLAG_OUT_LBAH) |
| 86 | hwif->OUTB(tf->lbah, IDE_HCYL_REG); |
Bartlomiej Zolnierkiewicz | 9e42237 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 87 | |
Bartlomiej Zolnierkiewicz | 807e35d | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 88 | if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) |
| 89 | hwif->OUTB((tf->device & HIHI) | drive->select.all, IDE_SELECT_REG); |
Bartlomiej Zolnierkiewicz | 9e42237 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf) |
| 93 | { |
| 94 | ide_task_t args; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | memset(&args, 0, sizeof(ide_task_t)); |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 97 | args.tf.nsect = 0x01; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | if (drive->media == ide_disk) |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 99 | args.tf.command = WIN_IDENTIFY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | else |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 101 | args.tf.command = WIN_PIDENTIFY; |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 102 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 103 | args.data_phase = TASKFILE_IN; |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 104 | return ide_raw_taskfile(drive, &args, buf, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Bartlomiej Zolnierkiewicz | 74095a9 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 107 | static int inline task_dma_ok(ide_task_t *task) |
| 108 | { |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 109 | if (blk_fs_request(task->rq) || (task->tf_flags & IDE_TFLAG_FLAGGED)) |
Bartlomiej Zolnierkiewicz | 74095a9 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 110 | return 1; |
| 111 | |
| 112 | switch (task->tf.command) { |
| 113 | case WIN_WRITEDMA_ONCE: |
| 114 | case WIN_WRITEDMA: |
| 115 | case WIN_WRITEDMA_EXT: |
| 116 | case WIN_READDMA_ONCE: |
| 117 | case WIN_READDMA: |
| 118 | case WIN_READDMA_EXT: |
| 119 | case WIN_IDENTIFY_DMA: |
| 120 | return 1; |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Bartlomiej Zolnierkiewicz | 1192e52 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 126 | static ide_startstop_t task_no_data_intr(ide_drive_t *); |
Bartlomiej Zolnierkiewicz | 57d7366 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 127 | static ide_startstop_t set_geometry_intr(ide_drive_t *); |
| 128 | static ide_startstop_t recal_intr(ide_drive_t *); |
| 129 | static ide_startstop_t set_multmode_intr(ide_drive_t *); |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 130 | static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *); |
| 131 | static ide_startstop_t task_in_intr(ide_drive_t *); |
Bartlomiej Zolnierkiewicz | 1192e52 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task) |
| 134 | { |
| 135 | ide_hwif_t *hwif = HWIF(drive); |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 136 | struct ide_taskfile *tf = &task->tf; |
Bartlomiej Zolnierkiewicz | 57d7366 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 137 | ide_handler_t *handler = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Bartlomiej Zolnierkiewicz | 1edee60 | 2008-01-25 22:17:15 +0100 | [diff] [blame] | 139 | if (task->data_phase == TASKFILE_MULTI_IN || |
| 140 | task->data_phase == TASKFILE_MULTI_OUT) { |
| 141 | if (!drive->mult_count) { |
| 142 | printk(KERN_ERR "%s: multimode not set!\n", |
| 143 | drive->name); |
| 144 | return ide_stopped; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if (task->tf_flags & IDE_TFLAG_FLAGGED) |
| 149 | task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS; |
| 150 | |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 151 | if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) |
| 152 | ide_tf_load(drive, task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Bartlomiej Zolnierkiewicz | 10d9015 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 154 | switch (task->data_phase) { |
| 155 | case TASKFILE_MULTI_OUT: |
| 156 | case TASKFILE_OUT: |
| 157 | hwif->OUTBSYNC(drive, tf->command, IDE_COMMAND_REG); |
| 158 | ndelay(400); /* FIXME */ |
| 159 | return pre_task_out_intr(drive, task->rq); |
| 160 | case TASKFILE_MULTI_IN: |
| 161 | case TASKFILE_IN: |
Bartlomiej Zolnierkiewicz | 57d7366 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 162 | handler = task_in_intr; |
Bartlomiej Zolnierkiewicz | 1192e52 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 163 | /* fall-through */ |
Bartlomiej Zolnierkiewicz | 10d9015 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 164 | case TASKFILE_NO_DATA: |
Bartlomiej Zolnierkiewicz | 57d7366 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 165 | if (handler == NULL) |
| 166 | handler = task_no_data_intr; |
Bartlomiej Zolnierkiewicz | 1192e52 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 167 | /* WIN_{SPECIFY,RESTORE,SETMULT} use custom handlers */ |
Bartlomiej Zolnierkiewicz | 57d7366 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 168 | if (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) { |
| 169 | switch (tf->command) { |
| 170 | case WIN_SPECIFY: handler = set_geometry_intr; break; |
| 171 | case WIN_RESTORE: handler = recal_intr; break; |
| 172 | case WIN_SETMULT: handler = set_multmode_intr; break; |
| 173 | } |
| 174 | } |
| 175 | ide_execute_command(drive, tf->command, handler, |
| 176 | WAIT_WORSTCASE, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | return ide_started; |
Bartlomiej Zolnierkiewicz | 10d9015 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 178 | default: |
| 179 | if (task_dma_ok(task) == 0 || drive->using_dma == 0 || |
| 180 | hwif->dma_setup(drive)) |
| 181 | return ide_stopped; |
Bartlomiej Zolnierkiewicz | 74095a9 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 182 | hwif->dma_exec_cmd(drive, tf->command); |
| 183 | hwif->dma_start(drive); |
| 184 | return ide_started; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 187 | EXPORT_SYMBOL_GPL(do_rw_taskfile); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* |
| 190 | * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd. |
| 191 | */ |
Bartlomiej Zolnierkiewicz | 57d7366 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 192 | static ide_startstop_t set_multmode_intr(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | ide_hwif_t *hwif = HWIF(drive); |
| 195 | u8 stat; |
| 196 | |
| 197 | if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) { |
| 198 | drive->mult_count = drive->mult_req; |
| 199 | } else { |
| 200 | drive->mult_req = drive->mult_count = 0; |
| 201 | drive->special.b.recalibrate = 1; |
| 202 | (void) ide_dump_status(drive, "set_multmode", stat); |
| 203 | } |
| 204 | return ide_stopped; |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd. |
| 209 | */ |
Bartlomiej Zolnierkiewicz | 57d7366 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 210 | static ide_startstop_t set_geometry_intr(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | ide_hwif_t *hwif = HWIF(drive); |
| 213 | int retries = 5; |
| 214 | u8 stat; |
| 215 | |
| 216 | while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--) |
| 217 | udelay(10); |
| 218 | |
| 219 | if (OK_STAT(stat, READY_STAT, BAD_STAT)) |
| 220 | return ide_stopped; |
| 221 | |
| 222 | if (stat & (ERR_STAT|DRQ_STAT)) |
| 223 | return ide_error(drive, "set_geometry_intr", stat); |
| 224 | |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 225 | BUG_ON(HWGROUP(drive)->handler != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL); |
| 227 | return ide_started; |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd. |
| 232 | */ |
Bartlomiej Zolnierkiewicz | 57d7366 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 233 | static ide_startstop_t recal_intr(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
| 235 | ide_hwif_t *hwif = HWIF(drive); |
| 236 | u8 stat; |
| 237 | |
| 238 | if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) |
| 239 | return ide_error(drive, "recal_intr", stat); |
| 240 | return ide_stopped; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * Handler for commands without a data phase |
| 245 | */ |
Bartlomiej Zolnierkiewicz | 1192e52 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 246 | static ide_startstop_t task_no_data_intr(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
| 248 | ide_task_t *args = HWGROUP(drive)->rq->special; |
| 249 | ide_hwif_t *hwif = HWIF(drive); |
| 250 | u8 stat; |
| 251 | |
Ingo Molnar | 366c7f5 | 2006-07-03 00:25:25 -0700 | [diff] [blame] | 252 | local_irq_enable_in_hardirq(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) { |
| 254 | return ide_error(drive, "task_no_data_intr", stat); |
| 255 | /* calls ide_end_drive_cmd */ |
| 256 | } |
| 257 | if (args) |
| 258 | ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG)); |
| 259 | |
| 260 | return ide_stopped; |
| 261 | } |
| 262 | |
Bartlomiej Zolnierkiewicz | 2624565 | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 263 | u8 wait_drive_not_busy(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
| 265 | ide_hwif_t *hwif = HWIF(drive); |
Masatake YAMATO | b42fa13 | 2007-07-03 22:28:34 +0200 | [diff] [blame] | 266 | int retries; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | u8 stat; |
| 268 | |
| 269 | /* |
| 270 | * Last sector was transfered, wait until drive is ready. |
Bartlomiej Zolnierkiewicz | 2624565 | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 271 | * This can take up to 10 usec, but we will wait max 1 ms. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | */ |
Masatake YAMATO | b42fa13 | 2007-07-03 22:28:34 +0200 | [diff] [blame] | 273 | for (retries = 0; retries < 100; retries++) { |
| 274 | if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) |
| 275 | udelay(10); |
| 276 | else |
| 277 | break; |
| 278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Masatake YAMATO | b42fa13 | 2007-07-03 22:28:34 +0200 | [diff] [blame] | 280 | if (stat & BUSY_STAT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | printk(KERN_ERR "%s: drive still BUSY!\n", drive->name); |
| 282 | |
| 283 | return stat; |
| 284 | } |
| 285 | |
| 286 | static void ide_pio_sector(ide_drive_t *drive, unsigned int write) |
| 287 | { |
| 288 | ide_hwif_t *hwif = drive->hwif; |
| 289 | struct scatterlist *sg = hwif->sg_table; |
Jens Axboe | 55c16a7 | 2007-07-25 08:13:56 +0200 | [diff] [blame] | 290 | struct scatterlist *cursg = hwif->cursg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | struct page *page; |
| 292 | #ifdef CONFIG_HIGHMEM |
| 293 | unsigned long flags; |
| 294 | #endif |
| 295 | unsigned int offset; |
| 296 | u8 *buf; |
| 297 | |
Jens Axboe | 55c16a7 | 2007-07-25 08:13:56 +0200 | [diff] [blame] | 298 | cursg = hwif->cursg; |
| 299 | if (!cursg) { |
| 300 | cursg = sg; |
| 301 | hwif->cursg = sg; |
| 302 | } |
| 303 | |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 304 | page = sg_page(cursg); |
Jens Axboe | 55c16a7 | 2007-07-25 08:13:56 +0200 | [diff] [blame] | 305 | offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 307 | /* get the current page and offset */ |
| 308 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
| 309 | offset %= PAGE_SIZE; |
| 310 | |
| 311 | #ifdef CONFIG_HIGHMEM |
| 312 | local_irq_save(flags); |
| 313 | #endif |
| 314 | buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset; |
| 315 | |
| 316 | hwif->nleft--; |
| 317 | hwif->cursg_ofs++; |
| 318 | |
Jens Axboe | 55c16a7 | 2007-07-25 08:13:56 +0200 | [diff] [blame] | 319 | if ((hwif->cursg_ofs * SECTOR_SIZE) == cursg->length) { |
| 320 | hwif->cursg = sg_next(hwif->cursg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | hwif->cursg_ofs = 0; |
| 322 | } |
| 323 | |
| 324 | /* do the actual data transfer */ |
| 325 | if (write) |
Bartlomiej Zolnierkiewicz | 9e47be0 | 2008-01-26 20:13:09 +0100 | [diff] [blame] | 326 | hwif->ata_output_data(drive, buf, SECTOR_WORDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | else |
Bartlomiej Zolnierkiewicz | 9e47be0 | 2008-01-26 20:13:09 +0100 | [diff] [blame] | 328 | hwif->ata_input_data(drive, buf, SECTOR_WORDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | kunmap_atomic(buf, KM_BIO_SRC_IRQ); |
| 331 | #ifdef CONFIG_HIGHMEM |
| 332 | local_irq_restore(flags); |
| 333 | #endif |
| 334 | } |
| 335 | |
| 336 | static void ide_pio_multi(ide_drive_t *drive, unsigned int write) |
| 337 | { |
| 338 | unsigned int nsect; |
| 339 | |
| 340 | nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count); |
| 341 | while (nsect--) |
| 342 | ide_pio_sector(drive, write); |
| 343 | } |
| 344 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 345 | static void ide_pio_datablock(ide_drive_t *drive, struct request *rq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | unsigned int write) |
| 347 | { |
Tejun Heo | 35cf2b9 | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 348 | u8 saved_io_32bit = drive->io_32bit; |
| 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (rq->bio) /* fs request */ |
| 351 | rq->errors = 0; |
| 352 | |
Tejun Heo | 35cf2b9 | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 353 | if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { |
| 354 | ide_task_t *task = rq->special; |
| 355 | |
| 356 | if (task->tf_flags & IDE_TFLAG_IO_16BIT) |
| 357 | drive->io_32bit = 0; |
| 358 | } |
| 359 | |
Andrew Morton | 651c29a | 2006-02-15 15:17:37 -0800 | [diff] [blame] | 360 | touch_softlockup_watchdog(); |
| 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | switch (drive->hwif->data_phase) { |
| 363 | case TASKFILE_MULTI_IN: |
| 364 | case TASKFILE_MULTI_OUT: |
| 365 | ide_pio_multi(drive, write); |
| 366 | break; |
| 367 | default: |
| 368 | ide_pio_sector(drive, write); |
| 369 | break; |
| 370 | } |
Tejun Heo | 35cf2b9 | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 371 | |
| 372 | drive->io_32bit = saved_io_32bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq, |
| 376 | const char *s, u8 stat) |
| 377 | { |
| 378 | if (rq->bio) { |
| 379 | ide_hwif_t *hwif = drive->hwif; |
| 380 | int sectors = hwif->nsect - hwif->nleft; |
| 381 | |
| 382 | switch (hwif->data_phase) { |
| 383 | case TASKFILE_IN: |
| 384 | if (hwif->nleft) |
| 385 | break; |
| 386 | /* fall through */ |
| 387 | case TASKFILE_OUT: |
| 388 | sectors--; |
| 389 | break; |
| 390 | case TASKFILE_MULTI_IN: |
| 391 | if (hwif->nleft) |
| 392 | break; |
| 393 | /* fall through */ |
| 394 | case TASKFILE_MULTI_OUT: |
| 395 | sectors -= drive->mult_count; |
| 396 | default: |
| 397 | break; |
| 398 | } |
| 399 | |
| 400 | if (sectors > 0) { |
| 401 | ide_driver_t *drv; |
| 402 | |
| 403 | drv = *(ide_driver_t **)rq->rq_disk->private_data; |
| 404 | drv->end_request(drive, 1, sectors); |
| 405 | } |
| 406 | } |
| 407 | return ide_error(drive, s, stat); |
| 408 | } |
| 409 | |
Tejun Heo | 4d7a984 | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 410 | void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 412 | if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { |
Tejun Heo | 4d7a984 | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 413 | u8 err = drive->hwif->INB(IDE_ERROR_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Tejun Heo | 4d7a984 | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 415 | ide_end_drive_cmd(drive, stat, err); |
| 416 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Richard Purdie | 03731fb | 2006-03-31 02:31:15 -0800 | [diff] [blame] | 419 | if (rq->rq_disk) { |
| 420 | ide_driver_t *drv; |
| 421 | |
| 422 | drv = *(ide_driver_t **)rq->rq_disk->private_data;; |
Bartlomiej Zolnierkiewicz | 79f21b8 | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 423 | drv->end_request(drive, 1, rq->nr_sectors); |
Richard Purdie | 03731fb | 2006-03-31 02:31:15 -0800 | [diff] [blame] | 424 | } else |
Bartlomiej Zolnierkiewicz | 79f21b8 | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 425 | ide_end_request(drive, 1, rq->nr_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /* |
| 429 | * Handler for command with PIO data-in phase (Read/Read Multiple). |
| 430 | */ |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 431 | static ide_startstop_t task_in_intr(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
| 433 | ide_hwif_t *hwif = drive->hwif; |
| 434 | struct request *rq = HWGROUP(drive)->rq; |
| 435 | u8 stat = hwif->INB(IDE_STATUS_REG); |
| 436 | |
| 437 | /* new way for dealing with premature shared PCI interrupts */ |
Bartlomiej Zolnierkiewicz | 4906f3b | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 438 | if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | if (stat & (ERR_STAT | DRQ_STAT)) |
| 440 | return task_error(drive, rq, __FUNCTION__, stat); |
| 441 | /* No data yet, so wait for another IRQ. */ |
| 442 | ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL); |
| 443 | return ide_started; |
| 444 | } |
| 445 | |
| 446 | ide_pio_datablock(drive, rq, 0); |
| 447 | |
| 448 | /* If it was the last datablock check status and finish transfer. */ |
| 449 | if (!hwif->nleft) { |
| 450 | stat = wait_drive_not_busy(drive); |
Bartlomiej Zolnierkiewicz | 73d7de0 | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 451 | if (!OK_STAT(stat, 0, BAD_STAT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return task_error(drive, rq, __FUNCTION__, stat); |
| 453 | task_end_request(drive, rq, stat); |
| 454 | return ide_stopped; |
| 455 | } |
| 456 | |
| 457 | /* Still data left to transfer. */ |
| 458 | ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL); |
| 459 | |
| 460 | return ide_started; |
| 461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | /* |
| 464 | * Handler for command with PIO data-out phase (Write/Write Multiple). |
| 465 | */ |
| 466 | static ide_startstop_t task_out_intr (ide_drive_t *drive) |
| 467 | { |
| 468 | ide_hwif_t *hwif = drive->hwif; |
| 469 | struct request *rq = HWGROUP(drive)->rq; |
| 470 | u8 stat = hwif->INB(IDE_STATUS_REG); |
| 471 | |
| 472 | if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) |
| 473 | return task_error(drive, rq, __FUNCTION__, stat); |
| 474 | |
| 475 | /* Deal with unexpected ATA data phase. */ |
| 476 | if (((stat & DRQ_STAT) == 0) ^ !hwif->nleft) |
| 477 | return task_error(drive, rq, __FUNCTION__, stat); |
| 478 | |
| 479 | if (!hwif->nleft) { |
| 480 | task_end_request(drive, rq, stat); |
| 481 | return ide_stopped; |
| 482 | } |
| 483 | |
| 484 | /* Still data left to transfer. */ |
| 485 | ide_pio_datablock(drive, rq, 1); |
| 486 | ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL); |
| 487 | |
| 488 | return ide_started; |
| 489 | } |
| 490 | |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 491 | static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
| 493 | ide_startstop_t startstop; |
| 494 | |
Bartlomiej Zolnierkiewicz | 4906f3b | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 495 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | drive->bad_wstat, WAIT_DRQ)) { |
| 497 | printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", |
| 498 | drive->name, |
| 499 | drive->hwif->data_phase ? "MULT" : "", |
| 500 | drive->addressing ? "_EXT" : ""); |
| 501 | return startstop; |
| 502 | } |
| 503 | |
| 504 | if (!drive->unmask) |
| 505 | local_irq_disable(); |
| 506 | |
| 507 | ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL); |
| 508 | ide_pio_datablock(drive, rq, 1); |
| 509 | |
| 510 | return ide_started; |
| 511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 513 | int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | { |
| 515 | struct request rq; |
| 516 | |
| 517 | memset(&rq, 0, sizeof(rq)); |
Bartlomiej Zolnierkiewicz | 02ac246 | 2007-11-05 21:42:27 +0100 | [diff] [blame] | 518 | rq.ref_count = 1; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 519 | rq.cmd_type = REQ_TYPE_ATA_TASKFILE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | rq.buffer = buf; |
| 521 | |
| 522 | /* |
| 523 | * (ks) We transfer currently only whole sectors. |
| 524 | * This is suffient for now. But, it would be great, |
| 525 | * if we would find a solution to transfer any size. |
| 526 | * To support special commands like READ LONG. |
| 527 | */ |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 528 | rq.hard_nr_sectors = rq.nr_sectors = nsect; |
| 529 | rq.hard_cur_sectors = rq.current_nr_sectors = nsect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 531 | if (task->tf_flags & IDE_TFLAG_WRITE) |
| 532 | rq.cmd_flags |= REQ_RW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 534 | rq.special = task; |
| 535 | task->rq = &rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return ide_do_drive_cmd(drive, &rq, ide_wait); |
| 538 | } |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | EXPORT_SYMBOL(ide_raw_taskfile); |
| 541 | |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 542 | int ide_no_data_taskfile(ide_drive_t *drive, ide_task_t *task) |
| 543 | { |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 544 | task->data_phase = TASKFILE_NO_DATA; |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 545 | |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 546 | return ide_raw_taskfile(drive, task, NULL, 0); |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 547 | } |
| 548 | EXPORT_SYMBOL_GPL(ide_no_data_taskfile); |
| 549 | |
Bartlomiej Zolnierkiewicz | 26a5b04 | 2007-11-05 21:42:27 +0100 | [diff] [blame] | 550 | #ifdef CONFIG_IDE_TASK_IOCTL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) |
| 552 | { |
| 553 | ide_task_request_t *req_task; |
| 554 | ide_task_t args; |
| 555 | u8 *outbuf = NULL; |
| 556 | u8 *inbuf = NULL; |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 557 | u8 *data_buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | int err = 0; |
| 559 | int tasksize = sizeof(struct ide_task_request_s); |
Alan Cox | 3a42bb2 | 2006-10-16 16:31:02 +0100 | [diff] [blame] | 560 | unsigned int taskin = 0; |
| 561 | unsigned int taskout = 0; |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 562 | u16 nsect = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | char __user *buf = (char __user *)arg; |
| 564 | |
| 565 | // printk("IDE Taskfile ...\n"); |
| 566 | |
Deepak Saxena | f5e3c2f | 2005-11-07 01:01:25 -0800 | [diff] [blame] | 567 | req_task = kzalloc(tasksize, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | if (req_task == NULL) return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | if (copy_from_user(req_task, buf, tasksize)) { |
| 570 | kfree(req_task); |
| 571 | return -EFAULT; |
| 572 | } |
| 573 | |
Alan Cox | 3a42bb2 | 2006-10-16 16:31:02 +0100 | [diff] [blame] | 574 | taskout = req_task->out_size; |
| 575 | taskin = req_task->in_size; |
| 576 | |
| 577 | if (taskin > 65536 || taskout > 65536) { |
| 578 | err = -EINVAL; |
| 579 | goto abort; |
| 580 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | if (taskout) { |
| 583 | int outtotal = tasksize; |
Deepak Saxena | f5e3c2f | 2005-11-07 01:01:25 -0800 | [diff] [blame] | 584 | outbuf = kzalloc(taskout, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (outbuf == NULL) { |
| 586 | err = -ENOMEM; |
| 587 | goto abort; |
| 588 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (copy_from_user(outbuf, buf + outtotal, taskout)) { |
| 590 | err = -EFAULT; |
| 591 | goto abort; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if (taskin) { |
| 596 | int intotal = tasksize + taskout; |
Deepak Saxena | f5e3c2f | 2005-11-07 01:01:25 -0800 | [diff] [blame] | 597 | inbuf = kzalloc(taskin, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (inbuf == NULL) { |
| 599 | err = -ENOMEM; |
| 600 | goto abort; |
| 601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | if (copy_from_user(inbuf, buf + intotal, taskin)) { |
| 603 | err = -EFAULT; |
| 604 | goto abort; |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | memset(&args, 0, sizeof(ide_task_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 610 | memcpy(&args.tf_array[0], req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE - 2); |
| 611 | memcpy(&args.tf_array[6], req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE); |
Bartlomiej Zolnierkiewicz | 866e2ec | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 612 | |
| 613 | args.data_phase = req_task->data_phase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 615 | args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE | |
| 616 | IDE_TFLAG_IN_TF; |
Bartlomiej Zolnierkiewicz | a3bbb9d | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 617 | if (drive->addressing == 1) |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 618 | args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB); |
Bartlomiej Zolnierkiewicz | a3bbb9d | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 619 | |
Bartlomiej Zolnierkiewicz | 74095a9 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 620 | if (req_task->out_flags.all) { |
| 621 | args.tf_flags |= IDE_TFLAG_FLAGGED; |
| 622 | |
| 623 | if (req_task->out_flags.b.data) |
| 624 | args.tf_flags |= IDE_TFLAG_OUT_DATA; |
| 625 | |
| 626 | if (req_task->out_flags.b.nsector_hob) |
| 627 | args.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT; |
| 628 | if (req_task->out_flags.b.sector_hob) |
| 629 | args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL; |
| 630 | if (req_task->out_flags.b.lcyl_hob) |
| 631 | args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM; |
| 632 | if (req_task->out_flags.b.hcyl_hob) |
| 633 | args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH; |
| 634 | |
| 635 | if (req_task->out_flags.b.error_feature) |
| 636 | args.tf_flags |= IDE_TFLAG_OUT_FEATURE; |
| 637 | if (req_task->out_flags.b.nsector) |
| 638 | args.tf_flags |= IDE_TFLAG_OUT_NSECT; |
| 639 | if (req_task->out_flags.b.sector) |
| 640 | args.tf_flags |= IDE_TFLAG_OUT_LBAL; |
| 641 | if (req_task->out_flags.b.lcyl) |
| 642 | args.tf_flags |= IDE_TFLAG_OUT_LBAM; |
| 643 | if (req_task->out_flags.b.hcyl) |
| 644 | args.tf_flags |= IDE_TFLAG_OUT_LBAH; |
Bartlomiej Zolnierkiewicz | a3bbb9d | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 645 | } else { |
| 646 | args.tf_flags |= IDE_TFLAG_OUT_TF; |
| 647 | if (args.tf_flags & IDE_TFLAG_LBA48) |
| 648 | args.tf_flags |= IDE_TFLAG_OUT_HOB; |
Bartlomiej Zolnierkiewicz | 74095a9 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 649 | } |
| 650 | |
Bartlomiej Zolnierkiewicz | 866e2ec | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 651 | if (req_task->in_flags.b.data) |
| 652 | args.tf_flags |= IDE_TFLAG_IN_DATA; |
| 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | switch(req_task->data_phase) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | case TASKFILE_MULTI_OUT: |
| 656 | if (!drive->mult_count) { |
| 657 | /* (hs): give up if multcount is not set */ |
| 658 | printk(KERN_ERR "%s: %s Multimode Write " \ |
| 659 | "multcount is not set\n", |
| 660 | drive->name, __FUNCTION__); |
| 661 | err = -EPERM; |
| 662 | goto abort; |
| 663 | } |
| 664 | /* fall through */ |
| 665 | case TASKFILE_OUT: |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 666 | /* fall through */ |
| 667 | case TASKFILE_OUT_DMAQ: |
| 668 | case TASKFILE_OUT_DMA: |
| 669 | nsect = taskout / SECTOR_SIZE; |
| 670 | data_buf = outbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | break; |
| 672 | case TASKFILE_MULTI_IN: |
| 673 | if (!drive->mult_count) { |
| 674 | /* (hs): give up if multcount is not set */ |
| 675 | printk(KERN_ERR "%s: %s Multimode Read failure " \ |
| 676 | "multcount is not set\n", |
| 677 | drive->name, __FUNCTION__); |
| 678 | err = -EPERM; |
| 679 | goto abort; |
| 680 | } |
| 681 | /* fall through */ |
| 682 | case TASKFILE_IN: |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 683 | /* fall through */ |
| 684 | case TASKFILE_IN_DMAQ: |
| 685 | case TASKFILE_IN_DMA: |
| 686 | nsect = taskin / SECTOR_SIZE; |
| 687 | data_buf = inbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | break; |
| 689 | case TASKFILE_NO_DATA: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | break; |
| 691 | default: |
| 692 | err = -EFAULT; |
| 693 | goto abort; |
| 694 | } |
| 695 | |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 696 | if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA) |
| 697 | nsect = 0; |
| 698 | else if (!nsect) { |
| 699 | nsect = (args.tf.hob_nsect << 8) | args.tf.nsect; |
| 700 | |
| 701 | if (!nsect) { |
| 702 | printk(KERN_ERR "%s: in/out command without data\n", |
| 703 | drive->name); |
| 704 | err = -EFAULT; |
| 705 | goto abort; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE) |
| 710 | args.tf_flags |= IDE_TFLAG_WRITE; |
| 711 | |
| 712 | err = ide_raw_taskfile(drive, &args, data_buf, nsect); |
| 713 | |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 714 | memcpy(req_task->hob_ports, &args.tf_array[0], HDIO_DRIVE_HOB_HDR_SIZE - 2); |
| 715 | memcpy(req_task->io_ports, &args.tf_array[6], HDIO_DRIVE_TASK_HDR_SIZE); |
Bartlomiej Zolnierkiewicz | 866e2ec | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 716 | |
| 717 | if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) && |
| 718 | req_task->in_flags.all == 0) { |
| 719 | req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS; |
| 720 | if (drive->addressing == 1) |
| 721 | req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8); |
| 722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | if (copy_to_user(buf, req_task, tasksize)) { |
| 725 | err = -EFAULT; |
| 726 | goto abort; |
| 727 | } |
| 728 | if (taskout) { |
| 729 | int outtotal = tasksize; |
| 730 | if (copy_to_user(buf + outtotal, outbuf, taskout)) { |
| 731 | err = -EFAULT; |
| 732 | goto abort; |
| 733 | } |
| 734 | } |
| 735 | if (taskin) { |
| 736 | int intotal = tasksize + taskout; |
| 737 | if (copy_to_user(buf + intotal, inbuf, taskin)) { |
| 738 | err = -EFAULT; |
| 739 | goto abort; |
| 740 | } |
| 741 | } |
| 742 | abort: |
| 743 | kfree(req_task); |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 744 | kfree(outbuf); |
| 745 | kfree(inbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
| 747 | // printk("IDE Taskfile ioctl ended. rc = %i\n", err); |
| 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | return err; |
| 750 | } |
Bartlomiej Zolnierkiewicz | 26a5b04 | 2007-11-05 21:42:27 +0100 | [diff] [blame] | 751 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) |
| 754 | { |
Bartlomiej Zolnierkiewicz | 5a9e77a | 2008-01-26 20:13:13 +0100 | [diff] [blame^] | 755 | u8 *buf = NULL; |
| 756 | int bufsize = 0, err = 0; |
| 757 | u8 args[4], xfer_rate = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | ide_task_t tfargs; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 759 | struct ide_taskfile *tf = &tfargs.tf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
| 761 | if (NULL == (void *) arg) { |
| 762 | struct request rq; |
Bartlomiej Zolnierkiewicz | 145b75e | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | ide_init_drive_cmd(&rq); |
Bartlomiej Zolnierkiewicz | 852738f | 2008-01-26 20:13:12 +0100 | [diff] [blame] | 765 | rq.cmd_type = REQ_TYPE_ATA_TASKFILE; |
Bartlomiej Zolnierkiewicz | 145b75e | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | return ide_do_drive_cmd(drive, &rq, ide_wait); |
| 768 | } |
| 769 | |
| 770 | if (copy_from_user(args, (void __user *)arg, 4)) |
| 771 | return -EFAULT; |
| 772 | |
| 773 | memset(&tfargs, 0, sizeof(ide_task_t)); |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 774 | tf->feature = args[2]; |
Bartlomiej Zolnierkiewicz | 5a9e77a | 2008-01-26 20:13:13 +0100 | [diff] [blame^] | 775 | if (args[0] == WIN_SMART) { |
| 776 | tf->nsect = args[3]; |
| 777 | tf->lbal = args[1]; |
| 778 | tf->lbam = 0x4f; |
| 779 | tf->lbah = 0xc2; |
| 780 | tfargs.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_IN_NSECT; |
| 781 | } else { |
| 782 | tf->nsect = args[1]; |
| 783 | tfargs.tf_flags = IDE_TFLAG_OUT_FEATURE | |
| 784 | IDE_TFLAG_OUT_NSECT | IDE_TFLAG_IN_NSECT; |
| 785 | } |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 786 | tf->command = args[0]; |
Bartlomiej Zolnierkiewicz | 5a9e77a | 2008-01-26 20:13:13 +0100 | [diff] [blame^] | 787 | tfargs.data_phase = args[3] ? TASKFILE_IN : TASKFILE_NO_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
| 789 | if (args[3]) { |
Bartlomiej Zolnierkiewicz | 5a9e77a | 2008-01-26 20:13:13 +0100 | [diff] [blame^] | 790 | tfargs.tf_flags |= IDE_TFLAG_IO_16BIT; |
| 791 | bufsize = SECTOR_WORDS * 4 * args[3]; |
| 792 | buf = kzalloc(bufsize, GFP_KERNEL); |
| 793 | if (buf == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | } |
Bartlomiej Zolnierkiewicz | 5a9e77a | 2008-01-26 20:13:13 +0100 | [diff] [blame^] | 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | if (set_transfer(drive, &tfargs)) { |
| 798 | xfer_rate = args[1]; |
| 799 | if (ide_ata66_check(drive, &tfargs)) |
| 800 | goto abort; |
| 801 | } |
| 802 | |
Bartlomiej Zolnierkiewicz | 5a9e77a | 2008-01-26 20:13:13 +0100 | [diff] [blame^] | 803 | err = ide_raw_taskfile(drive, &tfargs, buf, args[3]); |
| 804 | |
| 805 | args[0] = tf->status; |
| 806 | args[1] = tf->error; |
| 807 | args[2] = tf->nsect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
| 809 | if (!err && xfer_rate) { |
| 810 | /* active-retuning-calls future */ |
| 811 | ide_set_xfer_rate(drive, xfer_rate); |
| 812 | ide_driveid_update(drive); |
| 813 | } |
| 814 | abort: |
Bartlomiej Zolnierkiewicz | 5a9e77a | 2008-01-26 20:13:13 +0100 | [diff] [blame^] | 815 | if (copy_to_user((void __user *)arg, &args, 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | err = -EFAULT; |
Bartlomiej Zolnierkiewicz | 5a9e77a | 2008-01-26 20:13:13 +0100 | [diff] [blame^] | 817 | if (buf) { |
| 818 | if (copy_to_user((void __user *)(arg + 4), buf, bufsize)) |
| 819 | err = -EFAULT; |
| 820 | kfree(buf); |
| 821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | return err; |
| 823 | } |
| 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) |
| 826 | { |
| 827 | void __user *p = (void __user *)arg; |
| 828 | int err = 0; |
Bartlomiej Zolnierkiewicz | 14b89ef | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 829 | u8 args[7]; |
| 830 | ide_task_t task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
| 832 | if (copy_from_user(args, p, 7)) |
| 833 | return -EFAULT; |
Bartlomiej Zolnierkiewicz | 14b89ef | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 834 | |
| 835 | memset(&task, 0, sizeof(task)); |
| 836 | memcpy(&task.tf_array[7], &args[1], 6); |
| 837 | task.tf.command = args[0]; |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 838 | task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | 14b89ef | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 839 | |
| 840 | err = ide_no_data_taskfile(drive, &task); |
| 841 | |
| 842 | args[0] = task.tf.command; |
| 843 | memcpy(&args[1], &task.tf_array[7], 6); |
| 844 | |
| 845 | if (copy_to_user(p, args, 7)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | err = -EFAULT; |
Bartlomiej Zolnierkiewicz | 14b89ef | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | return err; |
| 849 | } |