History log of /u-boot/include/net.h
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# f01c961e 09-Nov-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add uri device path

This adds the URI device path option for 'boot add' subcommand.
User can add the URI load option for downloading ISO image file
or EFI application through network. Currently HTTP is only supported.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 8cf18da1 09-Nov-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

net: wget: add wget with dns utility function

Current wget takes the target uri in this format:
"<http server ip>:<file path>" e.g.) 192.168.1.1:/bar
The http server ip address must be resolved before
calling wget.

This commit adds the utility function runs wget with dhs.
User can call wget with the uri like "http://foo/bar".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 798962ce 07-Oct-2023 Sean Anderson <seanga2@gmail.com>

net: Add option for tracing packets

Add an option to trace all packets send/received. This can be helpful when
debugging protocol issues, as the packets can then be imported into
wireshark [1] and analyzed further.

[1] https://www.wireshark.org/docs/wsug_html_chunked/ChIOImportSection.html

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c85e96d0 23-May-2023 Ioana Ciornei <ioana.ciornei@nxp.com>

cmd: net: add a 'net stats' command to dump network statistics

Add a new option to the 'net' command which can be used to dump network
statistics.

To do this, 3 new callbacks are added to the eth_ops structure:
.get_sset_count(), .get_strings(), .get_stats(). These callbacks
have the same functions as in Linux: to return the number of counters,
the strings which describe those counters and the actual values.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6de98b60 21-Apr-2023 Ehsan Mohandesi <emohandesi@linux.microsoft.com>

net: ipv6: Add support for default gateway discovery.

In IPv6, the default gateway and prefix length are determined by receiving
a router advertisement as defined in -
https://www.rfc-editor.org/rfc/rfc4861.

Add support for sending router solicitation (RS) and processing router
advertisements (RA).

If the RA has prefix info option and following conditions are met, then
gatewayip6 and net_prefix_length of ip6addr env variables are initialized.
These are later consumed by IPv6 code for non-local destination IP.

- "Router Lifetime" != 0
- Prefix is NOT link-local prefix (0xfe80::/10)
- L flag is 1
- "Valid Lifetime" != 0

Timing Parameters:
- MAX_RTR_SOLICITATION_DELAY (0-1s)
- RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
- MAX_RTR_SOLICITATIONS (3 RS transmissions)

The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked
automatically from net_init_loop().

Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com>
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by:
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Tested-by: Sergei Antonov <saproj@gmail.com>
Reviewed-by: Sergei Antonov <saproj@gmail.com>

# 443d3191 12-Apr-2023 Dmitrii Merkurev <dimorinny@google.com>

net: add fastboot TCP support

Known limitations are
1. fastboot reboot doesn't work (answering OK but not rebooting)
2. flashing isn't supported (TCP transport only limitation)

The command syntax is
fastboot tcp

Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a0245818 11-Apr-2023 Sean Edmond <seanedmond@microsoft.com>

net: dhcp6: Add DHCPv6 (DHCP for IPv6)

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options
required by RFC 8415. Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond <seanedmond@microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# c8c3fd24 17-Jan-2023 Simon Glass <sjg@chromium.org>

net: Add a function to run dhcp

At present this must be done by executing the command. Also it involves
fiddling with the environment to determine the correct autoload behaviour.

Ideally it should be possible to run network operations without even
having the command line present (CONFIG_CMDLINE).

For now, add a function to handle DHCP, so it can be called from a bootdev
more easily.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 70dd8865 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet bootdevs to be disabled for tests

Most tests don't want these and can create a lot of noise. Add a way to
disable them. Use that in tests, with a flag provided to enable them for
tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e524f3a4 27-Nov-2022 Tom Rini <trini@konsulko.com>

net: Remove eth_legacy.c

As there are no more non-DM_ETH cases for networking, remove this legacy
file and update the Makefile to match current usage.

Signed-off-by: Tom Rini <trini@konsulko.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <masahiroy@kernel.org>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 798962ce 07-Oct-2023 Sean Anderson <seanga2@gmail.com>

net: Add option for tracing packets

Add an option to trace all packets send/received. This can be helpful when
debugging protocol issues, as the packets can then be imported into
wireshark [1] and analyzed further.

[1] https://www.wireshark.org/docs/wsug_html_chunked/ChIOImportSection.html

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c85e96d0 23-May-2023 Ioana Ciornei <ioana.ciornei@nxp.com>

cmd: net: add a 'net stats' command to dump network statistics

Add a new option to the 'net' command which can be used to dump network
statistics.

To do this, 3 new callbacks are added to the eth_ops structure:
.get_sset_count(), .get_strings(), .get_stats(). These callbacks
have the same functions as in Linux: to return the number of counters,
the strings which describe those counters and the actual values.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6de98b60 21-Apr-2023 Ehsan Mohandesi <emohandesi@linux.microsoft.com>

net: ipv6: Add support for default gateway discovery.

In IPv6, the default gateway and prefix length are determined by receiving
a router advertisement as defined in -
https://www.rfc-editor.org/rfc/rfc4861.

Add support for sending router solicitation (RS) and processing router
advertisements (RA).

If the RA has prefix info option and following conditions are met, then
gatewayip6 and net_prefix_length of ip6addr env variables are initialized.
These are later consumed by IPv6 code for non-local destination IP.

- "Router Lifetime" != 0
- Prefix is NOT link-local prefix (0xfe80::/10)
- L flag is 1
- "Valid Lifetime" != 0

Timing Parameters:
- MAX_RTR_SOLICITATION_DELAY (0-1s)
- RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
- MAX_RTR_SOLICITATIONS (3 RS transmissions)

The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked
automatically from net_init_loop().

Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com>
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by:
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Tested-by: Sergei Antonov <saproj@gmail.com>
Reviewed-by: Sergei Antonov <saproj@gmail.com>

# 443d3191 12-Apr-2023 Dmitrii Merkurev <dimorinny@google.com>

net: add fastboot TCP support

Known limitations are
1. fastboot reboot doesn't work (answering OK but not rebooting)
2. flashing isn't supported (TCP transport only limitation)

The command syntax is
fastboot tcp

Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a0245818 11-Apr-2023 Sean Edmond <seanedmond@microsoft.com>

net: dhcp6: Add DHCPv6 (DHCP for IPv6)

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options
required by RFC 8415. Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond <seanedmond@microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# c8c3fd24 17-Jan-2023 Simon Glass <sjg@chromium.org>

net: Add a function to run dhcp

At present this must be done by executing the command. Also it involves
fiddling with the environment to determine the correct autoload behaviour.

Ideally it should be possible to run network operations without even
having the command line present (CONFIG_CMDLINE).

For now, add a function to handle DHCP, so it can be called from a bootdev
more easily.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 70dd8865 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet bootdevs to be disabled for tests

Most tests don't want these and can create a lot of noise. Add a way to
disable them. Use that in tests, with a flag provided to enable them for
tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e524f3a4 27-Nov-2022 Tom Rini <trini@konsulko.com>

net: Remove eth_legacy.c

As there are no more non-DM_ETH cases for networking, remove this legacy
file and update the Makefile to match current usage.

Signed-off-by: Tom Rini <trini@konsulko.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <masahiroy@kernel.org>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# c85e96d0 23-May-2023 Ioana Ciornei <ioana.ciornei@nxp.com>

cmd: net: add a 'net stats' command to dump network statistics

Add a new option to the 'net' command which can be used to dump network
statistics.

To do this, 3 new callbacks are added to the eth_ops structure:
.get_sset_count(), .get_strings(), .get_stats(). These callbacks
have the same functions as in Linux: to return the number of counters,
the strings which describe those counters and the actual values.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6de98b60 21-Apr-2023 Ehsan Mohandesi <emohandesi@linux.microsoft.com>

net: ipv6: Add support for default gateway discovery.

In IPv6, the default gateway and prefix length are determined by receiving
a router advertisement as defined in -
https://www.rfc-editor.org/rfc/rfc4861.

Add support for sending router solicitation (RS) and processing router
advertisements (RA).

If the RA has prefix info option and following conditions are met, then
gatewayip6 and net_prefix_length of ip6addr env variables are initialized.
These are later consumed by IPv6 code for non-local destination IP.

- "Router Lifetime" != 0
- Prefix is NOT link-local prefix (0xfe80::/10)
- L flag is 1
- "Valid Lifetime" != 0

Timing Parameters:
- MAX_RTR_SOLICITATION_DELAY (0-1s)
- RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
- MAX_RTR_SOLICITATIONS (3 RS transmissions)

The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked
automatically from net_init_loop().

Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com>
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by:
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Tested-by: Sergei Antonov <saproj@gmail.com>
Reviewed-by: Sergei Antonov <saproj@gmail.com>

# 443d3191 12-Apr-2023 Dmitrii Merkurev <dimorinny@google.com>

net: add fastboot TCP support

Known limitations are
1. fastboot reboot doesn't work (answering OK but not rebooting)
2. flashing isn't supported (TCP transport only limitation)

The command syntax is
fastboot tcp

Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a0245818 11-Apr-2023 Sean Edmond <seanedmond@microsoft.com>

net: dhcp6: Add DHCPv6 (DHCP for IPv6)

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options
required by RFC 8415. Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond <seanedmond@microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# c8c3fd24 17-Jan-2023 Simon Glass <sjg@chromium.org>

net: Add a function to run dhcp

At present this must be done by executing the command. Also it involves
fiddling with the environment to determine the correct autoload behaviour.

Ideally it should be possible to run network operations without even
having the command line present (CONFIG_CMDLINE).

For now, add a function to handle DHCP, so it can be called from a bootdev
more easily.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 70dd8865 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet bootdevs to be disabled for tests

Most tests don't want these and can create a lot of noise. Add a way to
disable them. Use that in tests, with a flag provided to enable them for
tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e524f3a4 27-Nov-2022 Tom Rini <trini@konsulko.com>

net: Remove eth_legacy.c

As there are no more non-DM_ETH cases for networking, remove this legacy
file and update the Makefile to match current usage.

Signed-off-by: Tom Rini <trini@konsulko.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 6de98b60 21-Apr-2023 Ehsan Mohandesi <emohandesi@linux.microsoft.com>

net: ipv6: Add support for default gateway discovery.

In IPv6, the default gateway and prefix length are determined by receiving
a router advertisement as defined in -
https://www.rfc-editor.org/rfc/rfc4861.

Add support for sending router solicitation (RS) and processing router
advertisements (RA).

If the RA has prefix info option and following conditions are met, then
gatewayip6 and net_prefix_length of ip6addr env variables are initialized.
These are later consumed by IPv6 code for non-local destination IP.

- "Router Lifetime" != 0
- Prefix is NOT link-local prefix (0xfe80::/10)
- L flag is 1
- "Valid Lifetime" != 0

Timing Parameters:
- MAX_RTR_SOLICITATION_DELAY (0-1s)
- RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
- MAX_RTR_SOLICITATIONS (3 RS transmissions)

The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked
automatically from net_init_loop().

Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com>
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by:
Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Tested-by: Sergei Antonov <saproj@gmail.com>
Reviewed-by: Sergei Antonov <saproj@gmail.com>

# 443d3191 12-Apr-2023 Dmitrii Merkurev <dimorinny@google.com>

net: add fastboot TCP support

Known limitations are
1. fastboot reboot doesn't work (answering OK but not rebooting)
2. flashing isn't supported (TCP transport only limitation)

The command syntax is
fastboot tcp

Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a0245818 11-Apr-2023 Sean Edmond <seanedmond@microsoft.com>

net: dhcp6: Add DHCPv6 (DHCP for IPv6)

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options
required by RFC 8415. Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond <seanedmond@microsoft.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# c8c3fd24 17-Jan-2023 Simon Glass <sjg@chromium.org>

net: Add a function to run dhcp

At present this must be done by executing the command. Also it involves
fiddling with the environment to determine the correct autoload behaviour.

Ideally it should be possible to run network operations without even
having the command line present (CONFIG_CMDLINE).

For now, add a function to handle DHCP, so it can be called from a bootdev
more easily.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 70dd8865 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet bootdevs to be disabled for tests

Most tests don't want these and can create a lot of noise. Add a way to
disable them. Use that in tests, with a flag provided to enable them for
tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e524f3a4 27-Nov-2022 Tom Rini <trini@konsulko.com>

net: Remove eth_legacy.c

As there are no more non-DM_ETH cases for networking, remove this legacy
file and update the Makefile to match current usage.

Signed-off-by: Tom Rini <trini@konsulko.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# c8c3fd24 17-Jan-2023 Simon Glass <sjg@chromium.org>

net: Add a function to run dhcp

At present this must be done by executing the command. Also it involves
fiddling with the environment to determine the correct autoload behaviour.

Ideally it should be possible to run network operations without even
having the command line present (CONFIG_CMDLINE).

For now, add a function to handle DHCP, so it can be called from a bootdev
more easily.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 70dd8865 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet bootdevs to be disabled for tests

Most tests don't want these and can create a lot of noise. Add a way to
disable them. Use that in tests, with a flag provided to enable them for
tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e524f3a4 27-Nov-2022 Tom Rini <trini@konsulko.com>

net: Remove eth_legacy.c

As there are no more non-DM_ETH cases for networking, remove this legacy
file and update the Makefile to match current usage.

Signed-off-by: Tom Rini <trini@konsulko.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# e524f3a4 27-Nov-2022 Tom Rini <trini@konsulko.com>

net: Remove eth_legacy.c

As there are no more non-DM_ETH cases for networking, remove this legacy
file and update the Makefile to match current usage.

Signed-off-by: Tom Rini <trini@konsulko.com>

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# eeb0a2c6 01-Dec-2022 Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>

net: ping6: Add ping6 command

Implement ping6 command to ping hosts using IPv6. It works the same way as
an ordinary ping command. There is no ICMP request so it is not possible
to ping our host. This patch adds options in Kconfig and Makefile to
build ping6 command.

Series-changes: 3
- Added structures and functions descriptions
- Added to ping6_receive() return value instead of void

Series-changes: 4
- Fixed structures and functions description style

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# cfbae482 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add wget application

This commit adds a simple wget command that can download files
from http server.

The command syntax is
wget ${loadaddr} <path of the file from server>

Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# a3bf193b 07-Nov-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

net: Add TCP protocol

Currently file transfers are done using tftp or NFS both
over udp. This requires a request to be sent from client
(u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com>
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 09bd3d0b 08-Aug-2022 Samuel Mendoza-Jonas <sam@mendozajonas.com>

net: NC-SI setup and handling

Add the handling of NC-SI ethernet frames, and add a check at the start
of net_loop() to configure NC-SI before starting other network commands.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 5e6e41b3 28-Jan-2022 Andre Kalb <svc.sw.rte.linux@sma.de>

net: bootp: Make root path (option 17) length configurable

to adjust the root path length.
Eg to 256 from Linux Kernel

Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
[trini: Guard extern so that !CONFIG_NET platforms will build]
Signed-off-by: Tom Rini <trini@konsulko.com>

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# b85d130e 26-May-2022 Fabio Estevam <festevam@denx.de>

net: Check for the minimum IP fragmented datagram size

Nicolas Bidron and Nicolas Guigo reported the two bugs below:

"
----------BUG 1----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE`
and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len`
comprised between `0` and `7`. This will ultimately result in a
truncated division by `8` resulting value of `0` forcing the hole
metadata and fragment to point to the same location. The subsequent
memcopy will overwrite the hole metadata with the fragment data. Through
a second fragment, this can be exploited to write to an arbitrary offset
controlled by that overwritten hole metadata value.

This bug is only exploitable locally as it requires crafting two packets
the first of which would most likely be dropped through routing due to
its unexpectedly low Total Length. However, this bug can potentially be
exploited to root linux based embedded devices locally.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows how
the attacker can control the value of `len` to be strictly lower than
`8` by issuing a packet with `ip_len` between `21` and `27`
(`IP_HDR_SIZE` has a value of `20`).

Also note that `offset8` here is `0` which leads to `thisfrag = payload`.

```C
} else if (h >= thisfrag) {
/* overlaps with initial part of the hole: move this hole */
newh = thisfrag + (len / 8);
*newh = *h;
h = newh;
if (h->next_hole)
payload[h->next_hole].prev_hole = (h - payload);
if (h->prev_hole)
payload[h->prev_hole].next_hole = (h - payload);
else
first_hole = (h - payload);

} else {
```

Lower down the same function, execution reaches the above code path.
Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note
that `first_hole` here is `0` since `h` and `payload` point to the same
location.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

Finally, in the above excerpt the `memcpy` overwrites the hole metadata
since `thisfrag` and `h` both point to the same location. The hole
metadata is effectively overwritten with arbitrary data from the
fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`,
`next_hole`, and `prev_hole` of the `first_hole` can be controlled by
the attacker.

Finally the arbitrary offset write occurs through a second fragment that
only needs to be crafted to write data in the hole pointed to by the
previously controlled hole metadata (`next_hole`) from the first packet.

### Recommendation

Handle cases where `len` is strictly lower than 8 by preventing the
overwrite of the hole metadata during the memcpy of the fragment. This
could be achieved by either:
* Moving the location where the hole metadata is stored when `len` is
lower than `8`.
* Or outright rejecting fragmented IP datagram with a Total Length
(`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP
datagram size (as defined as the minimum fragment of 8 octets in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25).

----------BUG 2----------

In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of
`ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE`
will lead to a negative value for `len` which will ultimately result in
a buffer overflow during the subsequent `memcpy` that uses `len` as it's
`count` parameter.

This bug is only exploitable on local ethernet as it requires crafting
an invalid packet to include an unexpected `ip_len` value in the IP UDP
header that's lower than the minimum accepted Total Length of a packet
(21 as defined in the IP Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet
would in all likelihood be dropped while being routed to its final
destination through most routing equipment and as such requires the
attacker to be in a local position in order to be exploited.

```C
static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
struct hole *payload, *thisfrag, *h, *newh;
struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
uchar *indata = (uchar *)ip;
int offset8, start, len, done = 0;
u16 ip_off = ntohs(ip->ip_off);

/* payload starts after IP header, this fragment is in there */
payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
offset8 = (ip_off & IP_OFFS);
thisfrag = payload + offset8;
start = offset8 * 8;
len = ntohs(ip->ip_len) - IP_HDR_SIZE;
```

The last line of the previous excerpt from `u-boot/net/net.c` shows
where the underflow to a negative `len` value occurs if `ip_len` is set
to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note
that in the above excerpt the `pkt_buff` buffer has a size of
`CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to
64 KB depending on configurations.

```C
/* finally copy this fragment and possibly return whole packet */
memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
```

In the above excerpt the `memcpy` overflows the destination by
attempting to make a copy of nearly 4 gigabytes in a buffer that's
designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS.

### Recommendation

Stop processing of the packet if `ip_len` is lower than 21 (as defined
by the minimum length of a data carrying datagram in the IP
Specification Document:
[RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34)."

Add a check for ip_len lesser than 28 and stop processing the packet
in this case.

Such a check covers the two reported bugs.

Reported-by: Nicolas Bidron <nicolas.bidron@nccgroup.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@amd.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 0b956e39 18-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_RX_ETH_BUFFER to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_RX_ETH_BUFFER

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.masahiro@socionext.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wd@denx.de>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wd@denx.de>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wd@denx.de>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wd@denx.de>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <sr@denx.de>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wd@denx.de>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wd@denx.de>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wd@denx.de>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <sr@denx.de>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wd@denx.de>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wd@denx.de>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wd@denx.de>

Initial revision

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# 631f3afb 30-Jun-2021 Tim Harvey <tharvey@gateworks.com>

net: add set_promisc function to enable/disable Promiscuous mode

Enabling promiscuous mode can be useful for DSA switches where each port
has its own MAC address.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# fc054d56 25-Jan-2021 Claudiu Manoil <claudiu.manoil@nxp.com>

net: Introduce DSA class for Ethernet switches

DSA stands for Distributed Switch Architecture and it covers switches that
are connected to the CPU through an Ethernet link and generally use frame
tags to pass information about the source/destination ports to/from CPU.
Front panel ports are presented as regular ethernet devices in U-Boot and
they are expected to support the typical networking commands.
DSA switches may be cascaded, DSA class code does not currently support
this.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# 36ea0cab 07-Oct-2020 Patrick Wildt <patrick@blueri.se>

net: add a define for the number of packets received as batch

With a define for the magic number of packets received as batch
we can make sure that the EFI network stack caches the same amount
of packets.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# c3f0278e 12-Sep-2020 Sean Anderson <seanga2@gmail.com>

net: Expose some errors generated in net_init

net_init does not always succeed, and there is no existing mechanism to
discover errors. This patch allows callers of net_init (such as net_init)
to handle errors. The root issue is that eth_get_dev can fail, but
net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would
be to return an error with ERR_PTR, but there are a lot of callers, and all
of them just check if it's NULL. Another approach would be to change the
signature to something like

int eth_get_dev(struct udevice **pdev)

but that would require rewriting all of the many callers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b43ea1bf 18-Sep-2020 Philippe Reynes <philippe.reynes@softathome.com>

net: add a generic udp protocol

This commit adds a generic udp protocol framework in the
network loop. So protocol based on udp may be implemented
without modifying the network loop (for example custom
wait magic packet).

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# f1d925d9 20-May-2020 Baruch Siach <baruch@tkos.co.il>

net: move random_port() to dns

The random_port() routine is not used anywhere else. Make it local to
dns.c to reduce code clutter, and shrink generated code a little.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 90526e9f 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop net.h from common header

Move this header out of the common header. Network support is used in
quite a few places but it still does not warrant blanket inclusion.

Note that this net.h header itself has quite a lot in it. It could be
split into the driver-mode support, functions, structures, checksumming,
etc.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c3dc39a2 10-May-2020 Simon Glass <sjg@chromium.org>

arm: Don't include common.h in header files

It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# f641a8ac 17-Jun-2019 Samuel Mendoza-Jonas <sam@mendozajonas.com>

phy: Add support for the NC-SI protocol

This introduces support for the NC-SI protocol, modelled as a phy driver
for other ethernet drivers to consume.

NC-SI (Network Controller Sideband Interface) is a protocol to manage a
sideband connection to a proper network interface, for example a BMC
(Baseboard Management Controller) sharing the NIC of the host system.
Probing and configuration occurs by communicating with the "remote" NIC
via NC-SI control frames (Ethernet header 0x88f8).

This implementation is roughly based on the upstream Linux
implementation[0], with a reduced feature set and an emphasis on getting
a link up as fast as possible rather than probing the full possible
topology of the bus.
The current phy model relies on the network being "up", sending NC-SI
command frames via net_send_packet() and receiving them from the
net_loop() loop (added in a following patch).

The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent
field definitions.

[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# 5e6267af 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move reset_phy() to net.h

This is a network function so let's move it into that header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 77f4e477 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move do_tftpb() to net.h

This function belongs in the network header file. Move it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@csgraf.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@csgraf.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 Wolfgang Denk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 Wolfgang Denk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 Wolfgang Denk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 Wolfgang Denk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 Stefan Roese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 Wolfgang Denk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 Wolfgang Denk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 Wolfgang Denk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 Stefan Roese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 Wolfgang Denk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 Wolfgang Denk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 Wolfgang Denk <wdenk>

Initial revision

# d724321f 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Improve documentation for string_to_ip()

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

# fb8977c5 13-Sep-2019 Joe Hershberger <joe.hershberger@ni.com>

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@suse.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@suse.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 wdenk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 wdenk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 wdenk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 wdenk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 wdenk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 stroese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 wdenk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 wdenk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 wdenk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 wdenk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 stroese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 wdenk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 wdenk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 wdenk <wdenk>

Initial revision

# 8d5babb4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move env_get_ip() to net.h

This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 840ef4d4 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move random-number functions into their own header

Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@suse.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@suse.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 wdenk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 wdenk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 wdenk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 wdenk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 wdenk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 stroese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 wdenk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 wdenk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 wdenk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 wdenk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 stroese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 wdenk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 wdenk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 wdenk <wdenk>

Initial revision

# 12c2a310 27-Aug-2019 Michael Walle <michael@walle.cc>

net: make net_random_ethaddr() more random

The net_random_ethaddr() tries to get some entropy from different
startup times of a board. The seed is initialized with get_timer() which
has only a granularity of milliseconds. We can do better if we use
get_ticks() which returns the raw timer ticks. Using this we have a
higher chance of getting different values at startup.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 36c8b143 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: net: Move eth_parse_enetaddr() to net.c/h

This function fits better with the network subsystem, so move it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Joe Hershberger <joe.hershberger@ni.com>

# 9fb625ce 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Move env_set() to env.h

Move env_set() over to the new header file.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# bbfc5627 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: unaligned copying of unsigned long

The inline functions net_read_u32() and net_copy_u32() have been created to
copy unaligned u32. But this is not obvious to the compiler. GCC 9.1
introduces a check -Werror=address-of-packed-member which leads to a build
error on Travis CI:

net/bootp.c: In function ‘dhcp_send_request_packet’:
net/bootp.c:1011:27: error: taking address of packed member of
‘struct bootp_hdr’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
1011 | net_copy_u32(&bp->bp_id, &bp_offer->bp_id);

Change the type of the function parameters to void * to avoid the build
error.

Reported-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 3c6add98 18-Mar-2019 Faiz Abbas <faiz_abbas@ti.com>

net: Add priv_pdata to eth_pdata

Add a priv member for eth_pdata for platform specific platform data.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 67bb9842 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: remove CONFIG_MCAST_TFTP

No mainline board enables CONFIG_MCAST_TFTP and there have been
compilation issues with the code for some time. Additionally, it has a
potential buffer underrun issue (reported as a side note in
CVE-2018-18439).

Remove the multicast TFTP code but keep the driver API for the future
addition of IPv6.

Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1a4af5c5 26-Nov-2018 Chris Packham <judge.packham@gmail.com>

net: move ether_crc to tsec driver

ether_crc was added to the core net code in commit 53a5c424bf86
("multicast tftp: RFC2090") so that other drivers could use it. However
the only current user of it is tsec.c so move it there.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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

# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>

# 449312c1 15-Jun-2018 Alexander Graf <agraf@suse.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>

# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>

# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>

# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>

# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

# 0efe1bcf 06-May-2016 Alexander Graf <agraf@suse.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>

# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 82d72a1b 28-Jan-2016 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-net


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3

# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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

# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)

# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989

# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com

# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>

# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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

# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>

# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>

# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>

# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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

# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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

# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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

# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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

# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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

# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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

# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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

# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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

# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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

# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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

# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>

# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>

# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>

# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>

# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>

# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>

# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>

# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>

# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.

# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x

# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.

# ea287deb 31-Mar-2005 wdenk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver

# 3e01d75f 09-Oct-2004 wdenk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()

# 68ceb29e 02-Aug-2004 wdenk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)

# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 5bb226e8 17-Nov-2003 wdenk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set

# 42d1f039 15-Oct-2003 wdenk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup

# fe389a82 28-Aug-2003 stroese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.

# 77846748 26-Jul-2003 wdenk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work

# 8bde7f77 27-Jun-2003 wdenk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)

# 71f95118 15-Jun-2003 wdenk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 73a8b27c 05-Jun-2003 wdenk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)

# c6028835 05-Jun-2003 stroese <stroese>

- CFG_ETH_RX_BUFFER added.

# aacf9a49 17-Jan-2003 wdenk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)

# 1d0350ed 11-Nov-2002 wdenk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h

# 2d966958 31-Oct-2002 wdenk <wdenk>

Initial revision

# 5d457ecb 24-Jun-2018 Duncan Hare <DH@Synoia.com>

net: Consolidate UDP header functions

Make it possible to add TCP versions of the same, while reusing
IP portions. This patch should not change any behavior.

Signed-off-by: Duncan Hare <DH@Synoia.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# ac3f26cc 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Don't overwrite waiting packets with asynchronous replies

Peter originally sent a fix, but it breaks a number of other things.
This addresses the original reported issue in a different way.

That report was:

> U-Boot has 1 common buffer to send Ethernet frames, pointed to by
> net_tx_packet. When sending to an IP address without knowing the MAC
> address, U-Boot makes an ARP request (using the arp_tx_packet buffer)
> to find out the MAC address of the IP addressr. When a matching ARP
> reply is received, U-Boot continues sending the frame stored in the
> net_tx_packet buffer.
>
> However, in the mean time, if U-Boot needs to send out any network
> packets (e.g. replying ping packets or ARP requests for its own IP
> address etc.), it will use the net_tx_packet buffer to prepare the
> new packet. Thus this buffer is no longer the original packet meant
> to be transmitted after the ARP reply. The original packet will be
> lost.

This instead uses the ARP tx buffer to send async replies in the case
where we are actively waiting for an ARP reply.

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

Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>


# 3f02c98b 26-Sep-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Add an accessor to know if waiting for ARP

This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>


# dda52510 31-Jul-2018 Bin Meng <bmeng.cn@gmail.com>

net.h: Include linux/if_ether.h to avoid duplication

There are plenty of existing drivers that have macros like ETH_ALEN
defined in their own source files. Now that we imported the kernel's
if_ether.h to U-Boot we can reduce some duplication.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 1666fa58 02-Aug-2018 Pankaj Bansal <pankaj.bansal@nxp.com>

net: Increase ethernet name string size to 20 chars

The 16 char ethernet name size is inadequate to hold the name of ethernet
name "DPMAC17@rgmii-id", which is a valid name in LX2160AQDS/LX2160ARDB.

Therefore, increase the name string size to 20 chars.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>


# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

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


# 3a66fcb7 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: When checking prerequisites, consider boot_file_name

For net_boot_common, we allow the serverip to be specified as part of
the boot file name. For net commands that require serverip, include that
source as a valid specification of serverip.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Alexander Graf <agraf@suse.de>


# 449312c1 15-Jun-2018 Alexander Graf <agraf@suse.de>

net: Prefer command line arguments

We can call commands like dhcp and bootp without arguments or with
explicit command line arguments that really should tell the code where
to look for files instead.

Unfortunately, the current code simply overwrites command line arguments
in the dhcp case with dhcp values.

This patch allows the code to preserve the command line values if they
were set on the command line. That way the semantics are slightly more
intuitive.

The reason this patch does that by introducing a new variable is that we
can not rely on net_boot_file_name[0] being unset, as today it's
completely legal to call "dhcp" and afterwards run "tftp" and expect the
latter to repeat the same query as before. I would prefer not to break
that behavior in case anyone relies on it.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# d8970dae 22-Jun-2018 Lothar Felten <lothar.felten@gmail.com>

net: Add new wol command - Wake on LAN

Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).

Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.

This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.

Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.

By default enabled in pengwyn_defconfig.

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# f73a7df9 29-May-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: fastboot: Merge AOSP UDP fastboot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
Signed-off-by: Jocelyn Bohr <bohr@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# f739fcd8 07-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert a few files that were missed before

As part of the main conversion a few files were missed. These files had
additional whitespace after the '*' and before the SPDX tag and my
previous regex was too strict. This time I did a grep for all SPDX tags
and then filtered out anything that matched the correct styles.

Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style")
Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de>
Signed-off-by: Tom Rini <trini@konsulko.com>


# 9925f1db 01-Apr-2018 Alex Kiernan <alex.kiernan@gmail.com>

net: Move enetaddr env access code to env config instead of net config

In order that we can use eth_env_* even when CONFIG_NET isn't set, move
these functions to environment code from net code.

This fixes failures such as:

board/ti/am335x/built-in.o: In function `board_late_init':
board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr'
u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr'

which caters for use cases such as:

commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment
variable")

when Ethernet is required in Linux, but not U-Boot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>


# 99761e53 07-Mar-2018 Jason Kridner <jkridner@beagleboard.org>

Handle NETCONSOLE and SPL enabled

NETCONSOLE isn't compiled in with SPL, so the include file needs to recognize that.

Signed-off-by: Jason Kridner <jdk@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 723806cc 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename some other getenv()-related functions

We are now using an env_ prefix for environment functions. Rename these
other functions as well, for consistency:

getenv_vlan()
getenv_bootm_size()
getenv_bootm_low()
getenv_bootm_mapsize()
env_get_default()

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>


# 35affd7a 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_getenv_enetaddr() to eth_env_get_enetaddr()

Rename this function for consistency with env_get().

Signed-off-by: Simon Glass <sjg@chromium.org>


# fd1e959e 03-Aug-2017 Simon Glass <sjg@chromium.org>

env: Rename eth_setenv_enetaddr() to eth_env_set_enetaddr()

Rename this function for consistency with env_set().

Signed-off-by: Simon Glass <sjg@chromium.org>


# 704f3acf 21-Jul-2017 Denis Pynkin <denis.pynkin@collabora.com>

net: Use packed structures for networking

PXE boot is broken with GCC 7.1 due option '-fstore-merging' enabled
by default for '-O2':

BOOTP broadcast 1
data abort
pc : [<8ff8bb30>] lr : [<00004f1f>]
reloc pc : [<17832b30>] lr : [<878abf1f>]
sp : 8f558bc0 ip : 00000000 fp : 8ffef5a4
r10: 8ffed248 r9 : 8f558ee0 r8 : 8ffef594
r7 : 0000000e r6 : 8ffed700 r5 : 00000000 r4 : 8ffed74e
r3 : 00060101 r2 : 8ffed230 r1 : 8ffed706 r0 : 00000ddd
Flags: nzcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...

Core reason is usage of structures for network headers without packed
attribute.

Reviewed-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 5b8e76c3 07-Jun-2017 Heiko Schocher <hs@denx.de>

powerpc, 8xx: remove support for 8xx

There was for long time no activity in the 8xx area.
We need to go further and convert to Kconfig, but it
turned out, nobody is interested anymore in 8xx,
so remove it (with a heavy heart, knowing that I remove
here the root of U-Boot).

Signed-off-by: Heiko Schocher <hs@denx.de>


# 2c07c329 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Define ethernet name length

There are various places where the ethernet device name is defined to
several different sizes. Lets add a define and start using it.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 9f455bcb 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Make the MAC address string less magical

In u-boot printf has been extended with the %pM formatter to allow
printing of MAC addresses. However buffers that want to store a MAC
address cannot safely get the size. Add a define for this case so the
string of a MAC address can be reliably obtained.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# a40db6d5 25-Nov-2016 oliver@schinagl.nl <oliver@schinagl.nl>

net: cosmetic: Do not use magic values for ARP_HLEN

Commit 674bb249825a ("net: cosmetic: Replace magic numbers in arp.c with
constants") introduced a nice define to replace the magic value 6 for
the ethernet hardware address. Replace more hardcoded instances of 6
which really reference the ARP_HLEN (iow the MAC/Hardware/Ethernet
address).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# d4a37553 17-Nov-2016 Mugunthan V N <mugunthanvnm@ti.com>

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>


# 62a3b7dd 15-Jul-2016 Robert P. J. Day <rpjday@crashcourse.ca>

Various, unrelated tree-wide typo fixes.

Fix a number of typos, including:

* "compatble" -> "compatible"
* "eanbeld" -> "enabled"
* "envrionment" -> "environment"
* "FTD" -> "FDT" (for "flattened device tree")
* "ommitted" -> "omitted"
* "overriden" -> "overridden"
* "partiton" -> "partition"
* "propogate" -> "propagate"
* "resourse" -> "resource"
* "rest in piece" -> "rest in peace"
* "suport" -> "support"
* "varible" -> "variable"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>


# 0efe1bcf 06-May-2016 Alexander Graf <agraf@suse.de>

efi_loader: Add network access support

We can now successfully boot EFI applications from disk, but users
may want to also run them from a PXE setup.

This patch implements rudimentary network support, allowing a payload
to send and receive network packets.

With this patch, I was able to successfully run grub2 with network
access inside of QEMU's -M xlnx-ep108.

Signed-off-by: Alexander Graf <agraf@suse.de>


# 700877a6 13-Apr-2016 Stefan Agner <stefan@agner.ch>

net: increase maximum frame size to accomediate VLAN packets

Ethernet packages with IEEE 802.1Q VLAN support may be up to 1522
bytes long. Increase the default size used to allocate packet
storage by 4 bytes. While at it, let git care about history and
rewrite the comment to represent the situation today only.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 99d4c6d3 09-Feb-2016 Stefan Roese <sr@denx.de>

net: mvpp2.c: Add Marvell mvpp2 network driver for Armada 375

This patch adds support for the mvpp2 ethernet controller which is integrated
in the Marvell Armada 375 SoC. This port is based on the Linux driver (v4.4),
which has been stripped of the in U-Boot unused portions.

Tested on the Marvell Armada 375 eval board db-88f6720.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>


# 5350bc8f 18-Mar-2016 Roger Quadros <rogerq@ti.com>

net: export eth_setenv_enetaddr_by_index() to net.h

Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and
this function is handy at board.c to configure the
MAC address of the ports.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>


# f74264d6 13-Jan-2016 Alexey Brodkin <Alexey.Brodkin@synopsys.com>

include/net.h: add max_speed member in struct eth_pdata

This will be used for getting max speed mode of Ethernet interface that
a particular MAC supports from Device Tree blob and later being used for
phy configuration.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 92163873 08-Nov-2015 Fabio Estevam <fabio.estevam@freescale.com>

include: net: Simplify the usage of __always_inline

Since commit de4d2e9e7ce0f9 (" bitops: Add fls_long and __ffs64")
<linux/compiler.h> is included in include/linux/bitops.h,
which allows us to marking a function as 'always_inline' in a simpler
format.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 11a69ff8 30-Sep-2015 Jacob Stiffler <j-stiffler@ti.com>

net: Increase the size of the net_boot_file_name buffer

The net_boot_file_name buffer is used as storage for the bootfilename
command line argument to network boot commands such as tftp and nfs.

Increase the size of this buffer to 1024 bytes as the current size of
128 bytes is restrictive for arbitrary paths on the server.

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 219cc94a 01-Sep-2015 Josh Wu <josh.wu@atmel.com>

net: change the env name to use const

As we don't modify the 'name' parameter, so change it to const.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# eaa8a195 14-Sep-2015 Bernhard Nortmann <bernhard.nortmann@web.de>

net: expose eth_is_active() function to test network device state

The previous eth_device struct returned by eth_get_dev() allowed
code to directly query the state member field. However, with
CONFIG_DM_ETH this data gets encapsulated (i.e. private), and
eth_get_dev() returns a udevice struct 'abstraction' instead.

This breaks legacy code relying on the former behaviour - e.g.
netconsole.
(see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html)

The patch introduces a method to retrieve the ethernet device
state in a 'clean' and uniform way, supporting both legacy code
and driver model. The new function eth_is_active() accepts a
device struct pointer and tests it for ETH_STATE_ACTIVE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# c7ff5528 23-Aug-2015 Lukasz Majewski <l.majewski@majess.pl>

update: tftp: dfu: Extend update_tftp() function to support DFU

This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# b86f795a 06-Jul-2015 Simon Glass <sjg@chromium.org>

net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>


# a1ca92ea 06-Jul-2015 Simon Glass <sjg@chromium.org>

dm: eth: Avoid blocking on packet reception

Some devices can take a long time to work out whether they have a new packet
or now. For example the ASIX USB Ethernet dongle can take 5 seconds to do
this, since it waits until it gets a new packet on the wire before allowing
the USB bulk read packet to be submitted.

At present with driver mode the Ethernet receive code reads 32 packets. This
can take a very long time if we must wait for all 32 packets. The old code
(before driver model) worked by reading a single set of packets from the USB
device, then processing all the packets with in. It would be nice to use
the same behaviour with driver model.

Add a flag to the receive method which indicates that the driver should try
to find a packet if available, by consulting the hardware. When the flag is
not set, it should just return any packet data it has already received. If
there is none, it should return -EAGAIN so that the loop will terminate.

Signed-off-by: Simon Glass <sjg@chromium.org>


# c74c8e66 05-Apr-2015 Simon Glass <sjg@chromium.org>

dm: net: Adjust PHY interface to work with CONFIG_DM_ETH

When driver model is used for Ethernet a few functions are passed a udevice
instead of an eth_device. Also add a function to find a PHY type given its
name. This will be used to decode the device tree node.

Finally, put a phy_interface field in struct eth_pdata since this is an
important part of the platform data for Ethernet.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 717234e0 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Convert protocol structures to use explicit sizes

Convert uchar/ushort to u8/u16 respectively.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 5917e7d1 08-Apr-2015 Sergey Temerkhanov <s.temerkhanov@gmail.com>

net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.

Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com>
Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# a34f2075 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.h

There were still a few remaining complains in the legacy eth_device
definition that hadn't been addressed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 4fd5055f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up cmd_net variables and functions

Make a thorough pass through all variables and function names contained
within common/cmd_net.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 6a38a5f3 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up netconsole variables and functions

Make a thorough pass through all variables and function names contained
within netconsole.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 786eac5f 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 6aede5b7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 1fd92db8 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix var naming net <-> eth drivers

Update the naming convention used in the network stack functions and
variables that Ethernet drivers use to interact with it.

This cleans up the temporary hacks that were added to this interface
along with the DM support.

This patch has a few remaining checkpatch.pl failures that would be out
of the scope of this patch to fix (drivers that are in gross violation
of checkpatch.pl).

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

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


# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 586cbe51 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names for DHCP strings

Remove CamelCase variable naming.
Move the definition to the same compilation unit as the primary use.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 63c9729a 03-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Provide a way for drivers to manage packet buffers

Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3


# 60304592 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Improve error handling

Take a pass at plumbing errors through to the users of the network stack

Currently only the start() function errors will be returned from
NetLoop(). recv() tends not to have errors, so that is likely not worth
adding. send() certainly can return errors, but this patch does not
attempt to plumb them yet. halt() is not expected to error.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# e58780dc 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add support for aliases

Allow network devices to be referred to as "eth0" instead of
"eth@12345678" when specified in ethact.

Add tests to verify this behavior.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 17591405 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Pass the packet pointer as a parameter to recv

Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

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


# 2a504df0 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Clean up network stack names used in DM drivers

Take the opportunity to enforce better names on newly written or
retrofitted Ethernet drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 05c3e68f 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

dm: eth: Add basic driver model support to Ethernet stack

First just add support for MAC drivers.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# d2eaec60 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove the bd* parameter from net stack functions

This value is not used by the network stack and is available in the
global data, so stop passing it around. For the one legacy function
that still expects it (init op on old Ethernet drivers) pass in the
global pointer version directly to avoid changing that interface.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
(Trival fix to remove an unneeded variable declaration in 4xx_enet.c)


# fce6900b 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Use int instead of u8 for boolean flag

On some archs masking the parameter is inefficient, so don't use u8.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 84eb1fba 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor in preparation for driver model

Move some things around and organize things so that the driver model
implementation will fit in more easily.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# ff997432 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Remove unneeded "extern" in net.h

Many of the functions in net.h were preceded extern needlessly. Removing
them to limit the number of checkpatch.pl complaints.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 8b2c9a71 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Provide a function to get the current MAC address

The current implementation exposes the eth_device struct to code that
needs to access the MAC address. Add a wrapper function for this to
abstract away the pointer for this operation.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# a7c3d5e2 20-Mar-2015 Bin Meng <bmeng.cn@gmail.com>

net: Add ethernet FCS length macro in net.h

Some ethernet drivers use their own version of ethernet FCS length
macro which is really common. We define ETH_FCS_LEN in net.h and
replace those custom versions in various places.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 0da0fcd5 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Use new checksum functions

Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 9b0e35cb 19-Jan-2015 Simon Glass <sjg@chromium.org>

net: Add a separate file for IP checksumming

Move the checksum code out into its own file so it can be used elsewhere.
Also use a new version which supports a length which is not a multiple of
2 and add a new function to add two checksums.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 16ae7827 14-Jan-2015 Michal Simek <michal.simek@xilinx.com>

net: Declare physical address as phys_addr_t unsigned type

Use phys_addr_t instead of int for addresses.
Addresses can't be < 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>


# 2ea91039 30-Sep-2014 Wolfgang Denk <wd@denx.de>

SPDX License cleanup for LiMon imported files

A number of network related files were imported from the LiMon
project; these contain a somewhat unclear license statement:

Copyright 1994 - 2000 Neil Russell.
(See License)

I analyzed the source code of LiMon v1.4.2 which was used for this
import. It does not contain any "License" file, but the top level
directory contains a file "COPYING", which turns out to be GPL v2
of June 1991. So it is legitimate to conclude that the LiMon derived
files are also to be released under GPLv2. Mark them as such.

Signed-off-by: Wolfgang Denk <wd@denx.de>


# da384a9d 18-Apr-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

net: rename and refactor eth_rand_ethaddr() function

Some functions in include/net.h are ported from
include/linux/etherdevice.h of Linux Kernel.

For ex.
is_zero_ether_addr()
is_multicast_ether_addr()
is_broadcast_ether_addr()
is_valid_ether_addr();

So, we should use the same function name as that of Linux Kernel,
eth_rand_addr(), for consistency.

Besides, eth_rand_addr() has been implemented as an inline function.
So it should not be surrounded by #ifdef CONFIG_RANDOM_MACADDR.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 9c4cffac 29-Sep-2013 Claudiu Manoil <claudiu.manoil@freescale.com>

net: Fix mcast function pointer prototype

This fixes the following compiler warnings when activating
CONFIG_MCAST_TFTP:

tsec.c: In function 'tsec_mcast_addr':
tsec.c:130:2: warning: passing argument 2 of 'ether_crc' makes pointer
from integer without a cast [enabled by default]
In file included from /work/u-boot-net/include/common.h:874:0,
from tsec.c:15:
/work/u-boot-net/include/net.h:189:5: note: expected 'const unsigned
char *' but argument is of type 'u8'
tsec.c: In function 'tsec_initialize':
tsec.c:646:13: warning: assignment from incompatible pointer type
[enabled by default]
eth.c: In function 'eth_mcast_join':
eth.c:358:2: warning: passing argument 2 of 'eth_current->mcast' makes
integer from pointer without a cast [enabled by default]
eth.c:358:2: note: expected 'u32' but argument is of type 'u8 *'

In the eth_mcast_join() implementation, eth_current->mcast()
takes a u8 pointer to the multicast mac address and not a ip
address value as implied by its prototype.

Fix parameter type mismatch for tsec_macst_addr() (tsec.c):
ether_crc() takes a u8 pointer not a u8 value.
mcast() is given a u8 pointer to the multicats mac address.
Update parameter type for the rest of mcast() instances.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Patch: 278989


# 6e840ebc 10-Aug-2013 Jeroen Hofstee <jeroen@myspectrum.nl>

net.h: don't use the reserved name __unused

The __* keywords are reserved. On FreeBSD __unused evaluates
to the attribute unused, causing a compilation failure.
Just use unused instead.

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
cc: joe.hershberger@gmail.com


# 3d49412d 16-Jan-2013 Kim Phillips <kim.phillips@freescale.com>

net: make IPaddr type big endian

for use with sparse.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>


# ea5427e2 15-May-2013 Simon Glass <sjg@chromium.org>

net: Add prototype for update_tftp

This function should be declared in net.h.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>


# 06370590 29-Oct-2012 Kim Phillips <kim.phillips@freescale.com>

net/: sparse fixes

bootp.c:44:14: warning: symbol 'dhcp_state' was not declared. Should it be static?
bootp.c:45:15: warning: symbol 'dhcp_leasetime' was not declared. Should it be static?
bootp.c:46:10: warning: symbol 'NetDHCPServerIP' was not declared. Should it be static?
arp.c:30:17: warning: symbol 'NetArpWaitReplyIP' was not declared. Should it be static?
arp.c:37:16: warning: symbol 'NetArpTxPacket' was not declared. Should it be static?
arp.c:38:17: warning: symbol 'NetArpPacketBuf' was not declared. Should it be static?
atheros.c:33:19: warning: symbol 'AR8021_driver' was not declared. Should it be static?
net.c:183:7: warning: symbol 'PktBuf' was not declared. Should it be static?
net.c:159:21: warning: symbol 'net_state' was not declared. Should it be static?
ping.c:73:6: warning: symbol 'ping_start' was not declared. Should it be static?
ping.c:82:13: warning: symbol 'ping_receive' was not declared. Should it be static?
tftp.c:53:7: warning: symbol 'TftpRRQTimeoutMSecs' was not declared. Should it be static?
tftp.c:54:5: warning: symbol 'TftpRRQTimeoutCountMax' was not declared. Should it be static?
eth.c:125:19: warning: symbol 'eth_current' was not declared. Should it be static?

Note: in the ping.c fix, commit a36b12f95a29647a06b5459198684fc142482020
"net: Move PING out of net.c" mistakenly carried the ifdef CMD_PING
clause from when it was necessary to avoid warnings when it was embedded
in net.c.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>


# 8a0eccb1 18-Sep-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Filter incoming netconsole packets by IP

Check the incoming packets' source IP address... if ncip isn't set to a
broadcast address, only listen to the client at ncip.

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


# f8be7d65 03-Aug-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Improve the speed of netconsole

Previously u-boot would initialize the network interface for every
network operation and then shut it down again. This makes sense for
most operations where the network in not known to be needed soon after
the operation is complete. In the case of netconsole, it will use the
network for every interaction with the shell or every printf. This
means that the network is being reinitialized very often. On many
devices, this intialization is very slow.

This patch checks for consecutive netconsole actions and leaves the
ethernet hardware initialized between them. It will still behave the
same old way for all other network operations and any time another
network operation happens between netconsole operations.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Stefano Babic <sbabic@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>


# 03c1b04f 05-Jun-2012 Michael Walle <michael@walle.cc>

net: add helper to generate random mac address

Add new function eth_random_enetaddr() to generate a locally administered
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Joe Hershberger <joe.hershberger@gmail.com>


# 4ef8d53c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

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>


# d22c338e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add link-local addressing support

Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

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


# e94070c4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Don't copy every packet that waits for an ARP

Use the NetArpTxPacket for the ARP packet, not to hold what used to
be in NetTxPacket.
This saves a copy and makes the code easier to understand.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 46c495d5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Fix net buffer initialization

A new non-static function net_init() will initialize buffers and
read from the environment. Only update from the env on each entry
to NetLoop().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# e7111015 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Add net_update_ether() to handle ARP and Ping replies

When the network is VLAN or SNAP, net_update_ether() will preserve
the original Ethernet packet header and simply replace the src and
dest MACs and the protocol

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

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


# adf5d93e 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to use NetSendPacket instead of eth_send directly

Use this entry-point consistently across the net/ code
Use a static inline function to preserve code size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 4b11c916 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor IP, UPD, and ICMP header writing functions

ICMP (ping) was reimplementing IP header code... it now shares code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# 674bb249 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Replace magic numbers in arp.c with constants

Use field names and sizes when accessing ARP packets

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


# da5ebe2c 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Add a more explicit comment about 802.2

Make the comment more accurate about the header including SNAP

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 206d07fd 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Rename parameter len to payload_len

This name more explicitly claims that it does not include the
header size

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# e0a63079 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ICMP_t

Remove typedef and lower-case name

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


# 738853bb 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef ARP_t

Remove typedef and lower-case letters

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


# c68cca35 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef VLAN_Ethernet_t

Eliminate the typedef and remove capital letters

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


# cb487f56 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef Ethernet_t

Separate the Ethernet header from the 802 header.
Base the size constants on the structs.

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


# c5c59df0 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Split struct ip_udp_hdr into ip_hdr

Add a structure that only contains IP header fields to be used by
functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE

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


# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

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


# d280d3f4 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move ARP out of net.c

Separate this functionality out of the net.c behemoth

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# 17351883 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Encapsulate CDP packet identification

Checking for CDP packets should be encapsulated, not copied code.

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


# f575ae1f 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Move CDP out of net.c

Separate this functionality out of the net.c behemoth

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


# 13dfe943 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: tftp.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 48522bb5 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.c checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# b28e28bb 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: net.h checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# db288a96 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Remove volatile from net API

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 2c4b3c19 15-Mar-2012 Eric Nelson <eric.nelson@boundarydevices.com>

net: force PKTALIGN to ARCH_DMA_MINALIGN

This will prevent the need for architectures whose DMA alignment
is greater than 32 to have bounce buffers.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>


# f6add132 10-Nov-2011 Mike Frysinger <vapier@gentoo.org>

net/miiphy/serial: drop duplicate "NAMESIZE" define

A few subsystems are using the same define "NAMESIZE". This has been
working so far because they define it to the same number. However, I
want to change the size of eth_device's NAMESIZE, so rather than tweak
the define names, simply drop references to it. Almost no one does,
and the handful that do can easily be changed to a sizeof().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# e7e982d6 09-Jan-2012 Vincent Palatin <vpalatin@chromium.org>

eth: remove usb-ethernet devices before re-enumerating them

Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>


# fea7dcae 27-Oct-2011 Michael Walle <michael@walle.cc>

net: introduce per device index

Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.

Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# e4a3d57d 27-Oct-2011 Simon Glass <sjg@chromium.org>

net: Export auto_load, use it in rarp

The rarp code includes another instance of the auto_load logic, so call
what is now net_auto_load() instead.

This also fixes an incorrect call to TftpStart() which was never seen
since apparently no boards enable rarp.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# 58f317d1 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Support selecting get/put for tftp

TftpStart should support starting either a get or a put.

Signed-off-by: Simon Glass <sjg@chromium.org>


# e4bf0c5c 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Rename TFTP to TFTPGET

This is a better name for this protocol. Also remove the typedef to keep
checkpatch happy, and move zeroing of NetBootFileXferSize a little
earlier since TFTPPUT will need to change this.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 4793ee65 24-Oct-2011 Simon Glass <sjg@chromium.org>

net: tftpput: Add support for receiving ICMP packets

ICMP packets can tell you when there is no server at the other end. It
is useful for tftp to figure this out, so that a quick error can be
displayed, rather than pointlessly retrying.

This adds an ICMP packet handler to the net interface.

Signed-off-by: Simon Glass <sjg@chromium.org>


# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# 7616e785 13-Jun-2011 Simon Glass <sjg@chromium.org>

Add Ethernet hardware MAC address framework to usbnet

Built-in Ethernet adapters support setting the mac address by means of a
ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names
usbethaddr, usbeth1addr, etc. They are kept separate since we don't want
a USB device taking the MAC address of a built-in device or vice versa.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Eric Bénard <eric@eukrea.com>


# 7a83af07 16-May-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

TFTP: add tftpsrv command

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>


# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>


# 908c6b62 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_ip: constify "s" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# 2e3ef6e4 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

string_to_VLAN: constify "var" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# b920ee9d 20-Oct-2010 Mike Frysinger <vapier@gentoo.org>

copy_filename: constify "src" arg

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# 23cd1385 29-Jul-2009 Remy Bohmer <linux@bohmer.net>

Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

Signed-off-by: Thomas Smits <ts.smits@gmail.com>
Signed-off-by: Remy Bohmer <linux@bohmer.net>


# d7fb9bcf 29-Jul-2010 Ben Warren <biggerbadderben@gmail.com>

Fix compile warnings for const correctness

Commit 6e37b1a3a25004d3df5867de49fff6b3fc9c4f04 modifies several net calls
to take a (const char *) parameter instead of (char *), but in some cases
the modified functions call other functions taking (char *). The end result
is warnings about discarding the const qualifier.

This patch fixes these other function signatures.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# ecee9324 26-Apr-2010 Ben Warren <biggerbadderben@gmail.com>

Program net device MAC addresses after initializing

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address
for each has been determined, make a device driver call to program the
address into the device. Only device instances with valid unicast addresses
will be programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Detlev Zundel <dzu@denx.de>
Tested-by: Prafulla Wadaskar <prafulla@marvell.com>
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Thomas Chou <thomas@wytron.com.tw>


# 6a45e384 03-Jan-2010 Dirk Behme <dirk.behme@googlemail.com>

Make getenv_IPaddr() global

There are boards out there that do not have network support in
U-Boot (CONFIG_CMD_NET not set), but they do so in Linux. This
makes it desirable to be able to port network configuration (like
the IP address) to the Linux kernel.

We should not make the passing of the IP configuration to Linux
dependent on U-Boot features / settings.

For this, make getenv_IPaddr() global. This fixes build error

u-boot/lib_xxx/board.c:360: undefined reference to `getenv_IPaddr'

on various architectures.

Signed-off-by: Dirk Behme <dirk.behme@googlemail.com>
Acked-by: Ben Warren <biggerbadderben@gmail.com>


# 91b469c9 02-Sep-2009 Mike Frysinger <vapier@gentoo.org>

net: add random_port() prototype

The random_port() is meant to be used by other net code, but without a
prototype, we get fun warnings like:
dns.c: In function 'DnsSend':
dns.c:89: warning: implicit declaration of function 'random_port'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 86848a74 15-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: sync env ethaddr to device enetaddr in eth_init()

In the previous enetaddr refactoring, the assumption with commit 56b555a644
was that the eth layer would handle the env -> device enetaddr syncing.
This was not the case as eth_initialize() is called only once and the sync
occurs there. So make sure the eth_init() function does the env -> device
sync with every network init.

Reported-by: Andrzej Wolski <awolski@poczta.fm>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 1a32bf41 20-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

Add DNS support

On 04 Oct 2008 Pieter posted a dns implementation for U-Boot.

http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg10216.html
>
> DNS can be enabled by setting CFG_CMD_DNS. After performing a query,
> the serverip environment var is updated.
>
> Probably there are some cosmetic issues with the patch. Unfortunatly I
> do not have the time to correct these. So if anybody else likes DNS
> support in U-Boot and has the time, feel free to patch it in the main tree.

Here it is again - slightly modified & smaller:
- update to 2009-06 (Pieter's patch was for U-Boot 1.2.0)
- README.dns is added
- syntax is changed (now takes a third option, the env var to store
the result in)
- add a random port() function in net.c
- sort Makefile in ./net/Makefile
- dns just returns unless a env var is given
- run through checkpatch, and clean up style issues
- remove packet from stack
- cleaned up some comments
- failure returns much faster (if server responds, don't wait for
timeout)
- use built in functions (memcpy) rather than byte copy.

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Pieter Voorthuijsen <pieter.voorthuijsen@prodrive.nl>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# d9bec9f4 18-Jul-2009 Mike Frysinger <vapier@gentoo.org>

net: rename NetRxPkt to NetRxPacket

The net code is mostly consistent in using 'Packet' rather than 'Pkt', so
rename the minor detractor to follow suite.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 3f6e6993 29-Jan-2009 Mike Frysinger <vapier@gentoo.org>

net: new utility functions for working with enetaddr's

Declare new utility functions for converting between the environment
variables (eth*addr) and the binary MAC address representation. This way
we can unify all the random places that already do this kind of thing.

The functions in question:
eth_parse_enetaddr - "..." -> {...}
eth_getenv_enetaddr - env -> {...}
eth_setenv_enetaddr - {...} -> env

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>


# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>


# 5dc0cf68 11-Feb-2009 Andy Fleming <afleming@freescale.com>

Make some minor whitespace changes to eliminate line-wrapping

Signed-off-by: Andy Fleming <afleming@freescale.com>


# 75edebe3 27-Jan-2009 Mike Frysinger <vapier@gentoo.org>

Move is_valid_ether_addr() to include/net.h

Import the is_valid_ether_addr() function from the Linux kernel.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# e0c07b86 01-Dec-2008 Peter Tyser <ptyser@xes-inc.com>

net: Define IP flag field values

These defines were pulled from the "Add simple
IP/UDP fragmentation support" patch from Frank
Haverkamp <haver@vnet.ibm.com>.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>


# 53677ef1 20-May-2008 Wolfgang Denk <wd@denx.de>

Big white-space cleanup.

This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>


# 33a4a70d 30-Apr-2008 Anatolij Gustschin <agust@denx.de>

Fix warnings while compiling net/net.c for MPC8610HPCD board

MPC8610HPCD board adds -O2 gcc option to PLATFORM_CPPFLAGS
causing overriding default -Os option. New gcc (ver. 4.2.2)
produces warnings while compiling net/net.c file with -O2
option. The patch is an attempt to fix this.

Signed-off-by: Anatolij Gustschin <agust@denx.de>


# f85b6071 27-Dec-2007 Rafal Jaworowski <raj@semihalf.com>

Introduce new eth_receive routine

The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.

The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).

Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# 53a5c424 11-Jun-2007 David Updegraff <dave@cray.com>

multicast tftp: RFC2090

Implemented IETF RFC2090, Multicast TFTP. Initial implementation
on Realtek RTL8139 and Freescale TSEC.

Signed-off-by: David Updegraff <dave@cray.com>
Signed-off-by: Ben Warren <bwarren@qstreams.com>


# 50cca8b9 11-Aug-2007 Mike Rapoport <mike@compulab.co.il>

Add ability to take MAC address from the environment to DM9000 driver

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Ben Warren <bwarren@qstreams.com>


# 1fe80d79 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

Finally retire cmd_confdefs.h and CONFIG_BOOTP_MASK!

All of the choices for CONFIG_BOOTP_ are now documented in
the README file. You must now individually select exactly
the set that you want using a series of
#define CONFIG_BOOTP_<x>
statements in the board port config files now.

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 639221c7 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

include/: Remove obsolete references to CONFIG_COMMANDS
Mostly removed from comments here.

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 72a074ce 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

include/ non-config: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 63ff004c 28-Oct-2005 Marian Balakowicz <m8@semihalf.com>

Add support for multiple PHYs.


# 77ddac94 13-Oct-2005 Wolfgang Denk <wd@pollux.denx.de>

Cleanup for GCC-4.x


# 9c4c5ae3 23-Jul-2005 Jon Loeliger <jdl@freescale.com>

* Patch by Jon Loeliger, Kumar Gala 2005-02-08
- Convert the CPM2 based functionality to use new CONFIG_CPM2
option rather than a myriad of CONFIG_MPC8560-like variants.
Applies to MPC85xx and MPC8260 boards, includes stxgp3 and sbc8560.
Eliminates the CONFIG_MPC8560 option entirely. Distributes the
new CONFIG_CPM2 option to each 8260 board.


# ea287deb 31-Mar-2005 wdenk <wdenk>

* Patch by Masami Komiya, 30 Mar 2005:
add SNTP support and expand time server and time offset fields of
DHCP support. See doc/README.SNTP

* Patch by Steven Scholz, 13 Dec 2004:
Fix bug in at91rm920 ethernet driver


# 3e01d75f 09-Oct-2004 wdenk <wdenk>

Patch by Andreas Engel, 16 Aug 2004:
parameter type cleanup for NetSetTimeout()


# 68ceb29e 02-Aug-2004 wdenk <wdenk>

Add support for console over UDP (compatible to Ingo Molnar's
netconsole patch under Linux)


# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)


# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup


# 5bb226e8 17-Nov-2003 wdenk <wdenk>

* Use "-fPIC" instead of "-mrelocatable" to prevent problems with
recent tools

* Add checksum verification to 'imls' command

* Add bd_info fields needed for 4xx Linux I2C driver

* Patch by Martin Krause, 4 Nov. 2003:
Fix error in cmd_vfd.c (TRAB board: "vfd /1" shows now only one Bitmap)

* Print used network interface when CONFIG_NET_MULTI is set


# 42d1f039 15-Oct-2003 wdenk <wdenk>

* Patches by Xianghua Xiao, 15 Oct 2003:

- Added Motorola CPU 8540/8560 support (cpu/85xx)
- Added Motorola MPC8540ADS board support (board/mpc8540ads)
- Added Motorola MPC8560ADS board support (board/mpc8560ads)

* Minor code cleanup


# fe389a82 28-Aug-2003 stroese <stroese>

- Added CONFIG_BOOTP_DNS2 and CONFIG_BOOTP_SEND_HOSTNAME to CONFIG_BOOTP_MASK.


# 77846748 26-Jul-2003 wdenk <wdenk>

* Allow crc32 to be used at address 0x000

* Provide consistent interface to standalone applications to access
the 'global_data' structure
Provide a doc/README.standalone more useful to users/developers.

* Make IceCube MGT5100 FEC driver work


# 8bde7f77 27-Jun-2003 wdenk <wdenk>

* Code cleanup:
- remove trailing white space, trailing empty lines, C++ comments, etc.
- split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c)

* Patches by Kenneth Johansson, 25 Jun 2003:
- major rework of command structure
(work done mostly by Michal Cendrowski and Joakim Kristiansen)


# 71f95118 15-Jun-2003 wdenk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board


# 73a8b27c 05-Jun-2003 wdenk <wdenk>

* Add support for RMU board

* Add support for TQM862L at 100/50 MHz

* Patch by Pantelis Antoniou, 02 Jun 2003:
major reconstruction of networking code;
add "ping" support (outgoing only!)


# c6028835 05-Jun-2003 stroese <stroese>

- CFG_ETH_RX_BUFFER added.


# aacf9a49 17-Jan-2003 wdenk <wdenk>

* Add dual ethernet support on PM826

* Add support for LXT971 PHY on PM826

* Patch by Tord Andersson, 16 Jan 2003:
Fix flash sector count for TQM8xxL

* Fix I2C EEPROM problem on ICU862 board (would only write the first
16 bytes out of each 32 byte block)


# 1d0350ed 11-Nov-2002 wdenk <wdenk>

* Patch by Jim Sandoz, 07 Nov 2002:
Increase number of network RX buffers (PKTBUFSRX in
"include/net.h") for EEPRO100 based boards (especially SP8240)
which showed "Receiver is not ready" errors when U-Boot was
processing the receive buffers slower than the network controller
was filling them.

* Get rid of obsolete include/mpc74xx.h


# 2d966958 31-Oct-2002 wdenk <wdenk>

Initial revision