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/st_atapi.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: st_atapi.c,v 1.20 2006/11/16 01:33:26 christos Exp $ */
    2 
    3 /*
    4  * Copyright (c) 2001 Manuel Bouyer.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 3. All advertising materials mentioning features or use of this software
   15  *    must display the following acknowledgement:
   16  *      This product includes software developed by Manuel Bouyer.
   17  * 4. The name of the author may not be used to endorse or promote products
   18  *    derived from this software without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   30  *
   31  */
   32 
   33 #include <sys/cdefs.h>
   34 __KERNEL_RCSID(0, "$NetBSD: st_atapi.c,v 1.20 2006/11/16 01:33:26 christos Exp $");
   35 
   36 #include "opt_scsi.h"
   37 #include "rnd.h"
   38 
   39 #include <sys/param.h>
   40 #include <sys/device.h>
   41 #include <sys/buf.h>
   42 #include <sys/bufq.h>
   43 #include <sys/conf.h>
   44 #include <sys/kernel.h>
   45 #include <sys/systm.h>
   46 
   47 #include <dev/scsipi/stvar.h>
   48 #include <dev/scsipi/atapi_tape.h>
   49 
   50 static int      st_atapibus_match(struct device *, struct cfdata *, void *);
   51 static void     st_atapibus_attach(struct device *, struct device *, void *);
   52 static int      st_atapibus_ops(struct st_softc *, int, int);
   53 static int      st_atapibus_mode_sense(struct st_softc *, int);
   54 static int      st_atapibus_mode_select(struct st_softc *, int);
   55 
   56 CFATTACH_DECL(st_atapibus, sizeof(struct st_softc),
   57     st_atapibus_match, st_atapibus_attach, stdetach, stactivate);
   58 
   59 static const struct scsipi_inquiry_pattern st_atapibus_patterns[] = {
   60         {T_SEQUENTIAL, T_REMOV,
   61          "",     "",             ""},
   62 };
   63 
   64 static int
   65 st_atapibus_match(struct device *parent, struct cfdata *match,
   66     void *aux)
   67 {
   68         struct scsipibus_attach_args *sa = aux;
   69         int priority;
   70 
   71         if (scsipi_periph_bustype(sa->sa_periph) != SCSIPI_BUSTYPE_ATAPI)
   72                 return (0);
   73 
   74         (void)scsipi_inqmatch(&sa->sa_inqbuf,
   75             st_atapibus_patterns,
   76             sizeof(st_atapibus_patterns)/sizeof(st_atapibus_patterns[0]),
   77             sizeof(st_atapibus_patterns[0]), &priority);
   78         return (priority);
   79 }
   80 
   81 static void
   82 st_atapibus_attach(struct device *parent, struct device *self, void *aux)
   83 {
   84         struct st_softc *st = device_private(self);
   85         struct scsipibus_attach_args *sa = aux;
   86         struct scsipi_periph *periph = sa->sa_periph;
   87 
   88         if (strcmp(sa->sa_inqbuf.vendor, "OnStream DI-30") == 0) {
   89                 struct ast_identifypage identify;
   90                 int error;
   91 
   92                 error = scsipi_mode_sense(periph, SMS_DBD,
   93                     ATAPI_TAPE_IDENTIFY_PAGE, &identify.header,
   94                     sizeof(identify), XS_CTL_DISCOVERY | XS_CTL_DATA_ONSTACK,
   95                     ST_RETRIES, ST_CTL_TIME);
   96                 if (error) {
   97                         printf("onstream get identify: error %d\n", error);
   98                         return;
   99                 }
  100                 strncpy(identify.ident, "NBSD", 4);
  101                 error = scsipi_mode_select(periph, SMS_PF,
  102                     &identify.header, sizeof(identify),
  103                     XS_CTL_DISCOVERY | XS_CTL_DATA_ONSTACK,
  104                     ST_RETRIES, ST_CTL_TIME);
  105                 if (error) {
  106                         printf("onstream set identify: error %d\n", error);
  107                         return;
  108                 }
  109         }
  110 
  111         st->ops = st_atapibus_ops;
  112         stattach(parent, st, aux);
  113 }
  114 
  115 static int
  116 st_atapibus_ops(struct st_softc *st, int op, int flags)
  117 {
  118         switch(op) {
  119         case ST_OPS_RBL:
  120                 /* done in mode_sense */
  121                 return 0;
  122         case ST_OPS_MODESENSE:
  123                 return st_atapibus_mode_sense(st, flags);
  124         case ST_OPS_MODESELECT:
  125                 return st_atapibus_mode_select(st, flags);
  126         case ST_OPS_CMPRSS_ON:
  127         case ST_OPS_CMPRSS_OFF:
  128                 return ENODEV;
  129         default:
  130                 panic("st_scsibus_ops: invalid op");
  131                 /* NOTREACHED */
  132         }
  133 }
  134 
  135 static int
  136 st_atapibus_mode_sense(struct st_softc *st, int flags)
  137 {
  138         int count, error;
  139         struct atapi_cappage cappage;
  140         struct scsipi_periph *periph = st->sc_periph;
  141 
  142         /* get drive capabilities, some drives needs this repeated */
  143         for (count = 0 ; count < 5 ; count++) {
  144                 error = scsipi_mode_sense(periph, SMS_DBD,
  145                     ATAPI_TAPE_CAP_PAGE, &cappage.header, sizeof(cappage),
  146                     flags | XS_CTL_DATA_ONSTACK, ST_RETRIES, ST_CTL_TIME);
  147                 if (error == 0) {
  148                         st->numblks = 0; /* unused anyway */
  149                         if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK32K)
  150                                 st->media_blksize = 32768;
  151                         else if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK1K)
  152                                 st->media_blksize = 1024;
  153                         else if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK512)
  154                                 st->media_blksize = 512;
  155                         else {
  156                                 error = ENODEV;
  157                                 continue;
  158                         }
  159                         st->blkmin = st->blkmax = st->media_blksize;
  160                         st->media_density = 0;
  161                         if (cappage.header.dev_spec & SMH_DSP_WRITE_PROT)
  162                                 st->flags |= ST_READONLY;
  163                         else
  164                                 st->flags &= ~ST_READONLY;
  165                         SC_DEBUG(periph, SCSIPI_DB3,
  166                             ("density code %d, %d-byte blocks, write-%s, ",
  167                             st->media_density, st->media_blksize,
  168                             st->flags & ST_READONLY ? "protected" : "enabled"));
  169                         SC_DEBUG(periph, SCSIPI_DB3,
  170                             ("%sbuffered\n",
  171                             cappage.header.dev_spec & SMH_DSP_BUFF_MODE ?
  172                             "" : "un"));
  173                         periph->periph_flags |= PERIPH_MEDIA_LOADED;
  174                         return 0;
  175                 }
  176         }
  177         return error;
  178 }
  179 
  180 static int
  181 st_atapibus_mode_select(struct st_softc *st, int flags)
  182 {
  183         return ENODEV; /* for now ... */
  184 }

Cache object: bf4c9a44b58cb15e83934f047c8f3177


[ 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.