/drivers/ide/ide-taskfile.c

http://github.com/mirrors/linux · C · 669 lines · 516 code · 110 blank · 43 comment · 139 complexity · 0df9b764679b4a35710baecc2010f54b MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org>
  4. * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
  5. * Copyright (C) 2001-2002 Klaus Smolin
  6. * IBM Storage Technology Division
  7. * Copyright (C) 2003-2004, 2007 Bartlomiej Zolnierkiewicz
  8. *
  9. * The big the bad and the ugly.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/string.h>
  13. #include <linux/kernel.h>
  14. #include <linux/export.h>
  15. #include <linux/sched.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/errno.h>
  18. #include <linux/slab.h>
  19. #include <linux/delay.h>
  20. #include <linux/hdreg.h>
  21. #include <linux/ide.h>
  22. #include <linux/nmi.h>
  23. #include <linux/scatterlist.h>
  24. #include <linux/uaccess.h>
  25. #include <asm/io.h>
  26. void ide_tf_readback(ide_drive_t *drive, struct ide_cmd *cmd)
  27. {
  28. ide_hwif_t *hwif = drive->hwif;
  29. const struct ide_tp_ops *tp_ops = hwif->tp_ops;
  30. /* Be sure we're looking at the low order bytes */
  31. tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
  32. tp_ops->tf_read(drive, &cmd->tf, cmd->valid.in.tf);
  33. if (cmd->tf_flags & IDE_TFLAG_LBA48) {
  34. tp_ops->write_devctl(hwif, ATA_HOB | ATA_DEVCTL_OBS);
  35. tp_ops->tf_read(drive, &cmd->hob, cmd->valid.in.hob);
  36. }
  37. }
  38. void ide_tf_dump(const char *s, struct ide_cmd *cmd)
  39. {
  40. #ifdef DEBUG
  41. printk("%s: tf: feat 0x%02x nsect 0x%02x lbal 0x%02x "
  42. "lbam 0x%02x lbah 0x%02x dev 0x%02x cmd 0x%02x\n",
  43. s, cmd->tf.feature, cmd->tf.nsect,
  44. cmd->tf.lbal, cmd->tf.lbam, cmd->tf.lbah,
  45. cmd->tf.device, cmd->tf.command);
  46. printk("%s: hob: nsect 0x%02x lbal 0x%02x lbam 0x%02x lbah 0x%02x\n",
  47. s, cmd->hob.nsect, cmd->hob.lbal, cmd->hob.lbam, cmd->hob.lbah);
  48. #endif
  49. }
  50. int taskfile_lib_get_identify(ide_drive_t *drive, u8 *buf)
  51. {
  52. struct ide_cmd cmd;
  53. memset(&cmd, 0, sizeof(cmd));
  54. cmd.tf.nsect = 0x01;
  55. if (drive->media == ide_disk)
  56. cmd.tf.command = ATA_CMD_ID_ATA;
  57. else
  58. cmd.tf.command = ATA_CMD_ID_ATAPI;
  59. cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
  60. cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
  61. cmd.protocol = ATA_PROT_PIO;
  62. return ide_raw_taskfile(drive, &cmd, buf, 1);
  63. }
  64. static ide_startstop_t task_no_data_intr(ide_drive_t *);
  65. static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct ide_cmd *);
  66. static ide_startstop_t task_pio_intr(ide_drive_t *);
  67. ide_startstop_t do_rw_taskfile(ide_drive_t *drive, struct ide_cmd *orig_cmd)
  68. {
  69. ide_hwif_t *hwif = drive->hwif;
  70. struct ide_cmd *cmd = &hwif->cmd;
  71. struct ide_taskfile *tf = &cmd->tf;
  72. ide_handler_t *handler = NULL;
  73. const struct ide_tp_ops *tp_ops = hwif->tp_ops;
  74. const struct ide_dma_ops *dma_ops = hwif->dma_ops;
  75. if (orig_cmd->protocol == ATA_PROT_PIO &&
  76. (orig_cmd->tf_flags & IDE_TFLAG_MULTI_PIO) &&
  77. drive->mult_count == 0) {
  78. pr_err("%s: multimode not set!\n", drive->name);
  79. return ide_stopped;
  80. }
  81. if (orig_cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
  82. orig_cmd->ftf_flags |= IDE_FTFLAG_SET_IN_FLAGS;
  83. memcpy(cmd, orig_cmd, sizeof(*cmd));
  84. if ((cmd->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
  85. ide_tf_dump(drive->name, cmd);
  86. tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
  87. if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) {
  88. u8 data[2] = { cmd->tf.data, cmd->hob.data };
  89. tp_ops->output_data(drive, cmd, data, 2);
  90. }
  91. if (cmd->valid.out.tf & IDE_VALID_DEVICE) {
  92. u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ?
  93. 0xE0 : 0xEF;
  94. if (!(cmd->ftf_flags & IDE_FTFLAG_FLAGGED))
  95. cmd->tf.device &= HIHI;
  96. cmd->tf.device |= drive->select;
  97. }
  98. tp_ops->tf_load(drive, &cmd->hob, cmd->valid.out.hob);
  99. tp_ops->tf_load(drive, &cmd->tf, cmd->valid.out.tf);
  100. }
  101. switch (cmd->protocol) {
  102. case ATA_PROT_PIO:
  103. if (cmd->tf_flags & IDE_TFLAG_WRITE) {
  104. tp_ops->exec_command(hwif, tf->command);
  105. ndelay(400); /* FIXME */
  106. return pre_task_out_intr(drive, cmd);
  107. }
  108. handler = task_pio_intr;
  109. /* fall through */
  110. case ATA_PROT_NODATA:
  111. if (handler == NULL)
  112. handler = task_no_data_intr;
  113. ide_execute_command(drive, cmd, handler, WAIT_WORSTCASE);
  114. return ide_started;
  115. case ATA_PROT_DMA:
  116. if (ide_dma_prepare(drive, cmd))
  117. return ide_stopped;
  118. hwif->expiry = dma_ops->dma_timer_expiry;
  119. ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD);
  120. dma_ops->dma_start(drive);
  121. /* fall through */
  122. default:
  123. return ide_started;
  124. }
  125. }
  126. EXPORT_SYMBOL_GPL(do_rw_taskfile);
  127. static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
  128. {
  129. ide_hwif_t *hwif = drive->hwif;
  130. struct ide_cmd *cmd = &hwif->cmd;
  131. struct ide_taskfile *tf = &cmd->tf;
  132. int custom = (cmd->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0;
  133. int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
  134. u8 stat;
  135. local_irq_enable_in_hardirq();
  136. while (1) {
  137. stat = hwif->tp_ops->read_status(hwif);
  138. if ((stat & ATA_BUSY) == 0 || retries-- == 0)
  139. break;
  140. udelay(10);
  141. };
  142. if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
  143. if (custom && tf->command == ATA_CMD_SET_MULTI) {
  144. drive->mult_req = drive->mult_count = 0;
  145. drive->special_flags |= IDE_SFLAG_RECALIBRATE;
  146. (void)ide_dump_status(drive, __func__, stat);
  147. return ide_stopped;
  148. } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) {
  149. if ((stat & (ATA_ERR | ATA_DRQ)) == 0) {
  150. ide_set_handler(drive, &task_no_data_intr,
  151. WAIT_WORSTCASE);
  152. return ide_started;
  153. }
  154. }
  155. return ide_error(drive, "task_no_data_intr", stat);
  156. }
  157. if (custom && tf->command == ATA_CMD_SET_MULTI)
  158. drive->mult_count = drive->mult_req;
  159. if (custom == 0 || tf->command == ATA_CMD_IDLEIMMEDIATE ||
  160. tf->command == ATA_CMD_CHK_POWER) {
  161. struct request *rq = hwif->rq;
  162. if (ata_pm_request(rq))
  163. ide_complete_pm_rq(drive, rq);
  164. else
  165. ide_finish_cmd(drive, cmd, stat);
  166. }
  167. return ide_stopped;
  168. }
  169. static u8 wait_drive_not_busy(ide_drive_t *drive)
  170. {
  171. ide_hwif_t *hwif = drive->hwif;
  172. int retries;
  173. u8 stat;
  174. /*
  175. * Last sector was transferred, wait until device is ready. This can
  176. * take up to 6 ms on some ATAPI devices, so we will wait max 10 ms.
  177. */
  178. for (retries = 0; retries < 1000; retries++) {
  179. stat = hwif->tp_ops->read_status(hwif);
  180. if (stat & ATA_BUSY)
  181. udelay(10);
  182. else
  183. break;
  184. }
  185. if (stat & ATA_BUSY)
  186. pr_err("%s: drive still BUSY!\n", drive->name);
  187. return stat;
  188. }
  189. void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
  190. unsigned int write, unsigned int len)
  191. {
  192. ide_hwif_t *hwif = drive->hwif;
  193. struct scatterlist *sg = hwif->sg_table;
  194. struct scatterlist *cursg = cmd->cursg;
  195. unsigned long uninitialized_var(flags);
  196. struct page *page;
  197. unsigned int offset;
  198. u8 *buf;
  199. if (cursg == NULL)
  200. cursg = cmd->cursg = sg;
  201. while (len) {
  202. unsigned nr_bytes = min(len, cursg->length - cmd->cursg_ofs);
  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. nr_bytes = min_t(unsigned, nr_bytes, (PAGE_SIZE - offset));
  209. buf = kmap_atomic(page) + offset;
  210. cmd->nleft -= nr_bytes;
  211. cmd->cursg_ofs += nr_bytes;
  212. if (cmd->cursg_ofs == cursg->length) {
  213. cursg = cmd->cursg = sg_next(cmd->cursg);
  214. cmd->cursg_ofs = 0;
  215. }
  216. /* do the actual data transfer */
  217. if (write)
  218. hwif->tp_ops->output_data(drive, cmd, buf, nr_bytes);
  219. else
  220. hwif->tp_ops->input_data(drive, cmd, buf, nr_bytes);
  221. kunmap_atomic(buf);
  222. len -= nr_bytes;
  223. }
  224. }
  225. EXPORT_SYMBOL_GPL(ide_pio_bytes);
  226. static void ide_pio_datablock(ide_drive_t *drive, struct ide_cmd *cmd,
  227. unsigned int write)
  228. {
  229. unsigned int nr_bytes;
  230. u8 saved_io_32bit = drive->io_32bit;
  231. if (cmd->tf_flags & IDE_TFLAG_FS)
  232. scsi_req(cmd->rq)->result = 0;
  233. if (cmd->tf_flags & IDE_TFLAG_IO_16BIT)
  234. drive->io_32bit = 0;
  235. touch_softlockup_watchdog();
  236. if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
  237. nr_bytes = min_t(unsigned, cmd->nleft, drive->mult_count << 9);
  238. else
  239. nr_bytes = SECTOR_SIZE;
  240. ide_pio_bytes(drive, cmd, write, nr_bytes);
  241. drive->io_32bit = saved_io_32bit;
  242. }
  243. static void ide_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
  244. {
  245. if (cmd->tf_flags & IDE_TFLAG_FS) {
  246. int nr_bytes = cmd->nbytes - cmd->nleft;
  247. if (cmd->protocol == ATA_PROT_PIO &&
  248. ((cmd->tf_flags & IDE_TFLAG_WRITE) || cmd->nleft == 0)) {
  249. if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
  250. nr_bytes -= drive->mult_count << 9;
  251. else
  252. nr_bytes -= SECTOR_SIZE;
  253. }
  254. if (nr_bytes > 0)
  255. ide_complete_rq(drive, BLK_STS_OK, nr_bytes);
  256. }
  257. }
  258. void ide_finish_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat)
  259. {
  260. struct request *rq = drive->hwif->rq;
  261. u8 err = ide_read_error(drive), nsect = cmd->tf.nsect;
  262. u8 set_xfer = !!(cmd->tf_flags & IDE_TFLAG_SET_XFER);
  263. ide_complete_cmd(drive, cmd, stat, err);
  264. scsi_req(rq)->result = err;
  265. if (err == 0 && set_xfer) {
  266. ide_set_xfer_rate(drive, nsect);
  267. ide_driveid_update(drive);
  268. }
  269. ide_complete_rq(drive, err ? BLK_STS_IOERR : BLK_STS_OK, blk_rq_bytes(rq));
  270. }
  271. /*
  272. * Handler for command with PIO data phase.
  273. */
  274. static ide_startstop_t task_pio_intr(ide_drive_t *drive)
  275. {
  276. ide_hwif_t *hwif = drive->hwif;
  277. struct ide_cmd *cmd = &drive->hwif->cmd;
  278. u8 stat = hwif->tp_ops->read_status(hwif);
  279. u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
  280. if (write == 0) {
  281. /* Error? */
  282. if (stat & ATA_ERR)
  283. goto out_err;
  284. /* Didn't want any data? Odd. */
  285. if ((stat & ATA_DRQ) == 0) {
  286. /* Command all done? */
  287. if (OK_STAT(stat, ATA_DRDY, ATA_BUSY))
  288. goto out_end;
  289. /* Assume it was a spurious irq */
  290. goto out_wait;
  291. }
  292. } else {
  293. if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
  294. goto out_err;
  295. /* Deal with unexpected ATA data phase. */
  296. if (((stat & ATA_DRQ) == 0) ^ (cmd->nleft == 0))
  297. goto out_err;
  298. }
  299. if (write && cmd->nleft == 0)
  300. goto out_end;
  301. /* Still data left to transfer. */
  302. ide_pio_datablock(drive, cmd, write);
  303. /* Are we done? Check status and finish transfer. */
  304. if (write == 0 && cmd->nleft == 0) {
  305. stat = wait_drive_not_busy(drive);
  306. if (!OK_STAT(stat, 0, BAD_STAT))
  307. goto out_err;
  308. goto out_end;
  309. }
  310. out_wait:
  311. /* Still data left to transfer. */
  312. ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  313. return ide_started;
  314. out_end:
  315. if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
  316. ide_finish_cmd(drive, cmd, stat);
  317. else
  318. ide_complete_rq(drive, BLK_STS_OK, blk_rq_sectors(cmd->rq) << 9);
  319. return ide_stopped;
  320. out_err:
  321. ide_error_cmd(drive, cmd);
  322. return ide_error(drive, __func__, stat);
  323. }
  324. static ide_startstop_t pre_task_out_intr(ide_drive_t *drive,
  325. struct ide_cmd *cmd)
  326. {
  327. ide_startstop_t startstop;
  328. if (ide_wait_stat(&startstop, drive, ATA_DRQ,
  329. drive->bad_wstat, WAIT_DRQ)) {
  330. pr_err("%s: no DRQ after issuing %sWRITE%s\n", drive->name,
  331. (cmd->tf_flags & IDE_TFLAG_MULTI_PIO) ? "MULT" : "",
  332. (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
  333. return startstop;
  334. }
  335. if (!force_irqthreads && (drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  336. local_irq_disable();
  337. ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  338. ide_pio_datablock(drive, cmd, 1);
  339. return ide_started;
  340. }
  341. int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
  342. u16 nsect)
  343. {
  344. struct request *rq;
  345. int error;
  346. rq = blk_get_request(drive->queue,
  347. (cmd->tf_flags & IDE_TFLAG_WRITE) ?
  348. REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
  349. ide_req(rq)->type = ATA_PRIV_TASKFILE;
  350. /*
  351. * (ks) We transfer currently only whole sectors.
  352. * This is suffient for now. But, it would be great,
  353. * if we would find a solution to transfer any size.
  354. * To support special commands like READ LONG.
  355. */
  356. if (nsect) {
  357. error = blk_rq_map_kern(drive->queue, rq, buf,
  358. nsect * SECTOR_SIZE, GFP_NOIO);
  359. if (error)
  360. goto put_req;
  361. }
  362. ide_req(rq)->special = cmd;
  363. cmd->rq = rq;
  364. blk_execute_rq(drive->queue, NULL, rq, 0);
  365. error = scsi_req(rq)->result ? -EIO : 0;
  366. put_req:
  367. blk_put_request(rq);
  368. return error;
  369. }
  370. EXPORT_SYMBOL(ide_raw_taskfile);
  371. int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd)
  372. {
  373. cmd->protocol = ATA_PROT_NODATA;
  374. return ide_raw_taskfile(drive, cmd, NULL, 0);
  375. }
  376. EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
  377. #ifdef CONFIG_IDE_TASK_IOCTL
  378. int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
  379. {
  380. ide_task_request_t *req_task;
  381. struct ide_cmd cmd;
  382. u8 *outbuf = NULL;
  383. u8 *inbuf = NULL;
  384. u8 *data_buf = NULL;
  385. int err = 0;
  386. int tasksize = sizeof(struct ide_task_request_s);
  387. unsigned int taskin = 0;
  388. unsigned int taskout = 0;
  389. u16 nsect = 0;
  390. char __user *buf = (char __user *)arg;
  391. req_task = memdup_user(buf, tasksize);
  392. if (IS_ERR(req_task))
  393. return PTR_ERR(req_task);
  394. taskout = req_task->out_size;
  395. taskin = req_task->in_size;
  396. if (taskin > 65536 || taskout > 65536) {
  397. err = -EINVAL;
  398. goto abort;
  399. }
  400. if (taskout) {
  401. int outtotal = tasksize;
  402. outbuf = kzalloc(taskout, GFP_KERNEL);
  403. if (outbuf == NULL) {
  404. err = -ENOMEM;
  405. goto abort;
  406. }
  407. if (copy_from_user(outbuf, buf + outtotal, taskout)) {
  408. err = -EFAULT;
  409. goto abort;
  410. }
  411. }
  412. if (taskin) {
  413. int intotal = tasksize + taskout;
  414. inbuf = kzalloc(taskin, GFP_KERNEL);
  415. if (inbuf == NULL) {
  416. err = -ENOMEM;
  417. goto abort;
  418. }
  419. if (copy_from_user(inbuf, buf + intotal, taskin)) {
  420. err = -EFAULT;
  421. goto abort;
  422. }
  423. }
  424. memset(&cmd, 0, sizeof(cmd));
  425. memcpy(&cmd.hob, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE - 2);
  426. memcpy(&cmd.tf, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE);
  427. cmd.valid.out.tf = IDE_VALID_DEVICE;
  428. cmd.valid.in.tf = IDE_VALID_DEVICE | IDE_VALID_IN_TF;
  429. cmd.tf_flags = IDE_TFLAG_IO_16BIT;
  430. if (drive->dev_flags & IDE_DFLAG_LBA48) {
  431. cmd.tf_flags |= IDE_TFLAG_LBA48;
  432. cmd.valid.in.hob = IDE_VALID_IN_HOB;
  433. }
  434. if (req_task->out_flags.all) {
  435. cmd.ftf_flags |= IDE_FTFLAG_FLAGGED;
  436. if (req_task->out_flags.b.data)
  437. cmd.ftf_flags |= IDE_FTFLAG_OUT_DATA;
  438. if (req_task->out_flags.b.nsector_hob)
  439. cmd.valid.out.hob |= IDE_VALID_NSECT;
  440. if (req_task->out_flags.b.sector_hob)
  441. cmd.valid.out.hob |= IDE_VALID_LBAL;
  442. if (req_task->out_flags.b.lcyl_hob)
  443. cmd.valid.out.hob |= IDE_VALID_LBAM;
  444. if (req_task->out_flags.b.hcyl_hob)
  445. cmd.valid.out.hob |= IDE_VALID_LBAH;
  446. if (req_task->out_flags.b.error_feature)
  447. cmd.valid.out.tf |= IDE_VALID_FEATURE;
  448. if (req_task->out_flags.b.nsector)
  449. cmd.valid.out.tf |= IDE_VALID_NSECT;
  450. if (req_task->out_flags.b.sector)
  451. cmd.valid.out.tf |= IDE_VALID_LBAL;
  452. if (req_task->out_flags.b.lcyl)
  453. cmd.valid.out.tf |= IDE_VALID_LBAM;
  454. if (req_task->out_flags.b.hcyl)
  455. cmd.valid.out.tf |= IDE_VALID_LBAH;
  456. } else {
  457. cmd.valid.out.tf |= IDE_VALID_OUT_TF;
  458. if (cmd.tf_flags & IDE_TFLAG_LBA48)
  459. cmd.valid.out.hob |= IDE_VALID_OUT_HOB;
  460. }
  461. if (req_task->in_flags.b.data)
  462. cmd.ftf_flags |= IDE_FTFLAG_IN_DATA;
  463. if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE) {
  464. /* fixup data phase if needed */
  465. if (req_task->data_phase == TASKFILE_IN_DMAQ ||
  466. req_task->data_phase == TASKFILE_IN_DMA)
  467. cmd.tf_flags |= IDE_TFLAG_WRITE;
  468. }
  469. cmd.protocol = ATA_PROT_DMA;
  470. switch (req_task->data_phase) {
  471. case TASKFILE_MULTI_OUT:
  472. if (!drive->mult_count) {
  473. /* (hs): give up if multcount is not set */
  474. pr_err("%s: %s Multimode Write multcount is not set\n",
  475. drive->name, __func__);
  476. err = -EPERM;
  477. goto abort;
  478. }
  479. cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
  480. /* fall through */
  481. case TASKFILE_OUT:
  482. cmd.protocol = ATA_PROT_PIO;
  483. /* fall through */
  484. case TASKFILE_OUT_DMAQ:
  485. case TASKFILE_OUT_DMA:
  486. cmd.tf_flags |= IDE_TFLAG_WRITE;
  487. nsect = taskout / SECTOR_SIZE;
  488. data_buf = outbuf;
  489. break;
  490. case TASKFILE_MULTI_IN:
  491. if (!drive->mult_count) {
  492. /* (hs): give up if multcount is not set */
  493. pr_err("%s: %s Multimode Read 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. pr_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. return err;
  558. }
  559. #endif