The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/scsipi/scsi_base.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: scsi_base.c,v 1.77.18.1 2004/09/11 12:52:07 he Exp $   */
    2 
    3 /*-
    4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Charles M. Hannum.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __KERNEL_RCSID(0, "$NetBSD: scsi_base.c,v 1.77.18.1 2004/09/11 12:52:07 he Exp $");
   41 
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/kernel.h>
   45 #include <sys/buf.h>
   46 #include <sys/uio.h>
   47 #include <sys/malloc.h>
   48 #include <sys/errno.h>
   49 #include <sys/device.h>
   50 #include <sys/proc.h>
   51 
   52 #include <dev/scsipi/scsipi_all.h>
   53 #include <dev/scsipi/scsi_all.h>
   54 #include <dev/scsipi/scsi_disk.h>
   55 #include <dev/scsipi/scsiconf.h>
   56 #include <dev/scsipi/scsipi_base.h>
   57 
   58 /*
   59  * Do a scsi operation, asking a device to run as SCSI-II if it can.
   60  */
   61 int
   62 scsi_change_def(periph, flags)
   63         struct scsipi_periph *periph;
   64         int flags;
   65 {
   66         struct scsi_changedef scsipi_cmd;
   67 
   68         memset(&scsipi_cmd, 0, sizeof(scsipi_cmd));
   69         scsipi_cmd.opcode = SCSI_CHANGE_DEFINITION;
   70         scsipi_cmd.how = SC_SCSI_2;
   71 
   72         return (scsipi_command(periph, NULL,
   73             (struct scsipi_generic *) &scsipi_cmd, sizeof(scsipi_cmd),
   74             0, 0, SCSIPIRETRIES, 100000, NULL, flags));
   75 }
   76 
   77 /*
   78  * ask the scsi driver to perform a command for us.
   79  * tell it where to read/write the data, and how
   80  * long the data is supposed to be. If we have  a buf
   81  * to associate with the transfer, we need that too.
   82  */
   83 int
   84 scsi_scsipi_cmd(periph, xs, scsipi_cmd, cmdlen, data, datalen,
   85         retries, timeout, bp, flags)
   86         struct scsipi_periph *periph;
   87         struct scsipi_xfer *xs;
   88         struct scsipi_generic *scsipi_cmd;
   89         int cmdlen;
   90         void *data;
   91         size_t datalen;
   92         int retries;
   93         int timeout;
   94         struct buf *bp;
   95         int flags;
   96 {
   97         int error;
   98 
   99         SC_DEBUG(periph, SCSIPI_DB2, ("scsi_scsipi_cmd\n"));
  100 
  101 #ifdef DIAGNOSTIC
  102         if (bp != NULL && (flags & XS_CTL_ASYNC) == 0)
  103                 panic("scsi_scsipi_cmd: buffer without async");
  104 #endif
  105 
  106         if (xs == NULL) {
  107                 if ((xs = scsipi_make_xs(periph, scsipi_cmd, cmdlen, data,
  108                     datalen, retries, timeout, bp, flags)) == NULL) {
  109                         /* let the caller deal with this */
  110                         return (ENOMEM);
  111                 }
  112         }
  113 
  114         /*
  115          * Set the LUN in the CDB if we have an older device.  We also
  116          * set it for more modern SCSI-2 devices "just in case".
  117          */
  118         if (periph->periph_version <= 2)
  119                 xs->cmd->bytes[0] |=
  120                     ((periph->periph_lun << SCSI_CMD_LUN_SHIFT) &
  121                         SCSI_CMD_LUN_MASK);
  122 
  123         if ((error = scsipi_execute_xs(xs)) == EJUSTRETURN)
  124                 return (0);
  125         return (error);
  126 }
  127 
  128 /*
  129  * Utility routines often used in SCSI stuff
  130  */
  131 
  132 /*
  133  * Print out the periph's address info.
  134  */
  135 void
  136 scsi_print_addr(periph)
  137         struct scsipi_periph *periph;
  138 {
  139         struct scsipi_channel *chan = periph->periph_channel;
  140         struct scsipi_adapter *adapt = chan->chan_adapter;
  141 
  142         printf("%s(%s:%d:%d:%d): ", periph->periph_dev != NULL ?
  143             periph->periph_dev->dv_xname : "probe",
  144             adapt->adapt_dev->dv_xname,
  145             chan->chan_channel, periph->periph_target,
  146             periph->periph_lun);
  147 }
  148 
  149 /*
  150  * Kill off all pending xfers for a periph.
  151  *
  152  * Must be called at splbio().
  153  */
  154 void
  155 scsi_kill_pending(periph)
  156         struct scsipi_periph *periph;
  157 {
  158         struct scsipi_xfer *xs;
  159 
  160         while ((xs = TAILQ_FIRST(&periph->periph_xferq)) != NULL) {
  161                 xs->error = XS_DRIVER_STUFFUP;
  162                 scsipi_done(xs);
  163         }
  164 }

Cache object: d6d3eb6952a50c77e484a8324296067b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.