Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic - Since rtk_rxeof() was rewritten, we don't have ...



details:   https://anonhg.NetBSD.org/src/rev/0d42d8de1bbd
branches:  trunk
changeset: 500096:0d42d8de1bbd
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Tue Dec 05 11:11:49 2000 +0000

description:
- Since rtk_rxeof() was rewritten, we don't have to reserve a few bytes
  before the Rx buffer.
- Reduce delay on EEPROM access.
- Some more cosmetics.

diffstat:

 sys/dev/ic/rtl81x9.c    |  154 +++++++++++++++++++----------------------------
 sys/dev/ic/rtl81x9var.h |   10 +-
 2 files changed, 68 insertions(+), 96 deletions(-)

diffs (truncated from 573 to 300 lines):

diff -r 93a6ba8487e6 -r 0d42d8de1bbd sys/dev/ic/rtl81x9.c
--- a/sys/dev/ic/rtl81x9.c      Tue Dec 05 10:45:09 2000 +0000
+++ b/sys/dev/ic/rtl81x9.c      Tue Dec 05 11:11:49 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtl81x9.c,v 1.22 2000/12/03 14:24:17 tsutsui Exp $     */
+/*     $NetBSD: rtl81x9.c,v 1.23 2000/12/05 11:11:49 tsutsui Exp $     */
 
 /*
  * Copyright (c) 1997, 1998
@@ -132,7 +132,7 @@
 #include <dev/ic/rtl81x9reg.h>
 #include <dev/ic/rtl81x9var.h>
 
-#if defined DEBUG
+#if defined(DEBUG)
 #define STATIC
 #else
 #define STATIC static
@@ -192,17 +192,17 @@
        /*
         * Feed in each bit and stobe the clock.
         */
-       for (i = RTK_EECMD_LEN + addr_len - 1; i >= 0; i--) {
-               if (d & (1 << i)) {
+       for (i = RTK_EECMD_LEN + addr_len; i > 0; i--) {
+               if (d & (1 << (i - 1))) {
                        EE_SET(RTK_EE_DATAIN);
                } else {
                        EE_CLR(RTK_EE_DATAIN);
                }
-               DELAY(100);
+               DELAY(4);
                EE_SET(RTK_EE_CLK);
-               DELAY(150);
+               DELAY(4);
                EE_CLR(RTK_EE_CLK);
-               DELAY(100);
+               DELAY(4);
        }
 }
 
@@ -229,13 +229,13 @@
        /*
         * Start reading bits from EEPROM.
         */
-       for (i = 15; i >= 0; i--) {
+       for (i = 16; i > 0; i--) {
                EE_SET(RTK_EE_CLK);
-               DELAY(100);
+               DELAY(4);
                if (CSR_READ_1(sc, RTK_EECMD) & RTK_EE_DATAOUT)
-                       word |= (1 << i);
+                       word |= 1 << (i - 1);
                EE_CLR(RTK_EE_CLK);
-               DELAY(100);
+               DELAY(4);
        }
 
        /* Turn off EEPROM access mode. */
@@ -251,11 +251,11 @@
  * direct access PHY registers.
  */
 #define MII_SET(x)                                     \
-       CSR_WRITE_1(sc, RTK_MII,                                \
+       CSR_WRITE_1(sc, RTK_MII,                        \
                CSR_READ_1(sc, RTK_MII) | (x))
 
 #define MII_CLR(x)                                     \
-       CSR_WRITE_1(sc, RTK_MII,                                \
+       CSR_WRITE_1(sc, RTK_MII,                        \
                CSR_READ_1(sc, RTK_MII) & ~(x))
 
 /*
@@ -274,8 +274,6 @@
                MII_CLR(RTK_MII_CLK);
                DELAY(1);
        }
-
-       return;
 }
 
 /*
@@ -290,8 +288,8 @@
 
        MII_CLR(RTK_MII_CLK);
 
-       for (i = (0x1 << (cnt - 1)); i; i >>= 1) {
-                if (bits & i) {
+       for (i = cnt; i > 0; i--) {
+                if (bits & (1 << (i - 1))) {
                        MII_SET(RTK_MII_DATAOUT);
                 } else {
                        MII_CLR(RTK_MII_DATAOUT);
@@ -309,7 +307,6 @@
 STATIC int rtk_mii_readreg(sc, frame)
        struct rtk_softc        *sc;
        struct rtk_mii_frame    *frame;
-       
 {
        int                     i, ack, s;
 
@@ -322,7 +319,7 @@
        frame->mii_opcode = RTK_MII_READOP;
        frame->mii_turnaround = 0;
        frame->mii_data = 0;
-       
+
        CSR_WRITE_2(sc, RTK_MII, 0);
 
        /*
@@ -361,7 +358,7 @@
         * need to clock through 16 cycles to keep the PHY(s) in sync.
         */
        if (ack) {
-               for(i = 0; i < 16; i++) {
+               for (i = 0; i < 16; i++) {
                        MII_CLR(RTK_MII_CLK);
                        DELAY(1);
                        MII_SET(RTK_MII_CLK);
@@ -370,20 +367,19 @@
                goto fail;
        }
 
-       for (i = 0x8000; i; i >>= 1) {
+       for (i = 16; i > 0; i--) {
                MII_CLR(RTK_MII_CLK);
                DELAY(1);
                if (!ack) {
                        if (CSR_READ_2(sc, RTK_MII) & RTK_MII_DATAIN)
-                               frame->mii_data |= i;
+                               frame->mii_data |= 1 << (i - 1);
                        DELAY(1);
                }
                MII_SET(RTK_MII_CLK);
                DELAY(1);
        }
 
-fail:
-
+ fail:
        MII_CLR(RTK_MII_CLK);
        DELAY(1);
        MII_SET(RTK_MII_CLK);
@@ -392,8 +388,8 @@
        splx(s);
 
        if (ack)
-               return(1);
-       return(0);
+               return (1);
+       return (0);
 }
 
 /*
@@ -402,7 +398,6 @@
 STATIC int rtk_mii_writereg(sc, frame)
        struct rtk_softc        *sc;
        struct rtk_mii_frame    *frame;
-       
 {
        int                     s;
 
@@ -410,7 +405,6 @@
        /*
         * Set up frame for TX.
         */
-
        frame->mii_stdelim = RTK_MII_STARTDELIM;
        frame->mii_opcode = RTK_MII_WRITEOP;
        frame->mii_turnaround = RTK_MII_TURNAROUND;
@@ -442,7 +436,7 @@
 
        splx(s);
 
-       return(0);
+       return (0);
 }
 
 STATIC int rtk_phy_readreg(self, phy, reg)
@@ -451,8 +445,8 @@
 {
        struct rtk_softc        *sc = (void *)self;
        struct rtk_mii_frame    frame;
-       u_int16_t               rval = 0;
-       u_int16_t               rtk8139_reg = 0;
+       int                     rval = 0;
+       int                     rtk8139_reg = 0;
 
        if (sc->rtk_type == RTK_8139) {
                if (phy != 7)
@@ -478,10 +472,10 @@
 #if 0
                        printf("%s: bad phy register\n", sc->sc_dev.dv_xname);
 #endif
-                       return(0);
+                       return (0);
                }
                rval = CSR_READ_2(sc, rtk8139_reg);
-               return(rval);
+               return (rval);
        }
 
        bzero((char *)&frame, sizeof(frame));
@@ -490,7 +484,7 @@
        frame.mii_regaddr = reg;
        rtk_mii_readreg(sc, &frame);
 
-       return(frame.mii_data);
+       return (frame.mii_data);
 }
 
 STATIC void rtk_phy_writereg(self, phy, reg, data)
@@ -500,7 +494,7 @@
 {
        struct rtk_softc        *sc = (void *)self;
        struct rtk_mii_frame    frame;
-       u_int16_t               rtk8139_reg = 0;
+       int                     rtk8139_reg = 0;
 
        if (sc->rtk_type == RTK_8139) {
                if (phy != 7)
@@ -539,8 +533,6 @@
        frame.mii_data = data;
 
        rtk_mii_writereg(sc, &frame);
-
-       return;
 }
 
 STATIC void
@@ -608,8 +600,6 @@
        CSR_WRITE_4(sc, RTK_RXCFG, rxfilt);
        CSR_WRITE_4(sc, RTK_MAR0, hashes[0]);
        CSR_WRITE_4(sc, RTK_MAR4, hashes[1]);
-
-       return;
 }
 
 void rtk_reset(sc)
@@ -621,13 +611,11 @@
 
        for (i = 0; i < RTK_TIMEOUT; i++) {
                DELAY(10);
-               if (!(CSR_READ_1(sc, RTK_COMMAND) & RTK_CMD_RESET))
+               if ((CSR_READ_1(sc, RTK_COMMAND) & RTK_CMD_RESET) == 0)
                        break;
        }
        if (i == RTK_TIMEOUT)
                printf("%s: reset never completed!\n", sc->sc_dev.dv_xname);
-
-        return;
 }
 
 /*
@@ -638,12 +626,11 @@
 rtk_attach(sc)
        struct rtk_softc *sc;
 {
-
        struct ifnet *ifp;
        u_int16_t val;
        u_int8_t eaddr[ETHER_ADDR_LEN];
        int error;
-       int i,addr_len;
+       int i, addr_len;
 
        callout_init(&sc->rtk_tick_ch);
 
@@ -669,7 +656,7 @@
        eaddr[5] = val >> 8;
 
        if ((error = bus_dmamem_alloc(sc->sc_dmat,
-           RTK_RXBUFLEN + 32, PAGE_SIZE, 0, &sc->sc_dmaseg, 1, &sc->sc_dmanseg,
+           RTK_RXBUFLEN + 16, PAGE_SIZE, 0, &sc->sc_dmaseg, 1, &sc->sc_dmanseg,
            BUS_DMA_NOWAIT)) != 0) {
                printf("%s: can't allocate recv buffer, error = %d\n",
                       sc->sc_dev.dv_xname, error);
@@ -677,20 +664,15 @@
        }
 
        if ((error = bus_dmamem_map(sc->sc_dmat, &sc->sc_dmaseg, sc->sc_dmanseg,
-           RTK_RXBUFLEN + 32, (caddr_t *)&sc->rtk_cdata.rtk_rx_buf,
+           RTK_RXBUFLEN + 16, (caddr_t *)&sc->rtk_cdata.rtk_rx_buf,
            BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
                printf("%s: can't map recv buffer, error = %d\n",
                       sc->sc_dev.dv_xname, error);
                goto fail_1;
        }
 
-       /* Leave a few bytes before the start of the RX ring buffer. */
-       sc->rtk_cdata.rtk_rx_buf_ptr = sc->rtk_cdata.rtk_rx_buf;
-       sc->rtk_cdata.rtk_rx_buf += sizeof(u_int64_t);
-
        if ((error = bus_dmamap_create(sc->sc_dmat,
-           RTK_RXBUFLEN + 32 - sizeof(u_int64_t), 1,
-           RTK_RXBUFLEN + 32 - sizeof(u_int64_t), 0, BUS_DMA_NOWAIT,
+           RTK_RXBUFLEN + 16, 1, RTK_RXBUFLEN + 16, 0, BUS_DMA_NOWAIT,
            &sc->recv_dmamap)) != 0) {
                printf("%s: can't create recv buffer DMA map, error = %d\n",
                       sc->sc_dev.dv_xname, error);



Home | Main Index | Thread Index | Old Index