License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/blkdev.h>
|
2011-05-27 13:47:43 +00:00
|
|
|
#include <linux/module.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/blkpg.h>
|
|
|
|
#include <linux/cdrom.h>
|
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/io.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_dbg.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
#include <scsi/scsi_eh.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <scsi/scsi_ioctl.h>
|
2005-06-13 03:21:29 +00:00
|
|
|
#include <scsi/scsi_cmnd.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "sr.h"
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define DEBUG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The sr_is_xa() seems to trigger firmware bugs with some drives :-(
|
|
|
|
* It is off by default and can be turned on with this module parameter */
|
|
|
|
static int xa_test = 0;
|
|
|
|
|
|
|
|
module_param(xa_test, int, S_IRUGO | S_IWUSR);
|
|
|
|
|
2006-01-11 13:28:06 +00:00
|
|
|
/* primitive to determine whether we need to have GFP_DMA set based on
|
|
|
|
* the status of the unchecked_isa_dma flag in the host structure */
|
|
|
|
#define SR_GFP_DMA(cd) (((cd)->device->host->unchecked_isa_dma) ? GFP_DMA : 0)
|
|
|
|
|
|
|
|
static int sr_read_tochdr(struct cdrom_device_info *cdi,
|
|
|
|
struct cdrom_tochdr *tochdr)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
struct packet_command cgc;
|
|
|
|
int result;
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
|
|
|
|
if (!buffer)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
|
|
|
|
cgc.cmd[8] = 12; /* LSB of length */
|
|
|
|
cgc.buffer = buffer;
|
|
|
|
cgc.buflen = 12;
|
|
|
|
cgc.quiet = 1;
|
|
|
|
cgc.data_direction = DMA_FROM_DEVICE;
|
|
|
|
|
|
|
|
result = sr_do_ioctl(cd, &cgc);
|
|
|
|
|
|
|
|
tochdr->cdth_trk0 = buffer[2];
|
|
|
|
tochdr->cdth_trk1 = buffer[3];
|
|
|
|
|
|
|
|
kfree(buffer);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sr_read_tocentry(struct cdrom_device_info *cdi,
|
|
|
|
struct cdrom_tocentry *tocentry)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
struct packet_command cgc;
|
|
|
|
int result;
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
|
|
|
|
if (!buffer)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
|
|
|
|
cgc.cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
|
|
|
|
cgc.cmd[6] = tocentry->cdte_track;
|
|
|
|
cgc.cmd[8] = 12; /* LSB of length */
|
|
|
|
cgc.buffer = buffer;
|
|
|
|
cgc.buflen = 12;
|
|
|
|
cgc.data_direction = DMA_FROM_DEVICE;
|
|
|
|
|
|
|
|
result = sr_do_ioctl(cd, &cgc);
|
|
|
|
|
|
|
|
tocentry->cdte_ctrl = buffer[5] & 0xf;
|
|
|
|
tocentry->cdte_adr = buffer[5] >> 4;
|
|
|
|
tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
|
|
|
|
if (tocentry->cdte_format == CDROM_MSF) {
|
|
|
|
tocentry->cdte_addr.msf.minute = buffer[9];
|
|
|
|
tocentry->cdte_addr.msf.second = buffer[10];
|
|
|
|
tocentry->cdte_addr.msf.frame = buffer[11];
|
|
|
|
} else
|
|
|
|
tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
|
|
|
|
+ buffer[10]) << 8) + buffer[11];
|
|
|
|
|
|
|
|
kfree(buffer);
|
|
|
|
return result;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define IOCTL_RETRIES 3
|
|
|
|
|
|
|
|
/* ATAPI drives don't have a SCMD_PLAYAUDIO_TI command. When these drives
|
|
|
|
are emulating a SCSI device via the idescsi module, they need to have
|
|
|
|
CDROMPLAYTRKIND commands translated into CDROMPLAYMSF commands for them */
|
|
|
|
|
|
|
|
static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti)
|
|
|
|
{
|
|
|
|
struct cdrom_tocentry trk0_te, trk1_te;
|
|
|
|
struct cdrom_tochdr tochdr;
|
|
|
|
struct packet_command cgc;
|
|
|
|
int ntracks, ret;
|
|
|
|
|
2006-01-11 13:28:06 +00:00
|
|
|
ret = sr_read_tochdr(cdi, &tochdr);
|
|
|
|
if (ret)
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
ntracks = tochdr.cdth_trk1 - tochdr.cdth_trk0 + 1;
|
|
|
|
|
|
|
|
if (ti->cdti_trk1 == ntracks)
|
|
|
|
ti->cdti_trk1 = CDROM_LEADOUT;
|
|
|
|
else if (ti->cdti_trk1 != CDROM_LEADOUT)
|
|
|
|
ti->cdti_trk1 ++;
|
|
|
|
|
|
|
|
trk0_te.cdte_track = ti->cdti_trk0;
|
|
|
|
trk0_te.cdte_format = CDROM_MSF;
|
|
|
|
trk1_te.cdte_track = ti->cdti_trk1;
|
|
|
|
trk1_te.cdte_format = CDROM_MSF;
|
|
|
|
|
2006-01-11 13:28:06 +00:00
|
|
|
ret = sr_read_tocentry(cdi, &trk0_te);
|
|
|
|
if (ret)
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
2006-01-11 13:28:06 +00:00
|
|
|
ret = sr_read_tocentry(cdi, &trk1_te);
|
|
|
|
if (ret)
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
|
|
|
|
cgc.cmd[3] = trk0_te.cdte_addr.msf.minute;
|
|
|
|
cgc.cmd[4] = trk0_te.cdte_addr.msf.second;
|
|
|
|
cgc.cmd[5] = trk0_te.cdte_addr.msf.frame;
|
|
|
|
cgc.cmd[6] = trk1_te.cdte_addr.msf.minute;
|
|
|
|
cgc.cmd[7] = trk1_te.cdte_addr.msf.second;
|
|
|
|
cgc.cmd[8] = trk1_te.cdte_addr.msf.frame;
|
|
|
|
cgc.data_direction = DMA_NONE;
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
return sr_do_ioctl(cdi->handle, &cgc);
|
|
|
|
}
|
|
|
|
|
2006-01-11 13:28:06 +00:00
|
|
|
static int sr_play_trkind(struct cdrom_device_info *cdi,
|
|
|
|
struct cdrom_ti *ti)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
struct packet_command cgc;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
cgc.cmd[0] = GPCMD_PLAYAUDIO_TI;
|
|
|
|
cgc.cmd[4] = ti->cdti_trk0;
|
|
|
|
cgc.cmd[5] = ti->cdti_ind0;
|
|
|
|
cgc.cmd[7] = ti->cdti_trk1;
|
|
|
|
cgc.cmd[8] = ti->cdti_ind1;
|
|
|
|
cgc.data_direction = DMA_NONE;
|
|
|
|
|
|
|
|
result = sr_do_ioctl(cd, &cgc);
|
|
|
|
if (result == -EDRIVE_CANT_DO_THIS)
|
|
|
|
result = sr_fake_playtrkind(cdi, ti);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* We do our own retries because we want to know what the specific
|
|
|
|
error code is. Normally the UNIT_ATTENTION code will automatically
|
|
|
|
clear after one error */
|
|
|
|
|
|
|
|
int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
|
|
|
|
{
|
|
|
|
struct scsi_device *SDev;
|
2018-08-02 21:22:13 +00:00
|
|
|
struct scsi_sense_hdr local_sshdr, *sshdr = &local_sshdr;
|
2005-04-16 22:20:36 +00:00
|
|
|
int result, err = 0, retries = 0;
|
|
|
|
|
|
|
|
SDev = cd->device;
|
2005-06-13 03:21:29 +00:00
|
|
|
|
2018-08-02 21:22:13 +00:00
|
|
|
if (cgc->sshdr)
|
|
|
|
sshdr = cgc->sshdr;
|
2018-05-21 18:21:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
retry:
|
|
|
|
if (!scsi_block_when_processing_errors(SDev)) {
|
|
|
|
err = -ENODEV;
|
2005-06-13 03:21:29 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-06-13 03:21:29 +00:00
|
|
|
result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
|
2018-08-02 21:22:13 +00:00
|
|
|
cgc->buffer, cgc->buflen, NULL, sshdr,
|
2017-02-23 15:02:36 +00:00
|
|
|
cgc->timeout, IOCTL_RETRIES, 0, 0, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Minimal error checking. Ignore cases we know about, and report the rest. */
|
|
|
|
if (driver_byte(result) != 0) {
|
2018-08-02 21:22:13 +00:00
|
|
|
switch (sshdr->sense_key) {
|
2005-04-16 22:20:36 +00:00
|
|
|
case UNIT_ATTENTION:
|
|
|
|
SDev->changed = 1;
|
|
|
|
if (!cgc->quiet)
|
2014-06-25 14:39:54 +00:00
|
|
|
sr_printk(KERN_INFO, cd,
|
|
|
|
"disc change detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (retries++ < 10)
|
|
|
|
goto retry;
|
|
|
|
err = -ENOMEDIUM;
|
|
|
|
break;
|
|
|
|
case NOT_READY: /* This happens if there is no disc in drive */
|
2018-08-02 21:22:13 +00:00
|
|
|
if (sshdr->asc == 0x04 &&
|
|
|
|
sshdr->ascq == 0x01) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* sense: Logical unit is in process of becoming ready */
|
|
|
|
if (!cgc->quiet)
|
2014-06-25 14:39:54 +00:00
|
|
|
sr_printk(KERN_INFO, cd,
|
|
|
|
"CDROM not ready yet.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (retries++ < 10) {
|
|
|
|
/* sleep 2 sec and try again */
|
|
|
|
ssleep(2);
|
|
|
|
goto retry;
|
|
|
|
} else {
|
|
|
|
/* 20 secs are enough? */
|
|
|
|
err = -ENOMEDIUM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!cgc->quiet)
|
2014-06-25 14:39:54 +00:00
|
|
|
sr_printk(KERN_INFO, cd,
|
|
|
|
"CDROM not ready. Make sure there "
|
|
|
|
"is a disc in the drive.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
err = -ENOMEDIUM;
|
|
|
|
break;
|
|
|
|
case ILLEGAL_REQUEST:
|
|
|
|
err = -EIO;
|
2018-08-02 21:22:13 +00:00
|
|
|
if (sshdr->asc == 0x20 &&
|
|
|
|
sshdr->ascq == 0x00)
|
2005-04-16 22:20:36 +00:00
|
|
|
/* sense: Invalid command operation code */
|
|
|
|
err = -EDRIVE_CANT_DO_THIS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wake up a process waiting for device */
|
|
|
|
out:
|
|
|
|
cgc->stat = err;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
/* interface to cdrom.c */
|
|
|
|
|
|
|
|
int sr_tray_move(struct cdrom_device_info *cdi, int pos)
|
|
|
|
{
|
|
|
|
Scsi_CD *cd = cdi->handle;
|
|
|
|
struct packet_command cgc;
|
|
|
|
|
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.cmd[0] = GPCMD_START_STOP_UNIT;
|
|
|
|
cgc.cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
|
|
|
|
cgc.data_direction = DMA_NONE;
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
return sr_do_ioctl(cd, &cgc);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sr_lock_door(struct cdrom_device_info *cdi, int lock)
|
|
|
|
{
|
|
|
|
Scsi_CD *cd = cdi->handle;
|
|
|
|
|
|
|
|
return scsi_set_medium_removal(cd->device, lock ?
|
|
|
|
SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sr_drive_status(struct cdrom_device_info *cdi, int slot)
|
|
|
|
{
|
2008-01-05 16:39:51 +00:00
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
struct media_event_desc med;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (CDSL_CURRENT != slot) {
|
|
|
|
/* we have no changer support */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-12-08 19:57:40 +00:00
|
|
|
if (!scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
|
2005-04-16 22:20:36 +00:00
|
|
|
return CDS_DISC_OK;
|
|
|
|
|
2008-07-11 20:17:05 +00:00
|
|
|
/* SK/ASC/ASCQ of 2/4/1 means "unit is becoming ready" */
|
|
|
|
if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
|
|
|
|
&& sshdr.asc == 0x04 && sshdr.ascq == 0x01)
|
|
|
|
return CDS_DRIVE_NOT_READY;
|
|
|
|
|
2008-01-05 16:39:51 +00:00
|
|
|
if (!cdrom_get_media_event(cdi, &med)) {
|
|
|
|
if (med.media_present)
|
|
|
|
return CDS_DISC_OK;
|
|
|
|
else if (med.door_open)
|
|
|
|
return CDS_TRAY_OPEN;
|
|
|
|
else
|
|
|
|
return CDS_NO_DISC;
|
|
|
|
}
|
|
|
|
|
2010-10-11 16:02:00 +00:00
|
|
|
/*
|
|
|
|
* SK/ASC/ASCQ of 2/4/2 means "initialization required"
|
|
|
|
* Using CD_TRAY_OPEN results in an START_STOP_UNIT to close
|
|
|
|
* the tray, which resolves the initialization requirement.
|
|
|
|
*/
|
|
|
|
if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
|
|
|
|
&& sshdr.asc == 0x04 && sshdr.ascq == 0x02)
|
|
|
|
return CDS_TRAY_OPEN;
|
|
|
|
|
2008-01-05 16:39:51 +00:00
|
|
|
/*
|
|
|
|
* 0x04 is format in progress .. but there must be a disc present!
|
|
|
|
*/
|
|
|
|
if (sshdr.sense_key == NOT_READY && sshdr.asc == 0x04)
|
|
|
|
return CDS_DISC_OK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If not using Mt Fuji extended media tray reports,
|
|
|
|
* just return TRAY_OPEN since ATAPI doesn't provide
|
|
|
|
* any other way to detect this...
|
|
|
|
*/
|
|
|
|
if (scsi_sense_valid(&sshdr) &&
|
|
|
|
/* 0x3a is medium not present */
|
|
|
|
sshdr.asc == 0x3a)
|
|
|
|
return CDS_NO_DISC;
|
|
|
|
else
|
|
|
|
return CDS_TRAY_OPEN;
|
|
|
|
|
|
|
|
return CDS_DRIVE_NOT_READY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sr_disk_status(struct cdrom_device_info *cdi)
|
|
|
|
{
|
|
|
|
Scsi_CD *cd = cdi->handle;
|
|
|
|
struct cdrom_tochdr toc_h;
|
|
|
|
struct cdrom_tocentry toc_e;
|
|
|
|
int i, rc, have_datatracks = 0;
|
|
|
|
|
|
|
|
/* look for data tracks */
|
2006-01-11 13:28:06 +00:00
|
|
|
rc = sr_read_tochdr(cdi, &toc_h);
|
|
|
|
if (rc)
|
2005-04-16 22:20:36 +00:00
|
|
|
return (rc == -ENOMEDIUM) ? CDS_NO_DISC : CDS_NO_INFO;
|
|
|
|
|
|
|
|
for (i = toc_h.cdth_trk0; i <= toc_h.cdth_trk1; i++) {
|
|
|
|
toc_e.cdte_track = i;
|
|
|
|
toc_e.cdte_format = CDROM_LBA;
|
2006-01-11 13:28:06 +00:00
|
|
|
if (sr_read_tocentry(cdi, &toc_e))
|
2005-04-16 22:20:36 +00:00
|
|
|
return CDS_NO_INFO;
|
|
|
|
if (toc_e.cdte_ctrl & CDROM_DATA_TRACK) {
|
|
|
|
have_datatracks = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!have_datatracks)
|
|
|
|
return CDS_AUDIO;
|
|
|
|
|
|
|
|
if (cd->xa_flag)
|
|
|
|
return CDS_XA_2_1;
|
|
|
|
else
|
|
|
|
return CDS_DATA_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sr_get_last_session(struct cdrom_device_info *cdi,
|
|
|
|
struct cdrom_multisession *ms_info)
|
|
|
|
{
|
|
|
|
Scsi_CD *cd = cdi->handle;
|
|
|
|
|
|
|
|
ms_info->addr.lba = cd->ms_offset;
|
|
|
|
ms_info->xa_flag = cd->xa_flag || cd->ms_offset > 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
|
|
|
|
{
|
|
|
|
Scsi_CD *cd = cdi->handle;
|
|
|
|
struct packet_command cgc;
|
|
|
|
char *buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
|
|
|
|
int result;
|
|
|
|
|
2005-04-21 20:14:05 +00:00
|
|
|
if (!buffer)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
|
|
|
|
cgc.cmd[2] = 0x40; /* I do want the subchannel info */
|
|
|
|
cgc.cmd[3] = 0x02; /* Give me medium catalog number info */
|
|
|
|
cgc.cmd[8] = 24;
|
|
|
|
cgc.buffer = buffer;
|
|
|
|
cgc.buflen = 24;
|
|
|
|
cgc.data_direction = DMA_FROM_DEVICE;
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
result = sr_do_ioctl(cd, &cgc);
|
|
|
|
|
|
|
|
memcpy(mcn->medium_catalog_number, buffer + 9, 13);
|
|
|
|
mcn->medium_catalog_number[13] = 0;
|
|
|
|
|
|
|
|
kfree(buffer);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sr_reset(struct cdrom_device_info *cdi)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sr_select_speed(struct cdrom_device_info *cdi, int speed)
|
|
|
|
{
|
|
|
|
Scsi_CD *cd = cdi->handle;
|
|
|
|
struct packet_command cgc;
|
|
|
|
|
|
|
|
if (speed == 0)
|
|
|
|
speed = 0xffff; /* set to max */
|
|
|
|
else
|
|
|
|
speed *= 177; /* Nx to kbyte/s */
|
|
|
|
|
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.cmd[0] = GPCMD_SET_SPEED; /* SET CD SPEED */
|
|
|
|
cgc.cmd[2] = (speed >> 8) & 0xff; /* MSB for speed (in kbytes/sec) */
|
|
|
|
cgc.cmd[3] = speed & 0xff; /* LSB */
|
|
|
|
cgc.data_direction = DMA_NONE;
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
|
|
|
|
if (sr_do_ioctl(cd, &cgc))
|
|
|
|
return -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* this is called by the generic cdrom driver. arg is a _kernel_ pointer, */
|
|
|
|
/* because the generic cdrom driver does the user access stuff for us. */
|
|
|
|
/* only cdromreadtochdr and cdromreadtocentry are left - for use with the */
|
|
|
|
/* sr_disk_status interface for the generic cdrom driver. */
|
|
|
|
|
|
|
|
int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case CDROMREADTOCHDR:
|
2006-01-11 13:28:06 +00:00
|
|
|
return sr_read_tochdr(cdi, arg);
|
2005-04-16 22:20:36 +00:00
|
|
|
case CDROMREADTOCENTRY:
|
2006-01-11 13:28:06 +00:00
|
|
|
return sr_read_tocentry(cdi, arg);
|
|
|
|
case CDROMPLAYTRKIND:
|
|
|
|
return sr_play_trkind(cdi, arg);
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
2006-01-11 13:28:06 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------
|
|
|
|
* a function to read all sorts of funny cdrom sectors using the READ_CD
|
|
|
|
* scsi-3 mmc command
|
|
|
|
*
|
|
|
|
* lba: linear block address
|
|
|
|
* format: 0 = data (anything)
|
|
|
|
* 1 = audio
|
|
|
|
* 2 = data (mode 1)
|
|
|
|
* 3 = data (mode 2)
|
|
|
|
* 4 = data (mode 2 form1)
|
|
|
|
* 5 = data (mode 2 form2)
|
|
|
|
* blksize: 2048 | 2336 | 2340 | 2352
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int sr_read_cd(Scsi_CD *cd, unsigned char *dest, int lba, int format, int blksize)
|
|
|
|
{
|
|
|
|
struct packet_command cgc;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-06-25 14:39:54 +00:00
|
|
|
sr_printk(KERN_INFO, cd, "sr_read_cd lba=%d format=%d blksize=%d\n",
|
|
|
|
lba, format, blksize);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.cmd[0] = GPCMD_READ_CD; /* READ_CD */
|
|
|
|
cgc.cmd[1] = ((format & 7) << 2);
|
|
|
|
cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
|
|
|
|
cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
|
|
|
|
cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
|
|
|
|
cgc.cmd[5] = (unsigned char) lba & 0xff;
|
|
|
|
cgc.cmd[8] = 1;
|
|
|
|
switch (blksize) {
|
|
|
|
case 2336:
|
|
|
|
cgc.cmd[9] = 0x58;
|
|
|
|
break;
|
|
|
|
case 2340:
|
|
|
|
cgc.cmd[9] = 0x78;
|
|
|
|
break;
|
|
|
|
case 2352:
|
|
|
|
cgc.cmd[9] = 0xf8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cgc.cmd[9] = 0x10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cgc.buffer = dest;
|
|
|
|
cgc.buflen = blksize;
|
|
|
|
cgc.data_direction = DMA_FROM_DEVICE;
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
return sr_do_ioctl(cd, &cgc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read sectors with blocksizes other than 2048
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int sr_read_sector(Scsi_CD *cd, int lba, int blksize, unsigned char *dest)
|
|
|
|
{
|
|
|
|
struct packet_command cgc;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* we try the READ CD command first... */
|
|
|
|
if (cd->readcd_known) {
|
|
|
|
rc = sr_read_cd(cd, dest, lba, 0, blksize);
|
|
|
|
if (-EDRIVE_CANT_DO_THIS != rc)
|
|
|
|
return rc;
|
|
|
|
cd->readcd_known = 0;
|
2014-06-25 14:39:54 +00:00
|
|
|
sr_printk(KERN_INFO, cd,
|
|
|
|
"CDROM does'nt support READ CD (0xbe) command\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
/* fall & retry the other way */
|
|
|
|
}
|
|
|
|
/* ... if this fails, we switch the blocksize using MODE SELECT */
|
|
|
|
if (blksize != cd->device->sector_size) {
|
|
|
|
if (0 != (rc = sr_set_blocklength(cd, blksize)))
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2014-06-25 14:39:54 +00:00
|
|
|
sr_printk(KERN_INFO, cd, "sr_read_sector lba=%d blksize=%d\n",
|
|
|
|
lba, blksize);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&cgc, 0, sizeof(struct packet_command));
|
|
|
|
cgc.cmd[0] = GPCMD_READ_10;
|
|
|
|
cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
|
|
|
|
cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
|
|
|
|
cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
|
|
|
|
cgc.cmd[5] = (unsigned char) lba & 0xff;
|
|
|
|
cgc.cmd[8] = 1;
|
|
|
|
cgc.buffer = dest;
|
|
|
|
cgc.buflen = blksize;
|
|
|
|
cgc.data_direction = DMA_FROM_DEVICE;
|
|
|
|
cgc.timeout = IOCTL_TIMEOUT;
|
|
|
|
rc = sr_do_ioctl(cd, &cgc);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a sector in raw mode to check the sector format
|
|
|
|
* ret: 1 == mode2 (XA), 0 == mode1, <0 == error
|
|
|
|
*/
|
|
|
|
|
|
|
|
int sr_is_xa(Scsi_CD *cd)
|
|
|
|
{
|
|
|
|
unsigned char *raw_sector;
|
|
|
|
int is_xa;
|
|
|
|
|
|
|
|
if (!xa_test)
|
|
|
|
return 0;
|
|
|
|
|
2006-12-13 08:35:56 +00:00
|
|
|
raw_sector = kmalloc(2048, GFP_KERNEL | SR_GFP_DMA(cd));
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!raw_sector)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (0 == sr_read_sector(cd, cd->ms_offset + 16,
|
|
|
|
CD_FRAMESIZE_RAW1, raw_sector)) {
|
|
|
|
is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
/* read a raw sector failed for some reason. */
|
|
|
|
is_xa = -1;
|
|
|
|
}
|
|
|
|
kfree(raw_sector);
|
|
|
|
#ifdef DEBUG
|
2014-06-25 14:39:54 +00:00
|
|
|
sr_printk(KERN_INFO, cd, "sr_is_xa: %d\n", is_xa);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
return is_xa;
|
|
|
|
}
|