ide-taskfile.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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 = HWIF(drive);
  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->tf_flags & IDE_TFLAG_FLAGGED)
  68. task->tf_flags |= IDE_TFLAG_FLAGGED_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. /* calls ide_end_drive_cmd */
  135. }
  136. if (!custom)
  137. ide_end_drive_cmd(drive, stat, ide_read_error(drive));
  138. else if (tf->command == ATA_CMD_SET_MULTI)
  139. drive->mult_count = drive->mult_req;
  140. return ide_stopped;
  141. }
  142. static u8 wait_drive_not_busy(ide_drive_t *drive)
  143. {
  144. ide_hwif_t *hwif = drive->hwif;
  145. int retries;
  146. u8 stat;
  147. /*
  148. * Last sector was transfered, wait until device is ready. This can
  149. * take up to 6 ms on some ATAPI devices, so we will wait max 10 ms.
  150. */
  151. for (retries = 0; retries < 1000; retries++) {
  152. stat = hwif->tp_ops->read_status(hwif);
  153. if (stat & ATA_BUSY)
  154. udelay(10);
  155. else
  156. break;
  157. }
  158. if (stat & ATA_BUSY)
  159. printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
  160. return stat;
  161. }
  162. static void ide_pio_sector(ide_drive_t *drive, struct request *rq,
  163. unsigned int write)
  164. {
  165. ide_hwif_t *hwif = drive->hwif;
  166. struct scatterlist *sg = hwif->sg_table;
  167. struct scatterlist *cursg = hwif->cursg;
  168. struct page *page;
  169. #ifdef CONFIG_HIGHMEM
  170. unsigned long flags;
  171. #endif
  172. unsigned int offset;
  173. u8 *buf;
  174. cursg = hwif->cursg;
  175. if (!cursg) {
  176. cursg = sg;
  177. hwif->cursg = sg;
  178. }
  179. page = sg_page(cursg);
  180. offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE;
  181. /* get the current page and offset */
  182. page = nth_page(page, (offset >> PAGE_SHIFT));
  183. offset %= PAGE_SIZE;
  184. #ifdef CONFIG_HIGHMEM
  185. local_irq_save(flags);
  186. #endif
  187. buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
  188. hwif->nleft--;
  189. hwif->cursg_ofs++;
  190. if ((hwif->cursg_ofs * SECTOR_SIZE) == cursg->length) {
  191. hwif->cursg = sg_next(hwif->cursg);
  192. hwif->cursg_ofs = 0;
  193. }
  194. /* do the actual data transfer */
  195. if (write)
  196. hwif->tp_ops->output_data(drive, rq, buf, SECTOR_SIZE);
  197. else
  198. hwif->tp_ops->input_data(drive, rq, buf, SECTOR_SIZE);
  199. kunmap_atomic(buf, KM_BIO_SRC_IRQ);
  200. #ifdef CONFIG_HIGHMEM
  201. local_irq_restore(flags);
  202. #endif
  203. }
  204. static void ide_pio_multi(ide_drive_t *drive, struct request *rq,
  205. unsigned int write)
  206. {
  207. unsigned int nsect;
  208. nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count);
  209. while (nsect--)
  210. ide_pio_sector(drive, rq, write);
  211. }
  212. static void ide_pio_datablock(ide_drive_t *drive, struct request *rq,
  213. unsigned int write)
  214. {
  215. u8 saved_io_32bit = drive->io_32bit;
  216. if (rq->bio) /* fs request */
  217. rq->errors = 0;
  218. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
  219. ide_task_t *task = rq->special;
  220. if (task->tf_flags & IDE_TFLAG_IO_16BIT)
  221. drive->io_32bit = 0;
  222. }
  223. touch_softlockup_watchdog();
  224. switch (drive->hwif->data_phase) {
  225. case TASKFILE_MULTI_IN:
  226. case TASKFILE_MULTI_OUT:
  227. ide_pio_multi(drive, rq, write);
  228. break;
  229. default:
  230. ide_pio_sector(drive, rq, write);
  231. break;
  232. }
  233. drive->io_32bit = saved_io_32bit;
  234. }
  235. static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
  236. const char *s, u8 stat)
  237. {
  238. if (rq->bio) {
  239. ide_hwif_t *hwif = drive->hwif;
  240. int sectors = hwif->nsect - hwif->nleft;
  241. switch (hwif->data_phase) {
  242. case TASKFILE_IN:
  243. if (hwif->nleft)
  244. break;
  245. /* fall through */
  246. case TASKFILE_OUT:
  247. sectors--;
  248. break;
  249. case TASKFILE_MULTI_IN:
  250. if (hwif->nleft)
  251. break;
  252. /* fall through */
  253. case TASKFILE_MULTI_OUT:
  254. sectors -= drive->mult_count;
  255. default:
  256. break;
  257. }
  258. if (sectors > 0) {
  259. ide_driver_t *drv;
  260. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  261. drv->end_request(drive, 1, sectors);
  262. }
  263. }
  264. return ide_error(drive, s, stat);
  265. }
  266. void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
  267. {
  268. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
  269. u8 err = ide_read_error(drive);
  270. ide_end_drive_cmd(drive, stat, err);
  271. return;
  272. }
  273. if (rq->rq_disk) {
  274. ide_driver_t *drv;
  275. drv = *(ide_driver_t **)rq->rq_disk->private_data;;
  276. drv->end_request(drive, 1, rq->nr_sectors);
  277. } else
  278. ide_end_request(drive, 1, rq->nr_sectors);
  279. }
  280. /*
  281. * We got an interrupt on a task_in case, but no errors and no DRQ.
  282. *
  283. * It might be a spurious irq (shared irq), but it might be a
  284. * command that had no output.
  285. */
  286. static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
  287. {
  288. /* Command all done? */
  289. if (OK_STAT(stat, ATA_DRDY, ATA_BUSY)) {
  290. task_end_request(drive, rq, stat);
  291. return ide_stopped;
  292. }
  293. /* Assume it was a spurious irq */
  294. ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
  295. return ide_started;
  296. }
  297. /*
  298. * Handler for command with PIO data-in phase (Read/Read Multiple).
  299. */
  300. static ide_startstop_t task_in_intr(ide_drive_t *drive)
  301. {
  302. ide_hwif_t *hwif = drive->hwif;
  303. struct request *rq = hwif->hwgroup->rq;
  304. u8 stat = hwif->tp_ops->read_status(hwif);
  305. /* Error? */
  306. if (stat & ATA_ERR)
  307. return task_error(drive, rq, __func__, stat);
  308. /* Didn't want any data? Odd. */
  309. if ((stat & ATA_DRQ) == 0)
  310. return task_in_unexpected(drive, rq, stat);
  311. ide_pio_datablock(drive, rq, 0);
  312. /* Are we done? Check status and finish transfer. */
  313. if (!hwif->nleft) {
  314. stat = wait_drive_not_busy(drive);
  315. if (!OK_STAT(stat, 0, BAD_STAT))
  316. return task_error(drive, rq, __func__, stat);
  317. task_end_request(drive, rq, stat);
  318. return ide_stopped;
  319. }
  320. /* Still data left to transfer. */
  321. ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
  322. return ide_started;
  323. }
  324. /*
  325. * Handler for command with PIO data-out phase (Write/Write Multiple).
  326. */
  327. static ide_startstop_t task_out_intr (ide_drive_t *drive)
  328. {
  329. ide_hwif_t *hwif = drive->hwif;
  330. struct request *rq = HWGROUP(drive)->rq;
  331. u8 stat = hwif->tp_ops->read_status(hwif);
  332. if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
  333. return task_error(drive, rq, __func__, stat);
  334. /* Deal with unexpected ATA data phase. */
  335. if (((stat & ATA_DRQ) == 0) ^ !hwif->nleft)
  336. return task_error(drive, rq, __func__, stat);
  337. if (!hwif->nleft) {
  338. task_end_request(drive, rq, stat);
  339. return ide_stopped;
  340. }
  341. /* Still data left to transfer. */
  342. ide_pio_datablock(drive, rq, 1);
  343. ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
  344. return ide_started;
  345. }
  346. static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
  347. {
  348. ide_startstop_t startstop;
  349. if (ide_wait_stat(&startstop, drive, ATA_DRQ,
  350. drive->bad_wstat, WAIT_DRQ)) {
  351. printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
  352. drive->name, drive->hwif->data_phase ? "MULT" : "",
  353. (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
  354. return startstop;
  355. }
  356. if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  357. local_irq_disable();
  358. ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
  359. ide_pio_datablock(drive, rq, 1);
  360. return ide_started;
  361. }
  362. int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect)
  363. {
  364. struct request *rq;
  365. int error;
  366. rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
  367. rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
  368. rq->buffer = buf;
  369. /*
  370. * (ks) We transfer currently only whole sectors.
  371. * This is suffient for now. But, it would be great,
  372. * if we would find a solution to transfer any size.
  373. * To support special commands like READ LONG.
  374. */
  375. rq->hard_nr_sectors = rq->nr_sectors = nsect;
  376. rq->hard_cur_sectors = rq->current_nr_sectors = nsect;
  377. if (task->tf_flags & IDE_TFLAG_WRITE)
  378. rq->cmd_flags |= REQ_RW;
  379. rq->special = task;
  380. task->rq = rq;
  381. error = blk_execute_rq(drive->queue, NULL, rq, 0);
  382. blk_put_request(rq);
  383. return error;
  384. }
  385. EXPORT_SYMBOL(ide_raw_taskfile);
  386. int ide_no_data_taskfile(ide_drive_t *drive, ide_task_t *task)
  387. {
  388. task->data_phase = TASKFILE_NO_DATA;
  389. return ide_raw_taskfile(drive, task, NULL, 0);
  390. }
  391. EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
  392. #ifdef CONFIG_IDE_TASK_IOCTL
  393. int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
  394. {
  395. ide_task_request_t *req_task;
  396. ide_task_t args;
  397. u8 *outbuf = NULL;
  398. u8 *inbuf = NULL;
  399. u8 *data_buf = NULL;
  400. int err = 0;
  401. int tasksize = sizeof(struct ide_task_request_s);
  402. unsigned int taskin = 0;
  403. unsigned int taskout = 0;
  404. u16 nsect = 0;
  405. char __user *buf = (char __user *)arg;
  406. // printk("IDE Taskfile ...\n");
  407. req_task = kzalloc(tasksize, GFP_KERNEL);
  408. if (req_task == NULL) return -ENOMEM;
  409. if (copy_from_user(req_task, buf, tasksize)) {
  410. kfree(req_task);
  411. return -EFAULT;
  412. }
  413. taskout = req_task->out_size;
  414. taskin = req_task->in_size;
  415. if (taskin > 65536 || taskout > 65536) {
  416. err = -EINVAL;
  417. goto abort;
  418. }
  419. if (taskout) {
  420. int outtotal = tasksize;
  421. outbuf = kzalloc(taskout, GFP_KERNEL);
  422. if (outbuf == NULL) {
  423. err = -ENOMEM;
  424. goto abort;
  425. }
  426. if (copy_from_user(outbuf, buf + outtotal, taskout)) {
  427. err = -EFAULT;
  428. goto abort;
  429. }
  430. }
  431. if (taskin) {
  432. int intotal = tasksize + taskout;
  433. inbuf = kzalloc(taskin, GFP_KERNEL);
  434. if (inbuf == NULL) {
  435. err = -ENOMEM;
  436. goto abort;
  437. }
  438. if (copy_from_user(inbuf, buf + intotal, taskin)) {
  439. err = -EFAULT;
  440. goto abort;
  441. }
  442. }
  443. memset(&args, 0, sizeof(ide_task_t));
  444. memcpy(&args.tf_array[0], req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE - 2);
  445. memcpy(&args.tf_array[6], req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
  446. args.data_phase = req_task->data_phase;
  447. args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
  448. IDE_TFLAG_IN_TF;
  449. if (drive->dev_flags & IDE_DFLAG_LBA48)
  450. args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
  451. if (req_task->out_flags.all) {
  452. args.tf_flags |= IDE_TFLAG_FLAGGED;
  453. if (req_task->out_flags.b.data)
  454. args.tf_flags |= IDE_TFLAG_OUT_DATA;
  455. if (req_task->out_flags.b.nsector_hob)
  456. args.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT;
  457. if (req_task->out_flags.b.sector_hob)
  458. args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL;
  459. if (req_task->out_flags.b.lcyl_hob)
  460. args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM;
  461. if (req_task->out_flags.b.hcyl_hob)
  462. args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH;
  463. if (req_task->out_flags.b.error_feature)
  464. args.tf_flags |= IDE_TFLAG_OUT_FEATURE;
  465. if (req_task->out_flags.b.nsector)
  466. args.tf_flags |= IDE_TFLAG_OUT_NSECT;
  467. if (req_task->out_flags.b.sector)
  468. args.tf_flags |= IDE_TFLAG_OUT_LBAL;
  469. if (req_task->out_flags.b.lcyl)
  470. args.tf_flags |= IDE_TFLAG_OUT_LBAM;
  471. if (req_task->out_flags.b.hcyl)
  472. args.tf_flags |= IDE_TFLAG_OUT_LBAH;
  473. } else {
  474. args.tf_flags |= IDE_TFLAG_OUT_TF;
  475. if (args.tf_flags & IDE_TFLAG_LBA48)
  476. args.tf_flags |= IDE_TFLAG_OUT_HOB;
  477. }
  478. if (req_task->in_flags.b.data)
  479. args.tf_flags |= IDE_TFLAG_IN_DATA;
  480. switch(req_task->data_phase) {
  481. case TASKFILE_MULTI_OUT:
  482. if (!drive->mult_count) {
  483. /* (hs): give up if multcount is not set */
  484. printk(KERN_ERR "%s: %s Multimode Write " \
  485. "multcount is not set\n",
  486. drive->name, __func__);
  487. err = -EPERM;
  488. goto abort;
  489. }
  490. /* fall through */
  491. case TASKFILE_OUT:
  492. /* fall through */
  493. case TASKFILE_OUT_DMAQ:
  494. case TASKFILE_OUT_DMA:
  495. nsect = taskout / SECTOR_SIZE;
  496. data_buf = outbuf;
  497. break;
  498. case TASKFILE_MULTI_IN:
  499. if (!drive->mult_count) {
  500. /* (hs): give up if multcount is not set */
  501. printk(KERN_ERR "%s: %s Multimode Read failure " \
  502. "multcount is not set\n",
  503. drive->name, __func__);
  504. err = -EPERM;
  505. goto abort;
  506. }
  507. /* fall through */
  508. case TASKFILE_IN:
  509. /* fall through */
  510. case TASKFILE_IN_DMAQ:
  511. case TASKFILE_IN_DMA:
  512. nsect = taskin / SECTOR_SIZE;
  513. data_buf = inbuf;
  514. break;
  515. case TASKFILE_NO_DATA:
  516. break;
  517. default:
  518. err = -EFAULT;
  519. goto abort;
  520. }
  521. if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
  522. nsect = 0;
  523. else if (!nsect) {
  524. nsect = (args.tf.hob_nsect << 8) | args.tf.nsect;
  525. if (!nsect) {
  526. printk(KERN_ERR "%s: in/out command without data\n",
  527. drive->name);
  528. err = -EFAULT;
  529. goto abort;
  530. }
  531. }
  532. if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE)
  533. args.tf_flags |= IDE_TFLAG_WRITE;
  534. err = ide_raw_taskfile(drive, &args, data_buf, nsect);
  535. memcpy(req_task->hob_ports, &args.tf_array[0], HDIO_DRIVE_HOB_HDR_SIZE - 2);
  536. memcpy(req_task->io_ports, &args.tf_array[6], HDIO_DRIVE_TASK_HDR_SIZE);
  537. if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) &&
  538. req_task->in_flags.all == 0) {
  539. req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
  540. if (drive->dev_flags & IDE_DFLAG_LBA48)
  541. req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
  542. }
  543. if (copy_to_user(buf, req_task, tasksize)) {
  544. err = -EFAULT;
  545. goto abort;
  546. }
  547. if (taskout) {
  548. int outtotal = tasksize;
  549. if (copy_to_user(buf + outtotal, outbuf, taskout)) {
  550. err = -EFAULT;
  551. goto abort;
  552. }
  553. }
  554. if (taskin) {
  555. int intotal = tasksize + taskout;
  556. if (copy_to_user(buf + intotal, inbuf, taskin)) {
  557. err = -EFAULT;
  558. goto abort;
  559. }
  560. }
  561. abort:
  562. kfree(req_task);
  563. kfree(outbuf);
  564. kfree(inbuf);
  565. // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
  566. return err;
  567. }
  568. #endif