CTC++ Coverage Report - Execution Profile    #415/1532

Files Summary | Functions Summary | Execution Profile | Index | No Index
First | Previous | Next | Last


File: drivers/ide/ide-cd.c
Instrumentation mode: function-decision-multicondition
TER: 22 % (280/1249)

Start/ End/    
True False - Line Source

  1 /*
  2  * linux/drivers/ide/ide-cd.c
  3  *
  4  * Copyright (C) 1994, 1995, 1996  scott snyder  <snyder@fnald0.fnal.gov>
  5  * Copyright (C) 1996-1998  Erik Andersen <andersee@debian.org>
  6  * Copyright (C) 1998-2000  Jens Axboe <axboe@suse.de>
  7  *
  8  * May be copied or modified under the terms of the GNU General Public
  9  * License.  See linux/COPYING for more information.
  10  *
  11  * ATAPI CD-ROM driver.  To be used with ide.c.
  12  * See Documentation/cdrom/ide-cd for usage information.
  13  *
  14  * Suggestions are welcome. Patches that work are more welcome though. ;-)
  15  * For those wishing to work on this driver, please be sure you download
  16  * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI 
  17  * (SFF-8020i rev 2.6) standards. These documents can be obtained by 
  18  * anonymous ftp from:
  19  * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps
  20  * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf
  21  *
  22  * Drives that deviate from these standards will be accommodated as much
  23  * as possible via compile time or command-line options.  Since I only have
  24  * a few drives, you generally need to send me patches...
  25  *
  26  * ----------------------------------
  27  * TO DO LIST:
  28  * -Make it so that Pioneer CD DR-A24X and friends don't get screwed up on
  29  *   boot
  30  *
  31  * ----------------------------------
  32  * 1.00  Oct 31, 1994 -- Initial version.
  33  * 1.01  Nov  2, 1994 -- Fixed problem with starting request in
  34  *                       cdrom_check_status.
  35  * 1.03  Nov 25, 1994 -- leaving unmask_intr[] as a user-setting (as for disks)
  36  * (from mlord)       -- minor changes to cdrom_setup()
  37  *                    -- renamed ide_dev_s to ide_drive_t, enable irq on command
  38  * 2.00  Nov 27, 1994 -- Generalize packet command interface;
  39  *                       add audio ioctls.
  40  * 2.01  Dec  3, 1994 -- Rework packet command interface to handle devices
  41  *                       which send an interrupt when ready for a command.
  42  * 2.02  Dec 11, 1994 -- Cache the TOC in the driver.
  43  *                       Don't use SCMD_PLAYAUDIO_TI; it's not included
  44  *                       in the current version of ATAPI.
  45  *                       Try to use LBA instead of track or MSF addressing
  46  *                       when possible.
  47  *                       Don't wait for READY_STAT.
  48  * 2.03  Jan 10, 1995 -- Rewrite block read routines to handle block sizes
  49  *                       other than 2k and to move multiple sectors in a
  50  *                       single transaction.
  51  * 2.04  Apr 21, 1995 -- Add work-around for Creative Labs CD220E drives.
  52  *                       Thanks to Nick Saw <cwsaw@pts7.pts.mot.com> for
  53  *                       help in figuring this out.  Ditto for Acer and
  54  *                       Aztech drives, which seem to have the same problem.
  55  * 2.04b May 30, 1995 -- Fix to match changes in ide.c version 3.16 -ml
  56  * 2.05  Jun  8, 1995 -- Don't attempt to retry after an illegal request
  57  *                        or data protect error.
  58  *                       Use HWIF and DEV_HWIF macros as in ide.c.
  59  *                       Always try to do a request_sense after
  60  *                        a failed command.
  61  *                       Include an option to give textual descriptions
  62  *                        of ATAPI errors.
  63  *                       Fix a bug in handling the sector cache which
  64  *                        showed up if the drive returned data in 512 byte
  65  *                        blocks (like Pioneer drives).  Thanks to
  66  *                        Richard Hirst <srh@gpt.co.uk> for diagnosing this.
  67  *                       Properly supply the page number field in the
  68  *                        MODE_SELECT command.
  69  *                       PLAYAUDIO12 is broken on the Aztech; work around it.
  70  * 2.05x Aug 11, 1995 -- lots of data structure renaming/restructuring in ide.c
  71  *                       (my apologies to Scott, but now ide-cd.c is independent)
  72  * 3.00  Aug 22, 1995 -- Implement CDROMMULTISESSION ioctl.
  73  *                       Implement CDROMREADAUDIO ioctl (UNTESTED).
  74  *                       Use input_ide_data() and output_ide_data().
  75  *                       Add door locking.
  76  *                       Fix usage count leak in cdrom_open, which happened
  77  *                        when a read-write mount was attempted.
  78  *                       Try to load the disk on open.
  79  *                       Implement CDROMEJECT_SW ioctl (off by default).
  80  *                       Read total cdrom capacity during open.
  81  *                       Rearrange logic in cdrom_decode_status.  Issue
  82  *                        request sense commands for failed packet commands
  83  *                        from here instead of from cdrom_queue_packet_command.
  84  *                        Fix a race condition in retrieving error information.
  85  *                       Suppress printing normal unit attention errors and
  86  *                        some drive not ready errors.
  87  *                       Implement CDROMVOLREAD ioctl.
  88  *                       Implement CDROMREADMODE1/2 ioctls.
  89  *                       Fix race condition in setting up interrupt handlers
  90  *                        when the `serialize' option is used.
  91  * 3.01  Sep  2, 1995 -- Fix ordering of reenabling interrupts in
  92  *                        cdrom_queue_request.
  93  *                       Another try at using ide_[input,output]_data.
  94  * 3.02  Sep 16, 1995 -- Stick total disk capacity in partition table as well.
  95  *                       Make VERBOSE_IDE_CD_ERRORS dump failed command again.
  96  *                       Dump out more information for ILLEGAL REQUEST errs.
  97  *                       Fix handling of errors occurring before the
  98  *                        packet command is transferred.
  99  *                       Fix transfers with odd bytelengths.
  100  * 3.03  Oct 27, 1995 -- Some Creative drives have an id of just `CD'.
  101  *                       `DCI-2S10' drives are broken too.
  102  * 3.04  Nov 20, 1995 -- So are Vertos drives.
  103  * 3.05  Dec  1, 1995 -- Changes to go with overhaul of ide.c and ide-tape.c
  104  * 3.06  Dec 16, 1995 -- Add support needed for partitions.
  105  *                       More workarounds for Vertos bugs (based on patches
  106  *                        from Holger Dietze <dietze@aix520.informatik.uni-leipzig.de>).
  107  *                       Try to eliminate byteorder assumptions.
  108  *                       Use atapi_cdrom_subchnl struct definition.
  109  *                       Add STANDARD_ATAPI compilation option.
  110  * 3.07  Jan 29, 1996 -- More twiddling for broken drives: Sony 55D,
  111  *                        Vertos 300.
  112  *                       Add NO_DOOR_LOCKING configuration option.
  113  *                       Handle drive_cmd requests w/NULL args (for hdparm -t).
  114  *                       Work around sporadic Sony55e audio play problem.
  115  * 3.07a Feb 11, 1996 -- check drive->id for NULL before dereferencing, to fix
  116  *                        problem with "hde=cdrom" with no drive present.  -ml
  117  * 3.08  Mar  6, 1996 -- More Vertos workarounds.
  118  * 3.09  Apr  5, 1996 -- Add CDROMCLOSETRAY ioctl.
  119  *                       Switch to using MSF addressing for audio commands.
  120  *                       Reformat to match kernel tabbing style.
  121  *                       Add CDROM_GET_UPC ioctl.
  122  * 3.10  Apr 10, 1996 -- Fix compilation error with STANDARD_ATAPI.
  123  * 3.11  Apr 29, 1996 -- Patch from Heiko Eissfeldt <heiko@colossus.escape.de>
  124  *                       to remove redundant verify_area calls.
  125  * 3.12  May  7, 1996 -- Rudimentary changer support.  Based on patches
  126  *                        from Gerhard Zuber <zuber@berlin.snafu.de>.
  127  *                       Let open succeed even if there's no loaded disc.
  128  * 3.13  May 19, 1996 -- Fixes for changer code.
  129  * 3.14  May 29, 1996 -- Add work-around for Vertos 600.
  130  *                        (From Hennus Bergman <hennus@sky.ow.nl>.)
  131  * 3.15  July 2, 1996 -- Added support for Sanyo 3 CD changers
  132  *                        from Ben Galliart <bgallia@luc.edu> with 
  133  *                        special help from Jeff Lightfoot 
  134  *                        <jeffml@pobox.com>
  135  * 3.15a July 9, 1996 -- Improved Sanyo 3 CD changer identification
  136  * 3.16  Jul 28, 1996 -- Fix from Gadi to reduce kernel stack usage for ioctl.
  137  * 3.17  Sep 17, 1996 -- Tweak audio reads for some drives.
  138  *                       Start changing CDROMLOADFROMSLOT to CDROM_SELECT_DISC.
  139  * 3.18  Oct 31, 1996 -- Added module and DMA support.
  140  *                       
  141  *                       
  142  * 4.00  Nov 5, 1996   -- New ide-cd maintainer,
  143  *                                 Erik B. Andersen <andersee@debian.org>
  144  *                     -- Newer Creative drives don't always set the error
  145  *                          register correctly.  Make sure we see media changes
  146  *                          regardless.
  147  *                     -- Integrate with generic cdrom driver.
  148  *                     -- CDROMGETSPINDOWN and CDROMSETSPINDOWN ioctls, based on
  149  *                          a patch from Ciro Cattuto <>.
  150  *                     -- Call set_device_ro.
  151  *                     -- Implement CDROMMECHANISMSTATUS and CDROMSLOTTABLE
  152  *                          ioctls, based on patch by Erik Andersen
  153  *                     -- Add some probes of drive capability during setup.
  154  *
  155  * 4.01  Nov 11, 1996  -- Split into ide-cd.c and ide-cd.h
  156  *                     -- Removed CDROMMECHANISMSTATUS and CDROMSLOTTABLE 
  157  *                          ioctls in favor of a generalized approach 
  158  *                          using the generic cdrom driver.
  159  *                     -- Fully integrated with the 2.1.X kernel.
  160  *                     -- Other stuff that I forgot (lots of changes)
  161  *
  162  * 4.02  Dec 01, 1996  -- Applied patch from Gadi Oxman <gadio@netvision.net.il>
  163  *                          to fix the drive door locking problems.
  164  *
  165  * 4.03  Dec 04, 1996  -- Added DSC overlap support.
  166  * 4.04  Dec 29, 1996  -- Added CDROMREADRAW ioclt based on patch 
  167  *                          by Ales Makarov (xmakarov@sun.felk.cvut.cz)
  168  *
  169  * 4.05  Nov 20, 1997  -- Modified to print more drive info on init
  170  *                        Minor other changes
  171  *                        Fix errors on CDROMSTOP (If you have a "Dolphin",
  172  *                          you must define IHAVEADOLPHIN)
  173  *                        Added identifier so new Sanyo CD-changer works
  174  *                        Better detection if door locking isn't supported
  175  *
  176  * 4.06  Dec 17, 1997  -- fixed endless "tray open" messages  -ml
  177  * 4.07  Dec 17, 1997  -- fallback to set pc->stat on "tray open"
  178  * 4.08  Dec 18, 1997  -- spew less noise when tray is empty
  179  *                     -- fix speed display for ACER 24X, 18X
  180  * 4.09  Jan 04, 1998  -- fix handling of the last block so we return
  181  *                         an end of file instead of an I/O error (Gadi)
  182  * 4.10  Jan 24, 1998  -- fixed a bug so now changers can change to a new
  183  *                         slot when there is no disc in the current slot.
  184  *                     -- Fixed a memory leak where info->changer_info was
  185  *                         malloc'ed but never free'd when closing the device.
  186  *                     -- Cleaned up the global namespace a bit by making more
  187  *                         functions static that should already have been.
  188  * 4.11  Mar 12, 1998  -- Added support for the CDROM_SELECT_SPEED ioctl
  189  *                         based on a patch for 2.0.33 by Jelle Foks 
  190  *                         <jelle@scintilla.utwente.nl>, a patch for 2.0.33
  191  *                         by Toni Giorgino <toni@pcape2.pi.infn.it>, the SCSI
  192  *                         version, and my own efforts.  -erik
  193  *                     -- Fixed a stupid bug which egcs was kind enough to
  194  *                         inform me of where "Illegal mode for this track"
  195  *                         was never returned due to a comparison on data
  196  *                         types of limited range.
  197  * 4.12  Mar 29, 1998  -- Fixed bug in CDROM_SELECT_SPEED so write speed is 
  198  *                         now set ionly for CD-R and CD-RW drives.  I had 
  199  *                         removed this support because it produced errors.
  200  *                         It produced errors _only_ for non-writers. duh.
  201  * 4.13  May 05, 1998  -- Suppress useless "in progress of becoming ready"
  202  *                         messages, since this is not an error.
  203  *                     -- Change error messages to be const
  204  *                     -- Remove a "\t" which looks ugly in the syslogs
  205  * 4.14  July 17, 1998 -- Change to pointing to .ps version of ATAPI spec
  206  *                         since the .pdf version doesn't seem to work...
  207  *                     -- Updated the TODO list to something more current.
  208  *
  209  * 4.15  Aug 25, 1998  -- Updated ide-cd.h to respect mechine endianess, 
  210  *                         patch thanks to "Eddie C. Dost" <ecd@skynet.be>
  211  *
  212  * 4.50  Oct 19, 1998  -- New maintainers!
  213  *                         Jens Axboe <axboe@image.dk>
  214  *                         Chris Zwilling <chris@cloudnet.com>
  215  *
  216  * 4.51  Dec 23, 1998  -- Jens Axboe <axboe@image.dk>
  217  *                      - ide_cdrom_reset enabled since the ide subsystem
  218  *                         handles resets fine now. <axboe@image.dk>
  219  *                      - Transfer size fix for Samsung CD-ROMs, thanks to
  220  *                        "Ville Hallik" <ville.hallik@mail.ee>.
  221  *                      - other minor stuff.
  222  *
  223  * 4.52  Jan 19, 1999  -- Jens Axboe <axboe@image.dk>
  224  *                      - Detect DVD-ROM/RAM drives
  225  *
  226  * 4.53  Feb 22, 1999   - Include other model Samsung and one Goldstar
  227  *                         drive in transfer size limit.
  228  *                      - Fix the I/O error when doing eject without a medium
  229  *                         loaded on some drives.
  230  *                      - CDROMREADMODE2 is now implemented through
  231  *                         CDROMREADRAW, since many drives don't support
  232  *                         MODE2 (even though ATAPI 2.6 says they must).
  233  *                      - Added ignore parameter to ide-cd (as a module), eg
  234  *                            insmod ide-cd ignore='hda hdb'
  235  *                         Useful when using ide-cd in conjunction with
  236  *                         ide-scsi. TODO: non-modular way of doing the
  237  *                         same.
  238  *
  239  * 4.54  Aug 5, 1999   - Support for MMC2 class commands through the generic
  240  *           packet interface to cdrom.c.
  241  *         - Unified audio ioctl support, most of it.
  242  *         - cleaned up various deprecated verify_area().
  243  *         - Added ide_cdrom_packet() as the interface for
  244  *           the Uniform generic_packet().
  245  *         - bunch of other stuff, will fill in logs later.
  246  *         - report 1 slot for non-changers, like the other
  247  *           cd-rom drivers. don't report select disc for
  248  *           non-changers as well.
  249  *         - mask out audio playing, if the device can't do it.
  250  *
  251  * 4.55  Sep 1, 1999   - Eliminated the rest of the audio ioctls, except
  252  *           for CDROMREADTOC[ENTRY|HEADER]. Some of the drivers
  253  *           use this independently of the actual audio handling.
  254  *           They will disappear later when I get the time to
  255  *           do it cleanly.
  256  *         - Minimize the TOC reading - only do it when we
  257  *           know a media change has occurred.
  258  *         - Moved all the CDROMREADx ioctls to the Uniform layer.
  259  *         - Heiko Eissfeldt <heiko@colossus.escape.de> supplied
  260  *           some fixes for CDI.
  261  *         - CD-ROM leaving door locked fix from Andries
  262  *           Brouwer <Andries.Brouwer@cwi.nl>
  263  *         - Erik Andersen <andersen@xmission.com> unified
  264  *           commands across the various drivers and how
  265  *           sense errors are handled.
  266  *
  267  * 4.56  Sep 12, 1999   - Removed changer support - it is now in the
  268  *           Uniform layer.
  269  *         - Added partition based multisession handling.
  270  *         - Mode sense and mode select moved to the
  271  *           Uniform layer.
  272  *         - Fixed a problem with WPI CDS-32X drive - it
  273  *           failed the capabilities 
  274  *
  275  * 4.57  Apr 7, 2000   - Fixed sense reporting.
  276  *         - Fixed possible oops in ide_cdrom_get_last_session()
  277  *         - Fix locking mania and make ide_cdrom_reset relock
  278  *         - Stop spewing errors to log when magicdev polls with
  279  *           TEST_UNIT_READY on some drives.
  280  *         - Various fixes from Tobias Ringstrom:
  281  *           tray if it was locked prior to the reset.
  282  *           - cdrom_read_capacity returns one frame too little.
  283  *           - Fix real capacity reporting.
  284  *
  285  * 4.58  May 1, 2000   - Clean up ACER50 stuff.
  286  *         - Fix small problem with ide_cdrom_capacity
  287  *
  288  * 4.59  Aug 11, 2000   - Fix changer problem in cdrom_read_toc, we weren't
  289  *           correctly sensing a disc change.
  290  *         - Rearranged some code
  291  *         - Use extended sense on drives that support it for
  292  *           correctly reporting tray status -- from
  293  *           Michael D Johnson <johnsom@orst.edu>
  294  * 4.60  Dec 17, 2003   - Add mt rainier support
  295  *         - Bump timeout for packet commands, matches sr
  296  *         - Odd stuff
  297  * 4.61  Jan 22, 2004   - support hardware sector sizes other than 2kB,
  298  *           Pascal Schmidt <der.eremit@email.de>
  299  *
  300  *************************************************************************/
  301  
  302 #define IDECD_VERSION "4.61"
  303 
  304 #include <linux/config.h>
  305 #include <linux/module.h>
  306 #include <linux/types.h>
  307 #include <linux/kernel.h>
  308 #include <linux/delay.h>
  309 #include <linux/timer.h>
  310 #include <linux/slab.h>
  311 #include <linux/interrupt.h>
  312 #include <linux/errno.h>
  313 #include <linux/cdrom.h>
  314 #include <linux/ide.h>
  315 #include <linux/completion.h>
  316 
  317 #include <scsi/scsi.h>   /* For SCSI -> ATAPI command conversion */
  318 
  319 #include <asm/irq.h>
  320 #include <asm/io.h>
  321 #include <asm/byteorder.h>
  322 #include <asm/uaccess.h>
  323 #include <asm/unaligned.h>
  324 
  325 #include "ide-cd.h"
  326 
  327 static DECLARE_MUTEX(idecd_ref_sem);
  328 
  329 #define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) 
  330 
  331 #define ide_cd_g(disk) \
  332    container_of((disk)->private_data, struct cdrom_info, driver)
  333 
 
22   334 static struct cdrom_info *ide_cd_get(struct gendisk *disk)
  335 {
  336    struct cdrom_info *cd = NULL;
  337 
  338    down(&idecd_ref_sem);
  339    cd = ide_cd_g(disk);
22 - 340    if (cd)
  341       kref_get(&cd->kref);
  342    up(&idecd_ref_sem);
22    343    return cd;
  344 }
  345 
  346 static void ide_cd_release(struct kref *);
  347 
 
22 22   348 static void ide_cd_put(struct cdrom_info *cd)
  349 {
  350    down(&idecd_ref_sem);
  351    kref_put(&cd->kref, ide_cd_release);
  352    up(&idecd_ref_sem);
  353 }
  354 
  355 /****************************************************************************
  356  * Generic packet command support and error handling routines.
  357  */
  358 
  359 /* Mark that we've seen a media change, and invalidate our internal
  360    buffers. */
 
106 106   361 static void cdrom_saw_media_change (ide_drive_t *drive)
  362 {
  363    struct cdrom_info *info = drive->driver_data;
  364    
  365    CDROM_STATE_FLAGS (drive)->media_changed = 1;
  366    CDROM_STATE_FLAGS (drive)->toc_valid = 0;
  367    info->nsectors_buffered = 0;
  368 }
  369 
 
106   370 static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
  371             struct request_sense *sense)
  372 {
  373    int log = 0;
  374 
78 28   375    if (!sense || !rq || (rq->flags & REQ_QUIET))
 - 375   T || _ || (_)
 - 375   F || T || (_)
78    375   F || F || (T)
 28   375   F || F || (F)
78    376       return 0;
  377 
    378    switch (sense->sense_key) {
 - 379       case NO_SENSE: case RECOVERED_ERROR:
 - 379 case 0x01:
 - 380          break;
28    381       case NOT_READY:
  382          /*
  383           * don't care about tray state messages for
  384           * e.g. capacity commands or in-progress or
  385           * becoming ready
  386           */
28 - 387          if (sense->asc == 0x3a || sense->asc == 0x04)
28    387     T || _
 - 387     F || T
 - 387     F || F
28    388             break;
  389          log = 1;
 - 390          break;
 - 391       case ILLEGAL_REQUEST:
  392          /*
  393           * don't log START_STOP unit with LoEj set, since
  394           * we cannot reliably check if drive can auto-close
  395           */
- 396          if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24)
 - 396     T && T
 - 396     T && F
 - 396     F && _
  397             log = 0;
 - 398          break;
 - 399       case UNIT_ATTENTION:
  400          /*
  401           * Make good and sure we've seen this potential media
  402           * change. Some drives (i.e. Creative) fail to present
  403           * the correct sense key in the error register.
  404           */
  405          cdrom_saw_media_change(drive);
 - 406          break;
 - 407       default:
  408          log = 1;
 - 409          break;
  410    }
28    411    return log;
  412 }
  413 
  414 static
 
106   415 void cdrom_analyze_sense_data(ide_drive_t *drive,
  416                struct request *failed_command,
  417                struct request_sense *sense)
  418 {
106 - 419    if (!cdrom_log_sense(drive, failed_command, sense))
106    420       return;
  421 
  422    /*
  423     * If a read toc is executed for a CD-R or CD-RW medium where
  424     * the first toc has not been recorded yet, it will fail with
  425     * 05/24/00 (which is a confusing error)
  426     */
- 427    if (failed_command && failed_command->cmd[0] == GPCMD_READ_TOC_PMA_ATIP)
 - 427   T && T
 - 427   T && F
 - 427   F && _
- 428       if (sense->sense_key == 0x05 && sense->asc == 0x24)
 - 428     T && T
 - 428     T && F
 - 428     F && _
 - 429          return;
  430 
  431 #if VERBOSE_IDE_CD_ERRORS
  432    {
  433       int i;
  434       const char *s = "bad sense key