ide-taskfile.c 16 KB

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