ide-taskfile.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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 = hwif->cursg;
  186. struct page *page;
  187. #ifdef CONFIG_HIGHMEM
  188. unsigned long flags;
  189. #endif
  190. unsigned int offset;
  191. u8 *buf;
  192. cursg = hwif->cursg;
  193. if (!cursg) {
  194. cursg = sg;
  195. hwif->cursg = sg;
  196. }
  197. page = sg_page(cursg);
  198. offset = cursg->offset + hwif->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. hwif->nleft--;
  207. hwif->cursg_ofs++;
  208. if ((hwif->cursg_ofs * SECTOR_SIZE) == cursg->length) {
  209. hwif->cursg = sg_next(hwif->cursg);
  210. hwif->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, drive->hwif->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. ide_hwif_t *hwif = drive->hwif;
  255. int sectors = hwif->nsect - hwif->nleft;
  256. switch (cmd->data_phase) {
  257. case TASKFILE_IN:
  258. if (hwif->nleft)
  259. break;
  260. /* fall through */
  261. case TASKFILE_OUT:
  262. sectors--;
  263. break;
  264. case TASKFILE_MULTI_IN:
  265. if (hwif->nleft)
  266. break;
  267. /* fall through */
  268. case TASKFILE_MULTI_OUT:
  269. sectors -= drive->mult_count;
  270. default:
  271. break;
  272. }
  273. if (sectors > 0)
  274. ide_end_request(drive, 1, sectors);
  275. }
  276. return ide_error(drive, s, stat);
  277. }
  278. void ide_finish_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat)
  279. {
  280. if ((cmd->tf_flags & IDE_TFLAG_FS) == 0) {
  281. u8 err = ide_read_error(drive);
  282. ide_complete_cmd(drive, cmd, stat, err);
  283. ide_complete_rq(drive, err);
  284. return;
  285. }
  286. ide_end_request(drive, 1, cmd->rq->nr_sectors);
  287. }
  288. /*
  289. * We got an interrupt on a task_in case, but no errors and no DRQ.
  290. *
  291. * It might be a spurious irq (shared irq), but it might be a
  292. * command that had no output.
  293. */
  294. static ide_startstop_t task_in_unexpected(ide_drive_t *drive,
  295. struct ide_cmd *cmd, u8 stat)
  296. {
  297. /* Command all done? */
  298. if (OK_STAT(stat, ATA_DRDY, ATA_BUSY)) {
  299. ide_finish_cmd(drive, cmd, stat);
  300. return ide_stopped;
  301. }
  302. /* Assume it was a spurious irq */
  303. ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
  304. return ide_started;
  305. }
  306. /*
  307. * Handler for command with PIO data-in phase (Read/Read Multiple).
  308. */
  309. static ide_startstop_t task_in_intr(ide_drive_t *drive)
  310. {
  311. ide_hwif_t *hwif = drive->hwif;
  312. struct ide_cmd *cmd = &drive->hwif->cmd;
  313. u8 stat = hwif->tp_ops->read_status(hwif);
  314. /* Error? */
  315. if (stat & ATA_ERR)
  316. return task_error(drive, cmd, __func__, stat);
  317. /* Didn't want any data? Odd. */
  318. if ((stat & ATA_DRQ) == 0)
  319. return task_in_unexpected(drive, cmd, stat);
  320. ide_pio_datablock(drive, cmd, 0);
  321. /* Are we done? Check status and finish transfer. */
  322. if (!hwif->nleft) {
  323. stat = wait_drive_not_busy(drive);
  324. if (!OK_STAT(stat, 0, BAD_STAT))
  325. return task_error(drive, cmd, __func__, stat);
  326. ide_finish_cmd(drive, cmd, stat);
  327. return ide_stopped;
  328. }
  329. /* Still data left to transfer. */
  330. ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
  331. return ide_started;
  332. }
  333. /*
  334. * Handler for command with PIO data-out phase (Write/Write Multiple).
  335. */
  336. static ide_startstop_t task_out_intr (ide_drive_t *drive)
  337. {
  338. ide_hwif_t *hwif = drive->hwif;
  339. struct ide_cmd *cmd = &drive->hwif->cmd;
  340. u8 stat = hwif->tp_ops->read_status(hwif);
  341. if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
  342. return task_error(drive, cmd, __func__, stat);
  343. /* Deal with unexpected ATA data phase. */
  344. if (((stat & ATA_DRQ) == 0) ^ !hwif->nleft)
  345. return task_error(drive, cmd, __func__, stat);
  346. if (!hwif->nleft) {
  347. ide_finish_cmd(drive, cmd, stat);
  348. return ide_stopped;
  349. }
  350. /* Still data left to transfer. */
  351. ide_pio_datablock(drive, cmd, 1);
  352. ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
  353. return ide_started;
  354. }
  355. static ide_startstop_t pre_task_out_intr(ide_drive_t *drive,
  356. struct ide_cmd *cmd)
  357. {
  358. ide_startstop_t startstop;
  359. if (ide_wait_stat(&startstop, drive, ATA_DRQ,
  360. drive->bad_wstat, WAIT_DRQ)) {
  361. printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
  362. drive->name,
  363. cmd->data_phase == TASKFILE_MULTI_OUT ? "MULT" : "",
  364. (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
  365. return startstop;
  366. }
  367. if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  368. local_irq_disable();
  369. ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
  370. ide_pio_datablock(drive, cmd, 1);
  371. return ide_started;
  372. }
  373. int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
  374. u16 nsect)
  375. {
  376. struct request *rq;
  377. int error;
  378. rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
  379. rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
  380. rq->buffer = buf;
  381. /*
  382. * (ks) We transfer currently only whole sectors.
  383. * This is suffient for now. But, it would be great,
  384. * if we would find a solution to transfer any size.
  385. * To support special commands like READ LONG.
  386. */
  387. rq->hard_nr_sectors = rq->nr_sectors = nsect;
  388. rq->hard_cur_sectors = rq->current_nr_sectors = nsect;
  389. if (cmd->tf_flags & IDE_TFLAG_WRITE)
  390. rq->cmd_flags |= REQ_RW;
  391. rq->special = cmd;
  392. cmd->rq = rq;
  393. error = blk_execute_rq(drive->queue, NULL, rq, 0);
  394. blk_put_request(rq);
  395. return error;
  396. }
  397. EXPORT_SYMBOL(ide_raw_taskfile);
  398. int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd)
  399. {
  400. cmd->data_phase = TASKFILE_NO_DATA;
  401. return ide_raw_taskfile(drive, cmd, NULL, 0);
  402. }
  403. EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
  404. #ifdef CONFIG_IDE_TASK_IOCTL
  405. int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
  406. {
  407. ide_task_request_t *req_task;
  408. struct ide_cmd cmd;
  409. u8 *outbuf = NULL;
  410. u8 *inbuf = NULL;
  411. u8 *data_buf = NULL;
  412. int err = 0;
  413. int tasksize = sizeof(struct ide_task_request_s);
  414. unsigned int taskin = 0;
  415. unsigned int taskout = 0;
  416. u16 nsect = 0;
  417. char __user *buf = (char __user *)arg;
  418. // printk("IDE Taskfile ...\n");
  419. req_task = kzalloc(tasksize, GFP_KERNEL);
  420. if (req_task == NULL) return -ENOMEM;
  421. if (copy_from_user(req_task, buf, tasksize)) {
  422. kfree(req_task);
  423. return -EFAULT;
  424. }
  425. taskout = req_task->out_size;
  426. taskin = req_task->in_size;
  427. if (taskin > 65536 || taskout > 65536) {
  428. err = -EINVAL;
  429. goto abort;
  430. }
  431. if (taskout) {
  432. int outtotal = tasksize;
  433. outbuf = kzalloc(taskout, GFP_KERNEL);
  434. if (outbuf == NULL) {
  435. err = -ENOMEM;
  436. goto abort;
  437. }
  438. if (copy_from_user(outbuf, buf + outtotal, taskout)) {
  439. err = -EFAULT;
  440. goto abort;
  441. }
  442. }
  443. if (taskin) {
  444. int intotal = tasksize + taskout;
  445. inbuf = kzalloc(taskin, GFP_KERNEL);
  446. if (inbuf == NULL) {
  447. err = -ENOMEM;
  448. goto abort;
  449. }
  450. if (copy_from_user(inbuf, buf + intotal, taskin)) {
  451. err = -EFAULT;
  452. goto abort;
  453. }
  454. }
  455. memset(&cmd, 0, sizeof(cmd));
  456. memcpy(&cmd.tf_array[0], req_task->hob_ports,
  457. HDIO_DRIVE_HOB_HDR_SIZE - 2);
  458. memcpy(&cmd.tf_array[6], req_task->io_ports,
  459. HDIO_DRIVE_TASK_HDR_SIZE);
  460. cmd.data_phase = req_task->data_phase;
  461. cmd.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
  462. IDE_TFLAG_IN_TF;
  463. if (drive->dev_flags & IDE_DFLAG_LBA48)
  464. cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
  465. if (req_task->out_flags.all) {
  466. cmd.ftf_flags |= IDE_FTFLAG_FLAGGED;
  467. if (req_task->out_flags.b.data)
  468. cmd.ftf_flags |= IDE_FTFLAG_OUT_DATA;
  469. if (req_task->out_flags.b.nsector_hob)
  470. cmd.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT;
  471. if (req_task->out_flags.b.sector_hob)
  472. cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL;
  473. if (req_task->out_flags.b.lcyl_hob)
  474. cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM;
  475. if (req_task->out_flags.b.hcyl_hob)
  476. cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH;
  477. if (req_task->out_flags.b.error_feature)
  478. cmd.tf_flags |= IDE_TFLAG_OUT_FEATURE;
  479. if (req_task->out_flags.b.nsector)
  480. cmd.tf_flags |= IDE_TFLAG_OUT_NSECT;
  481. if (req_task->out_flags.b.sector)
  482. cmd.tf_flags |= IDE_TFLAG_OUT_LBAL;
  483. if (req_task->out_flags.b.lcyl)
  484. cmd.tf_flags |= IDE_TFLAG_OUT_LBAM;
  485. if (req_task->out_flags.b.hcyl)
  486. cmd.tf_flags |= IDE_TFLAG_OUT_LBAH;
  487. } else {
  488. cmd.tf_flags |= IDE_TFLAG_OUT_TF;
  489. if (cmd.tf_flags & IDE_TFLAG_LBA48)
  490. cmd.tf_flags |= IDE_TFLAG_OUT_HOB;
  491. }
  492. if (req_task->in_flags.b.data)
  493. cmd.ftf_flags |= IDE_FTFLAG_IN_DATA;
  494. switch(req_task->data_phase) {
  495. case TASKFILE_MULTI_OUT:
  496. if (!drive->mult_count) {
  497. /* (hs): give up if multcount is not set */
  498. printk(KERN_ERR "%s: %s Multimode Write " \
  499. "multcount is not set\n",
  500. drive->name, __func__);
  501. err = -EPERM;
  502. goto abort;
  503. }
  504. /* fall through */
  505. case TASKFILE_OUT:
  506. /* fall through */
  507. case TASKFILE_OUT_DMAQ:
  508. case TASKFILE_OUT_DMA:
  509. nsect = taskout / SECTOR_SIZE;
  510. data_buf = outbuf;
  511. break;
  512. case TASKFILE_MULTI_IN:
  513. if (!drive->mult_count) {
  514. /* (hs): give up if multcount is not set */
  515. printk(KERN_ERR "%s: %s Multimode Read failure " \
  516. "multcount is not set\n",
  517. drive->name, __func__);
  518. err = -EPERM;
  519. goto abort;
  520. }
  521. /* fall through */
  522. case TASKFILE_IN:
  523. /* fall through */
  524. case TASKFILE_IN_DMAQ:
  525. case TASKFILE_IN_DMA:
  526. nsect = taskin / SECTOR_SIZE;
  527. data_buf = inbuf;
  528. break;
  529. case TASKFILE_NO_DATA:
  530. break;
  531. default:
  532. err = -EFAULT;
  533. goto abort;
  534. }
  535. if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
  536. nsect = 0;
  537. else if (!nsect) {
  538. nsect = (cmd.tf.hob_nsect << 8) | cmd.tf.nsect;
  539. if (!nsect) {
  540. printk(KERN_ERR "%s: in/out command without data\n",
  541. drive->name);
  542. err = -EFAULT;
  543. goto abort;
  544. }
  545. }
  546. if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE)
  547. cmd.tf_flags |= IDE_TFLAG_WRITE;
  548. err = ide_raw_taskfile(drive, &cmd, data_buf, nsect);
  549. memcpy(req_task->hob_ports, &cmd.tf_array[0],
  550. HDIO_DRIVE_HOB_HDR_SIZE - 2);
  551. memcpy(req_task->io_ports, &cmd.tf_array[6],
  552. HDIO_DRIVE_TASK_HDR_SIZE);
  553. if ((cmd.ftf_flags & IDE_FTFLAG_SET_IN_FLAGS) &&
  554. req_task->in_flags.all == 0) {
  555. req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
  556. if (drive->dev_flags & IDE_DFLAG_LBA48)
  557. req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
  558. }
  559. if (copy_to_user(buf, req_task, tasksize)) {
  560. err = -EFAULT;
  561. goto abort;
  562. }
  563. if (taskout) {
  564. int outtotal = tasksize;
  565. if (copy_to_user(buf + outtotal, outbuf, taskout)) {
  566. err = -EFAULT;
  567. goto abort;
  568. }
  569. }
  570. if (taskin) {
  571. int intotal = tasksize + taskout;
  572. if (copy_to_user(buf + intotal, inbuf, taskin)) {
  573. err = -EFAULT;
  574. goto abort;
  575. }
  576. }
  577. abort:
  578. kfree(req_task);
  579. kfree(outbuf);
  580. kfree(inbuf);
  581. // printk("IDE Taskfile ioctl ended. rc = %i\n", err);
  582. return err;
  583. }
  584. #endif