^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) pd.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) Under the terms of the GNU General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) This is the high-level driver for parallel port IDE hard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) drives based on chips supported by the paride module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) By default, the driver will autoprobe for a single parallel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) port IDE drive, but if their individual parameters are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) specified, the driver can handle up to 4 drives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) The behaviour of the pd driver can be altered by setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) some parameters from the insmod command line. The following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) parameters are adjustable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) drive0 These four arguments can be arrays of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) drive1 1-8 integers as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) drive2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) drive3 <prt>,<pro>,<uni>,<mod>,<geo>,<sby>,<dly>,<slv>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) Where,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) <prt> is the base of the parallel port address for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) the corresponding drive. (required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) <pro> is the protocol number for the adapter that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) supports this drive. These numbers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) logged by 'paride' when the protocol modules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) are initialised. (0 if not given)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) <uni> for those adapters that support chained
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) devices, this is the unit selector for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) chain of devices on the given port. It should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) be zero for devices that don't support chaining.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) (0 if not given)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) <mod> this can be -1 to choose the best mode, or one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) of the mode numbers supported by the adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) (-1 if not given)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) <geo> this defaults to 0 to indicate that the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) should use the CHS geometry provided by the drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) itself. If set to 1, the driver will provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) a logical geometry with 64 heads and 32 sectors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) per track, to be consistent with most SCSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) drivers. (0 if not given)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) <sby> set this to zero to disable the power saving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) standby mode, if needed. (1 if not given)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) <dly> some parallel ports require the driver to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) go more slowly. -1 sets a default value that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) should work with the chosen protocol. Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) set this to a small integer, the larger it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) the slower the port i/o. In some cases, setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) this to zero will speed up the device. (default -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) <slv> IDE disks can be jumpered to master or slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) Set this to 0 to choose the master drive, 1 to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) choose the slave, -1 (the default) to choose the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) first drive found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) major You may use this parameter to override the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) default major number (45) that this driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) will use. Be sure to change the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) name as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) name This parameter is a character string that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) contains the name the kernel will use for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) device (in /proc output, for instance).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) (default "pd")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) cluster The driver will attempt to aggregate requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) for adjacent blocks into larger multi-block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) clusters. The maximum cluster size (in 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) byte sectors) is set with this parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) (default 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) verbose This parameter controls the amount of logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) that the driver will do. Set it to 0 for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) normal operation, 1 to see autoprobe progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) messages, or 2 to see additional debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) output. (default 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) nice This parameter controls the driver's use of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) idle CPU time, at the expense of some speed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) If this driver is built into the kernel, you can use kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) the following command line parameters, with the same values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) as the corresponding module parameters listed above:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) pd.drive0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) pd.drive1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pd.drive2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) pd.drive3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) pd.cluster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) pd.nice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) In addition, you can use the parameter pd.disable to disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) the driver entirely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 1.01 GRG 1997.01.24 Restored pd_reset()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) Added eject ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 1.02 GRG 1998.05.06 SMP spinlock changes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) Added slave support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 1.03 GRG 1998.06.16 Eliminate an Ugh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 1.04 GRG 1998.08.15 Extra debugging, use HZ in loop timing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 1.05 GRG 1998.09.24 Added jumbo support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define PD_VERSION "1.05"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define PD_MAJOR 45
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define PD_NAME "pd"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define PD_UNITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* Here are things one can override from the insmod command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) Most are autoprobed by paride unless set here. Verbose is off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int verbose = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int major = PD_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static char *name = PD_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int cluster = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int nice = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int disable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int drive0[8] = { 0, 0, 0, -1, 0, 1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static int drive1[8] = { 0, 0, 0, -1, 0, 1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int drive2[8] = { 0, 0, 0, -1, 0, 1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static int drive3[8] = { 0, 0, 0, -1, 0, 1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int (*drives[4])[8] = {&drive0, &drive1, &drive2, &drive3};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) enum {D_PRT, D_PRO, D_UNI, D_MOD, D_GEO, D_SBY, D_DLY, D_SLV};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* end of parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #include <linux/hdreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #include <linux/cdrom.h> /* for the eject ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #include <linux/blk-mq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #include <linux/blkpg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static DEFINE_MUTEX(pd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static DEFINE_SPINLOCK(pd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) module_param(verbose, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) module_param(major, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) module_param(name, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) module_param(cluster, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) module_param(nice, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) module_param_array(drive0, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) module_param_array(drive1, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) module_param_array(drive2, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) module_param_array(drive3, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #include "paride.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #define PD_BITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* numbers for "SCSI" geometry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define PD_LOG_HEADS 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #define PD_LOG_SECTS 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define PD_ID_OFF 54
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define PD_ID_LEN 14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define PD_MAX_RETRIES 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define PD_TMO 800 /* interrupt timeout in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define PD_SPIN_DEL 50 /* spin delay in micro-seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define PD_SPIN (1000000*PD_TMO)/(HZ*PD_SPIN_DEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define STAT_ERR 0x00001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define STAT_INDEX 0x00002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define STAT_ECC 0x00004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #define STAT_DRQ 0x00008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define STAT_SEEK 0x00010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define STAT_WRERR 0x00020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #define STAT_READY 0x00040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #define STAT_BUSY 0x00080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define ERR_AMNF 0x00100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define ERR_TK0NF 0x00200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define ERR_ABRT 0x00400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #define ERR_MCR 0x00800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define ERR_IDNF 0x01000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define ERR_MC 0x02000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define ERR_UNC 0x04000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #define ERR_TMO 0x10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define IDE_READ 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define IDE_WRITE 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #define IDE_READ_VRFY 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define IDE_INIT_DEV_PARMS 0x91
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define IDE_STANDBY 0x96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define IDE_ACKCHANGE 0xdb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define IDE_DOORLOCK 0xde
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define IDE_DOORUNLOCK 0xdf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #define IDE_IDENTIFY 0xec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define IDE_EJECT 0xed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define PD_NAMELEN 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct pd_unit {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct pi_adapter pia; /* interface to paride layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct pi_adapter *pi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int access; /* count of active opens ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int capacity; /* Size of this volume in sectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int heads; /* physical geometry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int cylinders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int can_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int drive; /* master=0 slave=1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int changed; /* Have we seen a disk change ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) int removable; /* removable media device ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int standby;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int alt_geom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) char name[PD_NAMELEN]; /* pda, pdb, etc ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct gendisk *gd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct blk_mq_tag_set tag_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct list_head rq_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static struct pd_unit pd[PD_UNITS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct pd_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* for REQ_OP_DRV_IN: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) enum action (*func)(struct pd_unit *disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static char pd_scratch[512]; /* scratch block buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static char *pd_errs[17] = { "ERR", "INDEX", "ECC", "DRQ", "SEEK", "WRERR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) "READY", "BUSY", "AMNF", "TK0NF", "ABRT", "MCR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) "IDNF", "MC", "UNC", "???", "TMO"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static void *par_drv; /* reference of parport driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static inline int status_reg(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return pi_read_regr(disk->pi, 1, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static inline int read_reg(struct pd_unit *disk, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return pi_read_regr(disk->pi, 0, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static inline void write_status(struct pd_unit *disk, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) pi_write_regr(disk->pi, 1, 6, val);
^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) static inline void write_reg(struct pd_unit *disk, int reg, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) pi_write_regr(disk->pi, 0, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static inline u8 DRIVE(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return 0xa0+0x10*disk->drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* ide command interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static void pd_print_error(struct pd_unit *disk, char *msg, int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) printk("%s: %s: status = 0x%x =", disk->name, msg, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) for (i = 0; i < ARRAY_SIZE(pd_errs); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (status & (1 << i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) printk(" %s", pd_errs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static void pd_reset(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) { /* called only for MASTER drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) write_status(disk, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) udelay(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) write_status(disk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) udelay(250);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #define DBMSG(msg) ((verbose>1)?(msg):NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static int pd_wait_for(struct pd_unit *disk, int w, char *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) { /* polled wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) int k, r, e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) k = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) while (k < PD_SPIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) r = status_reg(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) k++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (((r & w) == w) && !(r & STAT_BUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) udelay(PD_SPIN_DEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) e = (read_reg(disk, 1) << 8) + read_reg(disk, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (k >= PD_SPIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) e |= ERR_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if ((e & (STAT_ERR | ERR_TMO)) && (msg != NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) pd_print_error(disk, msg, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static void pd_send_command(struct pd_unit *disk, int n, int s, int h, int c0, int c1, int func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) write_reg(disk, 6, DRIVE(disk) + h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) write_reg(disk, 1, 0); /* the IDE task file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) write_reg(disk, 2, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) write_reg(disk, 3, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) write_reg(disk, 4, c0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) write_reg(disk, 5, c1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) write_reg(disk, 7, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static void pd_ide_command(struct pd_unit *disk, int func, int block, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int c1, c0, h, s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (disk->can_lba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) s = block & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) c0 = (block >>= 8) & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) c1 = (block >>= 8) & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) h = ((block >>= 8) & 15) + 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) s = (block % disk->sectors) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) h = (block /= disk->sectors) % disk->heads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) c0 = (block /= disk->heads) % 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) c1 = (block >>= 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) pd_send_command(disk, count, s, h, c0, c1, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* The i/o request engine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) enum action {Fail = 0, Ok = 1, Hold, Wait};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static struct request *pd_req; /* current request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static enum action (*phase)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static void run_fsm(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static void ps_tq_int(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static DECLARE_DELAYED_WORK(fsm_tq, ps_tq_int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static void schedule_fsm(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (!nice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) schedule_delayed_work(&fsm_tq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) schedule_delayed_work(&fsm_tq, nice-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static void ps_tq_int(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) run_fsm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static enum action do_pd_io_start(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static enum action pd_special(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static enum action do_pd_read_start(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static enum action do_pd_write_start(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static enum action do_pd_read_drq(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static enum action do_pd_write_done(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static int pd_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static int pd_claimed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static struct pd_unit *pd_current; /* current request's drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static PIA *pi_current; /* current request's PIA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static int set_next_request(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct gendisk *disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct request_queue *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int old_pos = pd_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) disk = pd[pd_queue].gd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) q = disk ? disk->queue : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (++pd_queue == PD_UNITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) pd_queue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (q) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct pd_unit *disk = q->queuedata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (list_empty(&disk->rq_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) pd_req = list_first_entry(&disk->rq_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) list_del_init(&pd_req->queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) blk_mq_start_request(pd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) } while (pd_queue != old_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return pd_req != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static void run_fsm(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) enum action res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) int stop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (!phase) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) pd_current = pd_req->rq_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) pi_current = pd_current->pi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) phase = do_pd_io_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) switch (pd_claimed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) pd_claimed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (!pi_schedule_claimed(pi_current, run_fsm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) pd_claimed = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) pi_current->proto->connect(pi_current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) switch(res = phase()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) case Ok: case Fail: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) blk_status_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) err = res == Ok ? 0 : BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) pi_disconnect(pi_current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) pd_claimed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) phase = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) spin_lock_irq(&pd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (!blk_update_request(pd_req, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) blk_rq_cur_bytes(pd_req))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) __blk_mq_end_request(pd_req, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) pd_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) stop = !set_next_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) spin_unlock_irq(&pd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) case Hold:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) schedule_fsm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) case Wait:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) pi_disconnect(pi_current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) pd_claimed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static int pd_retries = 0; /* i/o error retry count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static int pd_block; /* address of next requested block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static int pd_count; /* number of blocks still to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static int pd_run; /* sectors in current cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static char *pd_buf; /* buffer for request in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static enum action do_pd_io_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) switch (req_op(pd_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) case REQ_OP_DRV_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) phase = pd_special;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return pd_special();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) case REQ_OP_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) case REQ_OP_WRITE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) pd_block = blk_rq_pos(pd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) pd_count = blk_rq_cur_sectors(pd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (pd_block + pd_count > get_capacity(pd_req->rq_disk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return Fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) pd_run = blk_rq_sectors(pd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) pd_buf = bio_data(pd_req->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) pd_retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (req_op(pd_req) == REQ_OP_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return do_pd_read_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return do_pd_write_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return Fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static enum action pd_special(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct pd_req *req = blk_mq_rq_to_pdu(pd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return req->func(pd_current);
^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) static int pd_next_buf(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) unsigned long saved_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) pd_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) pd_run--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) pd_buf += 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) pd_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (!pd_run)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (pd_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) spin_lock_irqsave(&pd_lock, saved_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (!blk_update_request(pd_req, 0, blk_rq_cur_bytes(pd_req))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) __blk_mq_end_request(pd_req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) pd_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) pd_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) pd_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) pd_count = blk_rq_cur_sectors(pd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) pd_buf = bio_data(pd_req->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) spin_unlock_irqrestore(&pd_lock, saved_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return !pd_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static unsigned long pd_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) static enum action do_pd_read_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (pd_wait_for(pd_current, STAT_READY, "do_pd_read") & STAT_ERR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (pd_retries < PD_MAX_RETRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) pd_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return Wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return Fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) pd_ide_command(pd_current, IDE_READ, pd_block, pd_run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) phase = do_pd_read_drq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) pd_timeout = jiffies + PD_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) return Hold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static enum action do_pd_write_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (pd_wait_for(pd_current, STAT_READY, "do_pd_write") & STAT_ERR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (pd_retries < PD_MAX_RETRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) pd_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return Wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return Fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) pd_ide_command(pd_current, IDE_WRITE, pd_block, pd_run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (pd_wait_for(pd_current, STAT_DRQ, "do_pd_write_drq") & STAT_ERR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (pd_retries < PD_MAX_RETRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) pd_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return Wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return Fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) pi_write_block(pd_current->pi, pd_buf, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (pd_next_buf())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) phase = do_pd_write_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) pd_timeout = jiffies + PD_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return Hold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static inline int pd_ready(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return !(status_reg(pd_current) & STAT_BUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static enum action do_pd_read_drq(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (!pd_ready() && !time_after_eq(jiffies, pd_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return Hold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (pd_wait_for(pd_current, STAT_DRQ, "do_pd_read_drq") & STAT_ERR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (pd_retries < PD_MAX_RETRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) pd_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) phase = do_pd_read_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return Wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return Fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) pi_read_block(pd_current->pi, pd_buf, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (pd_next_buf())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return Ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) static enum action do_pd_write_done(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (!pd_ready() && !time_after_eq(jiffies, pd_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return Hold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (pd_wait_for(pd_current, STAT_READY, "do_pd_write_done") & STAT_ERR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (pd_retries < PD_MAX_RETRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) pd_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) phase = do_pd_write_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return Wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) return Fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return Ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /* special io requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) /* According to the ATA standard, the default CHS geometry should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) available following a reset. Some Western Digital drives come up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) in a mode where only LBA addresses are accepted until the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) parameters are initialised.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static void pd_init_dev_parms(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) pd_wait_for(disk, 0, DBMSG("before init_dev_parms"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) pd_send_command(disk, disk->sectors, 0, disk->heads - 1, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) IDE_INIT_DEV_PARMS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) udelay(300);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) pd_wait_for(disk, 0, "Initialise device parameters");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static enum action pd_door_lock(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) pd_wait_for(disk, STAT_READY, "Lock done");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) return Ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static enum action pd_door_unlock(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) pd_wait_for(disk, STAT_READY, "Lock done");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return Ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) static enum action pd_eject(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) pd_wait_for(disk, 0, DBMSG("before unlock on eject"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) pd_wait_for(disk, 0, DBMSG("after unlock on eject"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) pd_wait_for(disk, 0, DBMSG("before eject"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) pd_send_command(disk, 0, 0, 0, 0, 0, IDE_EJECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) pd_wait_for(disk, 0, DBMSG("after eject"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) return Ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) static enum action pd_media_check(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) int r = pd_wait_for(disk, STAT_READY, DBMSG("before media_check"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (!(r & STAT_ERR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after READ_VRFY"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) disk->changed = 1; /* say changed if other error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (r & ERR_MC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) disk->changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) pd_send_command(disk, 1, 0, 0, 0, 0, IDE_ACKCHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) pd_wait_for(disk, STAT_READY, DBMSG("RDY after ACKCHANGE"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after VRFY"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) return Ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) static void pd_standby_off(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) pd_wait_for(disk, 0, DBMSG("before STANDBY"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) pd_send_command(disk, 0, 0, 0, 0, 0, IDE_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) pd_wait_for(disk, 0, DBMSG("after STANDBY"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) static enum action pd_identify(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) char id[PD_ID_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) /* WARNING: here there may be dragons. reset() applies to both drives,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) but we call it only on probing the MASTER. This should allow most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) common configurations to work, but be warned that a reset can clear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) settings on the SLAVE drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (disk->drive == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) pd_reset(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) write_reg(disk, 6, DRIVE(disk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) pd_wait_for(disk, 0, DBMSG("before IDENT"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) pd_send_command(disk, 1, 0, 0, 0, 0, IDE_IDENTIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (pd_wait_for(disk, STAT_DRQ, DBMSG("IDENT DRQ")) & STAT_ERR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) return Fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) pi_read_block(disk->pi, pd_scratch, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) disk->can_lba = pd_scratch[99] & 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) disk->sectors = le16_to_cpu(*(__le16 *) (pd_scratch + 12));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) disk->heads = le16_to_cpu(*(__le16 *) (pd_scratch + 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) disk->cylinders = le16_to_cpu(*(__le16 *) (pd_scratch + 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (disk->can_lba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) disk->capacity = le32_to_cpu(*(__le32 *) (pd_scratch + 120));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) disk->capacity = disk->sectors * disk->heads * disk->cylinders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) for (j = 0; j < PD_ID_LEN; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) id[j ^ 1] = pd_scratch[j + PD_ID_OFF];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) j = PD_ID_LEN - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) while ((j >= 0) && (id[j] <= 0x20))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) j--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) id[j] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) disk->removable = pd_scratch[0] & 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) printk("%s: %s, %s, %d blocks [%dM], (%d/%d/%d), %s media\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) disk->name, id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) disk->drive ? "slave" : "master",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) disk->capacity, disk->capacity / 2048,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) disk->cylinders, disk->heads, disk->sectors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) disk->removable ? "removable" : "fixed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (disk->capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) pd_init_dev_parms(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) if (!disk->standby)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) pd_standby_off(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) return Ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) /* end of io request engine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) static blk_status_t pd_queue_rq(struct blk_mq_hw_ctx *hctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) const struct blk_mq_queue_data *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) struct pd_unit *disk = hctx->queue->queuedata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) spin_lock_irq(&pd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (!pd_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) pd_req = bd->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) blk_mq_start_request(pd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) list_add_tail(&bd->rq->queuelist, &disk->rq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) spin_unlock_irq(&pd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) run_fsm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) return BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) static int pd_special_command(struct pd_unit *disk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) enum action (*func)(struct pd_unit *disk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) struct request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) struct pd_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) rq = blk_get_request(disk->gd->queue, REQ_OP_DRV_IN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (IS_ERR(rq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) return PTR_ERR(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) req = blk_mq_rq_to_pdu(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) req->func = func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) blk_execute_rq(disk->gd->queue, disk->gd, rq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) blk_put_request(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) /* kernel glue structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) static int pd_open(struct block_device *bdev, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) struct pd_unit *disk = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) mutex_lock(&pd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) disk->access++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (disk->removable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) pd_special_command(disk, pd_media_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) pd_special_command(disk, pd_door_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) mutex_unlock(&pd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) static int pd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct pd_unit *disk = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (disk->alt_geom) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) geo->heads = PD_LOG_HEADS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) geo->sectors = PD_LOG_SECTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) geo->cylinders = disk->capacity / (geo->heads * geo->sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) geo->heads = disk->heads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) geo->sectors = disk->sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) geo->cylinders = disk->cylinders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) static int pd_ioctl(struct block_device *bdev, fmode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) struct pd_unit *disk = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) case CDROMEJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) mutex_lock(&pd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (disk->access == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) pd_special_command(disk, pd_eject);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) mutex_unlock(&pd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) static void pd_release(struct gendisk *p, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) struct pd_unit *disk = p->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) mutex_lock(&pd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (!--disk->access && disk->removable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) pd_special_command(disk, pd_door_unlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) mutex_unlock(&pd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) static unsigned int pd_check_events(struct gendisk *p, unsigned int clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct pd_unit *disk = p->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if (!disk->removable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) pd_special_command(disk, pd_media_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) r = disk->changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) disk->changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return r ? DISK_EVENT_MEDIA_CHANGE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) static int pd_revalidate(struct gendisk *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) struct pd_unit *disk = p->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (pd_special_command(disk, pd_identify) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) set_capacity(p, disk->capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) set_capacity(p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) static const struct block_device_operations pd_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) .open = pd_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) .release = pd_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) .ioctl = pd_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) .compat_ioctl = pd_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) .getgeo = pd_getgeo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) .check_events = pd_check_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) .revalidate_disk= pd_revalidate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /* probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) static const struct blk_mq_ops pd_mq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) .queue_rq = pd_queue_rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) static void pd_probe_drive(struct pd_unit *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) struct gendisk *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) p = alloc_disk(1 << PD_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) strcpy(p->disk_name, disk->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) p->fops = &pd_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) p->major = major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) p->first_minor = (disk - pd) << PD_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) p->events = DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) disk->gd = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) p->private_data = disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) memset(&disk->tag_set, 0, sizeof(disk->tag_set));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) disk->tag_set.ops = &pd_mq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) disk->tag_set.cmd_size = sizeof(struct pd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) disk->tag_set.nr_hw_queues = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) disk->tag_set.nr_maps = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) disk->tag_set.queue_depth = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) disk->tag_set.numa_node = NUMA_NO_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) disk->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) if (blk_mq_alloc_tag_set(&disk->tag_set))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) p->queue = blk_mq_init_queue(&disk->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (IS_ERR(p->queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) blk_mq_free_tag_set(&disk->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) p->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) p->queue->queuedata = disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) blk_queue_max_hw_sectors(p->queue, cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) blk_queue_bounce_limit(p->queue, BLK_BOUNCE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) if (disk->drive == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) for (disk->drive = 0; disk->drive <= 1; disk->drive++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (pd_special_command(disk, pd_identify) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) } else if (pd_special_command(disk, pd_identify) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) disk->gd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) put_disk(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) static int pd_detect(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) int found = 0, unit, pd_drive_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct pd_unit *disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) for (unit = 0; unit < PD_UNITS; unit++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) int *parm = *drives[unit];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) struct pd_unit *disk = pd + unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) disk->pi = &disk->pia;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) disk->access = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) disk->changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) disk->capacity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) disk->drive = parm[D_SLV];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) snprintf(disk->name, PD_NAMELEN, "%s%c", name, 'a'+unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) disk->alt_geom = parm[D_GEO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) disk->standby = parm[D_SBY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) if (parm[D_PRT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) pd_drive_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) INIT_LIST_HEAD(&disk->rq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) par_drv = pi_register_driver(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) if (!par_drv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) pr_err("failed to register %s driver\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) if (pd_drive_count == 0) { /* nothing spec'd - so autoprobe for 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) disk = pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (pi_init(disk->pi, 1, -1, -1, -1, -1, -1, pd_scratch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) PI_PD, verbose, disk->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) pd_probe_drive(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (!disk->gd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) pi_release(disk->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) int *parm = *drives[unit];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (!parm[D_PRT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) if (pi_init(disk->pi, 0, parm[D_PRT], parm[D_MOD],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) parm[D_UNI], parm[D_PRO], parm[D_DLY],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) pd_scratch, PI_PD, verbose, disk->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) pd_probe_drive(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if (!disk->gd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) pi_release(disk->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) if (disk->gd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) set_capacity(disk->gd, disk->capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) add_disk(disk->gd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) printk("%s: no valid drive found\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) pi_unregister_driver(par_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) static int __init pd_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) if (register_blkdev(major, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) printk("%s: %s version %s, major %d, cluster %d, nice %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) name, name, PD_VERSION, major, cluster, nice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (!pd_detect())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) unregister_blkdev(major, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) static void __exit pd_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) struct pd_unit *disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) int unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) unregister_blkdev(major, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) struct gendisk *p = disk->gd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) disk->gd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) del_gendisk(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) blk_cleanup_queue(p->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) blk_mq_free_tag_set(&disk->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) put_disk(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) pi_release(disk->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) module_init(pd_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) module_exit(pd_exit)