Commit 49f3bdbba8071f56d950a9498b6cdb998b35340a

Authored by Bartlomiej Sieka
Committed by Wolfgang Denk
1 parent c68a05feeb

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>

Showing 7 changed files with 28 additions and 33 deletions Side-by-side Diff

... ... @@ -33,7 +33,7 @@
33 33  
34 34 #if defined(CONFIG_CMD_NET)
35 35  
36   -#define TIMEOUT 5UL /* Seconds before trying BOOTP again */
  36 +#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
37 37 #ifndef CONFIG_NET_RETRY_COUNT
38 38 # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
39 39 #else
... ... @@ -371,7 +371,7 @@
371 371 puts ("\nRetry count exceeded; starting again\n");
372 372 NetStartAgain ();
373 373 } else {
374   - NetSetTimeout (TIMEOUT * CFG_HZ, BootpTimeout);
  374 + NetSetTimeout (TIMEOUT, BootpTimeout);
375 375 BootpRequest ();
376 376 }
377 377 }
... ... @@ -671,7 +671,7 @@
671 671 bp->bp_htype = HWT_ETHER;
672 672 bp->bp_hlen = HWL_ETHER;
673 673 bp->bp_hops = 0;
674   - bp->bp_secs = htons(get_timer(0) / CFG_HZ);
  674 + bp->bp_secs = htons(get_timer(0) / 1000);
675 675 NetWriteIP(&bp->bp_ciaddr, 0);
676 676 NetWriteIP(&bp->bp_yiaddr, 0);
677 677 NetWriteIP(&bp->bp_siaddr, 0);
... ... @@ -688,7 +688,7 @@
688 688  
689 689 /*
690 690 * Bootp ID is the lower 4 bytes of our ethernet address
691   - * plus the current time in HZ.
  691 + * plus the current time in ms.
692 692 */
693 693 BootpID = ((ulong)NetOurEther[2] << 24)
694 694 | ((ulong)NetOurEther[3] << 16)
... ... @@ -705,7 +705,7 @@
705 705 pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + ext_len;
706 706 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
707 707 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
708   - NetSetTimeout(SELECT_TIMEOUT * CFG_HZ, BootpTimeout);
  708 + NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
709 709  
710 710 #if defined(CONFIG_CMD_DHCP)
711 711 dhcp_state = SELECTING;
... ... @@ -849,7 +849,7 @@
849 849 bp->bp_htype = HWT_ETHER;
850 850 bp->bp_hlen = HWL_ETHER;
851 851 bp->bp_hops = 0;
852   - bp->bp_secs = htons(get_timer(0) / CFG_HZ);
  852 + bp->bp_secs = htons(get_timer(0) / 1000);
853 853 /* Do not set the client IP, your IP, or server IP yet, since it hasn't been ACK'ed by
854 854 * the server yet */
855 855  
... ... @@ -924,7 +924,7 @@
924 924 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
925 925 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
926 926  
927   - NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout);
  927 + NetSetTimeout(TIMEOUT, BootpTimeout);
928 928 DhcpSendRequestPkt(bp);
929 929 #ifdef CFG_BOOTFILE_PREFIX
930 930 }
... ... @@ -88,7 +88,7 @@
88 88 #define DHCP_NAK 6
89 89 #define DHCP_RELEASE 7
90 90  
91   -#define SELECT_TIMEOUT 3UL /* Seconds to wait for offers */
  91 +#define SELECT_TIMEOUT 3000UL /* Milliseconds to wait for offers */
92 92  
93 93 /**********************************************************************/
94 94  
... ... @@ -95,14 +95,9 @@
95 95 DECLARE_GLOBAL_DATA_PTR;
96 96  
97 97 #ifndef CONFIG_ARP_TIMEOUT
98   -# define ARP_TIMEOUT 50UL /* Deciseconds before trying ARP again */
99   -#elif (CONFIG_ARP_TIMEOUT < 100)
100   -# error "Due to possible overflow CONFIG_ARP_TIMEOUT must be greater than 100ms"
  98 +# define ARP_TIMEOUT 5000UL /* Milliseconds before trying ARP again */
101 99 #else
102   -# if (CONFIG_ARP_TIMEOUT % 100)
103   -# warning "Supported ARP_TIMEOUT precision is 100ms"
104   -# endif
105   -# define ARP_TIMEOUT (CONFIG_ARP_TIMEOUT / 100)
  100 +# define ARP_TIMEOUT CONFIG_ARP_TIMEOUT
106 101 #endif
107 102  
108 103  
... ... @@ -264,7 +259,7 @@
264 259 t = get_timer(0);
265 260  
266 261 /* check for arp timeout */
267   - if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT * CFG_HZ / 10) {
  262 + if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT) {
268 263 NetArpWaitTry++;
269 264  
270 265 if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) {
... ... @@ -603,7 +598,7 @@
603 598 return;
604 599 }
605 600 #ifndef CONFIG_NET_MULTI
606   - NetSetTimeout (10UL * CFG_HZ, startAgainTimeout);
  601 + NetSetTimeout (10000UL, startAgainTimeout);
607 602 NetSetHandler (startAgainHandler);
608 603 #else /* !CONFIG_NET_MULTI*/
609 604 eth_halt ();
... ... @@ -614,7 +609,7 @@
614 609 if (NetRestartWrap) {
615 610 NetRestartWrap = 0;
616 611 if (NetDevExists && !once) {
617   - NetSetTimeout (10UL * CFG_HZ, startAgainTimeout);
  612 + NetSetTimeout (10000UL, startAgainTimeout);
618 613 NetSetHandler (startAgainHandler);
619 614 } else {
620 615 NetState = NETLOOP_FAIL;
... ... @@ -790,7 +785,7 @@
790 785 #if defined(CONFIG_NET_MULTI)
791 786 printf ("Using %s device\n", eth_get_name());
792 787 #endif /* CONFIG_NET_MULTI */
793   - NetSetTimeout (10UL * CFG_HZ, PingTimeout);
  788 + NetSetTimeout (10000UL, PingTimeout);
794 789 NetSetHandler (PingHandler);
795 790  
796 791 PingSend();
... ... @@ -813,7 +808,7 @@
813 808 #define CDP_SYSOBJECT_TLV 0x0015
814 809 #define CDP_MANAGEMENT_ADDRESS_TLV 0x0016
815 810  
816   -#define CDP_TIMEOUT (CFG_HZ/4) /* one packet every 250ms */
  811 +#define CDP_TIMEOUT 250UL /* one packet every 250ms */
817 812  
818 813 static int CDPSeq;
819 814 static int CDPOK;
... ... @@ -35,7 +35,7 @@
35 35  
36 36 #define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */
37 37 #define NFS_RETRY_COUNT 30
38   -#define NFS_TIMEOUT 2UL
  38 +#define NFS_TIMEOUT 2000UL
39 39  
40 40 static int fs_mounted = 0;
41 41 static unsigned long rpc_id = 0;
... ... @@ -674,7 +674,7 @@
674 674  
675 675 case STATE_READ_REQ:
676 676 rlen = nfs_read_reply (pkt, len);
677   - NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout);
  677 + NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
678 678 if (rlen > 0) {
679 679 nfs_offset += rlen;
680 680 NfsSend ();
... ... @@ -763,7 +763,7 @@
763 763 printf ("\nLoad address: 0x%lx\n"
764 764 "Loading: *\b", load_addr);
765 765  
766   - NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout);
  766 + NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
767 767 NetSetHandler (NfsHandler);
768 768  
769 769 NfsTimeoutCount = 0;
... ... @@ -31,7 +31,7 @@
31 31  
32 32 #if defined(CONFIG_CMD_NET)
33 33  
34   -#define TIMEOUT 5UL /* Seconds before trying BOOTP again */
  34 +#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
35 35 #ifndef CONFIG_NET_RETRY_COUNT
36 36 # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
37 37 #else
... ... @@ -80,7 +80,7 @@
80 80 puts ("\nRetry count exceeded; starting again\n");
81 81 NetStartAgain ();
82 82 } else {
83   - NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout);
  83 + NetSetTimeout (TIMEOUT, RarpTimeout);
84 84 RarpRequest ();
85 85 }
86 86 }
... ... @@ -115,7 +115,7 @@
115 115  
116 116 NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
117 117  
118   - NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout);
  118 + NetSetTimeout(TIMEOUT, RarpTimeout);
119 119 NetSetHandler(RarpHandler);
120 120 }
121 121  
... ... @@ -14,7 +14,7 @@
14 14  
15 15 #if defined(CONFIG_CMD_NET) && defined(CONFIG_CMD_SNTP)
16 16  
17   -#define SNTP_TIMEOUT 10
  17 +#define SNTP_TIMEOUT 10000UL
18 18  
19 19 static int SntpOurPort;
20 20  
... ... @@ -82,7 +82,7 @@
82 82 {
83 83 debug ("%s\n", __FUNCTION__);
84 84  
85   - NetSetTimeout (SNTP_TIMEOUT * CFG_HZ, SntpTimeout);
  85 + NetSetTimeout (SNTP_TIMEOUT, SntpTimeout);
86 86 NetSetHandler(SntpHandler);
87 87 memset (NetServerEther, 0, 6);
88 88  
... ... @@ -15,7 +15,7 @@
15 15 #if defined(CONFIG_CMD_NET)
16 16  
17 17 #define WELL_KNOWN_PORT 69 /* Well known TFTP port # */
18   -#define TIMEOUT 5UL /* Seconds to timeout for a lost pkt */
  18 +#define TIMEOUT 5000UL /* Millisecs to timeout for lost pkt */
19 19 #ifndef CONFIG_NET_RETRY_COUNT
20 20 # define TIMEOUT_COUNT 10 /* # of timeouts before giving up */
21 21 #else
... ... @@ -180,7 +180,7 @@
180 180 pkt += 5 /*strlen("octet")*/ + 1;
181 181 strcpy ((char *)pkt, "timeout");
182 182 pkt += 7 /*strlen("timeout")*/ + 1;
183   - sprintf((char *)pkt, "%lu", TIMEOUT);
  183 + sprintf((char *)pkt, "%lu", TIMEOUT / 1000);
184 184 #ifdef ET_DEBUG
185 185 printf("send option \"timeout %s\"\n", (char *)pkt);
186 186 #endif
... ... @@ -370,7 +370,7 @@
370 370 }
371 371  
372 372 TftpLastBlock = TftpBlock;
373   - NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
  373 + NetSetTimeout (TIMEOUT, TftpTimeout);
374 374  
375 375 store_block (TftpBlock - 1, pkt + 2, len);
376 376  
... ... @@ -449,7 +449,7 @@
449 449 NetStartAgain ();
450 450 } else {
451 451 puts ("T ");
452   - NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
  452 + NetSetTimeout (TIMEOUT, TftpTimeout);
453 453 TftpSend ();
454 454 }
455 455 }
... ... @@ -520,7 +520,7 @@
520 520  
521 521 puts ("Loading: *\b");
522 522  
523   - NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
  523 + NetSetTimeout (TIMEOUT, TftpTimeout);
524 524 NetSetHandler (TftpHandler);
525 525  
526 526 TftpServerPort = WELL_KNOWN_PORT;