Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic - Don't use bitfields.



details:   https://anonhg.NetBSD.org/src/rev/c28a13b2f631
branches:  trunk
changeset: 482881:c28a13b2f631
user:      ad <ad%NetBSD.org@localhost>
date:      Thu Feb 24 18:47:55 2000 +0000

description:
- Don't use bitfields.
- Cosmetic changes.
- Shut down all HBAs "simultaneously", not individually.
- Don't bother grokking HA_ST_MORE. It causes problems.
- Other bits and pieces.

diffstat:

 sys/dev/ic/dpt.c    |  417 ++++++++++++++++++++++-----------------------------
 sys/dev/ic/dptreg.h |  266 +++++++++++++++++---------------
 sys/dev/ic/dptvar.h |   33 +--
 3 files changed, 337 insertions(+), 379 deletions(-)

diffs (truncated from 1199 to 300 lines):

diff -r 1ae21db812c2 -r c28a13b2f631 sys/dev/ic/dpt.c
--- a/sys/dev/ic/dpt.c  Thu Feb 24 17:19:57 2000 +0000
+++ b/sys/dev/ic/dpt.c  Thu Feb 24 18:47:55 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dpt.c,v 1.18 2000/02/12 19:12:54 thorpej Exp $ */
+/*     $NetBSD: dpt.c,v 1.19 2000/02/24 18:47:55 ad Exp $      */
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -54,22 +54,8 @@
  * functioning of this software in any circumstances.
  */
 
-/*
- * Driver for DPT EATA SCSI adapters.
- *
- * TODO:
- *
- * o Need a front-end for (newer) ISA boards.
- * o Handle older firmware better.
- * o Find a bunch of different firmware EEPROMs and try them out.
- * o Test with a bunch of different boards.
- * o dpt_readcfg() should not be using CP_PIO_GETCFG.
- * o An interface to userland applications.
- * o Some sysctls or a utility (eg dptctl(8)) to control parameters.
- */
-
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dpt.c,v 1.18 2000/02/12 19:12:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dpt.c,v 1.19 2000/02/24 18:47:55 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -119,6 +105,9 @@
        NULL,     "unknown adapter, please report using send-pr(1)",
 };
 
+TAILQ_HEAD(, dpt_softc) dpt_hba;       /* tailq of HBA softc's */
+void *dpt_sdh;                         /* shutdown hook */
+
 /*
  * Handle an interrupt from the HBA.
  */
@@ -129,57 +118,42 @@
        struct dpt_softc *sc;
        struct dpt_ccb *ccb;
        struct eata_sp *sp;
-       static int moretimo;
-       int more;
+       volatile int junk;
 
        sc = xxx_sc;
-       sp = sc->sc_statpack;
-       more = 0;
+       sp = sc->sc_stp;
 
 #ifdef DEBUG
-       if ((dpt_inb(sc, HA_AUX_STATUS) & HA_AUX_INTR) == 0)
+       if ((dpt_inb(sc, HA_AUX_STATUS) & HA_AUX_INTR) == 0) {
                printf("%s: spurious intr\n", sc->sc_dv.dv_xname);
+               return (1);
+       }
 #endif
-       
-       /* Don't get stalled by HA_ST_MORE */
-       if (moretimo < DPT_MORE_TIMEOUT / 100)
-               moretimo = 0;
-       
+
        for (;;) {
                /*
                 * HBA might have interrupted while we were dealing with the
                 * last completed command, since we ACK before we deal; keep 
-                * polling. If no interrupt is signalled, but the HBA has
-                * indicated that more data will be available soon, hang 
-                * around. 
+                * polling.
                 */ 
-               if ((dpt_inb(sc, HA_AUX_STATUS) & HA_AUX_INTR) == 0) {
-                       if (more != 0 && moretimo++ < DPT_MORE_TIMEOUT / 100) {
-                               DELAY(10);
-                               continue;
-                       }
+               if ((dpt_inb(sc, HA_AUX_STATUS) & HA_AUX_INTR) == 0)
                        break;
-               }
                
-               bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap_ccb, sc->sc_spoff,
+               bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, sc->sc_stpoff,
                    sizeof(struct eata_sp), BUS_DMASYNC_POSTREAD);
 
                /* Might have looped before HBA can reset HBA_AUX_INTR */
                if (sp->sp_ccbid == -1) {
                        DELAY(50);
-#ifdef DIAGNOSTIC
-                       printf("%s: slow reset of HA_AUX_STATUS?",
-                           sc->sc_dv.dv_xname);
-#endif
+
                        if ((dpt_inb(sc, HA_AUX_STATUS) & HA_AUX_INTR) == 0)
                                return (0);
-#ifdef DIAGNOSTIC
-                       printf("%s: was a slow reset of HA_AUX_STATUS",
-                           sc->sc_dv.dv_xname);
-#endif
+
+                       printf("%s: no status\n", sc->sc_dv.dv_xname);
+
                        /* Re-sync DMA map */
-                       bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap_ccb, 
-                           sc->sc_spoff, sizeof(struct eata_sp),
+                       bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, 
+                           sc->sc_stpoff, sizeof(struct eata_sp),
                            BUS_DMASYNC_POSTREAD);
                }
 
@@ -188,7 +162,7 @@
                        /* Sync up DMA map and cache cmd status */
                        ccb = sc->sc_ccbs + sp->sp_ccbid;
 
-                       bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap_ccb, 
+                       bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, 
                            CCB_OFF(sc, ccb), sizeof(struct dpt_ccb), 
                            BUS_DMASYNC_POSTWRITE);
 
@@ -199,9 +173,9 @@
                         * Ack the interrupt and process the CCB. If this
                         * is a private CCB it's up to dpt_poll() to notice.
                         */
+                       junk = dpt_inb(sc, HA_STATUS);
                        sp->sp_ccbid = -1;
                        ccb->ccb_flg |= CCB_INTR;
-                       more = dpt_inb(sc, HA_STATUS) & HA_ST_MORE;
                        if ((ccb->ccb_flg & CCB_PRIVATE) == 0)
                                dpt_done_ccb(sc, ccb);
                } else {
@@ -209,16 +183,12 @@
                            sc->sc_dv.dv_xname, sp->sp_ccbid);
 
                        /* Ack the interrupt */
+                       junk = dpt_inb(sc, HA_STATUS);
                        sp->sp_ccbid = -1;
-                       more = dpt_inb(sc, HA_STATUS) & HA_ST_MORE;
                }
-               
-               /* Don't get stalled by HA_ST_MORE */
-               if (moretimo < DPT_MORE_TIMEOUT / 100)
-                       moretimo = 0;
        }
 
-       return (0);
+       return (1);
 }
 
 /*
@@ -231,55 +201,56 @@
        const char *intrstr;
 {
        struct eata_inquiry_data *ei;
-       int i, j, error, rseg, mapsize;
+       int i, j, error, rseg, maxchannel, maxtarget;
        bus_dma_segment_t seg;
        struct eata_cfg *ec;
+       struct scsipi_link *link;
        char model[16];
        
        ec = &sc->sc_ec;
        
        /* Allocate the CCB/status packet/scratch DMA map and load */
-       sc->sc_nccbs = min(be16toh(*(int16_t *)ec->ec_queuedepth), DPT_MAX_CCBS);
-       sc->sc_spoff = sc->sc_nccbs * sizeof(struct dpt_ccb);
-       sc->sc_scroff = sc->sc_spoff + sizeof(struct eata_sp);
-       sc->sc_scrlen = 256; /* XXX */
-       mapsize = sc->sc_nccbs * sizeof(struct dpt_ccb) + sc->sc_scrlen +
-           sizeof(struct eata_sp);
+       sc->sc_nccbs = 
+           min(be16toh(*(int16_t *)ec->ec_queuedepth), DPT_MAX_CCBS);
+       sc->sc_stpoff = sc->sc_nccbs * sizeof(struct dpt_ccb);
+       sc->sc_scroff = sc->sc_stpoff + sizeof(struct eata_sp);
+       sc->sc_scrlen = DPT_SCRATCH_SIZE;
+       sc->sc_dmamapsize = sc->sc_nccbs * sizeof(struct dpt_ccb) + 
+           sc->sc_scrlen + sizeof(struct eata_sp);
                
-       if ((error = bus_dmamem_alloc(sc->sc_dmat, mapsize, NBPG, 0, 
+       if ((error = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dmamapsize, NBPG, 0, 
            &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
                printf("%s: unable to allocate CCBs, error = %d\n",
                    sc->sc_dv.dv_xname, error);
                return;
        }
 
-       if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg, mapsize,
+       if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg, sc->sc_dmamapsize,
            (caddr_t *)&sc->sc_ccbs, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
                printf("%s: unable to map CCBs, error = %d\n",
                    sc->sc_dv.dv_xname, error);
                return;
        }
 
-       if ((error = bus_dmamap_create(sc->sc_dmat, mapsize, mapsize, 1, 0, 
-           BUS_DMA_NOWAIT, &sc->sc_dmamap_ccb)) != 0) {
+       if ((error = bus_dmamap_create(sc->sc_dmat, sc->sc_dmamapsize, 
+           sc->sc_dmamapsize, 1, 0, BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
                printf("%s: unable to create CCB DMA map, error = %d\n",
                    sc->sc_dv.dv_xname, error);
                return;
        }
 
-       if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap_ccb,
-           sc->sc_ccbs, mapsize, NULL, BUS_DMA_NOWAIT)) != 0) {
+       if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap,
+           sc->sc_ccbs, sc->sc_dmamapsize, NULL, BUS_DMA_NOWAIT)) != 0) {
                printf("%s: unable to load CCB DMA map, error = %d\n",
                    sc->sc_dv.dv_xname, error);
                return;
        }
 
-       sc->sc_statpack = (struct eata_sp *)((caddr_t)sc->sc_ccbs +
-           sc->sc_spoff);
-       sc->sc_sppa = sc->sc_dmamap_ccb->dm_segs[0].ds_addr + sc->sc_spoff;
+       sc->sc_stp = (struct eata_sp *)((caddr_t)sc->sc_ccbs + sc->sc_stpoff);
+       sc->sc_stppa = sc->sc_dmamap->dm_segs[0].ds_addr + sc->sc_stpoff;
        sc->sc_scr = (caddr_t)sc->sc_ccbs + sc->sc_scroff;
-       sc->sc_scrpa = sc->sc_dmamap_ccb->dm_segs[0].ds_addr + sc->sc_scroff;
-       sc->sc_statpack->sp_ccbid = -1;
+       sc->sc_scrpa = sc->sc_dmamap->dm_segs[0].ds_addr + sc->sc_scroff;
+       sc->sc_stp->sp_ccbid = -1;
 
        /* Initialize the CCBs */
        TAILQ_INIT(&sc->sc_free_ccb);
@@ -295,7 +266,10 @@
        }
 
        /* Set shutdownhook before we start any device activity */
-       sc->sc_sdh = shutdownhook_establish(dpt_shutdown, sc);
+       if (dpt_sdh == NULL) {
+               TAILQ_INIT(&dpt_hba);
+               dpt_sdh = shutdownhook_establish(dpt_shutdown, NULL);
+       }
 
        /* Get the page 0 inquiry data from the HBA */
        dpt_hba_inquire(sc, &ei);
@@ -325,38 +299,43 @@
        if (intrstr != NULL)
                printf("%s: interrupting at %s\n", sc->sc_dv.dv_xname, intrstr);
 
-       printf("%s: %d queued commands, %d channel(s), adapter on ID(s)", 
-           sc->sc_dv.dv_xname, sc->sc_nccbs, ec->ec_maxchannel + 1);
+       maxchannel = (ec->ec_feat3 & EC_F3_MAX_CHANNEL_MASK) >>
+           EC_F3_MAX_CHANNEL_SHIFT;
+       maxtarget = (ec->ec_feat3 & EC_F3_MAX_TARGET_MASK) >>
+           EC_F3_MAX_TARGET_SHIFT;
 
-       for (i = 0; i <= ec->ec_maxchannel; i++)
-               printf(" %d", ec->ec_hba[3 - i]);
+       printf("%s: %d queued commands, %d channel(s), adapter on ID(s)", 
+           sc->sc_dv.dv_xname, sc->sc_nccbs, maxchannel + 1);
+
+       for (i = 0; i <= maxchannel; i++) {
+               sc->sc_hbaid[i] = ec->ec_hba[3 - i];
+               printf(" %d", sc->sc_hbaid[i]);
+       }
        printf("\n");
 
        /* Reset the SCSI bus */
        if (dpt_cmd(sc, NULL, 0, CP_IMMEDIATE, CPI_BUS_RESET))
                panic("%s: dpt_cmd failed", sc->sc_dv.dv_xname);
-        DELAY(20000);
        
        /* Fill in the adapter, each link and attach in turn */
        sc->sc_adapter.scsipi_cmd = dpt_scsi_cmd;
        sc->sc_adapter.scsipi_minphys = dpt_minphys;
 
-       for (i = 0; i <= ec->ec_maxchannel; i++) {
-               struct scsipi_link *link;
-               
-               sc->sc_hbaid[i] = ec->ec_hba[3 - i];
+       for (i = 0; i <= maxchannel; i++) {
                link = &sc->sc_link[i];
                link->scsipi_scsi.channel = i;
                link->scsipi_scsi.adapter_target = sc->sc_hbaid[i];
                link->scsipi_scsi.max_lun = ec->ec_maxlun;
-               link->scsipi_scsi.max_target = ec->ec_maxtarget;
+               link->scsipi_scsi.max_target = maxtarget;
                link->type = BUS_SCSI;
                link->device = &dpt_dev;
                link->adapter = &sc->sc_adapter;
                link->adapter_softc = sc;
-               link->openings = sc->sc_nccbs;
+               link->openings = sc->sc_nccbs;  /* XXX */
                config_found(&sc->sc_dv, link, scsiprint);
        }
+
+       TAILQ_INSERT_TAIL(&dpt_hba, sc, sc_chain);
 }
 
 /*
@@ -369,9 +348,12 @@
 {
        struct dpt_softc *sc;



Home | Main Index | Thread Index | Old Index