]> git.sur5r.net Git - u-boot/blobdiff - net/net.c
board: arm: Add support for Broadcom BCM7445
[u-boot] / net / net.c
index be33c66b3ac6ab8e6dd80be8c735cfbbda338efc..f35695b4fc9f0b62ffd8189c4cc9693c9dc41f87 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  *     Copied from Linux Monitor (LiMon) - Networking.
  *
@@ -6,7 +7,6 @@
  *     Copyright 2000 Roland Borde
  *     Copyright 2000 Paolo Scaffardi
  *     Copyright 2000-2002 Wolfgang Denk, wd@denx.de
- *     SPDX-License-Identifier:        GPL-2.0
  */
 
 /*
  *                     - own IP address
  *     We want:        - network time
  *     Next step:      none
+ *
+ * WOL:
+ *
+ *     Prerequisites:  - own ethernet address
+ *     We want:        - magic packet or timeout
+ *     Next step:      none
  */
 
 
@@ -87,6 +93,7 @@
 #include <environment.h>
 #include <errno.h>
 #include <net.h>
+#include <net/fastboot.h>
 #include <net/tftp.h>
 #if defined(CONFIG_LED_STATUS)
 #include <miiphy.h>
 #if defined(CONFIG_CMD_SNTP)
 #include "sntp.h"
 #endif
-
-DECLARE_GLOBAL_DATA_PTR;
+#if defined(CONFIG_CMD_WOL)
+#include "wol.h"
+#endif
 
 /** BOOTP EXTENTIONS **/
 
@@ -166,6 +174,8 @@ ushort              net_native_vlan = 0xFFFF;
 
 /* Boot File name */
 char net_boot_file_name[1024];
+/* Indicates whether the file name was specified on the command line */
+bool net_boot_file_name_explicit;
 /* The actual transferred size of the bootfile (in bytes) */
 u32 net_boot_file_size;
 /* Boot file size in blocks as reported by the DHCP server */
@@ -319,7 +329,7 @@ U_BOOT_ENV_CALLBACK(dnsip, on_dnsip);
 void net_auto_load(void)
 {
 #if defined(CONFIG_CMD_NFS)
-       const char *s = getenv("autoload");
+       const char *s = env_get("autoload");
 
        if (s != NULL && strcmp(s, "NFS") == 0) {
                /*
@@ -329,7 +339,7 @@ void net_auto_load(void)
                return;
        }
 #endif
-       if (getenv_yesno("autoload") == 0) {
+       if (env_get_yesno("autoload") == 0) {
                /*
                 * Just use BOOTP/RARP to configure system;
                 * Do not use TFTP to load the bootfile.
@@ -394,6 +404,7 @@ void net_init(void)
 int net_loop(enum proto_t protocol)
 {
        int ret = -EINVAL;
+       enum net_loop_state prev_net_state = net_state;
 
        net_restarted = 0;
        net_dev_exists = 0;
@@ -431,6 +442,7 @@ restart:
        case 1:
                /* network not configured */
                eth_halt();
+               net_set_state(prev_net_state);
                return -ENODEV;
 
        case 2:
@@ -453,6 +465,11 @@ restart:
                        tftp_start_server();
                        break;
 #endif
+#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
+               case FASTBOOT:
+                       fastboot_start_server();
+                       break;
+#endif
 #if defined(CONFIG_CMD_DHCP)
                case DHCP:
                        bootp_reset();
@@ -508,6 +525,11 @@ restart:
                case LINKLOCAL:
                        link_local_start();
                        break;
+#endif
+#if defined(CONFIG_CMD_WOL)
+               case WOL:
+                       wol_start();
+                       break;
 #endif
                default:
                        break;
@@ -651,6 +673,7 @@ done:
        net_set_udp_handler(NULL);
        net_set_icmp_handler(NULL);
 #endif
+       net_set_state(prev_net_state);
        return ret;
 }
 
@@ -668,7 +691,7 @@ int net_start_again(void)
        unsigned long retrycnt = 0;
        int ret;
 
-       nretry = getenv("netretry");
+       nretry = env_get("netretry");
        if (nretry) {
                if (!strcmp(nretry, "yes"))
                        retry_forever = 1;
@@ -683,7 +706,7 @@ int net_start_again(void)
                retry_forever = 0;
        }
 
-       if ((!retry_forever) && (net_try_count >= retrycnt)) {
+       if ((!retry_forever) && (net_try_count > retrycnt)) {
                eth_halt();
                net_set_state(NETLOOP_FAIL);
                /*
@@ -1274,6 +1297,11 @@ void net_process_received_packet(uchar *in_packet, int len)
                                      ntohs(ip->udp_src),
                                      ntohs(ip->udp_len) - UDP_HDR_SIZE);
                break;
+#ifdef CONFIG_CMD_WOL
+       case PROT_WOL:
+               wol_receive(ip, len);
+               break;
+#endif
        }
 }
 
@@ -1324,6 +1352,7 @@ common:
                /* Fall through */
 
        case NETCONS:
+       case FASTBOOT:
        case TFTPSRV:
                if (net_ip.s_addr == 0) {
                        puts("*** ERROR: `ipaddr' not set\n");
@@ -1536,7 +1565,7 @@ ushort string_to_vlan(const char *s)
        return htons(id);
 }
 
-ushort getenv_vlan(char *var)
+ushort env_get_vlan(char *var)
 {
-       return string_to_vlan(getenv(var));
+       return string_to_vlan(env_get(var));
 }