Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic support 8bit mode, needed for ci20



details:   https://anonhg.NetBSD.org/src/rev/49a364046c57
branches:  trunk
changeset: 336688:49a364046c57
user:      macallan <macallan%NetBSD.org@localhost>
date:      Tue Mar 10 18:01:04 2015 +0000

description:
support 8bit mode, needed for ci20

diffstat:

 sys/dev/ic/dm9000.c |  85 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 81 insertions(+), 4 deletions(-)

diffs (124 lines):

diff -r dedaadc6687e -r 49a364046c57 sys/dev/ic/dm9000.c
--- a/sys/dev/ic/dm9000.c       Tue Mar 10 13:28:47 2015 +0000
+++ b/sys/dev/ic/dm9000.c       Tue Mar 10 18:01:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dm9000.c,v 1.5 2014/11/26 22:50:22 skrll Exp $ */
+/*     $NetBSD: dm9000.c,v 1.6 2015/03/10 18:01:04 macallan Exp $      */
 
 /*
  * Copyright (c) 2009 Paul Fleischer
@@ -200,7 +200,9 @@
 /* Read/write packet data from/to DM9000 IC in various transfer sizes */
 int    dme_pkt_read_2(struct dme_softc *sc, struct ifnet *ifp, struct mbuf **outBuf);
 int    dme_pkt_write_2(struct dme_softc *sc, struct mbuf *bufChain);
-/* TODO: Implement 8 and 32 bit read/write functions */
+int    dme_pkt_read_1(struct dme_softc *sc, struct ifnet *ifp, struct mbuf **outBuf);
+int    dme_pkt_write_1(struct dme_softc *sc, struct mbuf *bufChain);
+/* TODO: Implement 32 bit read/write functions */
 
 uint16_t
 dme_phy_read(struct dme_softc *sc, int reg)
@@ -494,8 +496,6 @@
 
        io_mode = (dme_read(sc, DM9000_ISR) &
            DM9000_IOMODE_MASK) >> DM9000_IOMODE_SHIFT;
-       if (io_mode != DM9000_MODE_16BIT )
-               panic("DM9000: Only 16-bit mode is supported!\n");
 
        DPRINTF(("DM9000 Operation Mode: "));
        switch( io_mode) {
@@ -508,10 +508,13 @@
        case DM9000_MODE_32BIT:
                DPRINTF(("32-bit mode"));
                sc->sc_data_width = 4;
+               panic("32bit mode is unsupported\n");
                break;
        case DM9000_MODE_8BIT:
                DPRINTF(("8-bit mode"));
                sc->sc_data_width = 1;
+               sc->sc_pkt_write = dme_pkt_write_1;
+               sc->sc_pkt_read = dme_pkt_read_1;
                break;
        default:
                DPRINTF(("Invalid mode"));
@@ -1105,6 +1108,80 @@
        return rx_status;
 }
 
+int
+dme_pkt_write_1(struct dme_softc *sc, struct mbuf *bufChain)
+{
+       int length = 0, i;
+       struct mbuf *buf;
+       uint8_t *write_ptr;
+
+       /* We expect that the DM9000 has been setup to accept writes before
+          this function is called. */
+
+       for (buf = bufChain; buf != NULL; buf = buf->m_next) {
+               int to_write = buf->m_len;
+
+               length += to_write;
+
+               write_ptr = buf->m_data;
+               for(i = 0; i < to_write; i++) {
+                       bus_space_write_1(sc->sc_iot, sc->sc_ioh,
+                           sc->dme_data, *write_ptr);
+                       write_ptr++;
+               }
+       } /* for(...) */
+
+       return length;
+}
+
+int
+dme_pkt_read_1(struct dme_softc *sc, struct ifnet *ifp, struct mbuf **outBuf)
+{
+       uint8_t rx_status;
+       struct mbuf *m;
+       uint8_t *buf;
+       uint16_t frame_length;
+       uint16_t i, reg;
+       uint8_t data;
+
+       reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->dme_data);
+       reg |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->dme_data) << 8;
+       rx_status = reg & 0xFF;
+
+       reg = bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->dme_data);
+       reg |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->dme_data) << 8;
+       frame_length = reg;
+       if (frame_length > ETHER_MAX_LEN) {
+               printf("Got frame of length: %d\n", frame_length);
+               printf("ETHER_MAX_LEN is: %d\n", ETHER_MAX_LEN);
+               panic("Something is rotten");
+       }
+       RX_DPRINTF(("dme_receive: "
+                   "rx_statux: 0x%x, frame_length: %d\n",
+                   rx_status, frame_length));
+
+
+       m = dme_alloc_receive_buffer(ifp, frame_length);
+
+       buf = mtod(m, uint8_t*);
+
+       RX_DPRINTF(("dme_receive: "));
+
+       for(i=0; i< frame_length; i+=1 ) {
+               data = bus_space_read_1(sc->sc_iot,
+                                       sc->sc_ioh, sc->dme_data);
+               *buf = data;
+               buf++;
+               RX_DATA_DPRINTF(("%02X ", data));
+       }
+
+       RX_DATA_DPRINTF(("\n"));
+       RX_DPRINTF(("Read %d bytes\n", i));
+
+       *outBuf = m;
+       return rx_status;
+}
+
 struct mbuf*
 dme_alloc_receive_buffer(struct ifnet *ifp, unsigned int frame_length)
 {



Home | Main Index | Thread Index | Old Index