ide-taskfile.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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, cmd, handler, WAIT_WORSTCASE);
  88. return ide_started;
  89. case ATA_PROT_DMA:
  90. if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
  91. ide_build_sglist(drive, cmd) == 0 ||
  92. dma_ops->dma_setup(drive, cmd))
  93. return ide_stopped;
  94. hwif->expiry = dma_ops->dma_timer_expiry;
  95. ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD);
  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);
  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_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
  165. unsigned int write, unsigned int len)
  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. unsigned long flags;
  172. unsigned int offset;
  173. u8 *buf;
  174. cursg = cmd->cursg;
  175. if (cursg == NULL)
  176. cursg = cmd->cursg = sg;
  177. while (len) {
  178. unsigned nr_bytes = min(len, cursg->length - cmd->cursg_ofs);
  179. if (nr_bytes > PAGE_SIZE)
  180. nr_bytes = PAGE_SIZE;
  181. page = sg_page(cursg);
  182. offset = cursg->offset + cmd->cursg_ofs;
  183. /* get the current page and offset */
  184. page = nth_page(page, (offset >> PAGE_SHIFT));
  185. offset %= PAGE_SIZE;
  186. if (PageHighMem(page))
  187. local_irq_save(flags);
  188. buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
  189. cmd->nleft -= nr_bytes;
  190. cmd->cursg_ofs += nr_bytes;
  191. if (cmd->cursg_ofs == cursg->length) {
  192. cursg = cmd->cursg = sg_next(cmd->cursg);
  193. cmd->cursg_ofs = 0;
  194. }
  195. /* do the actual data transfer */
  196. if (write)
  197. hwif->tp_ops->output_data(drive, cmd, buf, nr_bytes);
  198. else
  199. hwif->tp_ops->input_data(drive, cmd, buf, nr_bytes);
  200. kunmap_atomic(buf, KM_BIO_SRC_IRQ);
  201. if (PageHighMem(page))
  202. local_irq_restore(flags);
  203. len -= nr_bytes;
  204. }
  205. }
  206. static void ide_pio_datablock(ide_drive_t *drive, struct ide_cmd *cmd,
  207. unsigned int write)
  208. {
  209. unsigned int nr_bytes;
  210. u8 saved_io_32bit = drive->io_32bit;
  211. if (cmd->tf_flags & IDE_TFLAG_FS)
  212. cmd->rq->errors = 0;
  213. if (cmd->tf_flags & IDE_TFLAG_IO_16BIT)
  214. drive->io_32bit = 0;
  215. touch_softlockup_watchdog();
  216. if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
  217. nr_bytes = min_t(unsigned, cmd->nleft, drive->mult_count << 9);
  218. else
  219. nr_bytes = SECTOR_SIZE;
  220. ide_pio_bytes(drive, cmd, write, nr_bytes);
  221. drive->io_32bit = saved_io_32bit;
  222. }
  223. static void ide_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
  224. {
  225. if (cmd->tf_flags & IDE_TFLAG_FS) {
  226. int nr_bytes = cmd->nbytes - cmd->nleft;
  227. if (cmd->protocol == ATA_PROT_PIO &&
  228. ((cmd->tf_flags & IDE_TFLAG_WRITE) || cmd->nleft == 0)) {
  229. if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
  230. nr_bytes -= drive->mult_count << 9;
  231. else
  232. nr_bytes -= SECTOR_SIZE;
  233. }
  234. if (nr_bytes > 0)
  235. ide_complete_rq(drive, 0, nr_bytes);
  236. }
  237. }
  238. void ide_finish_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat)
  239. {
  240. struct request *rq = drive->hwif->rq;
  241. u8 err = ide_read_error(drive);
  242. ide_complete_cmd(drive, cmd, stat, err);
  243. rq->errors = err;
  244. ide_complete_rq(drive, err ? -EIO : 0, blk_rq_bytes(rq));
  245. }
  246. /*
  247. * Handler for command with PIO data phase.
  248. */
  249. static ide_startstop_t task_pio_intr(ide_drive_t *drive)
  250. {
  251. ide_hwif_t *hwif = drive->hwif;
  252. struct ide_cmd *cmd = &drive->hwif->cmd;
  253. u8 stat = hwif->tp_ops->read_status(hwif);
  254. u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
  255. if (write == 0) {
  256. /* Error? */
  257. if (stat & ATA_ERR)
  258. goto out_err;
  259. /* Didn't want any data? Odd. */
  260. if ((stat & ATA_DRQ) == 0) {
  261. /* Command all done? */
  262. if (OK_STAT(stat, ATA_DRDY, ATA_BUSY))
  263. goto out_end;
  264. /* Assume it was a spurious irq */
  265. goto out_wait;
  266. }
  267. } else {
  268. if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
  269. goto out_err;
  270. /* Deal with unexpected ATA data phase. */
  271. if (((stat & ATA_DRQ) == 0) ^ (cmd->nleft == 0))
  272. goto out_err;
  273. }
  274. if (write && cmd->nleft == 0)
  275. goto out_end;
  276. /* Still data left to transfer. */
  277. ide_pio_datablock(drive, cmd, write);
  278. /* Are we done? Check status and finish transfer. */
  279. if (write == 0 && cmd->nleft == 0) {
  280. stat = wait_drive_not_busy(drive);
  281. if (!OK_STAT(stat, 0, BAD_STAT))
  282. goto out_err;
  283. goto out_end;
  284. }
  285. out_wait:
  286. /* Still data left to transfer. */
  287. ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  288. return ide_started;
  289. out_end:
  290. if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
  291. ide_finish_cmd(drive, cmd, stat);
  292. else
  293. ide_complete_rq(drive, 0, cmd->rq->nr_sectors << 9);
  294. return ide_stopped;
  295. out_err:
  296. ide_error_cmd(drive, cmd);
  297. return ide_error(drive, __func__, stat);
  298. }
  299. static ide_startstop_t pre_task_out_intr(ide_drive_t *drive,
  300. struct ide_cmd *cmd)
  301. {
  302. ide_startstop_t startstop;
  303. if (ide_wait_stat(&startstop, drive, ATA_DRQ,
  304. drive->bad_wstat, WAIT_DRQ)) {
  305. printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
  306. drive->name,
  307. (cmd->tf_flags & IDE_TFLAG_MULTI_PIO) ? "MULT" : "",
  308. (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
  309. return startstop;
  310. }
  311. if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  312. local_irq_disable();
  313. ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  314. ide_pio_datablock(drive, cmd, 1);
  315. return ide_started;
  316. }
  317. int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
  318. u16 nsect)
  319. {
  320. struct request *rq;
  321. int error;
  322. rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
  323. rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
  324. rq->buffer = buf;
  325. /*
  326. * (ks) We transfer currently only whole sectors.
  327. * This is suffient for now. But, it would be great,
  328. * if we would find a solution to transfer any size.
  329. * To support special commands like READ LONG.
  330. */
  331. rq->hard_nr_sectors = rq->nr_sectors = nsect;
  332. rq->hard_cur_sectors = rq->current_nr_sectors = nsect;
  333. if (cmd->tf_flags & IDE_TFLAG_WRITE)
  334. rq->cmd_flags |= REQ_RW;
  335. rq->special = cmd;
  336. cmd->rq = rq;
  337. error = blk_execute_rq(drive->queue, NULL, rq, 0);
  338. blk_put_request(rq);
  339. return error;
  340. }
  341. EXPORT_SYMBOL(ide_raw_taskfile);
  342. int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd)
  343. {
  344. cmd->protocol = ATA_PROT_NODATA;
  345. return ide_raw_taskfile(drive, cmd, NULL, 0);
  346. }
  347. EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
  348. #ifdef CONFIG_IDE_TASK_IOCTL
  349. int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
  350. {
  351. ide_task_request_t *req_task;
  352. struct ide_cmd cmd;
  353. u8 *outbuf = NULL;
  354. u8 *inbuf = NULL;
  355. u8 *data_buf = NULL;
  356. int err = 0;
  357. int tasksize = sizeof(struct ide_task_request_s);
  358. unsigned int taskin = 0;
  359. unsigned int taskout = 0;
  360. u16 nsect = 0;
  361. char __user *buf = (char __user *)arg;
  362. // printk("IDE Taskfile ...\n");
  363. req_task = kzalloc(tasksize, GFP_KERNEL);
  364. if (req_task == NULL) return -ENOMEM;
  365. if (copy_from_user(req_task, buf, tasksize)) {
  366. kfree(req_task);
  367. return -EFAULT;
  368. }
  369. taskout = req_task->out_size;
  370. taskin = req_task->in_size;
  371. if (taskin > 65536 || taskout > 65536) {
  372. err = -EINVAL;
  373. goto abort;
  374. }
  375. if (taskout) {
  376. int outtotal = tasksize;
  377. outbuf = kzalloc(taskout, GFP_KERNEL);
  378. if (outbuf == NULL) {
  379. err = -ENOMEM;
  380. goto abort;
  381. }
  382. if (copy_from_user(outbuf, buf + outtotal, taskout)) {
  383. err = -EFAULT;
  384. goto abort;
  385. }
  386. }
  387. if (taskin) {
  388. int intotal = tasksize + taskout;
  389. inbuf = kzalloc(taskin, GFP_KERNEL);
  390. if (inbuf == NULL) {
  391. err = -ENOMEM;
  392. goto abort;
  393. }
  394. if (copy_from_user(inbuf, buf + intotal, taskin)) {
  395. err = -EFAULT;
  396. goto abort;
  397. }
  398. }
  399. memset(&cmd, 0, sizeof(cmd));
  400. memcpy(&cmd.tf_array[0], req_task->hob_ports,
  401. HDIO_DRIVE_HOB_HDR_SIZE - 2);
  402. memcpy(&cmd.tf_array[6], req_task->io_ports,
  403. HDIO_DRIVE_TASK_HDR_SIZE);
  404. cmd.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
  405. IDE_TFLAG_IN_TF;
  406. if (drive->dev_flags & IDE_DFLAG_LBA48)
  407. cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
  408. if (req_task->out_flags.all) {
  409. cmd.ftf_flags |= IDE_FTFLAG_FLAGGED;
  410. if (req_task->out_flags.b.data)
  411. cmd.ftf_flags |= IDE_FTFLAG_OUT_DATA;
  412. if (req_task->out_flags.b.nsector_hob)
  413. cmd.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT;
  414. if (req_task->out_flags.b.sector_hob)
  415. cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL;
  416. if (req_task->out_flags.b.lcyl_hob)
  417. cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM;
  418. if (req_task->out_flags.b.hcyl_hob)
  419. cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH;
  420. if (req_task->out_flags.b.error_feature)
  421. cmd.tf_flags |= IDE_TFLAG_OUT_FEATURE;
  422. if (req_task->out_flags.b.nsector)
  423. cmd.tf_flags |= IDE_TFLAG_OUT_NSECT;
  424. if (req_task->out_flags.b.sector)
  425. cmd.tf_flags |= IDE_TFLAG_OUT_LBAL;
  426. if (req_task->out_flags.b.lcyl)
  427. cmd.tf_flags |= IDE_TFLAG_OUT_LBAM;
  428. if (req_task->out_flags.b.hcyl)
  429. cmd.tf_flags |= IDE_TFLAG_OUT_LBAH;
  430. } else {
  431. cmd.tf_flags |= IDE_TFLAG_OUT_TF;
  432. if (cmd.tf_flags & IDE_TFLAG_LBA48)
  433. cmd.tf_flags |= IDE_TFLAG_OUT_HOB;
  434. }
  435. if (req_task->in_flags.b.data)
  436. cmd.ftf_flags |= IDE_FTFLAG_IN_DATA;
  437. if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE) {
  438. /* fixup data phase if needed */
  439. if (req_task->data_phase == TASKFILE_IN_DMAQ ||
  440. req_task->data_phase == TASKFILE_IN_DMA)
  441. cmd.tf_flags |= IDE_TFLAG_WRITE;
  442. }
  443. cmd.protocol = ATA_PROT_DMA;
  444. switch (req_task->data_phase) {
  445. case TASKFILE_MULTI_OUT:
  446. if (!drive->mult_count) {
  447. /* (hs): give up if multcount is not set */
  448. printk(KERN_ERR "%s: %s Multimode Write " \
  449. "multcount is not set\n",
  450. drive->name, __func__);
  451. err = -EPERM;
  452. goto abort;
  453. }
  454. cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
  455. /* fall through */
  456. case TASKFILE_OUT:
  457. cmd.protocol = ATA_PROT_PIO;
  458. /* fall through */
  459. case TASKFILE_OUT_DMAQ:
  460. case TASKFILE_OUT_DMA:
  461. cmd.tf_flags |= IDE_TFLAG_WRITE;
  462. nsect = taskout / SECTOR_SIZE;
  463. data_buf = outbuf;
  464. break;
  465. case TASKFILE_MULTI_IN:
  466. if (!drive->mult_count) {
  467. /* (hs): give up if multcount is not set */
  468. printk(KERN_ERR "%s: %s Multimode Read failure " \
  469. "multcount is not set\n",
  470. drive->name, __func__);
  471. err = -EPERM;
  472. goto abort;
  473. }
  474. cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
  475. /* fall through */
  476. case TASKFILE_IN:
  477. cmd.protocol = ATA_PROT_PIO;
  478. /* fall through */
  479. case TASKFILE_IN_DMAQ:
  480. case TASKFILE_IN_DMA:
  481. nsect = taskin / SECTOR_SIZE;
  482. data_buf = inbuf;
  483. break;
  484. case TASKFILE_NO_DATA:
  485. cmd.protocol = ATA_PROT_NODATA;
  486. break;
  487. default:
  488. err = -EFAULT;
  489. goto abort;
  490. }
  491. if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
  492. nsect = 0;
  493. else if (!nsect) {
  494. nsect = (cmd.tf.hob_nsect << 8) | cmd.tf.nsect;
  495. if (!nsect) {
  496. printk(KERN_ERR "%s: in/out command without data\n",
  497. drive->name);
  498. err = -EFAULT;
  499. goto abort;
  500. }
  501. }
  502. err = ide_raw_taskfile(drive, &cmd, data_buf, nsect);
  503. memcpy(req_task->hob_ports, &cmd.tf_array[0],
  504. HDIO_DRIVE_HOB_HDR_SIZE - 2);
  505. memcpy(req_task->io_ports, &cmd.tf_array[6],
  506. HDIO_DRIVE_TASK_HDR_SIZE);
  507. if ((cmd.ftf_flags & IDE_FTFLAG_SET_IN_FLAGS) &&
  508. req_task->in_flags.all == 0) {
  509. req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
  510. if (drive->dev_flags & IDE_DFLAG_LBA48)
  511. req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
  512. }
  513. if (copy_to_user(buf, req_task, tasksize)) {
  514. err = -EFAULT;
  515. goto abort;
  516. }
  517. if (taskout) {
  518. int outtotal = tasksize;
  519. if (copy_to_user(buf + outtotal, outbuf, taskout)) {
  520. err = -EFAULT;
  521. goto abort;
  522. }
  523. }
  524. if (taskin) {
  525. int intotal = tasksize + taskout;
  526. if (copy_to_user(buf + intotal, inbuf, taskin)) {
  527. err = -EFAULT;
  528. goto abort;
  529. }
  530. }
  531. abort:
  532. kfree(req_task);
  533. kfree(outbuf);
  534. kfree(inbuf);
  535. // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
  536. return err;
  537. }
  538. #endif