Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/scsipi add SES driver



details:   https://anonhg.NetBSD.org/src/rev/0e4bd7d75a49
branches:  trunk
changeset: 480803:0e4bd7d75a49
user:      mjacob <mjacob%NetBSD.org@localhost>
date:      Thu Jan 20 17:07:41 2000 +0000

description:
add SES driver

diffstat:

 sys/dev/scsipi/ses.c |  2403 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/scsipi/ses.h |   174 +++
 2 files changed, 2577 insertions(+), 0 deletions(-)

diffs (truncated from 2585 to 300 lines):

diff -r fc5d796cdc0d -r 0e4bd7d75a49 sys/dev/scsipi/ses.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/scsipi/ses.c      Thu Jan 20 17:07:41 2000 +0000
@@ -0,0 +1,2403 @@
+/*     $NetBSD: ses.c,v 1.1 2000/01/20 17:07:41 mjacob Exp $ */
+/*
+ * Copyright (C) 2000 National Aeronautics & Space Administration
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author:     mjacob%nas.nasa.gov@localhost
+ */
+
+
+#include "opt_scsi.h"
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/scsiio.h>
+#include <sys/buf.h>
+#include <sys/uio.h>
+#include <sys/malloc.h>
+#include <sys/errno.h>
+#include <sys/device.h>
+#include <sys/disklabel.h>
+#include <sys/disk.h>
+#include <sys/proc.h>
+#include <sys/conf.h>
+#include <sys/vnode.h>
+#include <machine/stdarg.h>
+
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsipi_disk.h>
+#include <dev/scsipi/scsi_disk.h>
+#include <dev/scsipi/scsiconf.h>
+#include <dev/scsipi/ses.h>
+
+/*
+ * Platform Independent Driver Internal Definitions for SES devices.
+ */
+typedef enum {
+       SES_NONE,
+       SES_SES_SCSI2,
+       SES_SES,
+       SES_SES_PASSTHROUGH,
+       SES_SEN,
+       SES_SAFT
+} enctyp;
+
+struct ses_softc;
+typedef struct ses_softc ses_softc_t;
+typedef struct {
+       int (*softc_init)       __P((ses_softc_t *, int));
+       int (*init_enc)         __P((ses_softc_t *));
+       int (*get_encstat)      __P((ses_softc_t *, int));
+       int (*set_encstat)      __P((ses_softc_t *, ses_encstat, int));
+       int (*get_objstat)      __P((ses_softc_t *, ses_objstat *, int));
+       int (*set_objstat)      __P((ses_softc_t *, ses_objstat *, int));
+} encvec;
+
+#define        ENCI_SVALID     0x80
+
+typedef struct {
+       uint32_t
+               enctype : 8,            /* enclosure type */
+               subenclosure : 8,       /* subenclosure id */
+               svalid  : 1,            /* enclosure information valid */
+               priv    : 15;           /* private data, per object */
+       uint8_t encstat[4];     /* state && stats */
+} encobj;
+
+#define        SEN_ID          "UNISYS           SUN_SEN"
+#define        SEN_ID_LEN      24
+
+
+static enctyp ses_type __P((void *, int));
+
+
+/* Forward reference to Enclosure Functions */
+static int ses_softc_init __P((ses_softc_t *, int));
+static int ses_init_enc __P((ses_softc_t *));
+static int ses_get_encstat __P((ses_softc_t *, int));
+static int ses_set_encstat __P((ses_softc_t *, uint8_t, int));
+static int ses_get_objstat __P((ses_softc_t *, ses_objstat *, int));
+static int ses_set_objstat __P((ses_softc_t *, ses_objstat *, int));
+
+static int safte_softc_init __P((ses_softc_t *, int));
+static int safte_init_enc __P((ses_softc_t *));
+static int safte_get_encstat __P((ses_softc_t *, int));
+static int safte_set_encstat __P((ses_softc_t *, uint8_t, int));
+static int safte_get_objstat __P((ses_softc_t *, ses_objstat *, int));
+static int safte_set_objstat __P((ses_softc_t *, ses_objstat *, int));
+
+/*
+ * Platform implementation defines/functions for SES internal kernel stuff
+ */
+
+#define        STRNCMP                 strncmp
+#define        PRINTF                  printf
+#define        SES_LOG                 ses_log
+#if    defined(DEBUG) || defined(SCSIDEBUG)
+#define        SES_VLOG                ses_log
+#else
+#define        SES_VLOG                if (0) ses_log
+#endif
+#define        SES_MALLOC(amt)         malloc(amt, M_DEVBUF, M_NOWAIT)
+#define        SES_FREE(ptr, amt)      free(ptr, M_DEVBUF)
+#define        MEMZERO                 bzero
+#define        MEMCPY(dest, src, amt)  bcopy(src, dest, amt)
+#define        RECEIVE_DIAGNOSTIC      0x1c
+#define        SEND_DIAGNOSTIC         0x1d
+#define        WRITE_BUFFER            0x3b
+#define        READ_BUFFER             0x3c
+
+int sesopen __P((dev_t, int, int, struct proc *));
+int sesclose __P((dev_t, int, int, struct proc *));
+int sesioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
+
+static int ses_runcmd  __P((struct ses_softc *, char *, int, char *, int *));
+static void ses_log    __P((struct ses_softc *, const char *, ...));
+
+/*
+ * General NetBSD kernel stuff.
+ */
+
+struct ses_softc {
+       struct device   sc_device;
+       struct scsipi_link *sc_link;
+       enctyp          ses_type;       /* type of enclosure */
+       encvec          ses_vec;        /* vector to handlers */
+       void *          ses_private;    /* per-type private data */
+       encobj *        ses_objmap;     /* objects */
+       u_int32_t       ses_nobjects;   /* number of objects */
+       ses_encstat     ses_encstat;    /* overall status */
+       u_int8_t        ses_flags;
+};
+#define        SES_FLAG_INVALID        0x01
+#define        SES_FLAG_OPEN           0x02
+#define        SES_FLAG_INITIALIZED    0x04
+
+#define SESUNIT(x)       (minor((x)))
+
+static int ses_match __P((struct device *, struct cfdata *, void *));
+static void ses_attach __P((struct device *, struct device *, void *));
+static enctyp ses_device_type __P((struct scsipibus_attach_args *));
+
+struct cfattach ses_ca = {
+       sizeof (struct ses_softc), ses_match, ses_attach
+};
+extern struct cfdriver ses_cd;
+
+struct scsipi_device ses_switch = {
+       NULL,
+       NULL,
+       NULL,
+       NULL
+};
+
+
+int
+ses_match(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+       struct scsipibus_attach_args *sa = aux;
+       switch (ses_device_type(sa)) {
+       case SES_SES:
+       case SES_SES_SCSI2:
+       case SES_SES_PASSTHROUGH:
+       case SES_SEN:
+       case SES_SAFT:
+               return (1);
+       default:
+               return (0);
+       }
+}
+
+
+/*
+ * Complete the attachment.
+ *
+ * We have to repeat the rerun of INQUIRY data as above because
+ * it's not until the return from the match routine that we have
+ * the softc available to set stuff in.
+ */
+void
+ses_attach(parent, self, aux)
+       struct device *parent;
+       struct device *self;
+       void *aux;
+{
+       char *tname;
+       struct ses_softc *softc = (void *)self;
+       struct scsipibus_attach_args *sa = aux;
+       struct scsipi_link *sc_link = sa->sa_sc_link;
+
+       SC_DEBUG(sc_link, SDEV_DB2, ("ssattach: "));
+       softc->sc_link = sa->sa_sc_link;
+       sc_link->device = &ses_switch;
+       sc_link->device_softc = softc;
+       sc_link->openings = 1;
+
+       softc->ses_type = ses_device_type(sa);
+       switch (softc->ses_type) {
+       case SES_SES:
+       case SES_SES_SCSI2:
+        case SES_SES_PASSTHROUGH:
+               softc->ses_vec.softc_init = ses_softc_init;
+               softc->ses_vec.init_enc = ses_init_enc;
+               softc->ses_vec.get_encstat = ses_get_encstat;
+               softc->ses_vec.set_encstat = ses_set_encstat;
+               softc->ses_vec.get_objstat = ses_get_objstat;
+               softc->ses_vec.set_objstat = ses_set_objstat;
+               break;
+        case SES_SAFT:
+               softc->ses_vec.softc_init = safte_softc_init;
+               softc->ses_vec.init_enc = safte_init_enc;
+               softc->ses_vec.get_encstat = safte_get_encstat;
+               softc->ses_vec.set_encstat = safte_set_encstat;
+               softc->ses_vec.get_objstat = safte_get_objstat;
+               softc->ses_vec.set_objstat = safte_set_objstat;
+               break;
+        case SES_SEN:
+               break;
+       case SES_NONE:
+       default:
+               break;
+       }
+
+       switch (softc->ses_type) {
+       default:
+       case SES_NONE:
+               tname = "No SES device";
+               break;
+       case SES_SES_SCSI2:
+               tname = "SCSI-2 SES Device";
+               break;
+       case SES_SES:
+               tname = "SCSI-3 SES Device";
+               break;
+        case SES_SES_PASSTHROUGH:
+               tname = "SES Passthrough Device";
+               break;
+        case SES_SEN:
+               tname = "UNISYS SEN Device (NOT HANDLED YET)";
+               break;
+        case SES_SAFT:
+               tname = "SAF-TE Compliant Device";
+               break;
+       }
+       printf("\n%s: %s\n", softc->sc_device.dv_xname, tname);
+}
+
+static enctyp
+ses_device_type(sa)
+       struct scsipibus_attach_args *sa;
+{
+       struct scsipi_inquiry_data *inqp = sa->sa_inqptr;
+       int length;
+ 
+       if (inqp == NULL)
+               return (SES_NONE);
+
+       /*
+        * If we can get longer data to check for the
+        * presence of a  SAF-TE device, try and do so.
+        *
+        * Because we do deferred target attach in NetBSD,
+        * we don't have to run this as a polled command.
+        */
+
+#define        MORESZ  64
+       if (inqp->additional_length > MORESZ-4) {
+               struct scsipi_generic cmd;
+               static u_char more[MORESZ];



Home | Main Index | Thread Index | Old Index