ide-taskfile.c 17 KB

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