Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Add bus_space_barrier.



details:   https://anonhg.NetBSD.org/src/rev/2381e800f28c
branches:  trunk
changeset: 483995:2381e800f28c
user:      ws <ws%NetBSD.org@localhost>
date:      Wed Mar 22 18:02:59 2000 +0000

description:
Add bus_space_barrier.
Add DELAY in some busy loops to allow the dma engine to actually do something
(neccessary on fast processors).

diffstat:

 sys/dev/ic/dp8390.c    |  24 ++++++++++++++++++++++--
 sys/dev/ic/dp8390var.h |   4 +++-
 sys/dev/ic/ne2000.c    |  43 ++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 6 deletions(-)

diffs (truncated from 352 to 300 lines):

diff -r 7e1037fc1e80 -r 2381e800f28c sys/dev/ic/dp8390.c
--- a/sys/dev/ic/dp8390.c       Wed Mar 22 17:42:57 2000 +0000
+++ b/sys/dev/ic/dp8390.c       Wed Mar 22 18:02:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dp8390.c,v 1.33 2000/02/09 15:40:23 enami Exp $        */
+/*     $NetBSD: dp8390.c,v 1.34 2000/03/22 18:02:59 ws Exp $   */
 
 /*
  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
@@ -221,8 +221,10 @@
        int n = 5000;
 
        /* Stop everything on the interface, and select page 0 registers. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P0_CR,
            sc->cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+       NIC_BARRIER(regt, regh);
 
        /*
         * Wait for interface to enter stopped state, but limit # of checks to
@@ -231,7 +233,7 @@
         */
        while (((NIC_GET(regt, regh,
            ED_P0_ISR) & ED_ISR_RST) == 0) && --n)
-               ;
+               DELAY(1);
 }
 
 /*
@@ -278,8 +280,10 @@
        sc->txb_next_tx = 0;
 
        /* Set interface for page 0, remote DMA complete, stopped. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P0_CR,
            sc->cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+       NIC_BARRIER(regt, regh);
 
        if (sc->dcr_reg & ED_DCR_LS) {
                NIC_PUT(regt, regh, ED_P0_DCR, sc->dcr_reg);
@@ -327,8 +331,10 @@
        NIC_PUT(regt, regh, ED_P0_ISR, 0xff);
 
        /* Program command register for page 1. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P0_CR,
            sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STP);
+       NIC_BARRIER(regt, regh);
 
        /* Copy out our station address. */
        for (i = 0; i < ETHER_ADDR_LEN; ++i)
@@ -348,8 +354,10 @@
        NIC_PUT(regt, regh, ED_P1_CURR, sc->next_packet);
 
        /* Program command register for page 0. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P1_CR,
            sc->cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+       NIC_BARRIER(regt, regh);
 
        /* Accept broadcast and multicast packets by default. */
        i = ED_RCR_AB | ED_RCR_AM | sc->rcr_proto;
@@ -370,6 +378,7 @@
                (*sc->init_card)(sc);
 
        /* Fire up the interface. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P0_CR,
            sc->cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
 
@@ -405,8 +414,10 @@
        len = sc->txb_len[sc->txb_next_tx];
 
        /* Set NIC for page 0 register access. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P0_CR,
            sc->cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
+       NIC_BARRIER(regt, regh);
 
        /* Set TX buffer start page. */
        NIC_PUT(regt, regh, ED_P0_TPSR, sc->tx_page_start +
@@ -417,6 +428,7 @@
        NIC_PUT(regt, regh, ED_P0_TBCR1, len >> 8);
 
        /* Set page 0, remote DMA complete, transmit packet, and *start*. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P0_CR,
            sc->cr_proto | ED_CR_PAGE_0 | ED_CR_TXP | ED_CR_STA);
 
@@ -511,8 +523,10 @@
 
 loop:
        /* Set NIC to page 1 registers to get 'current' pointer. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P0_CR,
            sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STA);
+       NIC_BARRIER(regt, regh);
 
        /*
         * 'sc->next_packet' is the logical beginning of the ring-buffer - i.e.
@@ -527,8 +541,10 @@
                return;
 
        /* Set NIC to page 0 registers to update boundary register. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P1_CR,
            sc->cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
+       NIC_BARRIER(regt, regh);
 
        do {
                /* Get pointer to this buffer's header structure. */
@@ -631,8 +647,10 @@
                return (0);
 
        /* Set NIC to page 0 registers. */
+       NIC_BARRIER(regt, regh);
        NIC_PUT(regt, regh, ED_P0_CR,
            sc->cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
+       NIC_BARRIER(regt, regh);
 
        isr = NIC_GET(regt, regh, ED_P0_ISR);
        if (!isr)
@@ -799,8 +817,10 @@
                 * set in the transmit routine, is *okay* - it is 'edge'
                 * triggered from low to high).
                 */
+               NIC_BARRIER(regt, regh);
                NIC_PUT(regt, regh, ED_P0_CR,
                    sc->cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
+               NIC_BARRIER(regt, regh);
 
                /*
                 * If the Network Talley Counters overflow, read them to reset
diff -r 7e1037fc1e80 -r 2381e800f28c sys/dev/ic/dp8390var.h
--- a/sys/dev/ic/dp8390var.h    Wed Mar 22 17:42:57 2000 +0000
+++ b/sys/dev/ic/dp8390var.h    Wed Mar 22 18:02:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dp8390var.h,v 1.16 2000/02/09 15:40:24 enami Exp $     */
+/*     $NetBSD: dp8390var.h,v 1.17 2000/03/22 18:02:59 ws Exp $        */
 
 /*
  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
@@ -139,6 +139,8 @@
                                    ((sc)->sc_reg_map[reg]))
 #define NIC_PUT(t, h, reg, val)        bus_space_write_1(t, h,                 \
                                    ((sc)->sc_reg_map[reg]), (val))
+#define        NIC_BARRIER(t, h)       bus_space_barrier(t, h, 0, 0x10,        \
+                           BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE)
 
 int    dp8390_config __P((struct dp8390_softc *, int *, int, int));
 int    dp8390_intr __P((void *));
diff -r 7e1037fc1e80 -r 2381e800f28c sys/dev/ic/ne2000.c
--- a/sys/dev/ic/ne2000.c       Wed Mar 22 17:42:57 2000 +0000
+++ b/sys/dev/ic/ne2000.c       Wed Mar 22 18:02:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ne2000.c,v 1.27 2000/02/09 15:40:24 enami Exp $        */
+/*     $NetBSD: ne2000.c,v 1.28 2000/03/22 18:02:59 ws Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -251,10 +251,13 @@
                /* Read the station address. */
                if (nsc->sc_type == NE2000_TYPE_AX88190) {
                        /* Select page 0 registers. */
+                       NIC_BARRIER(nict, nich);
                        bus_space_write_1(nict, nich, ED_P0_CR,
                            ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
+                       NIC_BARRIER(nict, nich);
                        /* Select word transfer. */
                        bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_WTS);
+                       NIC_BARRIER(nict, nich);
                        ne2000_readmem(nict, nich, asict, asich,
                            NE2000_AX88190_NODEID_OFFSET, dsc->sc_enaddr,
                            ETHER_ADDR_LEN, useword);
@@ -269,7 +272,9 @@
                bcopy(myea, dsc->sc_enaddr, sizeof(dsc->sc_enaddr));
 
        /* Clear any pending interrupts that might have occurred above. */
+       NIC_BARRIER(nict, nich);
        bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
+       NIC_BARRIER(nict, nich);
 
        if (dp8390_config(dsc, media, nmedia, defmedia)) {
                printf("%s: setup failed\n", dsc->sc_dev.dv_xname);
@@ -303,9 +308,13 @@
        /* Reset the board. */
 #ifdef GWETHER
        bus_space_write_1(asict, asich, NE2000_ASIC_RESET, 0);
+       bus_space_barrier(asict, asich, 0, NE2000_NPORTS,
+                         BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
        delay(200);
 #endif /* GWETHER */
        tmp = bus_space_read_1(asict, asich, NE2000_ASIC_RESET);
+       bus_space_barrier(asict, asich, 0, NE2000_NPORTS,
+                         BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
        delay(10000);
 
        /*
@@ -317,6 +326,8 @@
         * the invasive thing for now.  Yuck.]
         */
        bus_space_write_1(asict, asich, NE2000_ASIC_RESET, tmp);
+       bus_space_barrier(asict, asich, 0, NE2000_NPORTS,
+                         BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
        delay(5000);
 
        /*
@@ -327,6 +338,7 @@
         */
        bus_space_write_1(nict, nich, ED_P0_CR,
            ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STP);
+       NIC_BARRIER(nict, nich);
 
        delay(5000);
 
@@ -362,12 +374,14 @@
 
        bus_space_write_1(nict, nich,
            ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
+       NIC_BARRIER(nict, nich);
 
        for (i = 0; i < 100; i++) {
                if ((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RST) ==
                    ED_ISR_RST) {
                        /* Ack the reset bit. */
                        bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RST);
+                       NIC_BARRIER(nict, nich);
                        break;
                }
                delay(100);
@@ -389,6 +403,7 @@
         * the readmem routine turns on the start bit in the CR.
         */
        bus_space_write_1(nict, nich, ED_P0_RCR, ED_RCR_MON);
+       NIC_BARRIER(nict, nich);
 
        /* Temporarily initialize DCR for byte operations. */
        bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
@@ -434,6 +449,7 @@
        }
 
        /* Clear any pending interrupts that might have occurred above. */
+       NIC_BARRIER(nict, nich);
        bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
 
  out:
@@ -461,11 +477,14 @@
        savelen = m->m_pkthdr.len;
 
        /* Select page 0 registers. */
+       NIC_BARRIER(nict, nich);
        bus_space_write_1(nict, nich, ED_P0_CR,
            ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
+       NIC_BARRIER(nict, nich);
 
        /* Reset remote DMA complete flag. */
        bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC);
+       NIC_BARRIER(nict, nich);
 
        /* Set up DMA byte count. */
        bus_space_write_1(nict, nich, ED_P0_RBCR0, savelen);
@@ -476,8 +495,10 @@
        bus_space_write_1(nict, nich, ED_P0_RSAR1, buf >> 8);
 
        /* Set remote DMA write. */
+       NIC_BARRIER(nict, nich);
        bus_space_write_1(nict, nich,
            ED_P0_CR, ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
+       NIC_BARRIER(nict, nich);
 
        /*
         * Transfer the mbuf chain to the NIC memory.  NE2000 cards
@@ -566,6 +587,7 @@
                            *(u_int16_t *)savebyte);
                }
        }
+       NIC_BARRIER(nict, nich);
 
        /*
         * Wait for remote DMA to complete.  This is necessary because on the
@@ -575,7 +597,12 @@
         * the bus.
         */
        while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
-           ED_ISR_RDC) && --maxwait);
+           ED_ISR_RDC) && --maxwait) {
+               bus_space_read_1(nict, nich, ED_P0_CRDA1);
+               bus_space_read_1(nict, nich, ED_P0_CRDA0);
+               NIC_BARRIER(nict, nich);
+               DELAY(1);
+       }
 
        if (maxwait == 0) {
                log(LOG_WARNING,
@@ -669,8 +696,10 @@
 {
 
        /* Select page 0 registers. */
+       NIC_BARRIER(nict, nich);
        bus_space_write_1(nict, nich, ED_P0_CR,



Home | Main Index | Thread Index | Old Index