Orange Pi5 kernel

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

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/blkpg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/cdrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <scsi/scsi_dbg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <scsi/scsi_ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "sr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /* The sr_is_xa() seems to trigger firmware bugs with some drives :-(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * It is off by default and can be turned on with this module parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int xa_test = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) module_param(xa_test, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* primitive to determine whether we need to have GFP_DMA set based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * the status of the unchecked_isa_dma flag in the host structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define SR_GFP_DMA(cd) (((cd)->device->host->unchecked_isa_dma) ? GFP_DMA : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static int sr_read_tochdr(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		struct cdrom_tochdr *tochdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct scsi_cd *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	unsigned char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	cgc.cmd[8] = 12;		/* LSB of length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	cgc.buffer = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	cgc.buflen = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	cgc.data_direction = DMA_FROM_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	result = sr_do_ioctl(cd, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	tochdr->cdth_trk0 = buffer[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	tochdr->cdth_trk1 = buffer[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int sr_read_tocentry(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		struct cdrom_tocentry *tocentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct scsi_cd *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	unsigned char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	cgc.cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	cgc.cmd[6] = tocentry->cdte_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	cgc.cmd[8] = 12;		/* LSB of length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	cgc.buffer = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	cgc.buflen = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	cgc.data_direction = DMA_FROM_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	result = sr_do_ioctl(cd, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	tocentry->cdte_ctrl = buffer[5] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	tocentry->cdte_adr = buffer[5] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (tocentry->cdte_format == CDROM_MSF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		tocentry->cdte_addr.msf.minute = buffer[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		tocentry->cdte_addr.msf.second = buffer[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		tocentry->cdte_addr.msf.frame = buffer[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			+ buffer[10]) << 8) + buffer[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define IOCTL_RETRIES 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* ATAPI drives don't have a SCMD_PLAYAUDIO_TI command.  When these drives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)    are emulating a SCSI device via the idescsi module, they need to have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)    CDROMPLAYTRKIND commands translated into CDROMPLAYMSF commands for them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct cdrom_tocentry trk0_te, trk1_te;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct cdrom_tochdr tochdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	int ntracks, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	ret = sr_read_tochdr(cdi, &tochdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	ntracks = tochdr.cdth_trk1 - tochdr.cdth_trk0 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (ti->cdti_trk1 == ntracks) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		ti->cdti_trk1 = CDROM_LEADOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	else if (ti->cdti_trk1 != CDROM_LEADOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		ti->cdti_trk1 ++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	trk0_te.cdte_track = ti->cdti_trk0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	trk0_te.cdte_format = CDROM_MSF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	trk1_te.cdte_track = ti->cdti_trk1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	trk1_te.cdte_format = CDROM_MSF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ret = sr_read_tocentry(cdi, &trk0_te);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ret = sr_read_tocentry(cdi, &trk1_te);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	cgc.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	cgc.cmd[3] = trk0_te.cdte_addr.msf.minute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	cgc.cmd[4] = trk0_te.cdte_addr.msf.second;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	cgc.cmd[5] = trk0_te.cdte_addr.msf.frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	cgc.cmd[6] = trk1_te.cdte_addr.msf.minute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	cgc.cmd[7] = trk1_te.cdte_addr.msf.second;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	cgc.cmd[8] = trk1_te.cdte_addr.msf.frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	cgc.data_direction = DMA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return sr_do_ioctl(cdi->handle, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int sr_play_trkind(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		struct cdrom_ti *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct scsi_cd *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	cgc.cmd[0] = GPCMD_PLAYAUDIO_TI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	cgc.cmd[4] = ti->cdti_trk0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	cgc.cmd[5] = ti->cdti_ind0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	cgc.cmd[7] = ti->cdti_trk1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	cgc.cmd[8] = ti->cdti_ind1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	cgc.data_direction = DMA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	result = sr_do_ioctl(cd, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (result == -EDRIVE_CANT_DO_THIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		result = sr_fake_playtrkind(cdi, ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* We do our own retries because we want to know what the specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)    error code is.  Normally the UNIT_ATTENTION code will automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)    clear after one error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct scsi_device *SDev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct scsi_sense_hdr local_sshdr, *sshdr = &local_sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	int result, err = 0, retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	SDev = cd->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (cgc->sshdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		sshdr = cgc->sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)       retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (!scsi_block_when_processing_errors(SDev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			      cgc->buffer, cgc->buflen, NULL, sshdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			      cgc->timeout, IOCTL_RETRIES, 0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	/* Minimal error checking.  Ignore cases we know about, and report the rest. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (driver_byte(result) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		switch (sshdr->sense_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		case UNIT_ATTENTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			SDev->changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			if (!cgc->quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				sr_printk(KERN_INFO, cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 					  "disc change detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			if (retries++ < 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			err = -ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		case NOT_READY:	/* This happens if there is no disc in drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			if (sshdr->asc == 0x04 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			    sshdr->ascq == 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				/* sense: Logical unit is in process of becoming ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				if (!cgc->quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 					sr_printk(KERN_INFO, cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 						  "CDROM not ready yet.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 				if (retries++ < 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 					/* sleep 2 sec and try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 					ssleep(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 					goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					/* 20 secs are enough? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 					err = -ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			if (!cgc->quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				sr_printk(KERN_INFO, cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 					  "CDROM not ready.  Make sure there "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					  "is a disc in the drive.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			err = -ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		case ILLEGAL_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			if (sshdr->asc == 0x20 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			    sshdr->ascq == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				/* sense: Invalid command operation code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				err = -EDRIVE_CANT_DO_THIS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			err = -EIO;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	/* Wake up a process waiting for device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)       out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	cgc->stat = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* ---------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* interface to cdrom.c                                                   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int sr_tray_move(struct cdrom_device_info *cdi, int pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	Scsi_CD *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	cgc.cmd[0] = GPCMD_START_STOP_UNIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	cgc.cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	cgc.data_direction = DMA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return sr_do_ioctl(cd, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int sr_lock_door(struct cdrom_device_info *cdi, int lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	Scsi_CD *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return scsi_set_medium_removal(cd->device, lock ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		       SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
^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) int sr_drive_status(struct cdrom_device_info *cdi, int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct scsi_cd *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct scsi_sense_hdr sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct media_event_desc med;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (CDSL_CURRENT != slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		/* we have no changer support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (!scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		return CDS_DISC_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	/* SK/ASC/ASCQ of 2/4/1 means "unit is becoming ready" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			&& sshdr.asc == 0x04 && sshdr.ascq == 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		return CDS_DRIVE_NOT_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (!cdrom_get_media_event(cdi, &med)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		if (med.media_present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			return CDS_DISC_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		else if (med.door_open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			return CDS_TRAY_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			return CDS_NO_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	 * SK/ASC/ASCQ of 2/4/2 means "initialization required"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	 * Using CD_TRAY_OPEN results in an START_STOP_UNIT to close
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	 * the tray, which resolves the initialization requirement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			&& sshdr.asc == 0x04 && sshdr.ascq == 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		return CDS_TRAY_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	 * 0x04 is format in progress .. but there must be a disc present!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (sshdr.sense_key == NOT_READY && sshdr.asc == 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return CDS_DISC_OK;
^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) 	 * If not using Mt Fuji extended media tray reports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	 * just return TRAY_OPEN since ATAPI doesn't provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	 * any other way to detect this...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (scsi_sense_valid(&sshdr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	    /* 0x3a is medium not present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	    sshdr.asc == 0x3a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		return CDS_NO_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		return CDS_TRAY_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return CDS_DRIVE_NOT_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int sr_disk_status(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	Scsi_CD *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct cdrom_tochdr toc_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct cdrom_tocentry toc_e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	int i, rc, have_datatracks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* look for data tracks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	rc = sr_read_tochdr(cdi, &toc_h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		return (rc == -ENOMEDIUM) ? CDS_NO_DISC : CDS_NO_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	for (i = toc_h.cdth_trk0; i <= toc_h.cdth_trk1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		toc_e.cdte_track = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		toc_e.cdte_format = CDROM_LBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if (sr_read_tocentry(cdi, &toc_e))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			return CDS_NO_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		if (toc_e.cdte_ctrl & CDROM_DATA_TRACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			have_datatracks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (!have_datatracks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		return CDS_AUDIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (cd->xa_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		return CDS_XA_2_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		return CDS_DATA_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) int sr_get_last_session(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			struct cdrom_multisession *ms_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	Scsi_CD *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	ms_info->addr.lba = cd->ms_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	ms_info->xa_flag = cd->xa_flag || cd->ms_offset > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	Scsi_CD *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	char *buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	cgc.cmd[2] = 0x40;	/* I do want the subchannel info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	cgc.cmd[3] = 0x02;	/* Give me medium catalog number info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	cgc.cmd[8] = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	cgc.buffer = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	cgc.buflen = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	cgc.data_direction = DMA_FROM_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	result = sr_do_ioctl(cd, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	memcpy(mcn->medium_catalog_number, buffer + 9, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	mcn->medium_catalog_number[13] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) int sr_reset(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int sr_select_speed(struct cdrom_device_info *cdi, int speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	Scsi_CD *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (speed == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		speed = 0xffff;	/* set to max */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		speed *= 177;	/* Nx to kbyte/s */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	cgc.cmd[0] = GPCMD_SET_SPEED;	/* SET CD SPEED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	cgc.cmd[2] = (speed >> 8) & 0xff;	/* MSB for speed (in kbytes/sec) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	cgc.cmd[3] = speed & 0xff;	/* LSB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	cgc.data_direction = DMA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if (sr_do_ioctl(cd, &cgc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	return 0;
^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) /* ----------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /* this is called by the generic cdrom driver. arg is a _kernel_ pointer,  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* because the generic cdrom driver does the user access stuff for us.     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /* only cdromreadtochdr and cdromreadtocentry are left - for use with the  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /* sr_disk_status interface for the generic cdrom driver.                  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	case CDROMREADTOCHDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		return sr_read_tochdr(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	case CDROMREADTOCENTRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		return sr_read_tocentry(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	case CDROMPLAYTRKIND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		return sr_play_trkind(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /* -----------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  * a function to read all sorts of funny cdrom sectors using the READ_CD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  * scsi-3 mmc command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  * lba:     linear block address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  * format:  0 = data (anything)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)  *          1 = audio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  *          2 = data (mode 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  *          3 = data (mode 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  *          4 = data (mode 2 form1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  *          5 = data (mode 2 form2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * blksize: 2048 | 2336 | 2340 | 2352
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static int sr_read_cd(Scsi_CD *cd, unsigned char *dest, int lba, int format, int blksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	sr_printk(KERN_INFO, cd, "sr_read_cd lba=%d format=%d blksize=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		  lba, format, blksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	cgc.cmd[0] = GPCMD_READ_CD;	/* READ_CD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	cgc.cmd[1] = ((format & 7) << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	cgc.cmd[5] = (unsigned char) lba & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	cgc.cmd[8] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	switch (blksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	case 2336:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		cgc.cmd[9] = 0x58;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	case 2340:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		cgc.cmd[9] = 0x78;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	case 2352:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		cgc.cmd[9] = 0xf8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		cgc.cmd[9] = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	cgc.buffer = dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	cgc.buflen = blksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	cgc.data_direction = DMA_FROM_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	return sr_do_ioctl(cd, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)  * read sectors with blocksizes other than 2048
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static int sr_read_sector(Scsi_CD *cd, int lba, int blksize, unsigned char *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	/* we try the READ CD command first... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	if (cd->readcd_known) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		rc = sr_read_cd(cd, dest, lba, 0, blksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		if (-EDRIVE_CANT_DO_THIS != rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		cd->readcd_known = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		sr_printk(KERN_INFO, cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 			  "CDROM does'nt support READ CD (0xbe) command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		/* fall & retry the other way */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	/* ... if this fails, we switch the blocksize using MODE SELECT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	if (blksize != cd->device->sector_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		if (0 != (rc = sr_set_blocklength(cd, blksize)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	sr_printk(KERN_INFO, cd, "sr_read_sector lba=%d blksize=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		  lba, blksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	memset(&cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	cgc.cmd[0] = GPCMD_READ_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	cgc.cmd[5] = (unsigned char) lba & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	cgc.cmd[8] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	cgc.buffer = dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	cgc.buflen = blksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	cgc.data_direction = DMA_FROM_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	cgc.timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	rc = sr_do_ioctl(cd, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)  * read a sector in raw mode to check the sector format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)  * ret: 1 == mode2 (XA), 0 == mode1, <0 == error 
^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) int sr_is_xa(Scsi_CD *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	unsigned char *raw_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	int is_xa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	if (!xa_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	raw_sector = kmalloc(2048, GFP_KERNEL | SR_GFP_DMA(cd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	if (!raw_sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	if (0 == sr_read_sector(cd, cd->ms_offset + 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 				CD_FRAMESIZE_RAW1, raw_sector)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		/* read a raw sector failed for some reason. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		is_xa = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	kfree(raw_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	sr_printk(KERN_INFO, cd, "sr_is_xa: %d\n", is_xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	return is_xa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }