]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
net: express the first argument to NetSetTimeout() in milliseconds
authorBartlomiej Sieka <tur@semihalf.com>
Wed, 1 Oct 2008 13:26:28 +0000 (15:26 +0200)
committerWolfgang Denk <wd@denx.de>
Sat, 18 Oct 2008 19:54:00 +0000 (21:54 +0200)
Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
net/bootp.c
net/bootp.h
net/net.c
net/nfs.c
net/rarp.c
net/sntp.c
net/tftp.c

index 64552ac2a64ce125a62e8d98a33c545a9ce85c76..c2078c6c8cf16ab3cdc938208ebad6d3145d3000 100644 (file)
@@ -33,7 +33,7 @@
 
 #if defined(CONFIG_CMD_NET)
 
-#define TIMEOUT                5UL             /* Seconds before trying BOOTP again    */
+#define TIMEOUT                5000UL  /* Milliseconds before trying BOOTP again */
 #ifndef CONFIG_NET_RETRY_COUNT
 # define TIMEOUT_COUNT 5               /* # of timeouts before giving up  */
 #else
@@ -371,7 +371,7 @@ BootpTimeout(void)
                puts ("\nRetry count exceeded; starting again\n");
                NetStartAgain ();
        } else {
-               NetSetTimeout (TIMEOUT * CFG_HZ, BootpTimeout);
+               NetSetTimeout (TIMEOUT, BootpTimeout);
                BootpRequest ();
        }
 }
@@ -671,7 +671,7 @@ BootpRequest (void)
        bp->bp_htype = HWT_ETHER;
        bp->bp_hlen = HWL_ETHER;
        bp->bp_hops = 0;
-       bp->bp_secs = htons(get_timer(0) / CFG_HZ);
+       bp->bp_secs = htons(get_timer(0) / 1000);
        NetWriteIP(&bp->bp_ciaddr, 0);
        NetWriteIP(&bp->bp_yiaddr, 0);
        NetWriteIP(&bp->bp_siaddr, 0);
@@ -688,7 +688,7 @@ BootpRequest (void)
 
        /*
         *      Bootp ID is the lower 4 bytes of our ethernet address
-        *      plus the current time in HZ.
+        *      plus the current time in ms.
         */
        BootpID = ((ulong)NetOurEther[2] << 24)
                | ((ulong)NetOurEther[3] << 16)
@@ -705,7 +705,7 @@ BootpRequest (void)
        pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + ext_len;
        iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
        NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
-       NetSetTimeout(SELECT_TIMEOUT * CFG_HZ, BootpTimeout);
+       NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
 
 #if defined(CONFIG_CMD_DHCP)
        dhcp_state = SELECTING;
@@ -849,7 +849,7 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer)
        bp->bp_htype = HWT_ETHER;
        bp->bp_hlen = HWL_ETHER;
        bp->bp_hops = 0;
-       bp->bp_secs = htons(get_timer(0) / CFG_HZ);
+       bp->bp_secs = htons(get_timer(0) / 1000);
        /* Do not set the client IP, your IP, or server IP yet, since it hasn't been ACK'ed by
         * the server yet */
 
@@ -924,7 +924,7 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
                        if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
                                DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
 
-                       NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout);
+                       NetSetTimeout(TIMEOUT, BootpTimeout);
                        DhcpSendRequestPkt(bp);
 #ifdef CFG_BOOTFILE_PREFIX
                }
index c2f011c8c69b33900cc39fda0ca08688b4806566..50625abea1839e6ecff7d04c8137a3ab6ca64c32 100644 (file)
@@ -88,7 +88,7 @@ typedef enum { INIT,
 #define DHCP_NAK      6
 #define DHCP_RELEASE  7
 
-#define SELECT_TIMEOUT 3UL     /* Seconds to wait for offers */
+#define SELECT_TIMEOUT 3000UL  /* Milliseconds to wait for offers */
 
 /**********************************************************************/
 
index 313d5d8dab354cbbdc4d32b2f3888a37c11df68f..80262b933686b8231280a4647efc09197f02b113 100644 (file)
--- a/net/net.c
+++ b/net/net.c
 DECLARE_GLOBAL_DATA_PTR;
 
 #ifndef        CONFIG_ARP_TIMEOUT
-# define ARP_TIMEOUT           50UL    /* Deciseconds before trying ARP again */
-#elif (CONFIG_ARP_TIMEOUT < 100)
-# error "Due to possible overflow CONFIG_ARP_TIMEOUT must be greater than 100ms"
+# define ARP_TIMEOUT           5000UL  /* Milliseconds before trying ARP again */
 #else
-# if (CONFIG_ARP_TIMEOUT % 100)
-#  warning "Supported ARP_TIMEOUT precision is 100ms"
-# endif
-# define ARP_TIMEOUT           (CONFIG_ARP_TIMEOUT / 100)
+# define ARP_TIMEOUT           CONFIG_ARP_TIMEOUT
 #endif
 
 
@@ -264,7 +259,7 @@ void ArpTimeoutCheck(void)
        t = get_timer(0);
 
        /* check for arp timeout */
-       if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT * CFG_HZ / 10) {
+       if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT) {
                NetArpWaitTry++;
 
                if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) {
@@ -603,7 +598,7 @@ void NetStartAgain (void)
                return;
        }
 #ifndef CONFIG_NET_MULTI
-       NetSetTimeout (10UL * CFG_HZ, startAgainTimeout);
+       NetSetTimeout (10000UL, startAgainTimeout);
        NetSetHandler (startAgainHandler);
 #else  /* !CONFIG_NET_MULTI*/
        eth_halt ();
@@ -614,7 +609,7 @@ void NetStartAgain (void)
        if (NetRestartWrap) {
                NetRestartWrap = 0;
                if (NetDevExists && !once) {
-                       NetSetTimeout (10UL * CFG_HZ, startAgainTimeout);
+                       NetSetTimeout (10000UL, startAgainTimeout);
                        NetSetHandler (startAgainHandler);
                } else {
                        NetState = NETLOOP_FAIL;
@@ -790,7 +785,7 @@ static void PingStart(void)
 #if defined(CONFIG_NET_MULTI)
        printf ("Using %s device\n", eth_get_name());
 #endif /* CONFIG_NET_MULTI */
-       NetSetTimeout (10UL * CFG_HZ, PingTimeout);
+       NetSetTimeout (10000UL, PingTimeout);
        NetSetHandler (PingHandler);
 
        PingSend();
@@ -813,7 +808,7 @@ static void PingStart(void)
 #define CDP_SYSOBJECT_TLV              0x0015
 #define CDP_MANAGEMENT_ADDRESS_TLV     0x0016
 
-#define CDP_TIMEOUT                    (CFG_HZ/4)      /* one packet every 250ms */
+#define CDP_TIMEOUT                    250UL   /* one packet every 250ms */
 
 static int CDPSeq;
 static int CDPOK;
index 6573c1716bb07fd731f5a03426cf1fd4cedb84ba..0c8f08c9ae2e5a2067c4f48c3fa35fb3ea27a150 100644 (file)
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -35,7 +35,7 @@
 
 #define HASHES_PER_LINE 65     /* Number of "loading" hashes per line  */
 #define NFS_RETRY_COUNT 30
-#define NFS_TIMEOUT 2UL
+#define NFS_TIMEOUT 2000UL
 
 static int fs_mounted = 0;
 static unsigned long rpc_id = 0;
@@ -674,7 +674,7 @@ NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
 
        case STATE_READ_REQ:
                rlen = nfs_read_reply (pkt, len);
-               NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout);
+               NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
                if (rlen > 0) {
                        nfs_offset += rlen;
                        NfsSend ();
@@ -763,7 +763,7 @@ NfsStart (void)
        printf ("\nLoad address: 0x%lx\n"
                "Loading: *\b", load_addr);
 
-       NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout);
+       NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
        NetSetHandler (NfsHandler);
 
        NfsTimeoutCount = 0;
index ecf38e4ee5415505564d134dcadd77b9e9f4d981..71056962629f710dcb15db6040aaac09d0ca91c7 100644 (file)
@@ -31,7 +31,7 @@
 
 #if defined(CONFIG_CMD_NET)
 
-#define TIMEOUT                5UL             /* Seconds before trying BOOTP again */
+#define TIMEOUT                5000UL  /* Milliseconds before trying BOOTP again */
 #ifndef        CONFIG_NET_RETRY_COUNT
 # define TIMEOUT_COUNT 5               /* # of timeouts before giving up  */
 #else
@@ -80,7 +80,7 @@ RarpTimeout(void)
                puts ("\nRetry count exceeded; starting again\n");
                NetStartAgain ();
        } else {
-               NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout);
+               NetSetTimeout (TIMEOUT, RarpTimeout);
                RarpRequest ();
        }
 }
@@ -115,7 +115,7 @@ RarpRequest (void)
 
        NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
 
-       NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout);
+       NetSetTimeout(TIMEOUT, RarpTimeout);
        NetSetHandler(RarpHandler);
 }
 
index 95e75422c107dcdbd9eb8f25f021c0d21ba77e4a..425d35edd884e05b7a950de505e3560244ca65dd 100644 (file)
@@ -14,7 +14,7 @@
 
 #if defined(CONFIG_CMD_NET) && defined(CONFIG_CMD_SNTP)
 
-#define SNTP_TIMEOUT 10
+#define SNTP_TIMEOUT 10000UL
 
 static int SntpOurPort;
 
@@ -82,7 +82,7 @@ SntpStart (void)
 {
        debug ("%s\n", __FUNCTION__);
 
-       NetSetTimeout (SNTP_TIMEOUT * CFG_HZ, SntpTimeout);
+       NetSetTimeout (SNTP_TIMEOUT, SntpTimeout);
        NetSetHandler(SntpHandler);
        memset (NetServerEther, 0, 6);
 
index 9aeecb8d37febb68fc1839d228ef0838ace15c50..3f0a5163f34557c2ed909baa6294171c9f4ddf94 100644 (file)
@@ -15,7 +15,7 @@
 #if defined(CONFIG_CMD_NET)
 
 #define WELL_KNOWN_PORT        69              /* Well known TFTP port #               */
-#define TIMEOUT                5UL             /* Seconds to timeout for a lost pkt    */
+#define TIMEOUT                5000UL          /* Millisecs to timeout for lost pkt */
 #ifndef        CONFIG_NET_RETRY_COUNT
 # define TIMEOUT_COUNT 10              /* # of timeouts before giving up  */
 #else
@@ -180,7 +180,7 @@ TftpSend (void)
                pkt += 5 /*strlen("octet")*/ + 1;
                strcpy ((char *)pkt, "timeout");
                pkt += 7 /*strlen("timeout")*/ + 1;
-               sprintf((char *)pkt, "%lu", TIMEOUT);
+               sprintf((char *)pkt, "%lu", TIMEOUT / 1000);
 #ifdef ET_DEBUG
                printf("send option \"timeout %s\"\n", (char *)pkt);
 #endif
@@ -370,7 +370,7 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
                }
 
                TftpLastBlock = TftpBlock;
-               NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
+               NetSetTimeout (TIMEOUT, TftpTimeout);
 
                store_block (TftpBlock - 1, pkt + 2, len);
 
@@ -449,7 +449,7 @@ TftpTimeout (void)
                NetStartAgain ();
        } else {
                puts ("T ");
-               NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
+               NetSetTimeout (TIMEOUT, TftpTimeout);
                TftpSend ();
        }
 }
@@ -520,7 +520,7 @@ TftpStart (void)
 
        puts ("Loading: *\b");
 
-       NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
+       NetSetTimeout (TIMEOUT, TftpTimeout);
        NetSetHandler (TftpHandler);
 
        TftpServerPort = WELL_KNOWN_PORT;