]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
Merge branch 'master' of git://www.denx.de/git/u-boot-ppc4xx
authorWolfgang Denk <wd@denx.de>
Tue, 8 Jan 2008 12:41:42 +0000 (13:41 +0100)
committerWolfgang Denk <wd@denx.de>
Tue, 8 Jan 2008 12:41:42 +0000 (13:41 +0100)
include/net.h
net/eth.c
net/net.c

index 603452ab3281ec9adb54652c11c3755a69ed2faf..f6decdca8836bf91fbb69e64fa8372de59cdfa31 100644 (file)
@@ -122,6 +122,9 @@ extern void eth_set_enetaddr(int num, char* a);     /* Set new MAC address          */
 
 extern int eth_init(bd_t *bis);                        /* Initialize the device        */
 extern int eth_send(volatile void *packet, int length);           /* Send a packet     */
+#ifdef CONFIG_API
+extern int eth_receive(volatile void *packet, int length); /* Receive a packet */
+#endif
 extern int eth_rx(void);                       /* Check for received packets   */
 extern void eth_halt(void);                    /* stop SCC                     */
 extern char *eth_get_name(void);               /* get name of current device   */
index 1b56a356c4f4544623b1093b6ef614dd1ff21a38..3373a05252197665c54b493570a5231263b35c1d 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -62,6 +62,17 @@ extern int bfin_EMAC_initialize(bd_t *);
 extern int atstk1000_eth_initialize(bd_t *);
 extern int mcffec_initialize(bd_t*);
 
+#ifdef CONFIG_API
+extern void (*push_packet)(volatile void *, int);
+
+static struct {
+       uchar data[PKTSIZE];
+       int length;
+} eth_rcv_bufs[PKTBUFSRX];
+
+static unsigned int eth_rcv_current = 0, eth_rcv_last = 0;
+#endif
+
 static struct eth_device *eth_devices, *eth_current;
 
 struct eth_device *eth_get_dev(void)
@@ -138,7 +149,8 @@ int eth_register(struct eth_device* dev)
 
 int eth_initialize(bd_t *bis)
 {
-       char enetvar[32], env_enetaddr[6];
+       char enetvar[32];
+       unsigned char env_enetaddr[6];
        int i, eth_number = 0;
        char *tmp, *end;
 
@@ -412,23 +424,23 @@ int eth_init(bd_t *bis)
        struct eth_device* old_current;
 
        if (!eth_current)
-               return 0;
+               return -1;
 
        old_current = eth_current;
        do {
                debug ("Trying %s\n", eth_current->name);
 
-               if (eth_current->init(eth_current, bis)) {
+               if (!eth_current->init(eth_current,bis)) {
                        eth_current->state = ETH_STATE_ACTIVE;
 
-                       return 1;
+                       return 0;
                }
                debug  ("FAIL\n");
 
                eth_try_another(0);
        } while (old_current != eth_current);
 
-       return 0;
+       return -1;
 }
 
 void eth_halt(void)
@@ -457,6 +469,53 @@ int eth_rx(void)
        return eth_current->recv(eth_current);
 }
 
+#ifdef CONFIG_API
+static void eth_save_packet(volatile void *packet, int length)
+{
+       volatile char *p = packet;
+       int i;
+
+       if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current)
+               return;
+
+       if (PKTSIZE < length)
+               return;
+
+       for (i = 0; i < length; i++)
+               eth_rcv_bufs[eth_rcv_last].data[i] = p[i];
+
+       eth_rcv_bufs[eth_rcv_last].length = length;
+       eth_rcv_last = (eth_rcv_last + 1) % PKTBUFSRX;
+}
+
+int eth_receive(volatile void *packet, int length)
+{
+       volatile char *p = packet;
+       void *pp = push_packet;
+       int i;
+
+       if (eth_rcv_current == eth_rcv_last) {
+               push_packet = eth_save_packet;
+               eth_rx();
+               push_packet = pp;
+
+               if (eth_rcv_current == eth_rcv_last)
+                       return -1;
+       }
+
+       if (length < eth_rcv_bufs[eth_rcv_current].length)
+               return -1;
+
+       length = eth_rcv_bufs[eth_rcv_current].length;
+
+       for (i = 0; i < length; i++)
+               p[i] = eth_rcv_bufs[eth_rcv_current].data[i];
+
+       eth_rcv_current = (eth_rcv_current + 1) % PKTBUFSRX;
+       return length;
+}
+#endif /* CONFIG_API */
+
 void eth_try_another(int first_restart)
 {
        static struct eth_device *first_failed = NULL;
index c719bc4c0f36d84698e8ae8fc95a3641aa5ff256..44feee2290424a852b18e3fde99aa0b036634600 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -137,6 +137,9 @@ uchar               NetBcastAddr[6] =       /* Ethernet bcast address               */
                        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 uchar          NetEtherNullAddr[6] =
                        { 0, 0, 0, 0, 0, 0 };
+#ifdef CONFIG_API
+void           (*push_packet)(volatile void *, int len) = 0;
+#endif
 #if defined(CONFIG_CMD_CDP)
 uchar          NetCDPAddr[6] =         /* Ethernet bcast address               */
                        { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
@@ -593,7 +596,9 @@ void NetStartAgain (void)
        NetSetHandler (startAgainHandler);
 #else  /* !CONFIG_NET_MULTI*/
        eth_halt ();
+#if !defined(CONFIG_NET_DO_NOT_TRY_ANOTHER)
        eth_try_another (!NetRestarted);
+#endif
        eth_init (gd->bd);
        if (NetRestartWrap) {
                NetRestartWrap = 0;
@@ -1161,6 +1166,13 @@ NetReceive(volatile uchar * inpkt, int len)
        if (len < ETHER_HDR_SIZE)
                return;
 
+#ifdef CONFIG_API
+       if (push_packet) {
+               (*push_packet)(inpkt, len);
+               return;
+       }
+#endif
+
 #if defined(CONFIG_CMD_CDP)
        /* keep track if packet is CDP */
        iscdp = memcmp(et->et_dest, NetCDPAddr, 6) == 0;