Source-Changes-HG archive

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

[src/thorpej_scsipi]: src/sys/dev/ic - Sync with -current (untested as yet).



details:   https://anonhg.NetBSD.org/src/rev/fc5831e2568a
branches:  thorpej_scsipi
changeset: 477286:fc5831e2568a
user:      ad <ad%NetBSD.org@localhost>
date:      Tue Oct 19 23:34:54 1999 +0000

description:
- Sync with -current (untested as yet).
- One cosmetic change.

diffstat:

 sys/dev/ic/dpt.c |  117 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 68 insertions(+), 49 deletions(-)

diffs (273 lines):

diff -r 95626cc8488a -r fc5831e2568a sys/dev/ic/dpt.c
--- a/sys/dev/ic/dpt.c  Tue Oct 19 22:53:43 1999 +0000
+++ b/sys/dev/ic/dpt.c  Tue Oct 19 23:34:54 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dpt.c,v 1.8.2.3 1999/10/19 23:15:31 thorpej Exp $      */
+/*     $NetBSD: dpt.c,v 1.8.2.4 1999/10/19 23:34:54 ad Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dpt.c,v 1.8.2.3 1999/10/19 23:15:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dpt.c,v 1.8.2.4 1999/10/19 23:34:54 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -150,6 +150,7 @@
        struct dpt_softc *sc;
        struct dpt_ccb *ccb;
        struct eata_sp *sp;
+       static int moretimo;
        int more;
 
        sc = xxx_sc;
@@ -161,6 +162,10 @@
                printf("%s: spurious intr\n", sc->sc_dv.dv_xname);
 #endif
        
+       /* Don't get stalled by HA_ST_MORE */
+       if (moretimo < DPT_MORE_TIMEOUT / 10)
+               moretimo = 0;
+       
        for (;;) {
                /*
                 * HBA might have interrupted while we were dealing with the
@@ -170,7 +175,7 @@
                 * around. 
                 */ 
                if ((dpt_inb(sc, HA_AUX_STATUS) & HA_AUX_INTR) == 0) {
-                       if (more != 0) {
+                       if (more != 0 && moretimo++ < DPT_MORE_TIMEOUT / 10) {
                                DELAY(10);
                                continue;
                        }
@@ -208,7 +213,7 @@
                            CCB_OFF(sc, ccb), sizeof(struct dpt_ccb), 
                            BUS_DMASYNC_POSTWRITE);
 
-                       ccb->ccb_hba_status = sp->sp_hba_status;
+                       ccb->ccb_hba_status = sp->sp_hba_status & 0x7F;
                        ccb->ccb_scsi_status = sp->sp_scsi_status;
 
                        /* 
@@ -228,6 +233,10 @@
                        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 / 10)
+                       moretimo = 0;
        }
 
        return (0);
@@ -330,7 +339,7 @@
        model[i] = '\0';
 
        /* Find the cannonical name for the board */
-       for (i = 0; dpt_cname[i]; i += 2)
+       for (i = 0; dpt_cname[i] != NULL; i += 2)
                if (memcmp(ei->ei_model, dpt_cname[i], 6) == 0)
                        break;
                        
@@ -479,9 +488,10 @@
                panic("dpt_poll: called for non-CCB_PRIVATE request\n");
 #endif
 
+       if ((ccb->ccb_flg & CCB_INTR) != 0)
+               return (0);                
+
         for (i = ccb->ccb_timeout * 20; i; i--) {
-                if ((ccb->ccb_flg & CCB_INTR) != 0)
-                       return (0);                
                 if ((dpt_inb(sc, HA_AUX_STATUS) & HA_AUX_INTR) != 0)
                        dpt_intr(sc);
                 if ((ccb->ccb_flg & CCB_INTR) != 0)
@@ -546,7 +556,8 @@
        p = (u_int16_t *)ec;
        
        if (dpt_wait(sc, 0xFF, HA_ST_DATA_RDY, 2000)) {
-               printf("%s: cfg data didn't appear\n", sc->sc_dv.dv_xname);
+               printf("%s: cfg data didn't appear (status:%02x)\n", 
+                   sc->sc_dv.dv_xname, dpt_inb(sc, HA_STATUS));
                return (-1);
        }
 
@@ -684,9 +695,9 @@
 }
 
 /*
- * Get a free ccb. If there are none, see if we can allocate a new one. 
- * Otherwise either return an error or if we are permitted to, sleep until
- * one becomes free.
+ * Get a free ccb. If there are none, see if we can allocate a new one. If 
+ * none are available right now and we are permitted to sleep, then wait 
+ * until one becomes free, otherwise return an error.
  */
 struct dpt_ccb *
 dpt_alloc_ccb(sc)
@@ -797,17 +808,21 @@
        scsipi_adapter_req_t req;
        void *arg;
 {
-       struct dpt_softc *sc = (void *)chan->chan_adapter->adapt_dev;
+       struct dpt_softc *sc;
        struct scsipi_xfer *xs;
-       int error, seg, flags;
+       int error, i, flags;
        struct scsipi_periph *periph;
        struct dpt_ccb *ccb;
        struct eata_sg *sg;
        struct eata_cp *cp;
-       bus_dma_tag_t dmat = sc->sc_dmat;
+       bus_dma_tag_t dmat;
+       bus_dmamap_t xfer;
 
        SC_DEBUG(sc_link, SDEV_DB2, ("dpt_scsipi_request\n"));
 
+       sc = (void *)chan->chan_adapter->adapt_dev;
+       dmat = sc->sc_dmat;
+
        switch (req) {
        case ADAPTER_REQ_RUN_XFER:
                xs = arg;
@@ -846,11 +861,6 @@
                }
 #endif
 
-               /* Synchronous xfers musn't write-back through the cache */
-               if (xs->bp != NULL &&
-                   (xs->bp->b_flags & (B_ASYNC | B_READ)) == 0)
-                       ccb->ccb_flg |= CCB_SYNC;
-
                ccb->ccb_xs = xs;
                ccb->ccb_timeout = xs->timeout;
 
@@ -865,31 +875,34 @@
                cp->cp_dispri = 1;
                cp->cp_identify = 1;
                cp->cp_autosense = 1;
-               cp->cp_nocache = ((ccb->ccb_flg & CCB_SYNC) != 0);
                cp->cp_datain = ((flags & XS_CTL_DATA_IN) != 0);
                cp->cp_dataout = ((flags & XS_CTL_DATA_OUT) != 0);
                cp->cp_interpret = (sc->sc_hbaid[chan->chan_channel] ==
                    periph->periph_target);
 
+               /* Synchronous xfers musn't write-back through the cache */
+               if (xs->bp != NULL 
+                   && (xs->bp->b_flags & (B_ASYNC | B_READ)) == 0)
+                       cp->cp_nocache = 1;
+               else
+                       cp->cp_nocache = 0;
+
                cp->cp_senseaddr =
                    SWAP32(sc->sc_dmamap_ccb->dm_segs[0].ds_addr +
                    CCB_OFF(sc, ccb) + offsetof(struct dpt_ccb, ccb_sense));
            
                if (xs->datalen) {
-                       sg = ccb->ccb_sg;
-                       seg = 0;
+                       xfer = ccb->ccb_dmamap_xfer;
 #ifdef TFS
                        if (flags & XS_CTL_DATA_UIO) {
-                               error = bus_dmamap_load_uio(dmat,
-                                   ccb->ccb_dmamap_xfer,
+                               error = bus_dmamap_load_uio(dmat, xfer,
                                    (struct uio *)xs->data,
                                    (flags & XS_CTL_NOSLEEP) ? BUS_DMA_NOWAIT :
                                    BUS_DMA_WAITOK);
                        } else
 #endif /*TFS */
                        {
-                               error = bus_dmamap_load(dmat, 
-                                   ccb->ccb_dmamap_xfer, 
+                               error = bus_dmamap_load(dmat, xfer,
                                    xs->data, xs->datalen, NULL,
                                    (flags & XS_CTL_NOSLEEP) ? BUS_DMA_NOWAIT :
                                    BUS_DMA_WAITOK);
@@ -911,29 +924,36 @@
                                return;
                        }
 
-                       bus_dmamap_sync(dmat, ccb->ccb_dmamap_xfer, 0,
-                           ccb->ccb_dmamap_xfer->dm_mapsize,
+                       bus_dmamap_sync(dmat, xfer, 0, xfer->dm_mapsize,
                            (flags & XS_CTL_DATA_IN) ? BUS_DMASYNC_PREREAD :
                            BUS_DMASYNC_PREWRITE);
 
-                       /*
-                        * Load the hardware scatter/gather map with the
-                        * contents of the DMA map.
-                        */
-                       for (seg = 0;
-                            seg < ccb->ccb_dmamap_xfer->dm_nsegs; seg++) {
-                               ccb->ccb_sg[seg].sg_addr =
-                           SWAP32(ccb->ccb_dmamap_xfer->dm_segs[seg].ds_addr);
-                               ccb->ccb_sg[seg].sg_len =
-                           SWAP32(ccb->ccb_dmamap_xfer->dm_segs[seg].ds_len);
-                       }
-               
-                       cp->cp_dataaddr =
-                           SWAP32(sc->sc_dmamap_ccb->dm_segs[0].ds_addr 
-                           + CCB_OFF(sc, ccb) + offsetof(struct dpt_ccb,
-                           ccb_sg));
-                       cp->cp_datalen = SWAP32(seg * sizeof(struct eata_sg));
-                       cp->cp_scatter = 1;
+                       /* Don't bother using scatter/gather for just 1 seg */
+                       if (xfer->dm_nsegs == 1) {
+                               cp->cp_dataaddr = 
+                                   SWAP32(xfer->dm_segs[0].ds_addr);
+                               cp->cp_datalen = 
+                                   SWAP32(xfer->dm_segs[0].ds_len);
+                               cp->cp_scatter = 0;
+                       } else {
+                               /*
+                                * Load the hardware scatter/gather map with 
+                                * the contents of the DMA map.
+                                */
+                               sg = ccb->ccb_sg;
+                               for (i = 0; i < xfer->dm_nsegs; i++, sg++) {
+                                       sg->sg_addr = 
+                                           SWAP32(xfer->dm_segs[i].ds_addr);
+                                       sg->sg_len = 
+                                           SWAP32(xfer->dm_segs[i].ds_len);
+                               }
+                               cp->cp_dataaddr = SWAP32(CCB_OFF(sc, ccb) + 
+                                   sc->sc_dmamap_ccb->dm_segs[0].ds_addr +
+                                   offsetof(struct dpt_ccb, ccb_sg));
+                               cp->cp_datalen = 
+                                   SWAP32(i * sizeof(struct eata_sg));
+                               cp->cp_scatter = 1;
+                       }
                } else {
                        cp->cp_dataaddr = 0;
                        cp->cp_datalen = 0;
@@ -959,7 +979,7 @@
                    CP_DMA_CMD, 0)) {
                        printf("%s: dpt_cmd failed\n", sc->sc_dv.dv_xname);
                        xs->error = XS_DRIVER_STUFFUP;
-                       dpt_done_ccb(sc, ccb);
+                       dpt_free_ccb(sc, ccb);
                        return;
                }
 
@@ -1046,7 +1066,6 @@
        int i;
        
        printf("\thba_status\t%02x\n", sp->sp_hba_status);
-       printf("\teoc\t\t%d\n", sp->sp_eoc);
        printf("\tscsi_status\t%02x\n", sp->sp_scsi_status);    
        printf("\tinv_residue\t%d\n", sp->sp_inv_residue);      
        printf("\tccbid\t\t%d\n", sp->sp_ccbid);
@@ -1124,7 +1143,7 @@
        if (dpt_poll(sc, ccb))
                panic("%s: inquiry timed out", sc->sc_dv.dv_xname);
 
-       if (ccb->ccb_hba_status != HA_NO_ERROR || 
+       if (ccb->ccb_hba_status != HA_NO_ERROR ||
            ccb->ccb_scsi_status != SCSI_OK)
                panic("%s: inquiry failed (hba:%02x scsi:%02x", 
                    sc->sc_dv.dv_xname, ccb->ccb_hba_status,



Home | Main Index | Thread Index | Old Index