Commit 4ef8d53caadbab5585ccb4df2d087183b1383b86

Authored by Joe Hershberger
1 parent c697576262

net: Allow filtering on debug traces in the net subsystem

Add several levels of DEBUG prints so that you can limit the noise to
the severety of your problem.

DEBUG_LL_STATE = Link local state machine changes
DEBUG_DEV_PKT = Packets or info directed to the device
DEBUG_NET_PKT = Packets on info on the network at large
DEBUG_INT_STATE = Internal network state changes

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Showing 8 changed files with 68 additions and 38 deletions Side-by-side Diff

drivers/net/netconsole.c
... ... @@ -83,6 +83,8 @@
83 83 if (dest != nc_port || !len)
84 84 return 0; /* not for us */
85 85  
  86 + debug_cond(DEBUG_DEV_PKT, "input: \"%*.*s\"\n", len, len, pkt);
  87 +
86 88 if (input_size == sizeof(input_buffer))
87 89 return 1; /* no space */
88 90 if (len > sizeof(input_buffer) - input_size)
... ... @@ -111,6 +113,8 @@
111 113 uchar *pkt;
112 114 uchar *ether;
113 115 IPaddr_t ip;
  116 +
  117 + debug_cond(DEBUG_DEV_PKT, "output: \"%*.*s\"\n", len, len, buf);
114 118  
115 119 eth = eth_get_dev();
116 120 if (eth == NULL)
... ... @@ -729,13 +729,6 @@
729 729 int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
730 730 int stoponerr, int offset);
731 731  
732   -/* lib/net_utils.c */
733   -#include <net.h>
734   -static inline IPaddr_t getenv_IPaddr (char *var)
735   -{
736   - return (string_to_ip(getenv(var)));
737   -}
738   -
739 732 /* lib/qsort.c */
740 733 void qsort(void *base, size_t nmemb, size_t size,
741 734 int(*compar)(const void *, const void *));
... ... @@ -803,6 +796,13 @@
803 796 void fputc(int file, const char c);
804 797 int ftstc(int file);
805 798 int fgetc(int file);
  799 +
  800 +/* lib/net_utils.c */
  801 +#include <net.h>
  802 +static inline IPaddr_t getenv_IPaddr(char *var)
  803 +{
  804 + return string_to_ip(getenv(var));
  805 +}
806 806  
807 807 /*
808 808 * CONSOLE multiplexing.
... ... @@ -19,6 +19,10 @@
19 19 #include <asm/cache.h>
20 20 #include <asm/byteorder.h> /* for nton* / ntoh* stuff */
21 21  
  22 +#define DEBUG_LL_STATE 0 /* Link local state machine changes */
  23 +#define DEBUG_DEV_PKT 0 /* Packets or info directed to the device */
  24 +#define DEBUG_NET_PKT 0 /* Packets on info on the network at large */
  25 +#define DEBUG_INT_STATE 0 /* Internal network state changes */
22 26  
23 27 /*
24 28 * The number of receive packet buffers, and the required packet buffer
... ... @@ -480,6 +484,7 @@
480 484 {
481 485 extern enum net_loop_state net_state;
482 486  
  487 + debug_cond(DEBUG_INT_STATE, "--- NetState set to %d\n", state);
483 488 net_state = state;
484 489 }
485 490  
... ... @@ -55,7 +55,7 @@
55 55 struct arp_hdr *arp;
56 56 int eth_hdr_size;
57 57  
58   - debug("ARP broadcast %d\n", NetArpWaitTry);
  58 + debug_cond(DEBUG_DEV_PKT, "ARP broadcast %d\n", NetArpWaitTry);
59 59  
60 60 pkt = NetArpTxPacket;
61 61  
... ... @@ -135,7 +135,7 @@
135 135 * address; so if we receive such a packet, we set
136 136 * the server ethernet address
137 137 */
138   - debug("Got ARP\n");
  138 + debug_cond(DEBUG_NET_PKT, "Got ARP\n");
139 139  
140 140 arp = (struct arp_hdr *)ip;
141 141 if (len < ARP_HDR_SIZE) {
... ... @@ -160,7 +160,7 @@
160 160 switch (ntohs(arp->ar_op)) {
161 161 case ARPOP_REQUEST:
162 162 /* reply with our IP address */
163   - debug("Got ARP REQUEST, return our IP\n");
  163 + debug_cond(DEBUG_DEV_PKT, "Got ARP REQUEST, return our IP\n");
164 164 pkt = (uchar *)et;
165 165 eth_hdr_size = net_update_ether(et, et->et_src, PROT_ARP);
166 166 pkt += eth_hdr_size;
... ... @@ -203,7 +203,8 @@
203 203  
204 204 /* matched waiting packet's address */
205 205 if (reply_ip_addr == NetArpWaitReplyIP) {
206   - debug("Got ARP REPLY, set eth addr (%pM)\n",
  206 + debug_cond(DEBUG_DEV_PKT,
  207 + "Got ARP REPLY, set eth addr (%pM)\n",
207 208 arp->ar_data);
208 209  
209 210 /* save address for later use */
... ... @@ -93,7 +93,7 @@
93 93 /* set deadline_ms to the point in time when we timeout */
94 94 deadline_ms = MONOTONIC_MS() + timeout_ms;
95 95  
96   - debug("...wait %d %s nprobes=%u, nclaims=%u\n",
  96 + debug_cond(DEBUG_DEV_PKT, "...wait %d %s nprobes=%u, nclaims=%u\n",
97 97 timeout_ms, eth_get_name(), nprobes, nclaims);
98 98  
99 99 NetSetTimeout(timeout_ms, link_local_timeout);
... ... @@ -131,7 +131,7 @@
131 131 have been received, so we can progress through the states */
132 132 if (nprobes < PROBE_NUM) {
133 133 nprobes++;
134   - debug("probe/%u %s@%pI4\n",
  134 + debug_cond(DEBUG_LL_STATE, "probe/%u %s@%pI4\n",
135 135 nprobes, eth_get_name(), &ip);
136 136 arp_raw_request(0, NetEtherNullAddr, ip);
137 137 timeout_ms = PROBE_MIN * 1000;
... ... @@ -140,7 +140,7 @@
140 140 /* Switch to announce state */
141 141 state = ANNOUNCE;
142 142 nclaims = 0;
143   - debug("announce/%u %s@%pI4\n",
  143 + debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
144 144 nclaims, eth_get_name(), &ip);
145 145 arp_raw_request(ip, NetOurEther, ip);
146 146 timeout_ms = ANNOUNCE_INTERVAL * 1000;
... ... @@ -152,7 +152,7 @@
152 152 to the announce state */
153 153 state = ANNOUNCE;
154 154 nclaims = 0;
155   - debug("announce/%u %s@%pI4\n",
  155 + debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
156 156 nclaims, eth_get_name(), &ip);
157 157 arp_raw_request(ip, NetOurEther, ip);
158 158 timeout_ms = ANNOUNCE_INTERVAL * 1000;
... ... @@ -163,7 +163,7 @@
163 163 the states */
164 164 if (nclaims < ANNOUNCE_NUM) {
165 165 nclaims++;
166   - debug("announce/%u %s@%pI4\n",
  166 + debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
167 167 nclaims, eth_get_name(), &ip);
168 168 arp_raw_request(ip, NetOurEther, ip);
169 169 timeout_ms = ANNOUNCE_INTERVAL * 1000;
170 170  
... ... @@ -216,10 +216,11 @@
216 216 if ((int)(diff) < 0) {
217 217 /* Current time is greater than the expected timeout
218 218 time. This should never happen */
219   - debug("missed an expected timeout\n");
  219 + debug_cond(DEBUG_LL_STATE,
  220 + "missed an expected timeout\n");
220 221 timeout_ms = 0;
221 222 } else {
222   - debug("adjusting timeout\n");
  223 + debug_cond(DEBUG_INT_STATE, "adjusting timeout\n");
223 224 timeout_ms = diff | 1; /* never 0 */
224 225 }
225 226 }
226 227  
227 228  
... ... @@ -239,13 +240,13 @@
239 240 }
240 241 */
241 242  
242   - debug("%s recv arp type=%d, op=%d,\n",
  243 + debug_cond(DEBUG_INT_STATE, "%s recv arp type=%d, op=%d,\n",
243 244 eth_get_name(), ntohs(arp->ar_pro),
244 245 ntohs(arp->ar_op));
245   - debug("\tsource=%pM %pI4\n",
  246 + debug_cond(DEBUG_INT_STATE, "\tsource=%pM %pI4\n",
246 247 &arp->ar_sha,
247 248 &arp->ar_spa);
248   - debug("\ttarget=%pM %pI4\n",
  249 + debug_cond(DEBUG_INT_STATE, "\ttarget=%pM %pI4\n",
249 250 &arp->ar_tha,
250 251 &arp->ar_tpa);
251 252  
... ... @@ -271,8 +272,9 @@
271 272 target_ip_conflict = 1;
272 273 }
273 274  
274   - debug("state = %d, source ip conflict = %d, target ip conflict = %d\n",
275   - state, source_ip_conflict, target_ip_conflict);
  275 + debug_cond(DEBUG_NET_PKT,
  276 + "state = %d, source ip conflict = %d, target ip conflict = "
  277 + "%d\n", state, source_ip_conflict, target_ip_conflict);
276 278 switch (state) {
277 279 case PROBE:
278 280 case ANNOUNCE:
... ... @@ -310,6 +310,7 @@
310 310 NetRestarted = 0;
311 311 NetDevExists = 0;
312 312 NetTryCount = 1;
  313 + debug_cond(DEBUG_INT_STATE, "--- NetLoop Entry\n");
313 314  
314 315 bootstage_mark_name(BOOTSTAGE_ID_ETH_START, "eth_start");
315 316 net_init();
... ... @@ -330,6 +331,7 @@
330 331 * here on, this code is a state machine driven by received
331 332 * packets and timer events.
332 333 */
  334 + debug_cond(DEBUG_INT_STATE, "--- NetLoop Init\n");
333 335 NetInitLoop();
334 336  
335 337 switch (net_check_prereq(protocol)) {
... ... @@ -460,6 +462,9 @@
460 462 net_cleanup_loop();
461 463 eth_halt();
462 464 puts("\nAbort\n");
  465 + /* include a debug print as well incase the debug
  466 + messages are directed to stderr */
  467 + debug_cond(DEBUG_INT_STATE, "--- NetLoop Abort!\n");
463 468 goto done;
464 469 }
465 470  
... ... @@ -487,6 +492,7 @@
487 492 }
488 493 #endif /* CONFIG_SYS_FAULT_ECHO_LINK_DOWN, ... */
489 494 #endif /* CONFIG_MII, ... */
  495 + debug_cond(DEBUG_INT_STATE, "--- NetLoop timeout\n");
490 496 x = timeHandler;
491 497 timeHandler = (thand_f *)0;
492 498 (*x)();
493 499  
... ... @@ -514,10 +520,12 @@
514 520 }
515 521 eth_halt();
516 522 ret = NetBootFileXferSize;
  523 + debug_cond(DEBUG_INT_STATE, "--- NetLoop Success!\n");
517 524 goto done;
518 525  
519 526 case NETLOOP_FAIL:
520 527 net_cleanup_loop();
  528 + debug_cond(DEBUG_INT_STATE, "--- NetLoop Fail!\n");
521 529 goto done;
522 530  
523 531 case NETLOOP_CONTINUE:
... ... @@ -605,6 +613,7 @@
605 613  
606 614 void net_set_udp_handler(rxhand_f *f)
607 615 {
  616 + debug_cond(DEBUG_INT_STATE, "--- NetLoop UDP handler set (%p)\n", f);
608 617 if (f == NULL)
609 618 udp_packet_handler = dummy_handler;
610 619 else
... ... @@ -618,6 +627,7 @@
618 627  
619 628 void net_set_arp_handler(rxhand_f *f)
620 629 {
  630 + debug_cond(DEBUG_INT_STATE, "--- NetLoop ARP handler set (%p)\n", f);
621 631 if (f == NULL)
622 632 arp_packet_handler = dummy_handler;
623 633 else
624 634  
... ... @@ -635,8 +645,12 @@
635 645 NetSetTimeout(ulong iv, thand_f *f)
636 646 {
637 647 if (iv == 0) {
  648 + debug_cond(DEBUG_INT_STATE,
  649 + "--- NetLoop timeout handler cancelled\n");
638 650 timeHandler = (thand_f *)0;
639 651 } else {
  652 + debug_cond(DEBUG_INT_STATE,
  653 + "--- NetLoop timeout handler set (%p)\n", f);
640 654 timeHandler = f;
641 655 timeStart = get_timer(0);
642 656 timeDelta = iv;
... ... @@ -672,7 +686,7 @@
672 686  
673 687 /* if MAC address was not discovered yet, do an ARP request */
674 688 if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
675   - debug("sending ARP for %pI4\n", &dest);
  689 + debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &dest);
676 690  
677 691 /* save the ip and eth addr for the packet to send after arp */
678 692 NetArpWaitPacketIP = dest;
... ... @@ -687,7 +701,8 @@
687 701 ArpRequest();
688 702 return 1; /* waiting */
689 703 } else {
690   - debug("sending UDP to %pI4/%pM\n", &dest, ether);
  704 + debug_cond(DEBUG_DEV_PKT, "sending UDP to %pI4/%pM\n",
  705 + &dest, ether);
691 706 NetSendPacket(NetTxPacket, pkt_hdr_size + payload_len);
692 707 return 0; /* transmitted */
693 708 }
... ... @@ -910,7 +925,7 @@
910 925 #endif
911 926 ushort cti = 0, vlanid = VLAN_NONE, myvlanid, mynvlanid;
912 927  
913   - debug("packet received\n");
  928 + debug_cond(DEBUG_NET_PKT, "packet received\n");
914 929  
915 930 NetRxPacket = inpkt;
916 931 NetRxPacketLen = len;
... ... @@ -941,8 +956,6 @@
941 956  
942 957 eth_proto = ntohs(et->et_protlen);
943 958  
944   - debug("packet received\n");
945   -
946 959 if (eth_proto < 1514) {
947 960 struct e802_hdr *et802 = (struct e802_hdr *)et;
948 961 /*
... ... @@ -962,7 +975,7 @@
962 975 struct vlan_ethernet_hdr *vet =
963 976 (struct vlan_ethernet_hdr *)et;
964 977  
965   - debug("VLAN packet received\n");
  978 + debug_cond(DEBUG_NET_PKT, "VLAN packet received\n");
966 979  
967 980 /* too small packet? */
968 981 if (len < VLAN_ETHER_HDR_SIZE)
... ... @@ -984,7 +997,7 @@
984 997 len -= VLAN_ETHER_HDR_SIZE;
985 998 }
986 999  
987   - debug("Receive from protocol 0x%x\n", eth_proto);
  1000 + debug_cond(DEBUG_NET_PKT, "Receive from protocol 0x%x\n", eth_proto);
988 1001  
989 1002 #if defined(CONFIG_CMD_CDP)
990 1003 if (iscdp) {
... ... @@ -1013,7 +1026,7 @@
1013 1026 break;
1014 1027 #endif
1015 1028 case PROT_IP:
1016   - debug("Got IP\n");
  1029 + debug_cond(DEBUG_NET_PKT, "Got IP\n");
1017 1030 /* Before we start poking the header, make sure it is there */
1018 1031 if (len < IP_UDP_HDR_SIZE) {
1019 1032 debug("len bad %d < %lu\n", len,
1020 1033  
... ... @@ -1022,11 +1035,12 @@
1022 1035 }
1023 1036 /* Check the packet length */
1024 1037 if (len < ntohs(ip->ip_len)) {
1025   - printf("len bad %d < %d\n", len, ntohs(ip->ip_len));
  1038 + debug("len bad %d < %d\n", len, ntohs(ip->ip_len));
1026 1039 return;
1027 1040 }
1028 1041 len = ntohs(ip->ip_len);
1029   - debug("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff);
  1042 + debug_cond(DEBUG_NET_PKT, "len=%d, v=%02x\n",
  1043 + len, ip->ip_hl_v & 0xff);
1030 1044  
1031 1045 /* Can't deal with anything except IPv4 */
1032 1046 if ((ip->ip_hl_v & 0xf0) != 0x40)
... ... @@ -1036,7 +1050,7 @@
1036 1050 return;
1037 1051 /* Check the Checksum of the header */
1038 1052 if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE / 2)) {
1039   - puts("checksum bad\n");
  1053 + debug("checksum bad\n");
1040 1054 return;
1041 1055 }
1042 1056 /* If it is not for us, ignore it */
... ... @@ -1084,6 +1098,10 @@
1084 1098 } else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */
1085 1099 return;
1086 1100 }
  1101 +
  1102 + debug_cond(DEBUG_DEV_PKT,
  1103 + "received UDP (to=%pI4, from=%pI4, len=%d)\n",
  1104 + &dst_ip, &src_ip, len);
1087 1105  
1088 1106 #ifdef CONFIG_UDP_CHECKSUM
1089 1107 if (ip->udp_xsum != 0) {
... ... @@ -45,7 +45,7 @@
45 45  
46 46 /* XXX always send arp request */
47 47  
48   - debug("sending ARP for %pI4\n", &NetPingIP);
  48 + debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &NetPingIP);
49 49  
50 50 NetArpWaitPacketIP = NetPingIP;
51 51  
... ... @@ -93,7 +93,7 @@
93 93 case ICMP_ECHO_REQUEST:
94 94 eth_hdr_size = net_update_ether(et, et->et_src, PROT_IP);
95 95  
96   - debug("Got ICMP ECHO REQUEST, return "
  96 + debug_cond(DEBUG_DEV_PKT, "Got ICMP ECHO REQUEST, return "
97 97 "%d bytes\n", eth_hdr_size + len);
98 98  
99 99 ip->ip_sum = 0;
... ... @@ -45,7 +45,7 @@
45 45 {
46 46 struct arp_hdr *arp;
47 47  
48   - debug("Got RARP\n");
  48 + debug_cond(DEBUG_NET_PKT, "Got RARP\n");
49 49 arp = (struct arp_hdr *)ip;
50 50 if (len < ARP_HDR_SIZE) {
51 51 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
... ... @@ -63,7 +63,7 @@
63 63 if (NetServerIP == 0)
64 64 NetCopyIP(&NetServerIP, &arp->ar_data[6]);
65 65 memcpy(NetServerEther, &arp->ar_data[0], 6);
66   - debug("Got good RARP\n");
  66 + debug_cond(DEBUG_DEV_PKT, "Got good RARP\n");
67 67 net_auto_load();
68 68 }
69 69 }