ide-taskfile.c 17 KB

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