diff options
Diffstat (limited to 'include/net.h')
-rw-r--r-- | include/net.h | 138 |
1 files changed, 120 insertions, 18 deletions
diff --git a/include/net.h b/include/net.h index aad28e4f4c..5a6dd9ca7b 100644 --- a/include/net.h +++ b/include/net.h @@ -1,12 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: 1994-2000 Neil Russell /* - * LiMon Monitor (LiMon) - Network. + * net.h - barebox networking support * - * Copyright 1994 - 2000 Neil Russell. - * (See License) - * - * - * History - * 9/16/00 bor adapted to TQM823L/STK8xxL board, RARP/TFTP boot added + * based on U-Boot (LiMon) code */ #ifndef __NET_H__ @@ -19,6 +16,7 @@ #include <stdlib.h> #include <clock.h> #include <led.h> +#include <dma.h> #include <slice.h> #include <xfuncs.h> #include <linux/phy.h> @@ -31,7 +29,7 @@ /* The number of receive packet buffers */ #define PKTBUFSRX 4 -struct device_d; +struct device; struct eth_device { int active; @@ -44,16 +42,22 @@ struct eth_device { void (*halt) (struct eth_device*); int (*get_ethaddr) (struct eth_device*, u8 adr[6]); int (*set_ethaddr) (struct eth_device*, const unsigned char *adr); + int (*rx_preprocessor) (struct eth_device*, unsigned char **packet, + int *length); + void (*rx_monitor) (struct eth_device*, void *packet, int length); + void (*tx_monitor) (struct eth_device*, void *packet, int length); + /* Set promiscuous mode */ + int (*set_promisc) (struct eth_device*, bool enable); - struct eth_device *next; void *priv; + void *rx_preprocessor_priv; /* phy device may attach itself for hardware timestamping */ struct phy_device *phydev; - struct device_d dev; + struct device dev; char *devname; - struct device_d *parent; + struct device *parent; char *nodepath; struct list_head list; @@ -73,6 +77,8 @@ struct eth_device { #define ETH_MODE_STATIC 1 #define ETH_MODE_DISABLED 2 unsigned int global_mode; + + uint64_t last_link_check; }; #define dev_to_edev(d) container_of(d, struct eth_device, dev) @@ -87,13 +93,26 @@ static inline const char *eth_name(struct eth_device *edev) return edev->devname; } +static inline int eth_send_raw(struct eth_device *edev, void *packet, + int length) +{ + if (edev->tx_monitor) + edev->tx_monitor(edev, packet, length); + + return edev->send(edev, packet, length); +} + int eth_register(struct eth_device* dev); /* Register network device */ void eth_unregister(struct eth_device* dev); /* Unregister network device */ int eth_set_ethaddr(struct eth_device *edev, const char *ethaddr); +int eth_carrier_poll_once(struct eth_device *edev); int eth_open(struct eth_device *edev); void eth_close(struct eth_device *edev); int eth_send(struct eth_device *edev, void *packet, int length); /* Send a packet */ int eth_rx(void); /* Check for received packets */ +void eth_open_all(void); +struct eth_device *of_find_eth_device_by_node(struct device_node *np); +int eth_set_promisc(struct eth_device *edev, bool enable); /* associate a MAC address to a ethernet device. Should be called by * board code for boards which store their MAC address at some unusual @@ -216,9 +235,9 @@ struct icmphdr { * Maximum packet size; used to allocate packet storage. * TFTP packets can be 524 bytes + IP header + ethernet header. * Lets be conservative, and go for 38 * 16. (Must also be - * a multiple of 32 bytes). + * a multiple of 64 bytes). */ -#define PKTSIZE 1518 +#define PKTSIZE 1536 /**********************************************************************/ /* @@ -230,10 +249,9 @@ struct icmphdr { * (big endian). */ -extern unsigned char *NetRxPackets[PKTBUFSRX];/* Receive packets */ - void net_set_ip(struct eth_device *edev, IPaddr_t ip); void net_set_serverip(IPaddr_t ip); +const char *net_get_server(void); void net_set_serverip_empty(IPaddr_t ip); void net_set_netmask(struct eth_device *edev, IPaddr_t ip); void net_set_gateway(IPaddr_t ip); @@ -338,7 +356,6 @@ IPaddr_t getenv_ip(const char *name); int setenv_ip(const char *name, IPaddr_t ip); int string_to_ethaddr(const char *str, u8 enetaddr[6]); -void ethaddr_to_string(const u8 enetaddr[6], char *str); #ifdef CONFIG_NET_RESOLV int resolv(const char *host, IPaddr_t *ip); @@ -394,7 +411,10 @@ static inline int is_broadcast_ether_addr(const u8 *addr) return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; } -#define ETH_ALEN 6 +#define ETH_ALEN 6 /* Octets in an Ethernet address */ +#define ETH_HLEN 14 /* Total octets in header.*/ + +int generate_ether_addr(u8 *addr, int ethid); /** * random_ether_addr - Generate software assigned random Ethernet address @@ -427,6 +447,77 @@ static inline int is_valid_ether_addr(const u8 *addr) return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr); } +/** + * ether_addr_to_u64 - Convert an Ethernet address into a u64 value. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return a u64 value of the address + */ +static inline u64 ether_addr_to_u64(const u8 *addr) +{ + u64 u = 0; + int i; + + for (i = 0; i < ETH_ALEN; i++) + u = u << 8 | addr[i]; + + return u; +} + +/** + * u64_to_ether_addr - Convert a u64 to an Ethernet address. + * @u: u64 to convert to an Ethernet MAC address + * @addr: Pointer to a six-byte array to contain the Ethernet address + */ +static inline void u64_to_ether_addr(u64 u, u8 *addr) +{ + int i; + + for (i = ETH_ALEN - 1; i >= 0; i--) { + addr[i] = u & 0xff; + u = u >> 8; + } +} + +/** + * eth_addr_dec - Decrement the given MAC address + * + * @addr: Pointer to a six-byte array containing Ethernet address to decrement + */ +static inline void eth_addr_dec(u8 *addr) +{ + u64 u = ether_addr_to_u64(addr); + + u--; + u64_to_ether_addr(u, addr); +} + +/** + * eth_addr_inc() - Increment the given MAC address. + * @addr: Pointer to a six-byte array containing Ethernet address to increment. + */ +static inline void eth_addr_inc(u8 *addr) +{ + u64 u = ether_addr_to_u64(addr); + + u++; + u64_to_ether_addr(u, addr); +} + +/** + * eth_addr_add() - Add (or subtract) an offset to/from the given MAC address. + * + * @offset: Offset to add. + * @addr: Pointer to a six-byte array containing Ethernet address to increment. + */ +static inline void eth_addr_add(u8 *addr, long offset) +{ + u64 u = ether_addr_to_u64(addr); + + u += offset; + u64_to_ether_addr(u, addr); +} + typedef void rx_handler_f(void *ctx, char *packet, unsigned int len); struct eth_device *eth_get_byname(const char *name); @@ -455,9 +546,17 @@ struct net_connection { static inline char *net_alloc_packet(void) { - return xmemalign(32, PKTSIZE); + return dma_alloc(PKTSIZE); +} + +static inline void net_free_packet(char *pkt) +{ + return dma_free(pkt); } +int net_alloc_packets(void **packets, int count); +void net_free_packets(void **packets, unsigned count); + struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport, rx_handler_f *handler, void *ctx); @@ -488,6 +587,9 @@ int net_icmp_send(struct net_connection *con, int len); void led_trigger_network(enum led_trigger trigger); #define IFUP_FLAG_FORCE (1 << 0) +#define IFUP_FLAG_PARALLEL (1 << 1) +#define IFUP_FLAG_SKIP_CONF (1 << 2) +#define IFUP_FLAG_UNTIL_NET_SERVER (1 << 3) int ifup_edev(struct eth_device *edev, unsigned flags); int ifup(const char *name, unsigned flags); |