ide-taskfile.c 17 KB

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