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) /* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) 	pcd.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 a high-level driver for parallel port ATAPI CD-ROM
^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 ATAPI CD-ROM 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 pcd 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-6 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>,<slv>,<dly>
^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) 		<slv>   ATAPI CD-ROMs can be jumpered to master or slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 			Set this to 0 to choose the master drive, 1 to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)                         choose the slave, -1 (the default) to choose the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 			first drive found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)                 <dly>   some parallel ports require the driver to 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)                         go more slowly.  -1 sets a default value that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)                         should work with the chosen protocol.  Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)                         set this to a small integer, the larger it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)                         the slower the port i/o.  In some cases, setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)                         this to zero will speed up the device. (default -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)                         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)             major       You may use this parameter to override the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)                         default major number (46) that this driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)                         will use.  Be sure to change the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)                         name as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)             name        This parameter is a character string that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)                         contains the name the kernel will use for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)                         device (in /proc output, for instance).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)                         (default "pcd")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)             verbose     This parameter controls the amount of logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)                         that the driver will do.  Set it to 0 for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)                         normal operation, 1 to see autoprobe progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)                         messages, or 2 to see additional debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)                         output.  (default 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)             nice        This parameter controls the driver's use of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)                         idle CPU time, at the expense of some speed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	If this driver is built into the kernel, you can use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)         following kernel command line parameters, with the same values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)         as the corresponding module parameters listed above:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	    pcd.drive0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	    pcd.drive1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	    pcd.drive2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	    pcd.drive3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	    pcd.nice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)         In addition, you can use the parameter pcd.disable to disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)         the driver entirely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) /* Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	1.01	GRG 1998.01.24	Added test unit ready support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	1.02    GRG 1998.05.06  Changes to pcd_completion, ready_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 				and loosen interpretation of ATAPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 			        standard for clearing error status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 				Use spinlocks. Eliminate sti().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	1.03    GRG 1998.06.16  Eliminated an Ugh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	1.04	GRG 1998.08.15  Added extra debugging, improvements to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 				pcd_completion, use HZ in loop timing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	1.05	GRG 1998.08.16	Conformed to "Uniform CD-ROM" standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	1.06    GRG 1998.08.19  Added audio ioctl support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	1.07    GRG 1998.09.24  Increased reset timeout, added jumbo support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define	PCD_VERSION	"1.07"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #define PCD_MAJOR	46
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define PCD_NAME	"pcd"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #define PCD_UNITS	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) /* Here are things one can override from the insmod command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)    Most are autoprobed by paride unless set here.  Verbose is off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)    by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static int verbose = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static int major = PCD_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) static char *name = PCD_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) static int nice = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) static int disable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static int drive0[6] = { 0, 0, 0, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) static int drive1[6] = { 0, 0, 0, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) static int drive2[6] = { 0, 0, 0, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) static int drive3[6] = { 0, 0, 0, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) static int pcd_drive_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) /* end of parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) #include <linux/cdrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) #include <linux/blk-mq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static DEFINE_MUTEX(pcd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) static DEFINE_SPINLOCK(pcd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) module_param(verbose, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) module_param(major, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) module_param(name, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) module_param(nice, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) module_param_array(drive0, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) module_param_array(drive1, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) module_param_array(drive2, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) module_param_array(drive3, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) #include "paride.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #include "pseudo.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) #define PCD_RETRIES	     5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) #define PCD_TMO		   800	/* timeout in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) #define PCD_DELAY           50	/* spin delay in uS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) #define PCD_READY_TMO	    20	/* in seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) #define PCD_RESET_TMO	   100	/* in tenths of a second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) #define PCD_SPIN	(1000000*PCD_TMO)/(HZ*PCD_DELAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) #define IDE_ERR		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) #define IDE_DRQ         0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) #define IDE_READY       0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) #define IDE_BUSY        0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) static int pcd_open(struct cdrom_device_info *cdi, int purpose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) static void pcd_release(struct cdrom_device_info *cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) static int pcd_drive_status(struct cdrom_device_info *cdi, int slot_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) static unsigned int pcd_check_events(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 				     unsigned int clearing, int slot_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) static int pcd_tray_move(struct cdrom_device_info *cdi, int position);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) static int pcd_lock_door(struct cdrom_device_info *cdi, int lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) static int pcd_drive_reset(struct cdrom_device_info *cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static int pcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) static int pcd_audio_ioctl(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 			   unsigned int cmd, void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) static int pcd_packet(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		      struct packet_command *cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) static int pcd_detect(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) static void pcd_probe_capabilities(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) static void do_pcd_read_drq(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) static blk_status_t pcd_queue_rq(struct blk_mq_hw_ctx *hctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 				 const struct blk_mq_queue_data *bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) static void do_pcd_read(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) struct pcd_unit {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	struct pi_adapter pia;	/* interface to paride layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	struct pi_adapter *pi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	int drive;		/* master/slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	int last_sense;		/* result of last request sense */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	int changed;		/* media change seen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	int present;		/* does this unit exist ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	char *name;		/* pcd0, pcd1, etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	struct cdrom_device_info info;	/* uniform cdrom interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	struct gendisk *disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	struct blk_mq_tag_set tag_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	struct list_head rq_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) static struct pcd_unit pcd[PCD_UNITS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) static char pcd_scratch[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) static char pcd_buffer[2048];	/* raw block buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) static int pcd_bufblk = -1;	/* block in buffer, in CD units,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 				   -1 for nothing there. See also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 				   pd_unit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) /* the variables below are used mainly in the I/O request engine, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)    processes only one request at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) static struct pcd_unit *pcd_current; /* current request's drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) static struct request *pcd_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) static int pcd_retries;		/* retries on current request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static int pcd_busy;		/* request being processed ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) static int pcd_sector;		/* address of next requested sector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) static int pcd_count;		/* number of blocks still to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) static char *pcd_buf;		/* buffer for request in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) static void *par_drv;		/* reference of parport driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) /* kernel glue structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) static int pcd_block_open(struct block_device *bdev, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct pcd_unit *cd = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	bdev_check_media_change(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	mutex_lock(&pcd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	ret = cdrom_open(&cd->info, bdev, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	mutex_unlock(&pcd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) static void pcd_block_release(struct gendisk *disk, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	struct pcd_unit *cd = disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	mutex_lock(&pcd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	cdrom_release(&cd->info, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	mutex_unlock(&pcd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) static int pcd_block_ioctl(struct block_device *bdev, fmode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 				unsigned cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	struct pcd_unit *cd = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	mutex_lock(&pcd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	ret = cdrom_ioctl(&cd->info, bdev, mode, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	mutex_unlock(&pcd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) static unsigned int pcd_block_check_events(struct gendisk *disk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 					   unsigned int clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	struct pcd_unit *cd = disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	return cdrom_check_events(&cd->info, clearing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) static const struct block_device_operations pcd_bdops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	.open		= pcd_block_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	.release	= pcd_block_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	.ioctl		= pcd_block_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	.compat_ioctl	= blkdev_compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	.check_events	= pcd_block_check_events,
^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) static const struct cdrom_device_ops pcd_dops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	.open		= pcd_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	.release	= pcd_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	.drive_status	= pcd_drive_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	.check_events	= pcd_check_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	.tray_move	= pcd_tray_move,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	.lock_door	= pcd_lock_door,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	.get_mcn	= pcd_get_mcn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	.reset		= pcd_drive_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	.audio_ioctl	= pcd_audio_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	.generic_packet	= pcd_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	.capability	= CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			  CDC_MCN | CDC_MEDIA_CHANGED | CDC_RESET |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			  CDC_PLAY_AUDIO | CDC_GENERIC_PACKET | CDC_CD_R |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			  CDC_CD_RW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) static const struct blk_mq_ops pcd_mq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	.queue_rq	= pcd_queue_rq,
^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) static void pcd_init_units(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	struct pcd_unit *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	int unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	pcd_drive_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		struct gendisk *disk = alloc_disk(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		if (!disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		disk->queue = blk_mq_init_sq_queue(&cd->tag_set, &pcd_mq_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 						   1, BLK_MQ_F_SHOULD_MERGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		if (IS_ERR(disk->queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			disk->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			put_disk(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		INIT_LIST_HEAD(&cd->rq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		disk->queue->queuedata = cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		cd->disk = disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		cd->pi = &cd->pia;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		cd->present = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		cd->last_sense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		cd->changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		cd->drive = (*drives[unit])[D_SLV];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		if ((*drives[unit])[D_PRT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 			pcd_drive_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		cd->name = &cd->info.name[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		snprintf(cd->name, sizeof(cd->info.name), "%s%d", name, unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		cd->info.ops = &pcd_dops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		cd->info.handle = cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		cd->info.speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		cd->info.capacity = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		cd->info.mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		disk->major = major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		disk->first_minor = unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		strcpy(disk->disk_name, cd->name);	/* umm... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		disk->fops = &pcd_bdops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		disk->flags = GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		disk->events = DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) static int pcd_open(struct cdrom_device_info *cdi, int purpose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	struct pcd_unit *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	if (!cd->present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) static void pcd_release(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) static inline int status_reg(struct pcd_unit *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	return pi_read_regr(cd->pi, 1, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) static inline int read_reg(struct pcd_unit *cd, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	return pi_read_regr(cd->pi, 0, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) static inline void write_reg(struct pcd_unit *cd, int reg, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	pi_write_regr(cd->pi, 0, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) static int pcd_wait(struct pcd_unit *cd, int go, int stop, char *fun, char *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	int j, r, e, s, p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	while ((((r = status_reg(cd)) & go) || (stop && (!(r & stop))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	       && (j++ < PCD_SPIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		udelay(PCD_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	if ((r & (IDE_ERR & stop)) || (j > PCD_SPIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		s = read_reg(cd, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		e = read_reg(cd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		p = read_reg(cd, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		if (j > PCD_SPIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			e |= 0x100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		if (fun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			printk("%s: %s %s: alt=0x%x stat=0x%x err=0x%x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 			       " loop=%d phase=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			       cd->name, fun, msg, r, s, e, j, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		return (s << 8) + r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) static int pcd_command(struct pcd_unit *cd, char *cmd, int dlen, char *fun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	pi_connect(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	write_reg(cd, 6, 0xa0 + 0x10 * cd->drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	if (pcd_wait(cd, IDE_BUSY | IDE_DRQ, 0, fun, "before command")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		pi_disconnect(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	write_reg(cd, 4, dlen % 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	write_reg(cd, 5, dlen / 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	write_reg(cd, 7, 0xa0);	/* ATAPI packet command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	if (pcd_wait(cd, IDE_BUSY, IDE_DRQ, fun, "command DRQ")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		pi_disconnect(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	if (read_reg(cd, 2) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		printk("%s: %s: command phase error\n", cd->name, fun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		pi_disconnect(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	pi_write_block(cd->pi, cmd, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) static int pcd_completion(struct pcd_unit *cd, char *buf, char *fun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	int r, d, p, n, k, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	r = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	k = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	if (!pcd_wait(cd, IDE_BUSY, IDE_DRQ | IDE_READY | IDE_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		      fun, "completion")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		while (read_reg(cd, 7) & IDE_DRQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 			d = read_reg(cd, 4) + 256 * read_reg(cd, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			n = (d + 3) & 0xfffc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			p = read_reg(cd, 2) & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 			if ((p == 2) && (n > 0) && (j == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 				pi_read_block(cd->pi, buf, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 				if (verbose > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 					printk("%s: %s: Read %d bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 					       cd->name, fun, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 				r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 				j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 				if (verbose > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 					printk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 					    ("%s: %s: Unexpected phase %d, d=%d, k=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 					     cd->name, fun, p, d, k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 				if (verbose < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 					printk_once(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 					    "%s: WARNING: ATAPI phase errors\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 					    cd->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 			if (k++ > PCD_TMO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 				printk("%s: Stuck DRQ\n", cd->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			if (pcd_wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 			    (cd, IDE_BUSY, IDE_DRQ | IDE_READY | IDE_ERR, fun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			     "completion")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 				r = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	pi_disconnect(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) static void pcd_req_sense(struct pcd_unit *cd, char *fun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	char rs_cmd[12] = { 0x03, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	char buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	int r, c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	r = pcd_command(cd, rs_cmd, 16, "Request sense");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		pcd_completion(cd, buf, "Request sense");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	cd->last_sense = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	c = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	if (!r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		if (fun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 			printk("%s: %s: Sense key: %x, ASC: %x, ASQ: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 			       cd->name, fun, buf[2] & 0xf, buf[12], buf[13]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		c = buf[2] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		cd->last_sense =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		    c | ((buf[12] & 0xff) << 8) | ((buf[13] & 0xff) << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	if ((c == 2) || (c == 6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		cd->changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) static int pcd_atapi(struct pcd_unit *cd, char *cmd, int dlen, char *buf, char *fun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	r = pcd_command(cd, cmd, dlen, fun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		r = pcd_completion(cd, buf, fun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		pcd_req_sense(cd, fun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) static int pcd_packet(struct cdrom_device_info *cdi, struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	return pcd_atapi(cdi->handle, cgc->cmd, cgc->buflen, cgc->buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			 "generic packet");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) #define DBMSG(msg)	((verbose>1)?(msg):NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) static unsigned int pcd_check_events(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 				     unsigned int clearing, int slot_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	struct pcd_unit *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	int res = cd->changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		cd->changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	return res ? DISK_EVENT_MEDIA_CHANGE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) static int pcd_lock_door(struct cdrom_device_info *cdi, int lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	char un_cmd[12] = { 0x1e, 0, 0, 0, lock, 0, 0, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	return pcd_atapi(cdi->handle, un_cmd, 0, pcd_scratch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			 lock ? "lock door" : "unlock door");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static int pcd_tray_move(struct cdrom_device_info *cdi, int position)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	char ej_cmd[12] = { 0x1b, 0, 0, 0, 3 - position, 0, 0, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	return pcd_atapi(cdi->handle, ej_cmd, 0, pcd_scratch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 			 position ? "eject" : "close tray");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) static void pcd_sleep(int cs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	schedule_timeout_interruptible(cs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) static int pcd_reset(struct pcd_unit *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	int i, k, flg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	int expect[5] = { 1, 1, 1, 0x14, 0xeb };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	pi_connect(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	write_reg(cd, 6, 0xa0 + 0x10 * cd->drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	write_reg(cd, 7, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	pcd_sleep(20 * HZ / 1000);	/* delay a bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	k = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	while ((k++ < PCD_RESET_TMO) && (status_reg(cd) & IDE_BUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		pcd_sleep(HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	flg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	for (i = 0; i < 5; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		flg &= (read_reg(cd, i + 1) == expect[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	if (verbose) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		printk("%s: Reset (%d) signature = ", cd->name, k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		for (i = 0; i < 5; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 			printk("%3x", read_reg(cd, i + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		if (!flg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 			printk(" (incorrect)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	pi_disconnect(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	return flg - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) static int pcd_drive_reset(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	return pcd_reset(cdi->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) static int pcd_ready_wait(struct pcd_unit *cd, int tmo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	char tr_cmd[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	int k, p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	k = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	while (k < tmo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		cd->last_sense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		pcd_atapi(cd, tr_cmd, 0, NULL, DBMSG("test unit ready"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		p = cd->last_sense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		if (!(((p & 0xffff) == 0x0402) || ((p & 0xff) == 6)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		k++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		pcd_sleep(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	return 0x000020;	/* timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) static int pcd_drive_status(struct cdrom_device_info *cdi, int slot_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	char rc_cmd[12] = { 0x25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	struct pcd_unit *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	if (pcd_ready_wait(cd, PCD_READY_TMO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		return CDS_DRIVE_NOT_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	if (pcd_atapi(cd, rc_cmd, 8, pcd_scratch, DBMSG("check media")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		return CDS_NO_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	return CDS_DISC_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) static int pcd_identify(struct pcd_unit *cd, char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	int k, s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	char id_cmd[12] = { 0x12, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	pcd_bufblk = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	s = pcd_atapi(cd, id_cmd, 36, pcd_buffer, "identify");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	if (s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	if ((pcd_buffer[0] & 0x1f) != 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 			printk("%s: %s is not a CD-ROM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			       cd->name, cd->drive ? "Slave" : "Master");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	memcpy(id, pcd_buffer + 16, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	id[16] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	k = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	while ((k >= 0) && (id[k] <= 0x20)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		id[k] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		k--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	printk("%s: %s: %s\n", cd->name, cd->drive ? "Slave" : "Master", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665)  * returns  0, with id set if drive is detected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666)  *	    -1, if drive detection failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) static int pcd_probe(struct pcd_unit *cd, int ms, char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	if (ms == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		for (cd->drive = 0; cd->drive <= 1; cd->drive++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 			if (!pcd_reset(cd) && !pcd_identify(cd, id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		cd->drive = ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		if (!pcd_reset(cd) && !pcd_identify(cd, id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) static void pcd_probe_capabilities(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	int unit, r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	char buffer[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	char cmd[12] = { 0x5a, 1 << 3, 0x2a, 0, 0, 0, 0, 18, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	struct pcd_unit *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		if (!cd->present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		r = pcd_atapi(cd, cmd, 18, buffer, "mode sense capabilities");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		/* we should now have the cap page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		if ((buffer[11] & 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 			cd->info.mask |= CDC_CD_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		if ((buffer[11] & 2) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			cd->info.mask |= CDC_CD_RW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		if ((buffer[12] & 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			cd->info.mask |= CDC_PLAY_AUDIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		if ((buffer[14] & 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 			cd->info.mask |= CDC_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		if ((buffer[14] & 8) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			cd->info.mask |= CDC_OPEN_TRAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		if ((buffer[14] >> 6) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			cd->info.mask |= CDC_CLOSE_TRAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) static int pcd_detect(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	char id[18];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	int k, unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	struct pcd_unit *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	printk("%s: %s version %s, major %d, nice %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	       name, name, PCD_VERSION, major, nice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	par_drv = pi_register_driver(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	if (!par_drv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		pr_err("failed to register %s driver\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	k = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (pcd_drive_count == 0) { /* nothing spec'd - so autoprobe for 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		cd = pcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		if (cd->disk && pi_init(cd->pi, 1, -1, -1, -1, -1, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 			    pcd_buffer, PI_PCD, verbose, cd->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			if (!pcd_probe(cd, -1, id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 				cd->present = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 				k++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 				pi_release(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 			int *conf = *drives[unit];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			if (!conf[D_PRT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 			if (!cd->disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			if (!pi_init(cd->pi, 0, conf[D_PRT], conf[D_MOD],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 				     conf[D_UNI], conf[D_PRO], conf[D_DLY],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 				     pcd_buffer, PI_PCD, verbose, cd->name)) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			if (!pcd_probe(cd, conf[D_SLV], id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 				cd->present = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 				k++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 				pi_release(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	if (k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	printk("%s: No CD-ROM drive found\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		if (!cd->disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		blk_cleanup_queue(cd->disk->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		cd->disk->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		blk_mq_free_tag_set(&cd->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		put_disk(cd->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	pi_unregister_driver(par_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) /* I/O request processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) static int pcd_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) static int set_next_request(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	struct pcd_unit *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	int old_pos = pcd_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		cd = &pcd[pcd_queue];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		if (++pcd_queue == PCD_UNITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			pcd_queue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		if (cd->present && !list_empty(&cd->rq_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 			pcd_req = list_first_entry(&cd->rq_list, struct request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 							queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 			list_del_init(&pcd_req->queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			blk_mq_start_request(pcd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	} while (pcd_queue != old_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	return pcd_req != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) static void pcd_request(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	struct pcd_unit *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	if (pcd_busy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	if (!pcd_req && !set_next_request())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	cd = pcd_req->rq_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	if (cd != pcd_current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		pcd_bufblk = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	pcd_current = cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	pcd_sector = blk_rq_pos(pcd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	pcd_count = blk_rq_cur_sectors(pcd_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	pcd_buf = bio_data(pcd_req->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	pcd_busy = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	ps_set_intr(do_pcd_read, NULL, 0, nice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) static blk_status_t pcd_queue_rq(struct blk_mq_hw_ctx *hctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 				 const struct blk_mq_queue_data *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	struct pcd_unit *cd = hctx->queue->queuedata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	if (rq_data_dir(bd->rq) != READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		blk_mq_start_request(bd->rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		return BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	spin_lock_irq(&pcd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	list_add_tail(&bd->rq->queuelist, &cd->rq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	pcd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	spin_unlock_irq(&pcd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	return BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) static inline void next_request(blk_status_t err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	unsigned long saved_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	spin_lock_irqsave(&pcd_lock, saved_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (!blk_update_request(pcd_req, err, blk_rq_cur_bytes(pcd_req))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		__blk_mq_end_request(pcd_req, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		pcd_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	pcd_busy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	pcd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	spin_unlock_irqrestore(&pcd_lock, saved_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) static int pcd_ready(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	return (((status_reg(pcd_current) & (IDE_BUSY | IDE_DRQ)) == IDE_DRQ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) static void pcd_transfer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	while (pcd_count && (pcd_sector / 4 == pcd_bufblk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		int o = (pcd_sector % 4) * 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		memcpy(pcd_buf, pcd_buffer + o, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		pcd_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		pcd_buf += 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		pcd_sector++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) static void pcd_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	int b, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	char rd_cmd[12] = { 0xa8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	pcd_bufblk = pcd_sector / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	b = pcd_bufblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		rd_cmd[5 - i] = b & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		b = b >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	if (pcd_command(pcd_current, rd_cmd, 2048, "read block")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		pcd_bufblk = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		next_request(BLK_STS_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		return;
^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) 	mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	ps_set_intr(do_pcd_read_drq, pcd_ready, PCD_TMO, nice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) static void do_pcd_read(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	pcd_busy = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	pcd_retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	pcd_transfer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	if (!pcd_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		next_request(0);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	pi_do_claimed(pcd_current->pi, pcd_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) static void do_pcd_read_drq(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	unsigned long saved_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	if (pcd_completion(pcd_current, pcd_buffer, "read block")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		if (pcd_retries < PCD_RETRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 			mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 			pcd_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 			pi_do_claimed(pcd_current->pi, pcd_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		pcd_bufblk = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		next_request(BLK_STS_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	do_pcd_read();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	spin_lock_irqsave(&pcd_lock, saved_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	pcd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	spin_unlock_irqrestore(&pcd_lock, saved_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) /* the audio_ioctl stuff is adapted from sr_ioctl.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) static int pcd_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	struct pcd_unit *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	case CDROMREADTOCHDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 			char cmd[12] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 			    { GPCMD_READ_TOC_PMA_ATIP, 0, 0, 0, 0, 0, 0, 0, 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 			 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 			struct cdrom_tochdr *tochdr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 			    (struct cdrom_tochdr *) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			char buffer[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 			int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 			r = pcd_atapi(cd, cmd, 12, buffer, "read toc header");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 			tochdr->cdth_trk0 = buffer[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 			tochdr->cdth_trk1 = buffer[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			return r ? -EIO : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	case CDROMREADTOCENTRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			char cmd[12] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 			    { GPCMD_READ_TOC_PMA_ATIP, 0, 0, 0, 0, 0, 0, 0, 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 			 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 			struct cdrom_tocentry *tocentry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 			    (struct cdrom_tocentry *) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 			unsigned char buffer[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			cmd[1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			    (tocentry->cdte_format == CDROM_MSF ? 0x02 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 			cmd[6] = tocentry->cdte_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 			r = pcd_atapi(cd, cmd, 12, buffer, "read toc entry");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 			tocentry->cdte_ctrl = buffer[5] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 			tocentry->cdte_adr = buffer[5] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			tocentry->cdte_datamode =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 			    (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			if (tocentry->cdte_format == CDROM_MSF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 				tocentry->cdte_addr.msf.minute = buffer[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 				tocentry->cdte_addr.msf.second = buffer[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 				tocentry->cdte_addr.msf.frame = buffer[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 				tocentry->cdte_addr.lba =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 				    (((((buffer[8] << 8) + buffer[9]) << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 				      + buffer[10]) << 8) + buffer[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 			return r ? -EIO : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) static int pcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	char cmd[12] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	    { GPCMD_READ_SUBCHANNEL, 0, 0x40, 2, 0, 0, 0, 0, 24, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	char buffer[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	if (pcd_atapi(cdi->handle, cmd, 24, buffer, "get mcn"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	memcpy(mcn->medium_catalog_number, buffer + 9, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	mcn->medium_catalog_number[13] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) static int __init pcd_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	struct pcd_unit *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	int unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	if (disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	pcd_init_units();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	if (pcd_detect())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	/* get the atapi capabilities page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	pcd_probe_capabilities();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	if (register_blkdev(major, name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 			if (!cd->disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 			blk_cleanup_queue(cd->disk->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 			blk_mq_free_tag_set(&cd->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 			put_disk(cd->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		if (cd->present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 			register_cdrom(cd->disk, &cd->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 			cd->disk->private_data = cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			add_disk(cd->disk);
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static void __exit pcd_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	struct pcd_unit *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	int unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		if (!cd->disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		if (cd->present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 			del_gendisk(cd->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 			pi_release(cd->pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 			unregister_cdrom(&cd->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		blk_cleanup_queue(cd->disk->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		blk_mq_free_tag_set(&cd->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		put_disk(cd->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	unregister_blkdev(major, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	pi_unregister_driver(par_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) module_init(pcd_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) module_exit(pcd_exit)