1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/kernel.h>
7 DEFINE_MUTEX(ide_setting_mtx);
9 ide_devset_get(io_32bit, io_32bit);
11 static int set_io_32bit(ide_drive_t *drive, int arg)
13 if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
16 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
19 drive->io_32bit = arg;
24 ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
26 static int set_ksettings(ide_drive_t *drive, int arg)
28 if (arg < 0 || arg > 1)
32 drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
34 drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
39 ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
41 static int set_using_dma(ide_drive_t *drive, int arg)
43 #ifdef CONFIG_BLK_DEV_IDEDMA
46 if (arg < 0 || arg > 1)
49 if (ata_id_has_dma(drive->id) == 0)
52 if (drive->hwif->dma_ops == NULL)
58 if (ide_set_dma(drive))
66 if (arg < 0 || arg > 1)
74 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
76 static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
85 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
88 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
91 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
97 static int set_pio_mode(ide_drive_t *drive, int arg)
99 ide_hwif_t *hwif = drive->hwif;
100 const struct ide_port_ops *port_ops = hwif->port_ops;
102 if (arg < 0 || arg > 255)
105 if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
106 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
109 if (set_pio_mode_abuse(drive->hwif, arg)) {
110 drive->pio_mode = arg + XFER_PIO_0;
112 if (arg == 8 || arg == 9) {
115 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
116 spin_lock_irqsave(&hwif->lock, flags);
117 port_ops->set_pio_mode(hwif, drive);
118 spin_unlock_irqrestore(&hwif->lock, flags);
120 port_ops->set_pio_mode(hwif, drive);
122 int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
124 ide_set_pio(drive, arg);
126 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
135 ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
137 static int set_unmaskirq(ide_drive_t *drive, int arg)
139 if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
142 if (arg < 0 || arg > 1)
146 drive->dev_flags |= IDE_DFLAG_UNMASK;
148 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
153 ide_ext_devset_rw_sync(io_32bit, io_32bit);
154 ide_ext_devset_rw_sync(keepsettings, ksettings);
155 ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
156 ide_ext_devset_rw_sync(using_dma, using_dma);
157 __IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
159 int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
162 struct request_queue *q = drive->queue;
166 if (!(setting->flags & DS_SYNC))
167 return setting->set(drive, arg);
169 rq = blk_get_request(q, REQ_OP_DRV_IN, 0);
170 ide_req(rq)->type = ATA_PRIV_MISC;
171 scsi_req(rq)->cmd_len = 5;
172 scsi_req(rq)->cmd[0] = REQ_DEVSET_EXEC;
173 *(int *)&scsi_req(rq)->cmd[1] = arg;
174 ide_req(rq)->special = setting->set;
176 blk_execute_rq(q, NULL, rq, 0);
177 ret = scsi_req(rq)->result;
183 ide_startstop_t ide_do_devset(ide_drive_t *drive, struct request *rq)
185 int err, (*setfunc)(ide_drive_t *, int) = ide_req(rq)->special;
187 err = setfunc(drive, *(int *)&scsi_req(rq)->cmd[1]);
189 scsi_req(rq)->result = err;
190 ide_complete_rq(drive, 0, blk_rq_bytes(rq));