Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * ide-floppy IOCTLs handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/cdrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <scsi/scsi_ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "ide-floppy.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Obtain the list of formattable capacities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * Very similar to ide_floppy_get_capacity, except that we push the capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * descriptors to userland, instead of our own structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Userland gives us the following structure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * struct idefloppy_format_capacities {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *	int nformats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *		int nblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *		int blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *	} formats[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * userland initializes nformats to the number of allocated formats[] records.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * On exit we set nformats to the number of records we've actually initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static DEFINE_MUTEX(ide_floppy_ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int ide_floppy_get_format_capacities(ide_drive_t *drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 					    struct ide_atapi_pc *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 					    int __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int i, blocks, length, u_array_size, u_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int __user *argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	u8 pc_buf[256], header_len, desc_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (get_user(u_array_size, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (u_array_size <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	ide_floppy_create_read_capacity_cmd(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (ide_queue_pc_tail(drive, floppy->disk, pc, pc_buf, pc->req_xfer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	header_len = pc_buf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	argp = arg + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * We always skip the first capacity descriptor.  That's the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 * capacity.  We are interested in the remaining descriptors, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * formattable capacities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	for (i = 1; i < desc_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		unsigned int desc_start = 4 + i*8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (u_index >= u_array_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			break;	/* User-supplied buffer too small */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		blocks = be32_to_cpup((__be32 *)&pc_buf[desc_start]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		length = be16_to_cpup((__be16 *)&pc_buf[desc_start + 6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		if (put_user(blocks, argp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		++argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (put_user(length, argp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		++argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		++u_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (put_user(u_index, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static void ide_floppy_create_format_unit_cmd(struct ide_atapi_pc *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 					      u8 *buf, int b, int l,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 					      int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ide_init_pc(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	pc->c[0] = GPCMD_FORMAT_UNIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	pc->c[1] = 0x17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	memset(buf, 0, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	buf[1] = 0xA2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	/* Default format list header, u8 1: FOV/DCRT/IMM bits set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (flags & 1)				/* Verify bit on... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		buf[1] ^= 0x20;			/* ... turn off DCRT bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	buf[3] = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	put_unaligned(cpu_to_be32(b), (unsigned int *)(&buf[4]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	put_unaligned(cpu_to_be32(l), (unsigned int *)(&buf[8]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	pc->req_xfer = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	pc->flags |= PC_FLAG_WRITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int ide_floppy_get_sfrp_bit(ide_drive_t *drive, struct ide_atapi_pc *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	u8 buf[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	drive->atapi_flags &= ~IDE_AFLAG_SRFP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_CAPABILITIES_PAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	pc->flags |= PC_FLAG_SUPPRESS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (ide_queue_pc_tail(drive, floppy->disk, pc, buf, pc->req_xfer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (buf[8 + 2] & 0x40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		drive->atapi_flags |= IDE_AFLAG_SRFP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static int ide_floppy_format_unit(ide_drive_t *drive, struct ide_atapi_pc *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				  int __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u8 buf[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	int blocks, length, flags, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (floppy->openers > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		/* Don't format if someone is using the disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	drive->dev_flags |= IDE_DFLAG_FORMAT_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 * Send ATAPI_FORMAT_UNIT to the drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * Userland gives us the following structure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 * struct idefloppy_format_command {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 *        int nblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 *        int blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 *        int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 *        } ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	 * flags is a bitmask, currently, the only defined flag is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	 *        0x01 - verify media after format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (get_user(blocks, arg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			get_user(length, arg+1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			get_user(flags, arg+2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	ide_floppy_get_sfrp_bit(drive, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	ide_floppy_create_format_unit_cmd(pc, buf, blocks, length, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (ide_queue_pc_tail(drive, floppy->disk, pc, buf, pc->req_xfer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * Get ATAPI_FORMAT_UNIT progress indication.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * Userland gives a pointer to an int.  The int is set to a progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * indicator 0-65536, with 65536=100%.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * If the drive does not support format progress indication, we just check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * the dsc bit, and return either 0 or 65536.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int ide_floppy_get_format_progress(ide_drive_t *drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 					  struct ide_atapi_pc *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 					  int __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	u8 sense_buf[18];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	int progress_indication = 0x10000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (drive->atapi_flags & IDE_AFLAG_SRFP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		ide_create_request_sense_cmd(drive, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (ide_queue_pc_tail(drive, floppy->disk, pc, sense_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				      pc->req_xfer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (floppy->sense_key == 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		    floppy->asc == 4 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		    floppy->ascq == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			progress_indication = floppy->progress_indication;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		/* Else assume format_unit has finished, and we're at 0x10000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		u8 stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		stat = hwif->tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		progress_indication = ((stat & ATA_DSC) == 0) ? 0 : 0x10000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (put_user(progress_indication, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			       unsigned long arg, unsigned int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct ide_disk_obj *floppy = drive->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct gendisk *disk = floppy->disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (floppy->openers > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	ide_set_media_lock(drive, disk, prevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (cmd == CDROMEJECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		ide_do_start_stop(drive, disk, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int ide_floppy_format_ioctl(ide_drive_t *drive, struct ide_atapi_pc *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				   fmode_t mode, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				   void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return ide_floppy_get_format_capacities(drive, pc, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	case IDEFLOPPY_IOCTL_FORMAT_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		if (!(mode & FMODE_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return ide_floppy_format_unit(drive, pc, (int __user *)argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return ide_floppy_get_format_progress(drive, pc, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		     fmode_t mode, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct ide_atapi_pc pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	mutex_lock(&ide_floppy_ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		err = ide_floppy_lockdoor(drive, &pc, arg, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (err != -ENOTTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	 * and CDROM_SEND_PACKET (legacy) ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (err == -ENOTTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		err = generic_ide_ioctl(drive, bdev, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	mutex_unlock(&ide_floppy_ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int ide_floppy_compat_ioctl(ide_drive_t *drive, struct block_device *bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			    fmode_t mode, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	struct ide_atapi_pc pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	void __user *argp = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	mutex_lock(&ide_floppy_ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		err = ide_floppy_lockdoor(drive, &pc, arg, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (err != -ENOTTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	 * and CDROM_SEND_PACKET (legacy) ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (err == -ENOTTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		err = generic_ide_ioctl(drive, bdev, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	mutex_unlock(&ide_floppy_ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) #endif