]> git.sur5r.net Git - u-boot/blobdiff - net/net.c
netloop: speed up NetLoop
[u-boot] / net / net.c
index 77e83b5bd0a986a1f8853a52caf4b6e0e3284dd0..a55f4d33f984ce98f5dc1b046b03466974bd18bb 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -89,6 +89,9 @@
 #if defined(CONFIG_CMD_SNTP)
 #include "sntp.h"
 #endif
+#if defined(CONFIG_CDP_VERSION)
+#include <timestamp.h>
+#endif
 
 #if defined(CONFIG_CMD_NET)
 
@@ -206,6 +209,8 @@ uchar               NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
 ulong          NetArpWaitTimerStart;
 int            NetArpWaitTry;
 
+int            env_changed_id = 0;
+
 void ArpRequest (void)
 {
        int i;
@@ -273,6 +278,78 @@ void ArpTimeoutCheck(void)
        }
 }
 
+int
+NetInitLoop(proto_t protocol)
+{
+       bd_t *bd = gd->bd;
+       int env_id = get_env_id ();
+
+       /* update only when the environment has changed */
+       if (env_changed_id == env_id)
+               return 0;
+
+       switch (protocol) {
+#if defined(CONFIG_CMD_NFS)
+       case NFS:
+#endif
+#if defined(CONFIG_CMD_PING)
+       case PING:
+#endif
+#if defined(CONFIG_CMD_SNTP)
+       case SNTP:
+#endif
+       case NETCONS:
+       case TFTP:
+               NetCopyIP(&NetOurIP, &bd->bi_ip_addr);
+               NetOurGatewayIP = getenv_IPaddr ("gatewayip");
+               NetOurSubnetMask= getenv_IPaddr ("netmask");
+               NetOurVLAN = getenv_VLAN("vlan");
+               NetOurNativeVLAN = getenv_VLAN("nvlan");
+
+               switch (protocol) {
+#if defined(CONFIG_CMD_NFS)
+               case NFS:
+#endif
+               case NETCONS:
+               case TFTP:
+                       NetServerIP = getenv_IPaddr ("serverip");
+                       break;
+#if defined(CONFIG_CMD_PING)
+               case PING:
+                       /* nothing */
+                       break;
+#endif
+#if defined(CONFIG_CMD_SNTP)
+               case SNTP:
+                       /* nothing */
+                       break;
+#endif
+               default:
+                       break;
+               }
+
+               break;
+       case BOOTP:
+       case RARP:
+               /*
+                * initialize our IP addr to 0 in order to accept ANY
+                * IP addr assigned to us by the BOOTP / RARP server
+                */
+               NetOurIP = 0;
+               NetServerIP = getenv_IPaddr ("serverip");
+               NetOurVLAN = getenv_VLAN("vlan");       /* VLANs must be read */
+               NetOurNativeVLAN = getenv_VLAN("nvlan");
+       case CDP:
+               NetOurVLAN = getenv_VLAN("vlan");       /* VLANs must be read */
+               NetOurNativeVLAN = getenv_VLAN("nvlan");
+               break;
+       default:
+               break;
+       }
+       env_changed_id = env_id;
+       return 0;
+}
+
 /**********************************************************************/
 /*
  *     Main network processing loop.
@@ -337,65 +414,7 @@ restart:
         *      here on, this code is a state machine driven by received
         *      packets and timer events.
         */
-
-       switch (protocol) {
-#if defined(CONFIG_CMD_NFS)
-       case NFS:
-#endif
-#if defined(CONFIG_CMD_PING)
-       case PING:
-#endif
-#if defined(CONFIG_CMD_SNTP)
-       case SNTP:
-#endif
-       case NETCONS:
-       case TFTP:
-               NetCopyIP(&NetOurIP, &bd->bi_ip_addr);
-               NetOurGatewayIP = getenv_IPaddr ("gatewayip");
-               NetOurSubnetMask= getenv_IPaddr ("netmask");
-               NetOurVLAN = getenv_VLAN("vlan");
-               NetOurNativeVLAN = getenv_VLAN("nvlan");
-
-               switch (protocol) {
-#if defined(CONFIG_CMD_NFS)
-               case NFS:
-#endif
-               case NETCONS:
-               case TFTP:
-                       NetServerIP = getenv_IPaddr ("serverip");
-                       break;
-#if defined(CONFIG_CMD_PING)
-               case PING:
-                       /* nothing */
-                       break;
-#endif
-#if defined(CONFIG_CMD_SNTP)
-               case SNTP:
-                       /* nothing */
-                       break;
-#endif
-               default:
-                       break;
-               }
-
-               break;
-       case BOOTP:
-       case RARP:
-               /*
-                * initialize our IP addr to 0 in order to accept ANY
-                * IP addr assigned to us by the BOOTP / RARP server
-                */
-               NetOurIP = 0;
-               NetServerIP = getenv_IPaddr ("serverip");
-               NetOurVLAN = getenv_VLAN("vlan");       /* VLANs must be read */
-               NetOurNativeVLAN = getenv_VLAN("nvlan");
-       case CDP:
-               NetOurVLAN = getenv_VLAN("vlan");       /* VLANs must be read */
-               NetOurNativeVLAN = getenv_VLAN("nvlan");
-               break;
-       default:
-               break;
-       }
+       NetInitLoop(protocol);
 
        switch (net_check_prereq (protocol)) {
        case 1:
@@ -735,7 +754,7 @@ int PingSend(void)
        ip->ip_tos   = 0;
        ip->ip_len   = htons(IP_HDR_SIZE_NO_UDP + 8);
        ip->ip_id    = htons(NetIPID++);
-       ip->ip_off   = htons(0x4000);   /* No fragmentation */
+       ip->ip_off   = htons(IP_FLAGS_DFRAG);   /* Don't fragment */
        ip->ip_ttl   = 255;
        ip->ip_p     = 0x01;            /* ICMP */
        ip->ip_sum   = 0;
@@ -1399,7 +1418,8 @@ NetReceive(volatile uchar * inpkt, int len)
                if ((ip->ip_hl_v & 0xf0) != 0x40) {
                        return;
                }
-               if (ip->ip_off & htons(0x1fff)) { /* Can't deal w/ fragments */
+               /* Can't deal with fragments */
+               if (ip->ip_off & htons(IP_OFFS | IP_FLAGS_MFRAG)) {
                        return;
                }
                /* can't deal with headers > 20 bytes */
@@ -1680,7 +1700,7 @@ NetSetEther(volatile uchar * xet, uchar * addr, uint prot)
 void
 NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len)
 {
-       volatile IP_t *ip = (IP_t *)xip;
+       IP_t *ip = (IP_t *)xip;
 
        /*
         *      If the data is an odd number of bytes, zero the
@@ -1698,7 +1718,7 @@ NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len)
        ip->ip_tos   = 0;
        ip->ip_len   = htons(IP_HDR_SIZE + len);
        ip->ip_id    = htons(NetIPID++);
-       ip->ip_off   = htons(0x4000);   /* No fragmentation */
+       ip->ip_off   = htons(IP_FLAGS_DFRAG);   /* Don't fragment */
        ip->ip_ttl   = 255;
        ip->ip_p     = 17;              /* UDP */
        ip->ip_sum   = 0;