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