Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-2]: src/sys/dev Pull up following revision(s) (requested by he in...
details: https://anonhg.NetBSD.org/src/rev/1289c6318dbe
branches: netbsd-2
changeset: 564455:1289c6318dbe
user: riz <riz%NetBSD.org@localhost>
date: Tue Apr 11 01:15:22 2006 +0000
description:
Pull up following revision(s) (requested by he in ticket #10409):
sys/dev/ic/cissreg.h: revision 1.1
sys/dev/pci/ciss_pci.c: revision 1.1
sys/dev/ic/cissvar.h: revision 1.1
sys/dev/pci/files.pci: revision 1.245
sys/dev/ic/ciss.c: revision 1.1 via patch
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
diffstat:
sys/dev/ic/ciss.c | 1041 ++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/ic/cissreg.h | 217 ++++++++++
sys/dev/ic/cissvar.h | 68 +++
sys/dev/pci/ciss_pci.c | 351 ++++++++++++++++
sys/dev/pci/files.pci | 6 +-
5 files changed, 1682 insertions(+), 1 deletions(-)
diffs (truncated from 1713 to 300 lines):
diff -r 65cba4128ed1 -r 1289c6318dbe sys/dev/ic/ciss.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/ciss.c Tue Apr 11 01:15:22 2006 +0000
@@ -0,0 +1,1041 @@
+/* $NetBSD: ciss.c,v 1.1.6.2 2006/04/11 01:15:22 riz Exp $ */
+/* $OpenBSD: ciss.c,v 1.13 2006/02/02 22:13:04 brad Exp $ */
+
+/*
+ * Copyright (c) 2005 Michael Shalayeff
+ * All rights reserved.
+ *
+ * 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 MIND, 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.1.6.2 2006/04/11 01:15:22 riz Exp $");
+
+/* #define CISS_DEBUG */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/buf.h>
+#include <sys/ioctl.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/proc.h>
+#include <sys/kthread.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/bus.h>
+
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsi_disk.h>
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsiconf.h>
+
+#include <dev/ic/cissreg.h>
+#include <dev/ic/cissvar.h>
+
+#ifdef CISS_DEBUG
+#define CISS_DPRINTF(m,a) if (ciss_debug & (m)) printf a
+#define CISS_D_CMD 0x0001
+#define CISS_D_INTR 0x0002
+#define CISS_D_MISC 0x0004
+#define CISS_D_DMA 0x0008
+#define CISS_D_IOCTL 0x0010
+#define CISS_D_ERR 0x0020
+int ciss_debug = 0
+ | CISS_D_CMD
+ | CISS_D_INTR
+ | CISS_D_MISC
+ | CISS_D_DMA
+ | CISS_D_IOCTL
+ | CISS_D_ERR
+ ;
+#else
+#define CISS_DPRINTF(m,a) /* m, a */
+#endif
+
+/*
+ * Portability for older SCSIPI infrastructure, as found on netbsd-2.
+ */
+#ifndef SSD_RCODE_CURRENT
+#define SSD_RCODE_CURRENT 0x70
+#define SSD_RCODE_VALID SSD_ERRCODE_VALID
+#define response_code error_code
+#define asc add_sense_code
+#define ascq add_sense_code_qual
+#endif /* SSD_RCODE_CURRENT */
+
+static void ciss_scsi_cmd(struct scsipi_channel *chan,
+ scsipi_adapter_req_t req, void *arg);
+static int ciss_scsi_ioctl(struct scsipi_channel *chan, u_long cmd,
+ caddr_t addr, int flag, struct proc *p);
+static void cissminphys(struct buf *bp);
+
+#if 0
+static void ciss_scsi_raw_cmd(struct scsipi_channel *chan,
+ scsipi_adapter_req_t req, void *arg);
+#endif
+
+#if NBIO > 0
+static int ciss_ioctl(struct device *, u_long, caddr_t);
+#endif
+static int ciss_sync(struct ciss_softc *sc);
+static void ciss_heartbeat(void *v);
+static void ciss_shutdown(void *v);
+#if 0
+static void ciss_kthread(void *v);
+#endif
+
+static struct ciss_ccb *ciss_get_ccb(struct ciss_softc *sc);
+static void ciss_put_ccb(struct ciss_ccb *ccb);
+static int ciss_cmd(struct ciss_ccb *ccb, int flags, int wait);
+static int ciss_done(struct ciss_ccb *ccb);
+static int ciss_error(struct ciss_ccb *ccb);
+static int ciss_inq(struct ciss_softc *sc, struct ciss_inquiry *inq);
+static int ciss_ldmap(struct ciss_softc *sc);
+
+static struct ciss_ccb *
+ciss_get_ccb(struct ciss_softc *sc)
+{
+ struct ciss_ccb *ccb;
+
+ if ((ccb = TAILQ_LAST(&sc->sc_free_ccb, ciss_queue_head))) {
+ TAILQ_REMOVE(&sc->sc_free_ccb, ccb, ccb_link);
+ ccb->ccb_state = CISS_CCB_READY;
+ }
+ return ccb;
+}
+
+static void
+ciss_put_ccb(struct ciss_ccb *ccb)
+{
+ struct ciss_softc *sc = ccb->ccb_sc;
+
+ ccb->ccb_state = CISS_CCB_FREE;
+ TAILQ_INSERT_TAIL(&sc->sc_free_ccb, ccb, ccb_link);
+}
+
+int
+ciss_attach(struct ciss_softc *sc)
+{
+ struct ciss_ccb *ccb;
+ struct ciss_cmd *cmd;
+ struct ciss_inquiry *inq;
+ bus_dma_segment_t seg[1];
+ int error, i, total, rseg, maxfer;
+ ciss_lock_t lock;
+ paddr_t pa;
+
+ bus_space_read_region_4(sc->sc_iot, sc->cfg_ioh, sc->cfgoff,
+ (u_int32_t *)&sc->cfg, sizeof(sc->cfg) / 4);
+
+ if (sc->cfg.signature != CISS_SIGNATURE) {
+ printf(": bad sign 0x%08x\n", sc->cfg.signature);
+ return -1;
+ }
+
+ if (!(sc->cfg.methods & CISS_METH_SIMPL)) {
+ printf(": not simple 0x%08x\n", sc->cfg.methods);
+ return -1;
+ }
+
+ sc->cfg.rmethod = CISS_METH_SIMPL;
+ sc->cfg.paddr_lim = 0; /* 32bit addrs */
+ sc->cfg.int_delay = 0; /* disable coalescing */
+ sc->cfg.int_count = 0;
+ strlcpy(sc->cfg.hostname, "HUMPPA", sizeof(sc->cfg.hostname));
+ sc->cfg.driverf |= CISS_DRV_PRF; /* enable prefetch */
+ if (!sc->cfg.maxsg)
+ sc->cfg.maxsg = MAXPHYS / PAGE_SIZE + 1;
+
+ bus_space_write_region_4(sc->sc_iot, sc->cfg_ioh, sc->cfgoff,
+ (u_int32_t *)&sc->cfg, sizeof(sc->cfg) / 4);
+ bus_space_barrier(sc->sc_iot, sc->cfg_ioh, sc->cfgoff, sizeof(sc->cfg),
+ BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE);
+
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, CISS_IDB, CISS_IDB_CFG);
+ bus_space_barrier(sc->sc_iot, sc->sc_ioh, CISS_IDB, 4,
+ BUS_SPACE_BARRIER_WRITE);
+ for (i = 1000; i--; DELAY(1000)) {
+ /* XXX maybe IDB is really 64bit? - hp dl380 needs this */
+ (void)bus_space_read_4(sc->sc_iot, sc->sc_ioh, CISS_IDB + 4);
+ if (!(bus_space_read_4(sc->sc_iot, sc->sc_ioh, CISS_IDB) & CISS_IDB_CFG))
+ break;
+ bus_space_barrier(sc->sc_iot, sc->sc_ioh, CISS_IDB, 4,
+ BUS_SPACE_BARRIER_READ);
+ }
+
+ if (bus_space_read_4(sc->sc_iot, sc->sc_ioh, CISS_IDB) & CISS_IDB_CFG) {
+ printf(": cannot set config\n");
+ return -1;
+ }
+
+ bus_space_read_region_4(sc->sc_iot, sc->cfg_ioh, sc->cfgoff,
+ (u_int32_t *)&sc->cfg, sizeof(sc->cfg) / 4);
+
+ if (!(sc->cfg.amethod & CISS_METH_SIMPL)) {
+ printf(": cannot simplify 0x%08x\n", sc->cfg.amethod);
+ return -1;
+ }
+
+ /* i'm ready for you and i hope you're ready for me */
+ for (i = 30000; i--; DELAY(1000)) {
+ if (bus_space_read_4(sc->sc_iot, sc->cfg_ioh, sc->cfgoff +
+ offsetof(struct ciss_config, amethod)) & CISS_METH_READY)
+ break;
+ bus_space_barrier(sc->sc_iot, sc->cfg_ioh, sc->cfgoff +
+ offsetof(struct ciss_config, amethod), 4,
+ BUS_SPACE_BARRIER_READ);
+ }
+
+ if (!(bus_space_read_4(sc->sc_iot, sc->cfg_ioh, sc->cfgoff +
+ offsetof(struct ciss_config, amethod)) & CISS_METH_READY)) {
+ printf(": she never came ready for me 0x%08x\n",
+ sc->cfg.amethod);
+ return -1;
+ }
+
+ sc->maxcmd = sc->cfg.maxcmd;
+ sc->maxsg = sc->cfg.maxsg;
+ if (sc->maxsg > MAXPHYS / PAGE_SIZE + 1)
+ sc->maxsg = MAXPHYS / PAGE_SIZE + 1;
+ i = sizeof(struct ciss_ccb) +
+ sizeof(ccb->ccb_cmd.sgl[0]) * (sc->maxsg - 1);
+ for (sc->ccblen = 0x10; sc->ccblen < i; sc->ccblen <<= 1);
+
+ total = sc->ccblen * sc->maxcmd;
+ if ((error = bus_dmamem_alloc(sc->sc_dmat, total, PAGE_SIZE, 0,
+ sc->cmdseg, 1, &rseg, BUS_DMA_NOWAIT))) {
+ printf(": cannot allocate CCBs (%d)\n", error);
+ return -1;
+ }
+
+ if ((error = bus_dmamem_map(sc->sc_dmat, sc->cmdseg, rseg, total,
+ (caddr_t *)&sc->ccbs, BUS_DMA_NOWAIT))) {
+ printf(": cannot map CCBs (%d)\n", error);
+ return -1;
+ }
+ bzero(sc->ccbs, total);
+
+ if ((error = bus_dmamap_create(sc->sc_dmat, total, 1,
+ total, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &sc->cmdmap))) {
+ printf(": cannot create CCBs dmamap (%d)\n", error);
+ bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
+ return -1;
+ }
+
+ if ((error = bus_dmamap_load(sc->sc_dmat, sc->cmdmap, sc->ccbs, total,
+ NULL, BUS_DMA_NOWAIT))) {
+ printf(": cannot load CCBs dmamap (%d)\n", error);
+ bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
+ bus_dmamap_destroy(sc->sc_dmat, sc->cmdmap);
+ return -1;
+ }
+
+ TAILQ_INIT(&sc->sc_ccbq);
+ TAILQ_INIT(&sc->sc_ccbdone);
+ TAILQ_INIT(&sc->sc_free_ccb);
+
+ maxfer = sc->maxsg * PAGE_SIZE;
+ for (i = 0; total > 0 && i < sc->maxcmd; i++, total -= sc->ccblen) {
+ ccb = (struct ciss_ccb *) (sc->ccbs + i * sc->ccblen);
+ cmd = &ccb->ccb_cmd;
+ pa = sc->cmdseg[0].ds_addr + i * sc->ccblen;
+
+ ccb->ccb_sc = sc;
+ ccb->ccb_cmdpa = pa + offsetof(struct ciss_ccb, ccb_cmd);
+ ccb->ccb_state = CISS_CCB_FREE;
+
+ cmd->id = htole32(i << 2);
+ cmd->id_hi = htole32(0);
+ cmd->sgin = sc->maxsg;
+ cmd->sglen = htole16((u_int16_t)cmd->sgin);
+ cmd->err_len = htole32(sizeof(ccb->ccb_err));
+ pa += offsetof(struct ciss_ccb, ccb_err);
+ cmd->err_pa = htole64((u_int64_t)pa);
+
+ if ((error = bus_dmamap_create(sc->sc_dmat, maxfer, sc->maxsg,
+ maxfer, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
+ &ccb->ccb_dmamap)))
+ break;
+
+ TAILQ_INSERT_TAIL(&sc->sc_free_ccb, ccb, ccb_link);
+ }
+
+ if (i < sc->maxcmd) {
+ printf(": cannot create ccb#%d dmamap (%d)\n", i, error);
+ if (i == 0) {
+ /* TODO leaking cmd's dmamaps and shitz */
+ bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
+ bus_dmamap_destroy(sc->sc_dmat, sc->cmdmap);
+ return -1;
+ }
+ }
+
+ if ((error = bus_dmamem_alloc(sc->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0,
+ seg, 1, &rseg, BUS_DMA_NOWAIT))) {
+ printf(": cannot allocate scratch buffer (%d)\n", error);
+ return -1;
+ }
+
+ if ((error = bus_dmamem_map(sc->sc_dmat, seg, rseg, PAGE_SIZE,
+ (caddr_t *)&sc->scratch, BUS_DMA_NOWAIT))) {
+ printf(": cannot map scratch buffer (%d)\n", error);
+ return -1;
+ }
Home |
Main Index |
Thread Index |
Old Index