Merge tag 'tpm-030822' of https://source.denx.de/u-boot/custodians/u-boot-tpm
[platform/kernel/u-boot.git] / include / net.h
index a54d5ee..e3889a0 100644 (file)
 #ifndef __NET_H__
 #define __NET_H__
 
+#include <linux/types.h>
 #include <asm/cache.h>
 #include <asm/byteorder.h>     /* for nton* / ntoh* stuff */
 #include <env.h>
+#include <log.h>
+#include <time.h>
 #include <linux/if_ether.h>
+#include <rand.h>
+
+struct bd_info;
+struct cmd_tbl;
+struct udevice;
 
 #define DEBUG_LL_STATE 0       /* Link local state machine changes */
 #define DEBUG_DEV_PKT 0                /* Packets or info directed to the device */
  *     alignment in memory.
  *
  */
-
-#ifdef CONFIG_SYS_RX_ETH_BUFFER
-# define PKTBUFSRX     CONFIG_SYS_RX_ETH_BUFFER
-#else
-# define PKTBUFSRX     4
-#endif
-
+#define PKTBUFSRX      CONFIG_SYS_RX_ETH_BUFFER
 #define PKTALIGN       ARCH_DMA_MINALIGN
 
+/* Number of packets processed together */
+#define ETH_PACKETS_BATCH_RECV 32
+
 /* ARP hardware address length */
 #define ARP_HLEN 6
 /*
@@ -50,6 +55,17 @@ struct in_addr {
 };
 
 /**
+ * do_tftpb - Run the tftpboot command
+ *
+ * @cmdtp: Command information for tftpboot
+ * @flag: Command flags (CMD_FLAG_...)
+ * @argc: Number of arguments
+ * @argv: List of arguments
+ * Return: result (see enum command_ret_t)
+ */
+int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+
+/**
  * An incoming packet handler.
  * @param pkt    pointer to the application packet
  * @param dport  destination UDP port
@@ -93,7 +109,7 @@ enum eth_state_t {
  * @enetaddr: The Ethernet MAC address that is loaded from EEPROM or env
  * @phy_interface: PHY interface to use - see PHY_INTERFACE_MODE_...
  * @max_speed: Maximum speed of Ethernet connection supported by MAC
- * @priv_pdata: device specific platdata
+ * @priv_pdata: device specific plat
  */
 struct eth_pdata {
        phys_addr_t iobase;
@@ -136,6 +152,7 @@ enum eth_recv_flags {
  *                 ROM on the board. This is how the driver should expose it
  *                 to the network stack. This function should fill in the
  *                 eth_pdata::enetaddr field - optional
+ * set_promisc: Enable or Disable promiscuous mode
  */
 struct eth_ops {
        int (*start)(struct udevice *dev);
@@ -146,6 +163,7 @@ struct eth_ops {
        int (*mcast)(struct udevice *dev, const u8 *enetaddr, int join);
        int (*write_hwaddr)(struct udevice *dev);
        int (*read_rom_hwaddr)(struct udevice *dev);
+       int (*set_promisc)(struct udevice *dev, bool enable);
 };
 
 #define eth_get_ops(dev) ((struct eth_ops *)(dev)->driver->ops)
@@ -172,12 +190,12 @@ struct eth_device {
        phys_addr_t iobase;
        int state;
 
-       int (*init)(struct eth_device *, bd_t *);
+       int (*init)(struct eth_device *eth, struct bd_info *bd);
        int (*send)(struct eth_device *, void *packet, int length);
        int (*recv)(struct eth_device *);
        void (*halt)(struct eth_device *);
        int (*mcast)(struct eth_device *, const u8 *enetaddr, int join);
-       int (*write_hwaddr)(struct eth_device *);
+       int (*write_hwaddr)(struct eth_device *eth);
        struct eth_device *next;
        int index;
        void *priv;
@@ -230,7 +248,7 @@ static __always_inline void eth_halt_state_only(void)
 int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
                     int eth_number);
 
-int usb_eth_initialize(bd_t *bi);
+int usb_eth_initialize(struct bd_info *bi);
 #endif
 
 int eth_initialize(void);              /* Initialize network subsystem */
@@ -250,7 +268,7 @@ int eth_get_dev_index(void);                /* get the device index */
  * @base_name:  Base name for variable, typically "eth"
  * @index:      Index of interface being updated (>=0)
  * @enetaddr:   Pointer to MAC address to put into the variable
- * @return 0 if OK, other value on error
+ * Return: 0 if OK, other value on error
  */
 int eth_env_set_enetaddr_by_index(const char *base_name, int index,
                                 uchar *enetaddr);
@@ -344,6 +362,7 @@ struct vlan_ethernet_hdr {
 #define PROT_VLAN      0x8100          /* IEEE 802.1q protocol         */
 #define PROT_IPV6      0x86dd          /* IPv6 over bluebook           */
 #define PROT_PPP_SES   0x8864          /* PPPoE session messages       */
+#define PROT_NCSI      0x88f8          /* NC-SI control packets        */
 
 #define IPPROTO_ICMP    1      /* Internet Control Message Protocol    */
 #define IPPROTO_UDP    17      /* User Datagram Protocol               */
@@ -372,6 +391,8 @@ struct ip_hdr {
 
 #define IP_HDR_SIZE            (sizeof(struct ip_hdr))
 
+#define IP_MIN_FRAG_DATAGRAM_SIZE      (IP_HDR_SIZE + 8)
+
 /*
  *     Internet Protocol (IP) + UDP header.
  */
@@ -476,7 +497,13 @@ struct icmp_hdr {
  * maximum packet size and multiple of 32 bytes =  1536
  */
 #define PKTSIZE                        1522
+#ifndef CONFIG_DM_DSA
 #define PKTSIZE_ALIGN          1536
+#else
+/* Maximum DSA tagging overhead (headroom and/or tailroom) */
+#define DSA_MAX_OVR            256
+#define PKTSIZE_ALIGN          (1536 + DSA_MAX_OVR)
+#endif
 
 /*
  * Maximum receive ring size; that is, the number of packets
@@ -531,7 +558,7 @@ extern int          net_restart_wrap;       /* Tried all network devices */
 
 enum proto_t {
        BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
-       TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL
+       TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP
 };
 
 extern char    net_boot_file_name[1024];/* Boot File name */
@@ -573,7 +600,7 @@ extern int net_ntp_time_offset;                     /* offset time from UTC */
 #endif
 
 /* Initialize the network adapter */
-void net_init(void);
+int net_init(void);
 int net_loop(enum proto_t);
 
 /* Load failed.         Start again. */
@@ -597,7 +624,7 @@ void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport,
  *
  * @addr:      Address to check (must be 16-bit aligned)
  * @nbytes:    Number of bytes to check (normally a multiple of 2)
- * @return 16-bit IP checksum
+ * Return: 16-bit IP checksum
  */
 unsigned compute_ip_checksum(const void *addr, unsigned nbytes);
 
@@ -607,7 +634,7 @@ unsigned compute_ip_checksum(const void *addr, unsigned nbytes);
  * @offset:    Offset of first sum (if odd we do a byte-swap)
  * @sum:       First checksum
  * @new_sum:   New checksum to add
- * @return updated 16-bit IP checksum
+ * Return: updated 16-bit IP checksum
  */
 unsigned add_ip_checksums(unsigned offset, unsigned sum, unsigned new_sum);
 
@@ -618,7 +645,7 @@ unsigned add_ip_checksums(unsigned offset, unsigned sum, unsigned new_sum);
  *
  * @addr:      Address to check (must be 16-bit aligned)
  * @nbytes:    Number of bytes to check (normally a multiple of 2)
- * @return true if the checksum matches, false if not
+ * Return: true if the checksum matches, false if not
  */
 int ip_checksum_ok(const void *addr, unsigned nbytes);
 
@@ -816,7 +843,7 @@ static inline int is_valid_ethaddr(const u8 *addr)
 static inline void net_random_ethaddr(uchar *addr)
 {
        int i;
-       unsigned int seed = get_timer(0);
+       unsigned int seed = get_ticks();
 
        for (i = 0; i < 6; i++)
                addr[i] = rand_r(&seed);
@@ -825,10 +852,30 @@ static inline void net_random_ethaddr(uchar *addr)
        addr[0] |= 0x02;        /* set local assignment bit (IEEE802) */
 }
 
+/**
+ * string_to_enetaddr() - Parse a MAC address
+ *
+ * Convert a string MAC address
+ *
+ * Implemented in lib/net_utils.c (built unconditionally)
+ *
+ * @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit
+ *     hex value
+ * @enetaddr: Place to put MAC address (6 bytes)
+ */
+void string_to_enetaddr(const char *addr, uint8_t *enetaddr);
+
 /* Convert an IP address to a string */
 void ip_to_string(struct in_addr x, char *s);
 
-/* Convert a string to ip address */
+/**
+ * string_to_ip() - Convert a string to ip address
+ *
+ * Implemented in lib/net_utils.c (built unconditionally)
+ *
+ * @s: Input string to parse
+ * @return: in_addr struct containing the parsed IP address
+ */
 struct in_addr string_to_ip(const char *s);
 
 /* Convert a VLAN id to a string */
@@ -857,9 +904,6 @@ int is_serverip_in_cmd(void);
  */
 int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len);
 
-/* get a random source port */
-unsigned int random_port(void);
-
 /**
  * update_tftp - Update firmware over TFTP (via DFU)
  *
@@ -869,21 +913,28 @@ unsigned int random_port(void);
  * @param interface - the DFU medium name - e.g. "mmc"
  * @param devstring - the DFU medium number - e.g. "1"
  *
- * @return - 0 on success, other value on failure
+ * Return: - 0 on success, other value on failure
  */
 int update_tftp(ulong addr, char *interface, char *devstring);
 
-/**********************************************************************/
-
 /**
- * eth_parse_enetaddr() - Parse a MAC address
+ * env_get_ip() - Convert an environment value to to an ip address
  *
- * Convert a string MAC address
+ * @var: Environment variable to convert. The value of this variable must be
+ *     in the format format a.b.c.d, where each value is a decimal number from
+ *     0 to 255
+ * Return: IP address, or 0 if invalid
+ */
+static inline struct in_addr env_get_ip(char *var)
+{
+       return string_to_ip(env_get(var));
+}
+
+/**
+ * reset_phy() - Reset the Ethernet PHY
  *
- * @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit
- *     hex value
- * @enetaddr: Place to put MAC address (6 bytes)
+ * This should be implemented by boards if CONFIG_RESET_PHY_R is enabled
  */
-void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr);
+void reset_phy(void);
 
 #endif /* __NET_H__ */