Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Make this driver MP-safe by using a single spin l...



details:   https://anonhg.NetBSD.org/src/rev/2c46d180da7f
branches:  trunk
changeset: 542707:2c46d180da7f
user:      pk <pk%NetBSD.org@localhost>
date:      Tue Feb 04 20:05:11 2003 +0000

description:
Make this driver MP-safe by using a single spin lock to guard all its entrances.

diffstat:

 sys/dev/ic/ncr53c9x.c    |  75 ++++++++++++++++++++++++++++-------------------
 sys/dev/ic/ncr53c9xvar.h |   3 +-
 2 files changed, 47 insertions(+), 31 deletions(-)

diffs (truncated from 360 to 300 lines):

diff -r 88fc689b8f89 -r 2c46d180da7f sys/dev/ic/ncr53c9x.c
--- a/sys/dev/ic/ncr53c9x.c     Tue Feb 04 18:52:16 2003 +0000
+++ b/sys/dev/ic/ncr53c9x.c     Tue Feb 04 20:05:11 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ncr53c9x.c,v 1.104 2003/01/30 11:03:45 pk Exp $        */
+/*     $NetBSD: ncr53c9x.c,v 1.105 2003/02/04 20:05:12 pk Exp $        */
 
 /*-
  * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ncr53c9x.c,v 1.104 2003/01/30 11:03:45 pk Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ncr53c9x.c,v 1.105 2003/02/04 20:05:12 pk Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -200,6 +200,8 @@
        struct scsipi_adapter *adapt = &sc->sc_adapter;
        struct scsipi_channel *chan = &sc->sc_channel;
 
+       simple_lock_init(&sc->sc_lock);
+
        /*
         * Note, the front-end has set us up to print the chip variation.
         */
@@ -834,6 +836,9 @@
 
        NCR_TRACE(("[ncr53c9x_scsipi_request] "));
 
+       s = splbio();
+       simple_lock(&sc->sc_lock);
+
        switch (req) {
        case ADAPTER_REQ_RUN_XFER:
                xs = arg;
@@ -853,6 +858,8 @@
                        scsipi_printaddr(periph);
                        printf("unable to allocate ecb\n");
                        xs->error = XS_RESOURCE_SHORTAGE;
+                       simple_unlock(&sc->sc_lock);
+                       splx(s);
                        scsipi_done(xs);
                        return;
                }
@@ -873,17 +880,13 @@
                }
                ecb->stat = 0;
 
-               s = splbio();
-
                TAILQ_INSERT_TAIL(&sc->ready_list, ecb, chain);
                ecb->flags |= ECB_READY;
                if (sc->sc_state == NCR_IDLE)
                        ncr53c9x_sched(sc);
 
-               splx(s);
-
                if ((flags & XS_CTL_POLL) == 0)
-                       return;
+                       break;
 
                /* Not allowed to use interrupts, use polling instead */
                if (ncr53c9x_poll(sc, xs, ecb->timeout)) {
@@ -891,11 +894,11 @@
                        if (ncr53c9x_poll(sc, xs, ecb->timeout))
                                ncr53c9x_timeout(ecb);
                }
-               return;
+               break;
 
        case ADAPTER_REQ_GROW_RESOURCES:
                /* XXX Not supported. */
-               return;
+               break;
 
        case ADAPTER_REQ_SET_XFER_MODE:
            {
@@ -937,9 +940,12 @@
                 */
                if ((ti->flags & T_NEGOTIATE) == 0)
                        ncr53c9x_update_xfer_mode(sc, xm->xm_target);
-               return;
            }
+               break;
        }
+
+       simple_unlock(&sc->sc_lock);
+       splx(s);
 }
 
 void
@@ -982,7 +988,9 @@
        NCR_TRACE(("[ncr53c9x_poll] "));
        while (count) {
                if (NCRDMA_ISINTR(sc)) {
+                       simple_unlock(&sc->sc_lock);
                        ncr53c9x_intr(sc);
+                       simple_lock(&sc->sc_lock);
                }
 #if alternatively
                if (NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT)
@@ -1014,7 +1022,9 @@
        switch (cmd) {
        case SCBUSIORESET:
                s = splbio();
+               simple_lock(&sc->sc_lock);
                ncr53c9x_init(sc, 1);
+               simple_unlock(&sc->sc_lock);
                splx(s);
                break;
        default:
@@ -1042,9 +1052,9 @@
        struct ncr53c9x_ecb *ecb;
        struct scsipi_periph *periph;
        struct ncr53c9x_tinfo *ti;
+       struct ncr53c9x_linfo *li;
        int lun;
-       struct ncr53c9x_linfo *li;
-       int s, tag;
+       int tag;
 
        NCR_TRACE(("[ncr53c9x_sched] "));
        if (sc->sc_state != NCR_IDLE)
@@ -1075,13 +1085,11 @@
                        tag = 0;
 #endif
 
-               s = splbio();
                li = TINFO_LUN(ti, lun);
                if (li == NULL) {
                        /* Initialize LUN info and add to list. */
                        if ((li = malloc(sizeof(*li),
                            M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL) {
-                               splx(s);
                                continue;
                        }
                        li->lun = lun;
@@ -1104,7 +1112,6 @@
                                periph = ecb->xs->xs_periph;
                        } else {
                                /* Not ready yet */
-                               splx(s);
                                continue;
                        }
                }
@@ -1114,7 +1121,6 @@
                        ecb->tag[1] = ecb->xs->xs_tag_id;
                        li->used++;
                }
-               splx(s);
                if (li->untagged != NULL && (li->busy != 1)) {
                        li->busy = 1;
                        TAILQ_REMOVE(&sc->ready_list, ecb, chain);
@@ -1256,7 +1262,9 @@
 
        ncr53c9x_free_ecb(sc, ecb);
        ti->cmds++;
+       simple_unlock(&sc->sc_lock);
        scsipi_done(xs);
+       simple_lock(&sc->sc_lock);
 }
 
 void
@@ -2065,6 +2073,7 @@
        if (!NCRDMA_ISINTR(sc))
                return (0);
 
+       simple_lock(&sc->sc_lock);
 again:
        /* and what do the registers say... */
        ncr53c9x_readregs(sc);
@@ -2097,7 +2106,7 @@
                if (sc->sc_state != NCR_SBR) {
                        printf("%s: SCSI bus reset\n", sc->sc_dev.dv_xname);
                        ncr53c9x_init(sc, 0); /* Restart everything */
-                       return (1);
+                       goto out;
                }
 #if 0
 /*XXX*/                printf("<expected bus reset: "
@@ -2127,7 +2136,7 @@
                                ecb->xs->error = XS_TIMEOUT;
                                ncr53c9x_done(sc, ecb);
                        }
-                       return (1);
+                       goto out;
                }
 
                if ((sc->sc_espintr & NCRINTR_ILL) != 0) {
@@ -2143,7 +2152,7 @@
                                        sc->sc_dev.dv_xname);
 #endif
                                sc->sc_flags &= ~NCR_EXPECT_ILLCMD;
-                               return (1);
+                               goto out;
                        }
                        /* illegal command, out of sync ? */
                        printf("%s: illegal command: 0x%x "
@@ -2155,7 +2164,7 @@
                                DELAY(1);
                        }
                        ncr53c9x_init(sc, 1); /* Restart everything */
-                       return (1);
+                       goto out;
                }
        }
        sc->sc_flags &= ~NCR_EXPECT_ILLCMD;
@@ -2173,11 +2182,11 @@
                        printf("%s: DMA error; resetting\n",
                            sc->sc_dev.dv_xname);
                        ncr53c9x_init(sc, 1);
-                       return 1;
+                       goto out;
                }
                /* If DMA active here, then go back to work... */
                if (NCRDMA_ISACTIVE(sc))
-                       return (1);
+                       goto out;
 
                if ((sc->sc_espstat & NCRSTAT_TC) == 0) {
                        /*
@@ -2335,7 +2344,7 @@
        case NCR_SBR:
                printf("%s: waiting for SCSI Bus Reset to happen\n",
                    sc->sc_dev.dv_xname);
-               return (1);
+               goto out;
 
        case NCR_RESELECTED:
                /*
@@ -2345,7 +2354,7 @@
                        "state %d, intr %02x\n",
                        sc->sc_dev.dv_xname, sc->sc_state, sc->sc_espintr);
                ncr53c9x_init(sc, 1);
-               return (1);
+               goto out;
                break;
 
        case NCR_IDENTIFIED:
@@ -2363,7 +2372,7 @@
                                printf("[%d] ", NCR_READ_REG(sc, NCR_FIFO));
 
                        ncr53c9x_init(sc, 1);
-                       return (1);
+                       goto out;
                } else
                        goto msgin;
 
@@ -2397,7 +2406,7 @@
                                printf("%s: target didn't identify\n",
                                    sc->sc_dev.dv_xname);
                                ncr53c9x_init(sc, 1);
-                               return (1);
+                               goto out;
                        }
                        /*
                         * The C90 only inhibits FIFO writes until reselection
@@ -2440,7 +2449,7 @@
                                    sc->sc_espstep,
                                    sc->sc_prevphase);
                                ncr53c9x_init(sc, 1);
-                               return (1);
+                               goto out;
                        }
                        sc->sc_selid = sc->sc_imess[0];
                        NCR_INTS(("selid=%02x ", sc->sc_selid));
@@ -2456,7 +2465,7 @@
                                    sc->sc_dev.dv_xname, sc->sc_state,
                                    sc->sc_espintr);
                                ncr53c9x_init(sc, 1);
-                               return (1);
+                               goto out;
                        }
                        goto shortcut; /* ie. next phase expected soon */
                }
@@ -2550,7 +2559,7 @@
                                    sc->sc_espstep);
                                NCRCMD(sc, NCRCMD_FLUSH);
                                ncr53c9x_sched_msgout(SEND_ABORT);
-                               return (1);
+                               goto out;
                        case 2:
                                /* Select stuck at Command Phase */
                                NCRCMD(sc, NCRCMD_FLUSH);
@@ -2591,6 +2600,7 @@
                }
                if (sc->sc_state == NCR_IDLE) {
                        printf("%s: stray interrupt\n", sc->sc_dev.dv_xname);
+                       simple_unlock(&sc->sc_lock);
                        return (0);
                }
                break;
@@ -2758,7 +2768,7 @@
                NCRCMD(sc,
                    (size == 0 ? NCRCMD_TRPAD : NCRCMD_TRANS) | NCRCMD_DMA);
                NCRDMA_GO(sc);
-               return (1);
+               goto out;



Home | Main Index | Thread Index | Old Index