ne2000 wasn't converted to CONFIG_NET_MULTI when the non-multi support was
dropped, so boards using it (qemu-mips, shmin, r7780mp) failed to compile
for multiple definition of eth_rx() and friends due to old ne2000_base.c.

Changes:

In drivers/net/ne2000_base.c:

- Convert the driver to use a new probe function which calls eth_register():
  - move probing / MAC addr code from eth_init to new ne2000_initialize()
  - cleanup the moved code to use eth_setenv_enetaddr()
  - Rename eth_init, eth_rx, eth_send and eth_halt to ne2k_* and use new calls

qemu-mips, shmin, r7780mp:
- Call the new ne2000_initialize() from board_eth_init() of the boards.

Cleanups in drivers/net/ne2000_base.c:

- Use NE2000_RX_BUFFER_SIZE, defined to 2000 instead of a 2000 size constant.
- dp83902a_init():
  - Remove check for dp->base (nic.base): It is always assinged in probe func
  - Extend #ifdef NE2000_BASIC_INIT to whole function: The function does not
    have any useful code if NE2000_BASIC_INIT is not defined anymore.
  - Change printf of ESA MAC to debug PRINTK: Was always overridden(= not used)
  - In case somebody wants to use the ESA mac, add ifdef'ed memcpy to use it.
- Fix gcc warnings in two debug printf calls

- Tested using qemu-mips board,
- Tested the two renesas / sh boards r7780mp and shmin to compile again,
  and should work.

Signed-off-by: Bernhard Kaindl <bernhard.kai...@gmx.net>
---
 board/qemu-mips/qemu-mips.c     |    6 ++
 board/renesas/r7780mp/r7780mp.c |    3 +-
 board/shmin/shmin.c             |    5 ++
 drivers/net/ne2000_base.c       |  135 +++++++++++++++++++--------------------
 include/netdev.h                |    1 +
 5 files changed, 81 insertions(+), 69 deletions(-)

diff --git a/board/qemu-mips/qemu-mips.c b/board/qemu-mips/qemu-mips.c
index 7a69a00..e0372a6 100644
--- a/board/qemu-mips/qemu-mips.c
+++ b/board/qemu-mips/qemu-mips.c
@@ -87,3 +87,8 @@ int misc_init_r(void)
        set_io_port_base(0);
        return 0;
 }
+
+int board_eth_init(bd_t *bis)
+{
+       return ne2000_initialize();
+}
diff --git a/board/renesas/r7780mp/r7780mp.c b/board/renesas/r7780mp/r7780mp.c
index 0b80099..004c67e 100644
--- a/board/renesas/r7780mp/r7780mp.c
+++ b/board/renesas/r7780mp/r7780mp.c
@@ -81,5 +81,6 @@ void pci_init_board(void)
 
 int board_eth_init(bd_t *bis)
 {
-       return pci_eth_init(bis);
+       /* return >= 0 if a chip is found, the board's AX88796L is n2k-based */
+       return ne2000_initialize() + pci_eth_init(bis);
 }
diff --git a/board/shmin/shmin.c b/board/shmin/shmin.c
index 8742f10..9292af4 100644
--- a/board/shmin/shmin.c
+++ b/board/shmin/shmin.c
@@ -55,6 +55,11 @@ int dram_init(void)
        return 0;
 }
 
+int board_eth_init(bd_t *bis)
+{
+       return ne2000_initialize();
+}
+
 void led_set_state(unsigned short value)
 {
 
diff --git a/drivers/net/ne2000_base.c b/drivers/net/ne2000_base.c
index f93f932..eeda1c4 100644
--- a/drivers/net/ne2000_base.c
+++ b/drivers/net/ne2000_base.c
@@ -85,6 +85,8 @@ void uboot_push_tx_done(int key, int val);
 /* NE2000 base header file */
 #include "ne2000_base.h"
 
+#define NE2000_RX_BUFFER_SIZE 2000
+
 #if defined(CONFIG_DRIVER_AX88796L)
 /* AX88796L support */
 #include "ax88796.h"
@@ -96,23 +98,15 @@ void uboot_push_tx_done(int key, int val);
 static dp83902a_priv_data_t nic; /* just one instance of the card supported */
 
 static bool
-dp83902a_init(void)
+dp83902a_init(struct eth_device *dev)
 {
+#if defined(NE2000_BASIC_INIT)
        dp83902a_priv_data_t *dp = &nic;
        u8* base;
-#if defined(NE2000_BASIC_INIT)
        int i;
-#endif
-
-       DEBUG_FUNCTION();
 
        base = dp->base;
-       if (!base)
-               return false;   /* No device found */
-
-       DEBUG_LINE();
 
-#if defined(NE2000_BASIC_INIT)
        /* AX88796L doesn't need */
        /* Prepare ESA */
        DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE1); /* Select page 1 */
@@ -121,7 +115,7 @@ dp83902a_init(void)
                DP_IN(base, DP_P1_PAR0+i, dp->esa[i]);
        DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0); /* Select page 0 */
 
-       printf("NE2000 - %s ESA: %02x:%02x:%02x:%02x:%02x:%02x\n",
+       PRINTK("NE2000 - %s ESA: %02x:%02x:%02x:%02x:%02x:%02x\n",
                "eeprom",
                dp->esa[0],
                dp->esa[1],
@@ -129,6 +123,9 @@ dp83902a_init(void)
                dp->esa[3],
                dp->esa[4],
                dp->esa[5] );
+#ifdef NE2000_USE_MAC_FROM_SERIAL_EEPROM /* Define this to use it actually */
+       memcpy(dev->enetaddr, dp->esa, 6);
+#endif
 
 #endif /* NE2000_BASIC_INIT */
        return true;
@@ -301,7 +298,7 @@ dp83902a_send(u8 *data, int total_len, u32 key)
 
        /* Put data into buffer */
 #if DEBUG & 4
-       printf(" sg buf %08lx len %08x\n ", (u32)data, len);
+       printf(" sg buf %08x len %08x\n ", (u32)data, len);
        dx = 0;
 #endif
        while (len > 0) {
@@ -469,7 +466,7 @@ dp83902a_recv(u8 *data, int len)
                if (data) {
                        mlen = len;
 #if DEBUG & 4
-                       printf(" sg buf %08lx len %08x \n", (u32) data, mlen);
+                       printf(" sg buf %08x len %08x\n", (u32) data, mlen);
                        dx = 0;
 #endif
                        while (0 < mlen) {
@@ -651,7 +648,7 @@ static int initialized = 0;
 
 void uboot_push_packet_len(int len) {
        PRINTK("pushed len = %d\n", len);
-       if (len >= 2000) {
+       if (len >= NE2000_RX_BUFFER_SIZE) {
                printf("NE2000: packet too big\n");
                return;
        }
@@ -666,76 +663,33 @@ void uboot_push_tx_done(int key, int val) {
        pkey = key;
 }
 
-int eth_init(bd_t *bd) {
-       int r;
-       u8 dev_addr[6];
-       char ethaddr[20];
-
-       PRINTK("### eth_init\n");
-
-       if (!pbuf) {
-               pbuf = malloc(2000);
-               if (!pbuf) {
-                       printf("Cannot allocate rx buffer\n");
-                       return -1;
-               }
-       }
-
-#ifdef CONFIG_DRIVER_NE2000_CCR
-       {
-               vu_char *p = (vu_char *) CONFIG_DRIVER_NE2000_CCR;
-
-               PRINTK("CCR before is %x\n", *p);
-               *p = CONFIG_DRIVER_NE2000_VAL;
-               PRINTK("CCR after is %x\n", *p);
-       }
-#endif
-
-       nic.base = (u8 *) CONFIG_DRIVER_NE2000_BASE;
-
-       r = get_prom(dev_addr, nic.base);
-       if (!r)
-               return -1;
-
-       sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
-                dev_addr[0], dev_addr[1],
-                dev_addr[2], dev_addr[3],
-                dev_addr[4], dev_addr[5]) ;
-       PRINTK("Set environment from HW MAC addr = \"%s\"\n", ethaddr);
-       setenv ("ethaddr", ethaddr);
-
-       nic.data = nic.base + DP_DATA;
-       nic.tx_buf1 = START_PG;
-       nic.tx_buf2 = START_PG2;
-       nic.rx_buf_start = RX_START;
-       nic.rx_buf_end = RX_END;
-
-       if (dp83902a_init() == false)
-               return -1;
-
-       dp83902a_start(dev_addr);
+static int ne2k_init(struct eth_device *dev, bd_t *bd)
+{
+       dp83902a_start(dev->enetaddr);
        initialized = 1;
 
        return 0;
 }
 
-void eth_halt() {
-
-       PRINTK("### eth_halt\n");
+static void ne2k_halt(struct eth_device *dev)
+{
+       debug("### ne2k_halt\n");
        if(initialized)
                dp83902a_stop();
        initialized = 0;
 }
 
-int eth_rx() {
+static int ne2k_recv(struct eth_device *dev)
+{
        dp83902a_poll();
        return 1;
 }
 
-int eth_send(volatile void *packet, int length) {
+static int ne2k_send(struct eth_device *dev, volatile void *packet, int length)
+{
        int tmo;
 
-       PRINTK("### eth_send\n");
+       debug("### ne2k_send\n");
 
        pkey = -1;
 
@@ -755,3 +709,48 @@ int eth_send(volatile void *packet, int length) {
        }
        return 0;
 }
+
+int ne2000_initialize(void)
+{
+       struct eth_device *dev;
+
+       nic.base = (u8 *) CONFIG_DRIVER_NE2000_BASE;
+       nic.data = nic.base + DP_DATA;
+       nic.tx_buf1 = START_PG;
+       nic.tx_buf2 = START_PG2;
+       nic.rx_buf_start = RX_START;
+       nic.rx_buf_end = RX_END;
+
+       dev = calloc(sizeof(*dev), 1);
+       pbuf = malloc(NE2000_RX_BUFFER_SIZE);
+
+       if (dev == NULL || pbuf == NULL)
+               return -1;
+
+       if (!get_prom(dev->enetaddr, nic.base))
+               return -1;
+
+       dp83902a_init(dev);
+
+       eth_setenv_enetaddr("ethaddr", dev->enetaddr);
+
+       /* For PCMCIA support: See doc/README.ne2000 on how to enable */
+#ifdef CONFIG_DRIVER_NE2000_CCR
+       {
+               vu_char *p = (vu_char *) CONFIG_DRIVER_NE2000_CCR;
+
+               PRINTK("CCR before is %x\n", *p);
+               *p = CONFIG_DRIVER_NE2000_VAL;
+               PRINTK("CCR after is %x\n", *p);
+       }
+#endif
+
+       dev->init = ne2k_init;
+       dev->halt = ne2k_halt;
+       dev->send = ne2k_send;
+       dev->recv = ne2k_recv;
+
+       sprintf(dev->name, "NE2000");
+
+       return eth_register(dev);
+}
diff --git a/include/netdev.h b/include/netdev.h
index 480453e..d13a5e2 100644
--- a/include/netdev.h
+++ b/include/netdev.h
@@ -79,6 +79,7 @@ int mpc8220_fec_initialize(bd_t *bis);
 int mpc82xx_scc_enet_initialize(bd_t *bis);
 int mvgbe_initialize(bd_t *bis);
 int natsemi_initialize(bd_t *bis);
+int ne2000_initialize();
 int npe_initialize(bd_t *bis);
 int ns8382x_initialize(bd_t *bis);
 int pcnet_initialize(bd_t *bis);
-- 
1.7.3.4

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to