ide-taskfile.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org>
  3. * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
  4. * Copyright (C) 2001-2002 Klaus Smolin
  5. * IBM Storage Technology Division
  6. * Copyright (C) 2003-2004, 2007 Bartlomiej Zolnierkiewicz
  7. *
  8. * The big the bad and the ugly.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/string.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/errno.h>
  16. #include <linux/slab.h>
  17. #include <linux/delay.h>
  18. #include <linux/hdreg.h>
  19. #include <linux/ide.h>
  20. #include <linux/scatterlist.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/io.h>
  23. void ide_tf_dump(const char *s, struct ide_taskfile *tf)
  24. {
  25. #ifdef DEBUG
  26. printk("%s: tf: feat 0x%02x nsect 0x%02x lbal 0x%02x "
  27. "lbam 0x%02x lbah 0x%02x dev 0x%02x cmd 0x%02x\n",
  28. s, tf->feature, tf->nsect, tf->lbal,
  29. tf->lbam, tf->lbah, tf->device, tf->command);
  30. printk("%s: hob: nsect 0x%02x lbal 0x%02x "
  31. "lbam 0x%02x lbah 0x%02x\n",
  32. s, tf->hob_nsect, tf->hob_lbal,
  33. tf->hob_lbam, tf->hob_lbah);
  34. #endif
  35. }
  36. int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
  37. {
  38. ide_task_t args;
  39. memset(&args, 0, sizeof(ide_task_t));
  40. args.tf.nsect = 0x01;
  41. if (drive->media == ide_disk)
  42. args.tf.command = ATA_CMD_ID_ATA;
  43. else
  44. args.tf.command = ATA_CMD_ID_ATAPI;
  45. args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
  46. args.data_phase = TASKFILE_IN;
  47. return ide_raw_taskfile(drive, &args, buf, 1);
  48. }
  49. static ide_startstop_t task_no_data_intr(ide_drive_t *);
  50. static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
  51. static ide_startstop_t task_in_intr(ide_drive_t *);
  52. ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
  53. {
  54. ide_hwif_t *hwif = drive->hwif;
  55. struct ide_taskfile *tf = &task->tf;
  56. ide_handler_t *handler = NULL;
  57. const struct ide_tp_ops *tp_ops = hwif->tp_ops;
  58. const struct ide_dma_ops *dma_ops = hwif->dma_ops;
  59. if (task->data_phase == TASKFILE_MULTI_IN ||
  60. task->data_phase == TASKFILE_MULTI_OUT) {
  61. if (!drive->mult_count) {
  62. printk(KERN_ERR "%s: multimode not set!\n",
  63. drive->name);
  64. return ide_stopped;
  65. }
  66. }
  67. if (task->ftf_flags & IDE_FTFLAG_FLAGGED)
  68. task->ftf_flags |= IDE_FTFLAG_SET_IN_FLAGS;
  69. memcpy(&hwif->task, task, sizeof(*task));
  70. if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
  71. ide_tf_dump(drive->name, tf);
  72. tp_ops->set_irq(hwif, 1);
  73. SELECT_MASK(drive, 0);
  74. tp_ops->tf_load(drive, task);
  75. }
  76. switch (task->data_phase) {
  77. case TASKFILE_MULTI_OUT:
  78. case TASKFILE_OUT:
  79. tp_ops->exec_command(hwif, tf->command);
  80. ndelay(400); /* FIXME */
  81. return pre_task_out_intr(drive, task->rq);
  82. case TASKFILE_MULTI_IN:
  83. case TASKFILE_IN:
  84. handler = task_in_intr;
  85. /* fall-through */
  86. case TASKFILE_NO_DATA:
  87. if (handler == NULL)
  88. handler = task_no_data_intr;
  89. ide_execute_command(drive, tf->command, handler,
  90. WAIT_WORSTCASE, NULL);
  91. return ide_started;
  92. default:
  93. if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
  94. dma_ops->dma_setup(drive))
  95. return ide_stopped;
  96. dma_ops->dma_exec_cmd(drive, tf->command);
  97. dma_ops->dma_start(drive);
  98. return ide_started;
  99. }
  100. }
  101. EXPORT_SYMBOL_GPL(do_rw_taskfile);
  102. /*
  103. * Handler for commands without a data phase
  104. */
  105. static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
  106. {
  107. ide_hwif_t *hwif = drive->hwif;
  108. ide_task_t *task = &hwif->task;
  109. struct ide_taskfile *tf = &task->tf;
  110. int custom = (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0;
  111. int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
  112. u8 stat;
  113. local_irq_enable_in_hardirq();
  114. while (1) {
  115. stat = hwif->tp_ops->read_status(hwif);
  116. if ((stat & ATA_BUSY) == 0 || retries-- == 0)
  117. break;
  118. udelay(10);
  119. };
  120. if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
  121. if (custom && tf->command == ATA_CMD_SET_MULTI) {
  122. drive->mult_req = drive->mult_count = 0;
  123. drive->special.b.recalibrate = 1;
  124. (void)ide_dump_status(drive, __func__, stat);
  125. return ide_stopped;
  126. } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) {
  127. if ((stat & (ATA_ERR | ATA_DRQ)) == 0) {
  128. ide_set_handler(drive, &task_no_data_intr,
  129. WAIT_WORSTCASE, NULL);
  130. return ide_started;
  131. }
  132. }
  133. return ide_error(drive, "task_no_data_intr", stat);
  134. }
  135. if (custom && tf->command == ATA_CMD_IDLEIMMEDIATE) {
  136. hwif->tp_ops->tf_read(drive, task);
  137. if (tf->lbal != 0xc4) {
  138. printk(KERN_ERR "%s: head unload failed!\n",
  139. drive->name);
  140. ide_tf_dump(drive->name, tf);
  141. } else
  142. drive->dev_flags |= IDE_DFLAG_PARKED;
  143. } else if (custom && tf->command == ATA_CMD_SET_MULTI)
  144. drive->mult_count = drive->mult_req;
  145. if (custom == 0 || tf->command == ATA_CMD_IDLEIMMEDIATE) {
  146. struct request *rq = hwif->rq;
  147. u8 err = ide_read_error(drive);
  148. if (blk_pm_request(rq))
  149. ide_complete_pm_rq(drive, rq);
  150. else {
  151. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
  152. ide_complete_task(drive, task, stat, err);
  153. ide_complete_rq(drive, err);
  154. }
  155. }
  156. return ide_stopped;
  157. }
  158. static u8 wait_drive_not_busy(ide_drive_t *drive)
  159. {
  160. ide_hwif_t *hwif = drive->hwif;
  161. int retries;
  162. u8 stat;
  163. /*
  164. * Last sector was transfered, wait until device is ready. This can
  165. * take up to 6 ms on some ATAPI devices, so we will wait max 10 ms.
  166. */
  167. for (retries = 0; retries < 1000; retries++) {
  168. stat = hwif->tp_ops->read_status(hwif);
  169. if (stat & ATA_BUSY)
  170. udelay(10);
  171. else
  172. break;
  173. }
  174. if (stat & ATA_BUSY)
  175. printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
  176. return stat;
  177. }
  178. static void ide_pio_sector(ide_drive_t *drive, struct request *rq,
  179. unsigned int write)
  180. {
  181. ide_hwif_t *hwif = drive->hwif;
  182. struct scatterlist *sg = hwif->sg_table;
  183. struct scatterlist *cursg = hwif->cursg;
  184. struct page *page;
  185. #ifdef CONFIG_HIGHMEM
  186. unsigned long flags;
  187. #endif
  188. unsigned int offset;
  189. u8 *buf;
  190. cursg = hwif->cursg;
  191. if (!cursg) {
  192. cursg = sg;
  193. hwif->cursg = sg;
  194. }
  195. page = sg_page(cursg);
  196. offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE;
  197. /* get the current page and offset */
  198. page = nth_page(page, (offset >> PAGE_SHIFT));
  199. offset %= PAGE_SIZE;
  200. #ifdef CONFIG_HIGHMEM
  201. local_irq_save(flags);
  202. #endif
  203. buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
  204. hwif->nleft--;
  205. hwif->cursg_ofs++;
  206. if ((hwif->cursg_ofs * SECTOR_SIZE) == cursg->length) {
  207. hwif->cursg = sg_next(hwif->cursg);
  208. hwif->cursg_ofs = 0;
  209. }
  210. /* do the actual data transfer */
  211. if (write)
  212. hwif->tp_ops->output_data(drive, rq, buf, SECTOR_SIZE);
  213. else
  214. hwif->tp_ops->input_data(drive, rq, buf, SECTOR_SIZE);
  215. kunmap_atomic(buf, KM_BIO_SRC_IRQ);
  216. #ifdef CONFIG_HIGHMEM
  217. local_irq_restore(flags);
  218. #endif
  219. }
  220. static void ide_pio_multi(ide_drive_t *drive, struct request *rq,
  221. unsigned int write)
  222. {
  223. unsigned int nsect;
  224. nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count);
  225. while (nsect--)
  226. ide_pio_sector(drive, rq, write);
  227. }
  228. static void ide_pio_datablock(ide_drive_t *drive, struct request *rq,
  229. unsigned int write)
  230. {
  231. ide_task_t *task = &drive->hwif->task;
  232. u8 saved_io_32bit = drive->io_32bit;
  233. if (rq->bio) /* fs request */
  234. rq->errors = 0;
  235. if (task->tf_flags & IDE_TFLAG_IO_16BIT)
  236. drive->io_32bit = 0;
  237. touch_softlockup_watchdog();
  238. switch (task->data_phase) {
  239. case TASKFILE_MULTI_IN:
  240. case TASKFILE_MULTI_OUT:
  241. ide_pio_multi(drive, rq, write);
  242. break;
  243. default:
  244. ide_pio_sector(drive, rq, write);
  245. break;
  246. }
  247. drive->io_32bit = saved_io_32bit;
  248. }
  249. static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
  250. const char *s, u8 stat)
  251. {
  252. if (rq->bio) {
  253. ide_hwif_t *hwif = drive->hwif;
  254. ide_task_t *task = &hwif->task;
  255. int sectors = hwif->nsect - hwif->nleft;
  256. switch (task->data_phase) {
  257. case TASKFILE_IN:
  258. if (hwif->nleft)
  259. break;
  260. /* fall through */
  261. case TASKFILE_OUT:
  262. sectors--;
  263. break;
  264. case TASKFILE_MULTI_IN:
  265. if (hwif->nleft)
  266. break;
  267. /* fall through */
  268. case TASKFILE_MULTI_OUT:
  269. sectors -= drive->mult_count;
  270. default:
  271. break;
  272. }
  273. if (sectors > 0)
  274. ide_end_request(drive, 1, sectors);
  275. }
  276. return ide_error(drive, s, stat);
  277. }
  278. void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
  279. {
  280. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
  281. ide_task_t *task = rq->special;
  282. u8 err = ide_read_error(drive);
  283. if (task)
  284. ide_complete_task(drive, task, stat, err);
  285. ide_complete_rq(drive, err);
  286. return;
  287. }
  288. ide_end_request(drive, 1, rq->nr_sectors);
  289. }
  290. /*
  291. * We got an interrupt on a task_in case, but no errors and no DRQ.
  292. *
  293. * It might be a spurious irq (shared irq), but it might be a
  294. * command that had no output.
  295. */
  296. static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
  297. {
  298. /* Command all done? */
  299. if (OK_STAT(stat, ATA_DRDY, ATA_BUSY)) {
  300. task_end_request(drive, rq, stat);
  301. return ide_stopped;
  302. }
  303. /* Assume it was a spurious irq */
  304. ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
  305. return ide_started;
  306. }
  307. /*
  308. * Handler for command with PIO data-in phase (Read/Read Multiple).
  309. */
  310. static ide_startstop_t task_in_intr(ide_drive_t *drive)
  311. {
  312. ide_hwif_t *hwif = drive->hwif;
  313. struct request *rq = hwif->rq;
  314. u8 stat = hwif->tp_ops->read_status(hwif);
  315. /* Error? */
  316. if (stat & ATA_ERR)
  317. return task_error(drive, rq, __func__, stat);
  318. /* Didn't want any data? Odd. */
  319. if ((stat & ATA_DRQ) == 0)
  320. return task_in_unexpected(drive, rq, stat);
  321. ide_pio_datablock(drive, rq, 0);
  322. /* Are we done? Check status and finish transfer. */
  323. if (!hwif->nleft) {
  324. stat = wait_drive_not_busy(drive);
  325. if (!OK_STAT(stat, 0, BAD_STAT))
  326. return task_error(drive, rq, __func__, stat);
  327. task_end_request(drive, rq, stat);
  328. return ide_stopped;
  329. }
  330. /* Still data left to transfer. */
  331. ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
  332. return ide_started;
  333. }
  334. /*
  335. * Handler for command with PIO data-out phase (Write/Write Multiple).
  336. */
  337. static ide_startstop_t task_out_intr (ide_drive_t *drive)
  338. {
  339. ide_hwif_t *hwif = drive->hwif;
  340. struct request *rq = hwif->rq;
  341. u8 stat = hwif->tp_ops->read_status(hwif);
  342. if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
  343. return task_error(drive, rq, __func__, stat);
  344. /* Deal with unexpected ATA data phase. */
  345. if (((stat & ATA_DRQ) == 0) ^ !hwif->nleft)
  346. return task_error(drive, rq, __func__, stat);
  347. if (!hwif->nleft) {
  348. task_end_request(drive, rq, stat);
  349. return ide_stopped;
  350. }
  351. /* Still data left to transfer. */
  352. ide_pio_datablock(drive, rq, 1);
  353. ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
  354. return ide_started;
  355. }
  356. static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
  357. {
  358. ide_task_t *task = &drive->hwif->task;
  359. ide_startstop_t startstop;
  360. if (ide_wait_stat(&startstop, drive, ATA_DRQ,
  361. drive->bad_wstat, WAIT_DRQ)) {
  362. printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
  363. drive->name,
  364. task->data_phase == TASKFILE_MULTI_OUT ? "MULT" : "",
  365. (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
  366. return startstop;
  367. }
  368. if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  369. local_irq_disable();
  370. ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
  371. ide_pio_datablock(drive, rq, 1);
  372. return ide_started;
  373. }
  374. int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect)
  375. {
  376. struct request *rq;
  377. int error;
  378. rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
  379. rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
  380. rq->buffer = buf;
  381. /*
  382. * (ks) We transfer currently only whole sectors.
  383. * This is suffient for now. But, it would be great,
  384. * if we would find a solution to transfer any size.
  385. * To support special commands like READ LONG.
  386. */
  387. rq->hard_nr_sectors = rq->nr_sectors = nsect;
  388. rq->hard_cur_sectors = rq->current_nr_sectors = nsect;
  389. if (task->tf_flags & IDE_TFLAG_WRITE)
  390. rq->cmd_flags |= REQ_RW;
  391. rq->special = task;
  392. task->rq = rq;
  393. error = blk_execute_rq(drive->queue, NULL, rq, 0);
  394. blk_put_request(rq);
  395. return error;
  396. }
  397. EXPORT_SYMBOL(ide_raw_taskfile);
  398. int ide_no_data_taskfile(ide_drive_t *drive, ide_task_t *task)
  399. {
  400. task->data_phase = TASKFILE_NO_DATA;
  401. return ide_raw_taskfile(drive, task, NULL, 0);
  402. }
  403. EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
  404. #ifdef CONFIG_IDE_TASK_IOCTL
  405. int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
  406. {
  407. ide_task_request_t *req_task;
  408. ide_task_t args;
  409. u8 *outbuf = NULL;
  410. u8 *inbuf = NULL;
  411. u8 *data_buf = NULL;
  412. int err = 0;
  413. int tasksize = sizeof(struct ide_task_request_s);
  414. unsigned int taskin = 0;
  415. unsigned int taskout = 0;
  416. u16 nsect = 0;
  417. char __user *buf = (char __user *)arg;
  418. // printk("IDE Taskfile ...\n");
  419. req_task = kzalloc(tasksize, GFP_KERNEL);
  420. if (req_task == NULL) return -ENOMEM;
  421. if (copy_from_user(req_task, buf, tasksize)) {
  422. kfree(req_task);
  423. return -EFAULT;
  424. }
  425. taskout = req_task->out_size;
  426. taskin = req_task->in_size;
  427. if (taskin > 65536 || taskout > 65536) {
  428. err = -EINVAL;
  429. goto abort;
  430. }
  431. if (taskout) {
  432. int outtotal = tasksize;
  433. outbuf = kzalloc(taskout, GFP_KERNEL);
  434. if (outbuf == NULL) {
  435. err = -ENOMEM;
  436. goto abort;
  437. }
  438. if (copy_from_user(outbuf, buf + outtotal, taskout)) {
  439. err = -EFAULT;
  440. goto abort;
  441. }
  442. }
  443. if (taskin) {
  444. int intotal = tasksize + taskout;
  445. inbuf = kzalloc(taskin, GFP_KERNEL);
  446. if (inbuf == NULL) {
  447. err = -ENOMEM;
  448. goto abort;
  449. }
  450. if (copy_from_user(inbuf, buf + intotal, taskin)) {
  451. err = -EFAULT;
  452. goto abort;
  453. }
  454. }
  455. memset(&args, 0, sizeof(ide_task_t));
  456. memcpy(&args.tf_array[0], req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE - 2);
  457. memcpy(&args.tf_array[6], req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
  458. args.data_phase = req_task->data_phase;
  459. args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
  460. IDE_TFLAG_IN_TF;
  461. if (drive->dev_flags & IDE_DFLAG_LBA48)
  462. args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
  463. if (req_task->out_flags.all) {
  464. args.ftf_flags |= IDE_FTFLAG_FLAGGED;
  465. if (req_task->out_flags.b.data)
  466. args.ftf_flags |= IDE_FTFLAG_OUT_DATA;
  467. if (req_task->out_flags.b.nsector_hob)
  468. args.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT;
  469. if (req_task->out_flags.b.sector_hob)
  470. args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL;
  471. if (req_task->out_flags.b.lcyl_hob)
  472. args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM;
  473. if (req_task->out_flags.b.hcyl_hob)
  474. args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH;
  475. if (req_task->out_flags.b.error_feature)
  476. args.tf_flags |= IDE_TFLAG_OUT_FEATURE;
  477. if (req_task->out_flags.b.nsector)
  478. args.tf_flags |= IDE_TFLAG_OUT_NSECT;
  479. if (req_task->out_flags.b.sector)
  480. args.tf_flags |= IDE_TFLAG_OUT_LBAL;
  481. if (req_task->out_flags.b.lcyl)
  482. args.tf_flags |= IDE_TFLAG_OUT_LBAM;
  483. if (req_task->out_flags.b.hcyl)
  484. args.tf_flags |= IDE_TFLAG_OUT_LBAH;
  485. } else {
  486. args.tf_flags |= IDE_TFLAG_OUT_TF;
  487. if (args.tf_flags & IDE_TFLAG_LBA48)
  488. args.tf_flags |= IDE_TFLAG_OUT_HOB;
  489. }
  490. if (req_task->in_flags.b.data)
  491. args.ftf_flags |= IDE_FTFLAG_IN_DATA;
  492. switch(req_task->data_phase) {
  493. case TASKFILE_MULTI_OUT:
  494. if (!drive->mult_count) {
  495. /* (hs): give up if multcount is not set */
  496. printk(KERN_ERR "%s: %s Multimode Write " \
  497. "multcount is not set\n",
  498. drive->name, __func__);
  499. err = -EPERM;
  500. goto abort;
  501. }
  502. /* fall through */
  503. case TASKFILE_OUT:
  504. /* fall through */
  505. case TASKFILE_OUT_DMAQ:
  506. case TASKFILE_OUT_DMA:
  507. nsect = taskout / SECTOR_SIZE;
  508. data_buf = outbuf;
  509. break;
  510. case TASKFILE_MULTI_IN:
  511. if (!drive->mult_count) {
  512. /* (hs): give up if multcount is not set */
  513. printk(KERN_ERR "%s: %s Multimode Read failure " \
  514. "multcount is not set\n",
  515. drive->name, __func__);
  516. err = -EPERM;
  517. goto abort;
  518. }
  519. /* fall through */
  520. case TASKFILE_IN:
  521. /* fall through */
  522. case TASKFILE_IN_DMAQ:
  523. case TASKFILE_IN_DMA:
  524. nsect = taskin / SECTOR_SIZE;
  525. data_buf = inbuf;
  526. break;
  527. case TASKFILE_NO_DATA:
  528. break;
  529. default:
  530. err = -EFAULT;
  531. goto abort;
  532. }
  533. if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
  534. nsect = 0;
  535. else if (!nsect) {
  536. nsect = (args.tf.hob_nsect << 8) | args.tf.nsect;
  537. if (!nsect) {
  538. printk(KERN_ERR "%s: in/out command without data\n",
  539. drive->name);
  540. err = -EFAULT;
  541. goto abort;
  542. }
  543. }
  544. if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE)
  545. args.tf_flags |= IDE_TFLAG_WRITE;
  546. err = ide_raw_taskfile(drive, &args, data_buf, nsect);
  547. memcpy(req_task->hob_ports, &args.tf_array[0], HDIO_DRIVE_HOB_HDR_SIZE - 2);
  548. memcpy(req_task->io_ports, &args.tf_array[6], HDIO_DRIVE_TASK_HDR_SIZE);
  549. if ((args.ftf_flags & IDE_FTFLAG_SET_IN_FLAGS) &&
  550. req_task->in_flags.all == 0) {
  551. req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
  552. if (drive->dev_flags & IDE_DFLAG_LBA48)
  553. req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
  554. }
  555. if (copy_to_user(buf, req_task, tasksize)) {
  556. err = -EFAULT;
  557. goto abort;
  558. }
  559. if (taskout) {
  560. int outtotal = tasksize;
  561. if (copy_to_user(buf + outtotal, outbuf, taskout)) {
  562. err = -EFAULT;
  563. goto abort;
  564. }
  565. }
  566. if (taskin) {
  567. int intotal = tasksize + taskout;
  568. if (copy_to_user(buf + intotal, inbuf, taskin)) {
  569. err = -EFAULT;
  570. goto abort;
  571. }
  572. }
  573. abort:
  574. kfree(req_task);
  575. kfree(outbuf);
  576. kfree(inbuf);
  577. // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
  578. return err;
  579. }
  580. #endif