ide-taskfile.c 16 KB

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