Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci port ips(4) driver from OpenBSD; needs a lot mor...



details:   https://anonhg.NetBSD.org/src/rev/6a503e50a815
branches:  trunk
changeset: 828223:6a503e50a815
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sun Dec 03 14:26:38 2017 +0000

description:
port ips(4) driver from OpenBSD; needs a lot more work, right now just compilable

diffstat:

 sys/dev/pci/files.pci |     7 +-
 sys/dev/pci/ips.c     |  2013 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 2019 insertions(+), 1 deletions(-)

diffs (truncated from 2038 to 300 lines):

diff -r c6616cbf617b -r 6a503e50a815 sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Sun Dec 03 13:31:45 2017 +0000
+++ b/sys/dev/pci/files.pci     Sun Dec 03 14:26:38 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.391 2017/09/05 08:01:43 skrll Exp $
+#      $NetBSD: files.pci,v 1.392 2017/12/03 14:26:38 jdolecek Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -107,6 +107,11 @@
 attach aac at pci with aac_pci
 file   dev/pci/aac_pci.c               aac_pci
 
+# IBM ServeRAID RAID controllers
+device  ips: scsi
+attach  ips at pci
+file    dev/pci/ips.c                   ips
+
 # DPT EATA SCSI controllers
 attach dpt at pci with dpt_pci
 file   dev/pci/dpt_pci.c               dpt_pci
diff -r c6616cbf617b -r 6a503e50a815 sys/dev/pci/ips.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/ips.c Sun Dec 03 14:26:38 2017 +0000
@@ -0,0 +1,2013 @@
+/*     $NetBSD: ips.c,v 1.1 2017/12/03 14:26:38 jdolecek Exp $ */
+/*     $OpenBSD: ips.c,v 1.113 2016/08/14 04:08:03 dlg Exp $   */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * 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. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/*
+ * Copyright (c) 2006, 2007, 2009 Alexander Yurchenko <grange%openbsd.org@localhost>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * IBM (Adaptec) ServeRAID controllers driver.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ips.c,v 1.1 2017/12/03 14:26:38 jdolecek Exp $");
+
+#include "bio.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/queue.h>
+#include <sys/buf.h>
+#include <sys/endian.h>
+#include <sys/conf.h>
+#include <sys/malloc.h>
+#include <sys/ioctl.h>
+#include <sys/kthread.h>
+
+#include <sys/bus.h>
+#include <sys/intr.h>
+
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsi_disk.h>
+#include <dev/scsipi/scsipi_disk.h>
+#include <dev/scsipi/scsiconf.h>
+
+#include <dev/biovar.h>
+#include <dev/sysmon/sysmonvar.h>
+#include <sys/envsys.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+/* Debug levels */
+#define IPS_D_ERR      0x0001  /* errors */
+#define IPS_D_INFO     0x0002  /* information */
+#define IPS_D_XFER     0x0004  /* transfers */
+
+#ifdef IPS_DEBUG
+#define DPRINTF(a, b)  do { if (ips_debug & (a)) printf b; } while (0)
+int ips_debug = IPS_D_ERR;
+#else
+#define DPRINTF(a, b)
+#endif
+
+#define IPS_MAXDRIVES          8
+#define IPS_MAXCHANS           4
+#define IPS_MAXTARGETS         16
+#define IPS_MAXCHUNKS          16
+#define IPS_MAXCMDS            128
+
+#define IPS_MAXFER             (64 * 1024)
+#define IPS_MAXSGS             16
+#define IPS_MAXCDB             12
+
+#define IPS_SECSZ              512
+#define IPS_NVRAMPGSZ          128
+#define IPS_SQSZ               (IPS_MAXCMDS * sizeof(u_int32_t))
+
+#define        IPS_TIMEOUT             60000   /* ms */
+
+/* Command codes */
+#define IPS_CMD_READ           0x02
+#define IPS_CMD_WRITE          0x03
+#define IPS_CMD_DCDB           0x04
+#define IPS_CMD_GETADAPTERINFO 0x05
+#define IPS_CMD_FLUSH          0x0a
+#define IPS_CMD_REBUILDSTATUS  0x0c
+#define IPS_CMD_SETSTATE       0x10
+#define IPS_CMD_REBUILD                0x16
+#define IPS_CMD_ERRORTABLE     0x17
+#define IPS_CMD_GETDRIVEINFO   0x19
+#define IPS_CMD_RESETCHAN      0x1a
+#define IPS_CMD_DOWNLOAD       0x20
+#define IPS_CMD_RWBIOSFW       0x22
+#define IPS_CMD_READCONF       0x38
+#define IPS_CMD_GETSUBSYS      0x40
+#define IPS_CMD_CONFIGSYNC     0x58
+#define IPS_CMD_READ_SG                0x82
+#define IPS_CMD_WRITE_SG       0x83
+#define IPS_CMD_DCDB_SG                0x84
+#define IPS_CMD_EDCDB          0x95
+#define IPS_CMD_EDCDB_SG       0x96
+#define IPS_CMD_RWNVRAMPAGE    0xbc
+#define IPS_CMD_GETVERINFO     0xc6
+#define IPS_CMD_FFDC           0xd7
+#define IPS_CMD_SG             0x80
+#define IPS_CMD_RWNVRAM                0xbc
+
+/* DCDB attributes */
+#define IPS_DCDB_DATAIN                0x01    /* data input */
+#define IPS_DCDB_DATAOUT       0x02    /* data output */
+#define IPS_DCDB_XFER64K       0x08    /* 64K transfer */
+#define IPS_DCDB_TIMO10                0x10    /* 10 secs timeout */
+#define IPS_DCDB_TIMO60                0x20    /* 60 secs timeout */
+#define IPS_DCDB_TIMO20M       0x30    /* 20 mins timeout */
+#define IPS_DCDB_NOAUTOREQSEN  0x40    /* no auto request sense */
+#define IPS_DCDB_DISCON                0x80    /* disconnect allowed */
+
+/* Register definitions */
+#define IPS_REG_HIS            0x08    /* host interrupt status */
+#define IPS_REG_HIS_SCE                        0x01    /* status channel enqueue */
+#define IPS_REG_HIS_EN                 0x80    /* enable interrupts */
+#define IPS_REG_CCSA           0x10    /* command channel system address */
+#define IPS_REG_CCC            0x14    /* command channel control */
+#define IPS_REG_CCC_SEM                        0x0008  /* semaphore */
+#define IPS_REG_CCC_START              0x101a  /* start command */
+#define IPS_REG_SQH            0x20    /* status queue head */
+#define IPS_REG_SQT            0x24    /* status queue tail */
+#define IPS_REG_SQE            0x28    /* status queue end */
+#define IPS_REG_SQS            0x2c    /* status queue start */
+
+#define IPS_REG_OIS            0x30    /* outbound interrupt status */
+#define IPS_REG_OIS_PEND               0x0008  /* interrupt is pending */
+#define IPS_REG_OIM            0x34    /* outbound interrupt mask */
+#define IPS_REG_OIM_DS                 0x0008  /* disable interrupts */
+#define IPS_REG_IQP            0x40    /* inbound queue port */
+#define IPS_REG_OQP            0x44    /* outbound queue port */
+
+/* Status word fields */
+#define IPS_STAT_ID(x)         (((x) >> 8) & 0xff)     /* command id */
+#define IPS_STAT_BASIC(x)      (((x) >> 16) & 0xff)    /* basic status */
+#define IPS_STAT_EXT(x)                (((x) >> 24) & 0xff)    /* ext status */
+#define IPS_STAT_GSC(x)                ((x) & 0x0f)
+
+/* Basic status codes */
+#define IPS_STAT_OK            0x00    /* success */
+#define IPS_STAT_RECOV         0x01    /* recovered error */
+#define IPS_STAT_INVOP         0x03    /* invalid opcode */
+#define IPS_STAT_INVCMD                0x04    /* invalid command block */
+#define IPS_STAT_INVPARM       0x05    /* invalid parameters block */
+#define IPS_STAT_BUSY          0x08    /* busy */
+#define IPS_STAT_CMPLERR       0x0c    /* completed with error */
+#define IPS_STAT_LDERR         0x0d    /* logical drive error */
+#define IPS_STAT_TIMO          0x0e    /* timeout */
+#define IPS_STAT_PDRVERR       0x0f    /* physical drive error */
+
+/* Extended status codes */
+#define IPS_ESTAT_SELTIMO      0xf0    /* select timeout */
+#define IPS_ESTAT_OURUN                0xf2    /* over/underrun */
+#define IPS_ESTAT_HOSTRST      0xf7    /* host reset */
+#define IPS_ESTAT_DEVRST       0xf8    /* device reset */
+#define IPS_ESTAT_RECOV                0xfc    /* recovered error */
+#define IPS_ESTAT_CKCOND       0xff    /* check condition */
+
+#define IPS_IOSIZE             128     /* max space size to map */
+
+/* Command frame */
+struct ips_cmd {
+       u_int8_t        code;
+       u_int8_t        id;
+       u_int8_t        drive;
+       u_int8_t        sgcnt;
+       u_int32_t       lba;
+       u_int32_t       sgaddr;
+       u_int16_t       seccnt;
+       u_int8_t        seg4g;
+       u_int8_t        esg;
+       u_int32_t       ccsar;
+       u_int32_t       cccr;
+};
+
+/* Direct CDB (SCSI pass-through) frame */
+struct ips_dcdb {
+       u_int8_t        device;
+       u_int8_t        attr;
+       u_int16_t       datalen;
+       u_int32_t       sgaddr;
+       u_int8_t        cdblen;
+       u_int8_t        senselen;
+       u_int8_t        sgcnt;
+       u_int8_t        __reserved1;
+       u_int8_t        cdb[IPS_MAXCDB];
+       u_int8_t        sense[64];
+       u_int8_t        status;
+       u_int8_t        __reserved2[3];
+};
+
+/* Scatter-gather array element */
+struct ips_sg {
+       u_int32_t       addr;
+       u_int32_t       size;
+};
+
+/* Command block */
+struct ips_cmdb {
+       struct ips_cmd  cmd;
+       struct ips_dcdb dcdb;
+       struct ips_sg   sg[IPS_MAXSGS];
+};
+
+/* Data frames */
+struct ips_adapterinfo {
+       u_int8_t        drivecnt;
+       u_int8_t        miscflag;
+       u_int8_t        sltflag;
+       u_int8_t        bstflag;
+       u_int8_t        pwrchgcnt;
+       u_int8_t        wrongaddrcnt;
+       u_int8_t        unidentcnt;
+       u_int8_t        nvramdevchgcnt;
+       u_int8_t        firmware[8];
+       u_int8_t        bios[8];
+       u_int32_t       drivesize[IPS_MAXDRIVES];
+       u_int8_t        cmdcnt;
+       u_int8_t        maxphysdevs;
+       u_int16_t       flashrepgmcnt;
+       u_int8_t        defunctdiskcnt;
+       u_int8_t        rebuildflag;
+       u_int8_t        offdrivecnt;
+       u_int8_t        critdrivecnt;
+       u_int16_t       confupdcnt;
+       u_int8_t        blkflag;
+       u_int8_t        __reserved;
+       u_int16_t       deaddisk[IPS_MAXCHANS][IPS_MAXTARGETS];
+};
+
+struct ips_driveinfo {
+       u_int8_t        drivecnt;
+       u_int8_t        __reserved[3];
+       struct ips_drive {
+               u_int8_t        id;
+               u_int8_t        __reserved;
+               u_int8_t        raid;
+               u_int8_t        state;



Home | Main Index | Thread Index | Old Index