ide-taskfile.c 16 KB

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