net: express the first argument to NetSetTimeout() in milliseconds

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>
This commit is contained in:
Bartlomiej Sieka 2008-10-01 15:26:28 +02:00 committed by Wolfgang Denk
parent c68a05feeb
commit 49f3bdbba8
7 changed files with 28 additions and 33 deletions

View File

@ -33,7 +33,7 @@
#if defined(CONFIG_CMD_NET) #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 #ifndef CONFIG_NET_RETRY_COUNT
# define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
#else #else
@ -371,7 +371,7 @@ BootpTimeout(void)
puts ("\nRetry count exceeded; starting again\n"); puts ("\nRetry count exceeded; starting again\n");
NetStartAgain (); NetStartAgain ();
} else { } else {
NetSetTimeout (TIMEOUT * CFG_HZ, BootpTimeout); NetSetTimeout (TIMEOUT, BootpTimeout);
BootpRequest (); BootpRequest ();
} }
} }
@ -671,7 +671,7 @@ BootpRequest (void)
bp->bp_htype = HWT_ETHER; bp->bp_htype = HWT_ETHER;
bp->bp_hlen = HWL_ETHER; bp->bp_hlen = HWL_ETHER;
bp->bp_hops = 0; 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_ciaddr, 0);
NetWriteIP(&bp->bp_yiaddr, 0); NetWriteIP(&bp->bp_yiaddr, 0);
NetWriteIP(&bp->bp_siaddr, 0); NetWriteIP(&bp->bp_siaddr, 0);
@ -688,7 +688,7 @@ BootpRequest (void)
/* /*
* Bootp ID is the lower 4 bytes of our ethernet address * 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) BootpID = ((ulong)NetOurEther[2] << 24)
| ((ulong)NetOurEther[3] << 16) | ((ulong)NetOurEther[3] << 16)
@ -705,7 +705,7 @@ BootpRequest (void)
pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + ext_len; pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + ext_len;
iplen = BOOTP_HDR_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); NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
NetSetTimeout(SELECT_TIMEOUT * CFG_HZ, BootpTimeout); NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
#if defined(CONFIG_CMD_DHCP) #if defined(CONFIG_CMD_DHCP)
dhcp_state = SELECTING; dhcp_state = SELECTING;
@ -849,7 +849,7 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer)
bp->bp_htype = HWT_ETHER; bp->bp_htype = HWT_ETHER;
bp->bp_hlen = HWL_ETHER; bp->bp_hlen = HWL_ETHER;
bp->bp_hops = 0; 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 /* Do not set the client IP, your IP, or server IP yet, since it hasn't been ACK'ed by
* the server yet */ * 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)) if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp); DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout); NetSetTimeout(TIMEOUT, BootpTimeout);
DhcpSendRequestPkt(bp); DhcpSendRequestPkt(bp);
#ifdef CFG_BOOTFILE_PREFIX #ifdef CFG_BOOTFILE_PREFIX
} }

View File

@ -88,7 +88,7 @@ typedef enum { INIT,
#define DHCP_NAK 6 #define DHCP_NAK 6
#define DHCP_RELEASE 7 #define DHCP_RELEASE 7
#define SELECT_TIMEOUT 3UL /* Seconds to wait for offers */ #define SELECT_TIMEOUT 3000UL /* Milliseconds to wait for offers */
/**********************************************************************/ /**********************************************************************/

View File

@ -95,14 +95,9 @@
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
#ifndef CONFIG_ARP_TIMEOUT #ifndef CONFIG_ARP_TIMEOUT
# define ARP_TIMEOUT 50UL /* Deciseconds before trying ARP again */ # define ARP_TIMEOUT 5000UL /* Milliseconds before trying ARP again */
#elif (CONFIG_ARP_TIMEOUT < 100)
# error "Due to possible overflow CONFIG_ARP_TIMEOUT must be greater than 100ms"
#else #else
# if (CONFIG_ARP_TIMEOUT % 100) # define ARP_TIMEOUT CONFIG_ARP_TIMEOUT
# warning "Supported ARP_TIMEOUT precision is 100ms"
# endif
# define ARP_TIMEOUT (CONFIG_ARP_TIMEOUT / 100)
#endif #endif
@ -264,7 +259,7 @@ void ArpTimeoutCheck(void)
t = get_timer(0); t = get_timer(0);
/* check for arp timeout */ /* check for arp timeout */
if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT * CFG_HZ / 10) { if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT) {
NetArpWaitTry++; NetArpWaitTry++;
if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) { if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) {
@ -603,7 +598,7 @@ void NetStartAgain (void)
return; return;
} }
#ifndef CONFIG_NET_MULTI #ifndef CONFIG_NET_MULTI
NetSetTimeout (10UL * CFG_HZ, startAgainTimeout); NetSetTimeout (10000UL, startAgainTimeout);
NetSetHandler (startAgainHandler); NetSetHandler (startAgainHandler);
#else /* !CONFIG_NET_MULTI*/ #else /* !CONFIG_NET_MULTI*/
eth_halt (); eth_halt ();
@ -614,7 +609,7 @@ void NetStartAgain (void)
if (NetRestartWrap) { if (NetRestartWrap) {
NetRestartWrap = 0; NetRestartWrap = 0;
if (NetDevExists && !once) { if (NetDevExists && !once) {
NetSetTimeout (10UL * CFG_HZ, startAgainTimeout); NetSetTimeout (10000UL, startAgainTimeout);
NetSetHandler (startAgainHandler); NetSetHandler (startAgainHandler);
} else { } else {
NetState = NETLOOP_FAIL; NetState = NETLOOP_FAIL;
@ -790,7 +785,7 @@ static void PingStart(void)
#if defined(CONFIG_NET_MULTI) #if defined(CONFIG_NET_MULTI)
printf ("Using %s device\n", eth_get_name()); printf ("Using %s device\n", eth_get_name());
#endif /* CONFIG_NET_MULTI */ #endif /* CONFIG_NET_MULTI */
NetSetTimeout (10UL * CFG_HZ, PingTimeout); NetSetTimeout (10000UL, PingTimeout);
NetSetHandler (PingHandler); NetSetHandler (PingHandler);
PingSend(); PingSend();
@ -813,7 +808,7 @@ static void PingStart(void)
#define CDP_SYSOBJECT_TLV 0x0015 #define CDP_SYSOBJECT_TLV 0x0015
#define CDP_MANAGEMENT_ADDRESS_TLV 0x0016 #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 CDPSeq;
static int CDPOK; static int CDPOK;

View File

@ -35,7 +35,7 @@
#define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */ #define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */
#define NFS_RETRY_COUNT 30 #define NFS_RETRY_COUNT 30
#define NFS_TIMEOUT 2UL #define NFS_TIMEOUT 2000UL
static int fs_mounted = 0; static int fs_mounted = 0;
static unsigned long rpc_id = 0; static unsigned long rpc_id = 0;
@ -674,7 +674,7 @@ NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
case STATE_READ_REQ: case STATE_READ_REQ:
rlen = nfs_read_reply (pkt, len); rlen = nfs_read_reply (pkt, len);
NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout); NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
if (rlen > 0) { if (rlen > 0) {
nfs_offset += rlen; nfs_offset += rlen;
NfsSend (); NfsSend ();
@ -763,7 +763,7 @@ NfsStart (void)
printf ("\nLoad address: 0x%lx\n" printf ("\nLoad address: 0x%lx\n"
"Loading: *\b", load_addr); "Loading: *\b", load_addr);
NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout); NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
NetSetHandler (NfsHandler); NetSetHandler (NfsHandler);
NfsTimeoutCount = 0; NfsTimeoutCount = 0;

View File

@ -31,7 +31,7 @@
#if defined(CONFIG_CMD_NET) #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 #ifndef CONFIG_NET_RETRY_COUNT
# define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
#else #else
@ -80,7 +80,7 @@ RarpTimeout(void)
puts ("\nRetry count exceeded; starting again\n"); puts ("\nRetry count exceeded; starting again\n");
NetStartAgain (); NetStartAgain ();
} else { } else {
NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout); NetSetTimeout (TIMEOUT, RarpTimeout);
RarpRequest (); RarpRequest ();
} }
} }
@ -115,7 +115,7 @@ RarpRequest (void)
NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE); NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout); NetSetTimeout(TIMEOUT, RarpTimeout);
NetSetHandler(RarpHandler); NetSetHandler(RarpHandler);
} }

View File

@ -14,7 +14,7 @@
#if defined(CONFIG_CMD_NET) && defined(CONFIG_CMD_SNTP) #if defined(CONFIG_CMD_NET) && defined(CONFIG_CMD_SNTP)
#define SNTP_TIMEOUT 10 #define SNTP_TIMEOUT 10000UL
static int SntpOurPort; static int SntpOurPort;
@ -82,7 +82,7 @@ SntpStart (void)
{ {
debug ("%s\n", __FUNCTION__); debug ("%s\n", __FUNCTION__);
NetSetTimeout (SNTP_TIMEOUT * CFG_HZ, SntpTimeout); NetSetTimeout (SNTP_TIMEOUT, SntpTimeout);
NetSetHandler(SntpHandler); NetSetHandler(SntpHandler);
memset (NetServerEther, 0, 6); memset (NetServerEther, 0, 6);

View File

@ -15,7 +15,7 @@
#if defined(CONFIG_CMD_NET) #if defined(CONFIG_CMD_NET)
#define WELL_KNOWN_PORT 69 /* Well known TFTP port # */ #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 #ifndef CONFIG_NET_RETRY_COUNT
# define TIMEOUT_COUNT 10 /* # of timeouts before giving up */ # define TIMEOUT_COUNT 10 /* # of timeouts before giving up */
#else #else
@ -180,7 +180,7 @@ TftpSend (void)
pkt += 5 /*strlen("octet")*/ + 1; pkt += 5 /*strlen("octet")*/ + 1;
strcpy ((char *)pkt, "timeout"); strcpy ((char *)pkt, "timeout");
pkt += 7 /*strlen("timeout")*/ + 1; pkt += 7 /*strlen("timeout")*/ + 1;
sprintf((char *)pkt, "%lu", TIMEOUT); sprintf((char *)pkt, "%lu", TIMEOUT / 1000);
#ifdef ET_DEBUG #ifdef ET_DEBUG
printf("send option \"timeout %s\"\n", (char *)pkt); printf("send option \"timeout %s\"\n", (char *)pkt);
#endif #endif
@ -370,7 +370,7 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
} }
TftpLastBlock = TftpBlock; TftpLastBlock = TftpBlock;
NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout); NetSetTimeout (TIMEOUT, TftpTimeout);
store_block (TftpBlock - 1, pkt + 2, len); store_block (TftpBlock - 1, pkt + 2, len);
@ -449,7 +449,7 @@ TftpTimeout (void)
NetStartAgain (); NetStartAgain ();
} else { } else {
puts ("T "); puts ("T ");
NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout); NetSetTimeout (TIMEOUT, TftpTimeout);
TftpSend (); TftpSend ();
} }
} }
@ -520,7 +520,7 @@ TftpStart (void)
puts ("Loading: *\b"); puts ("Loading: *\b");
NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout); NetSetTimeout (TIMEOUT, TftpTimeout);
NetSetHandler (TftpHandler); NetSetHandler (TftpHandler);
TftpServerPort = WELL_KNOWN_PORT; TftpServerPort = WELL_KNOWN_PORT;