ide-taskfile.c 17 KB

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