ide-taskfile.c 16 KB

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