ide-taskfile.c 16 KB

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