Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2o Some changes from OpenBSD, and some of my own:



details:   https://anonhg.NetBSD.org/src/rev/39e7b134ed5e
branches:  trunk
changeset: 513587:39e7b134ed5e
user:      ad <ad%NetBSD.org@localhost>
date:      Sat Aug 04 16:54:18 2001 +0000

description:
Some changes from OpenBSD, and some of my own:

- More SCSI port defs.
- Nuke vtophys().
- Release resources in iop_init() upon failure.
- Don't use a message wrapper when initalising the outbound FIFO.
- A couple of field size/endian fixes.
- Just use iop_post() when we don't need special handling.
- IM_DISCARD is now pointless, since we don't queue at the driver level.
- Map data transfers from/to userspace directly.
- A few comment and stylistic changes.

diffstat:

 sys/dev/i2o/i2o.h      |   31 ++++-
 sys/dev/i2o/iop.c      |  318 +++++++++++++++++++++++++++---------------------
 sys/dev/i2o/iopsp.c    |   28 ++-
 sys/dev/i2o/iopspvar.h |    4 +-
 sys/dev/i2o/iopvar.h   |   82 ++++++------
 sys/dev/i2o/ld_iop.c   |   21 +-
 6 files changed, 278 insertions(+), 206 deletions(-)

diffs (truncated from 1120 to 300 lines):

diff -r 84fcc88068f6 -r 39e7b134ed5e sys/dev/i2o/i2o.h
--- a/sys/dev/i2o/i2o.h Sat Aug 04 16:26:49 2001 +0000
+++ b/sys/dev/i2o/i2o.h Sat Aug 04 16:54:18 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2o.h,v 1.5 2001/06/12 15:17:27 wiz Exp $      */
+/*     $NetBSD: i2o.h,v 1.6 2001/08/04 16:54:18 ad Exp $       */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -477,6 +477,35 @@
        u_int32_t       maxnumberofdevices;
 } __attribute__ ((__packed__));
 
+#define        I2O_PARAM_HBA_SCSI_PORT_GENERIC 0x01
+#define        I2O_PARAM_HBA_SCSI_PORT_UNKNOWN 0x02
+#define        I2O_PARAM_HBA_SCSI_PORT_PARINTF 0x03
+#define        I2O_PARAM_HBA_SCSI_PORT_FCL     0x04
+#define        I2O_PARAM_HBA_SCSI_PORT_1394    0x05
+#define        I2O_PARAM_HBA_SCSI_PORT_SSA     0x06
+
+#define        I2O_PARAM_HBA_SCSI_PORT_SE      0x03
+#define        I2O_PARAM_HBA_SCSI_PORT_DIFF    0x04
+#define        I2O_PARAM_HBA_SCSI_PORT_LVD     0x05
+#define        I2O_PARAM_HBA_SCSI_PORT_OPTCL   0x06
+
+#define        I2O_PARAM_HBA_SCSI_PORT_HDBS50  0x04
+#define        I2O_PARAM_HBA_SCSI_PORT_HDBU50  0x05
+#define        I2O_PARAM_HBA_SCSI_PORT_DBS50   0x06
+#define        I2O_PARAM_HBA_SCSI_PORT_DBU50   0x07
+#define        I2O_PARAM_HBA_SCSI_PORT_HDBS68  0x08
+#define        I2O_PARAM_HBA_SCSI_PORT_HDBU68  0x09
+#define        I2O_PARAM_HBA_SCSI_PORT_SCA1    0x0a
+#define        I2O_PARAM_HBA_SCSI_PORT_SCA2    0x0b
+#define        I2O_PARAM_HBA_SCSI_PORT_FCDB9   0x0c
+#define        I2O_PARAM_HBA_SCSI_PORT_FC      0x0d
+#define        I2O_PARAM_HBA_SCSI_PORT_FCSCA40 0x0e
+#define        I2O_PARAM_HBA_SCSI_PORT_FCSCA20 0x0f
+#define        I2O_PARAM_HBA_SCSI_PORT_FCBNC   0x10
+
+#define        I2O_PARAM_HBA_SCSI_PORT_FEMALE  0x03
+#define        I2O_PARAM_HBA_SCSI_PORT_MALE    0x04
+
 #define        I2O_PARAM_HBA_SCSI_CTLR_INFO    0x0200
 struct i2o_param_hba_scsi_ctlr_info {
        u_int8_t        scsitype;
diff -r 84fcc88068f6 -r 39e7b134ed5e sys/dev/i2o/iop.c
--- a/sys/dev/i2o/iop.c Sat Aug 04 16:26:49 2001 +0000
+++ b/sys/dev/i2o/iop.c Sat Aug 04 16:54:18 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iop.c,v 1.14 2001/06/12 15:17:27 wiz Exp $     */
+/*     $NetBSD: iop.c,v 1.15 2001/08/04 16:54:18 ad Exp $      */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -228,8 +228,8 @@
 static void    iop_msg_poll(struct iop_softc *, struct iop_msg *, int);
 static void    iop_msg_wait(struct iop_softc *, struct iop_msg *, int);
 static int     iop_ofifo_init(struct iop_softc *);
-static int     iop_passthrough(struct iop_softc *, struct ioppt *);
-static int     iop_post(struct iop_softc *, u_int32_t *);
+static int     iop_passthrough(struct iop_softc *, struct ioppt *,
+                               struct proc *);
 static void    iop_reconf_thread(void *);
 static void    iop_release_mfa(struct iop_softc *, u_int32_t);
 static int     iop_reset(struct iop_softc *);
@@ -268,25 +268,65 @@
 iop_init(struct iop_softc *sc, const char *intrstr)
 {
        struct iop_msg *im;
-       int rv, i;
+       int rv, i, j, state, nsegs;
        u_int32_t mask;
        char ident[64];
 
+       state = 0;
+
+       printf("I2O adapter");
+
        if (iop_ictxhashtbl == NULL)
                iop_ictxhashtbl = hashinit(IOP_ICTXHASH_NBUCKETS, HASH_LIST,
                    M_DEVBUF, M_NOWAIT, &iop_ictxhash);
 
-       /* Reset the IOP and request status. */
-       printf("I2O adapter");
+       /* Disable interrupts at the IOP. */
+       mask = iop_inl(sc, IOP_REG_INTR_MASK);
+       iop_outl(sc, IOP_REG_INTR_MASK, mask | IOP_INTR_OFIFO);
 
-       if ((rv = iop_reset(sc)) != 0) {
-               printf("%s: not responding (reset)\n", sc->sc_dv.dv_xname);
+       /* Allocate a scratch DMA map for small miscellaneous shared data. */
+       if (bus_dmamap_create(sc->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE, 0,
+           BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &sc->sc_scr_dmamap) != 0) {
+               printf("%s: cannot create scratch dmamap\n",
+                   sc->sc_dv.dv_xname);
                return;
        }
-       if ((rv = iop_status_get(sc, 1)) != 0) {
-               printf("%s: not responding (get status)\n", sc->sc_dv.dv_xname);
-               return;
+       state++;
+
+       if (bus_dmamem_alloc(sc->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0,
+           sc->sc_scr_seg, 1, &nsegs, BUS_DMA_NOWAIT) != 0) {
+               printf("%s: cannot alloc scratch dmamem\n",
+                   sc->sc_dv.dv_xname);
+               goto bail_out;
+       }
+       state++;
+
+       if (bus_dmamem_map(sc->sc_dmat, sc->sc_scr_seg, nsegs, PAGE_SIZE,
+           &sc->sc_scr, 0)) {
+               printf("%s: cannot map scratch dmamem\n", sc->sc_dv.dv_xname);
+               goto bail_out;
        }
+       state++;
+
+       if (bus_dmamap_load(sc->sc_dmat, sc->sc_scr_dmamap, sc->sc_scr,
+           PAGE_SIZE, NULL, BUS_DMA_NOWAIT)) {
+               printf("%s: cannot load scratch dmamap\n", sc->sc_dv.dv_xname);
+               goto bail_out;
+       }
+       state++;
+
+       /* Reset the adapter and request status. */
+       if ((rv = iop_reset(sc)) != 0) {
+               printf("%s: not responding (reset)\n", sc->sc_dv.dv_xname);
+               goto bail_out;
+       }
+
+       if ((rv = iop_status_get(sc, 1)) != 0) {
+               printf("%s: not responding (get status)\n",
+                   sc->sc_dv.dv_xname);
+               goto bail_out;
+       }
+
        sc->sc_flags |= IOP_HAVESTATUS;
        iop_strvis(sc, sc->sc_status.productid, sizeof(sc->sc_status.productid),
            ident, sizeof(ident));
@@ -320,7 +360,7 @@
        sc->sc_ims = im;
        SLIST_INIT(&sc->sc_im_freelist);
 
-       for (i = 0; i < sc->sc_maxib; i++, im++) {
+       for (i = 0, state++; i < sc->sc_maxib; i++, im++) {
                rv = bus_dmamap_create(sc->sc_dmat, IOP_MAX_XFER,
                    IOP_MAX_SEGS, IOP_MAX_XFER, 0,
                    BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
@@ -328,7 +368,7 @@
                if (rv != 0) {
                        printf("%s: couldn't create dmamap (%d)",
                            sc->sc_dv.dv_xname, rv);
-                       return;
+                       goto bail_out;
                }
 
                im->im_tctx = i;
@@ -337,8 +377,9 @@
 
        /* Initalise the IOP's outbound FIFO. */
        if (iop_ofifo_init(sc) != 0) {
-               printf("%s: unable to init oubound FIFO\n", sc->sc_dv.dv_xname);
-               return;
+               printf("%s: unable to init oubound FIFO\n",
+                   sc->sc_dv.dv_xname);
+               goto bail_out;
        }
 
        /*
@@ -367,6 +408,23 @@
 #endif
 
        lockinit(&sc->sc_conflock, PRIBIO, "iopconf", hz * 30, 0);
+       return;
+
+ bail_out:
+       if (state > 3) {
+               for (j = 0; j < i; j++)
+                       bus_dmamap_destroy(sc->sc_dmat,
+                           sc->sc_ims[j].im_xfer[0].ix_map);
+               free(sc->sc_ims, M_DEVBUF);
+       }
+       if (state > 2)
+               bus_dmamap_unload(sc->sc_dmat, sc->sc_scr_dmamap);
+       if (state > 1)
+               bus_dmamem_unmap(sc->sc_dmat, sc->sc_scr, PAGE_SIZE);
+       if (state > 0)
+               bus_dmamem_free(sc->sc_dmat, sc->sc_scr_seg, nsegs);
+       bus_dmamap_destroy(sc->sc_dmat, sc->sc_scr_dmamap);
+
 }
 
 /*
@@ -456,7 +514,7 @@
         */
        sc->sc_eventii.ii_dv = self;
        sc->sc_eventii.ii_intr = iop_intr_event;
-       sc->sc_eventii.ii_flags = II_DISCARD | II_UTILITY;
+       sc->sc_eventii.ii_flags = II_NOTCTX | II_UTILITY;
        sc->sc_eventii.ii_tid = I2O_TID_IOP;
        iop_initiator_register(sc, &sc->sc_eventii);
 
@@ -583,9 +641,9 @@
                        if ((le16toh(le->classid) & 4095) !=
                            I2O_CLASS_BUS_ADAPTER_PORT)
                                continue;
-                       tid = le32toh(le->localtid) & 4095;
+                       tid = le16toh(le->localtid) & 4095;
 
-                       im = iop_msg_alloc(sc, NULL, IM_WAIT);
+                       im = iop_msg_alloc(sc, IM_WAIT);
 
                        mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
                        mf.msgfunc = I2O_MSGFUNC(tid, I2O_HBA_BUS_SCAN);
@@ -692,7 +750,7 @@
 
        nent = sc->sc_nlctent;
        for (i = 0, le = sc->sc_lct->entry; i < nent; i++, le++) {
-               sc->sc_tidmap[i].it_tid = le32toh(le->localtid) & 4095;
+               sc->sc_tidmap[i].it_tid = le16toh(le->localtid) & 4095;
 
                /* Ignore the device if it's in use. */
                usertid = le32toh(le->usertid) & 4095;
@@ -840,26 +898,34 @@
 iop_status_get(struct iop_softc *sc, int nosleep)
 {
        struct i2o_exec_status_get mf;
+       struct i2o_status *st;
+       paddr_t pa;
        int rv, i;
 
+       pa = sc->sc_scr_seg->ds_addr;
+       st = (struct i2o_status *)sc->sc_scr;
+
        mf.msgflags = I2O_MSGFLAGS(i2o_exec_status_get);
        mf.msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_STATUS_GET);
        mf.reserved[0] = 0;
        mf.reserved[1] = 0;
        mf.reserved[2] = 0;
        mf.reserved[3] = 0;
-       mf.addrlow = kvtop((caddr_t)&sc->sc_status);    /* XXX */
-       mf.addrhigh = 0;
+       mf.addrlow = (u_int32_t)pa;
+       mf.addrhigh = (u_int32_t)((u_int64_t)pa >> 32);
        mf.length = sizeof(sc->sc_status);
 
-       memset(&sc->sc_status, 0, sizeof(sc->sc_status));
+       memset(st, 0, sizeof(*st));
+       bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*st),
+           BUS_DMASYNC_PREREAD);
 
        if ((rv = iop_post(sc, (u_int32_t *)&mf)) != 0)
                return (rv);
 
-       /* XXX */
        for (i = 25; i != 0; i--) {
-               if (*((volatile u_char *)&sc->sc_status.syncbyte) == 0xff)
+               bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0,
+                   sizeof(*st), BUS_DMASYNC_POSTREAD);
+               if (st->syncbyte == 0xff)
                        break;
                if (nosleep)
                        DELAY(100*1000);
@@ -867,10 +933,13 @@
                        tsleep(iop_status_get, PWAIT, "iopstat", hz / 10);
        }
 
-       if (*((volatile u_char *)&sc->sc_status.syncbyte) != 0xff)
+       if (st->syncbyte != 0xff)
                rv = EIO;
-       else
+       else {
+               memcpy(&sc->sc_status, st, sizeof(sc->sc_status));
                rv = 0;
+       }
+
        return (rv);
 }
 
@@ -880,44 +949,49 @@
 static int
 iop_ofifo_init(struct iop_softc *sc)
 {
-       struct iop_msg *im;
-       volatile u_int32_t status;
        bus_addr_t addr;
        bus_dma_segment_t seg;
        struct i2o_exec_outbound_init *mf;
        int i, rseg, rv;
-       u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
+       u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)], *sw;
 
-       im = iop_msg_alloc(sc, NULL, IM_POLL);
+       sw = (u_int32_t *)sc->sc_scr;
 
        mf = (struct i2o_exec_outbound_init *)mb;
        mf->msgflags = I2O_MSGFLAGS(i2o_exec_outbound_init);
        mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_OUTBOUND_INIT);
        mf->msgictx = IOP_ICTX;
-       mf->msgtctx = im->im_tctx;



Home | Main Index | Thread Index | Old Index