global: Migrate CONFIG_STACKBASE to CFG
[platform/kernel/u-boot.git] / include / net.h
index 778acf7..ee08f33 100644 (file)
@@ -35,15 +35,12 @@ struct udevice;
  *     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
 /*
@@ -64,7 +61,7 @@ struct in_addr {
  * @flag: Command flags (CMD_FLAG_...)
  * @argc: Number of arguments
  * @argv: List of arguments
- * @return result (see enum command_ret_t)
+ * Return: result (see enum command_ret_t)
  */
 int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 
@@ -104,7 +101,6 @@ enum eth_state_t {
        ETH_STATE_ACTIVE
 };
 
-#ifdef CONFIG_DM_ETH
 /**
  * struct eth_pdata - Platform data for Ethernet MAC controllers
  *
@@ -112,7 +108,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;
@@ -155,6 +151,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);
@@ -165,6 +162,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)
@@ -181,76 +179,6 @@ unsigned char *eth_get_ethaddr(void); /* get the current device MAC */
 int eth_is_active(struct udevice *dev); /* Test device for active state */
 int eth_init_state_only(void); /* Set active state */
 void eth_halt_state_only(void); /* Set passive state */
-#endif
-
-#ifndef CONFIG_DM_ETH
-struct eth_device {
-#define ETH_NAME_LEN 20
-       char name[ETH_NAME_LEN];
-       unsigned char enetaddr[ARP_HLEN];
-       phys_addr_t iobase;
-       int state;
-
-       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 *eth);
-       struct eth_device *next;
-       int index;
-       void *priv;
-};
-
-int eth_register(struct eth_device *dev);/* Register network device */
-int eth_unregister(struct eth_device *dev);/* Remove network device */
-
-extern struct eth_device *eth_current;
-
-static __always_inline struct eth_device *eth_get_dev(void)
-{
-       return eth_current;
-}
-struct eth_device *eth_get_dev_by_name(const char *devname);
-struct eth_device *eth_get_dev_by_index(int index); /* get dev @ index */
-
-/* get the current device MAC */
-static inline unsigned char *eth_get_ethaddr(void)
-{
-       if (eth_current)
-               return eth_current->enetaddr;
-       return NULL;
-}
-
-/* Used only when NetConsole is enabled */
-int eth_is_active(struct eth_device *dev); /* Test device for active state */
-/* Set active state */
-static __always_inline int eth_init_state_only(void)
-{
-       eth_get_dev()->state = ETH_STATE_ACTIVE;
-
-       return 0;
-}
-/* Set passive state */
-static __always_inline void eth_halt_state_only(void)
-{
-       eth_get_dev()->state = ETH_STATE_PASSIVE;
-}
-
-/*
- * Set the hardware address for an ethernet interface based on 'eth%daddr'
- * environment variable (or just 'ethaddr' if eth_number is 0).
- * Args:
- *     base_name - base name for device (normally "eth")
- *     eth_number - value of %d (0 for first device of this type)
- * Returns:
- *     0 is success, non-zero is error status from driver.
- */
-int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
-                    int eth_number);
-
-int usb_eth_initialize(struct bd_info *bi);
-#endif
 
 int eth_initialize(void);              /* Initialize network subsystem */
 void eth_try_another(int first_restart);       /* Change the device */
@@ -269,7 +197,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);
@@ -366,6 +294,7 @@ struct vlan_ethernet_hdr {
 #define PROT_NCSI      0x88f8          /* NC-SI control packets        */
 
 #define IPPROTO_ICMP    1      /* Internet Control Message Protocol    */
+#define IPPROTO_TCP    6       /* Transmission Control Protocol        */
 #define IPPROTO_UDP    17      /* User Datagram Protocol               */
 
 /*
@@ -392,6 +321,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.
  */
@@ -496,7 +427,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
@@ -529,7 +466,9 @@ extern struct in_addr net_dns_server2;
 #endif
 extern char    net_nis_domain[32];     /* Our IS domain */
 extern char    net_hostname[32];       /* Our hostname */
-extern char    net_root_path[64];      /* Our root path */
+#ifdef CONFIG_NET
+extern char    net_root_path[CONFIG_BOOTP_MAX_ROOT_PATH_LEN];  /* Our root path */
+#endif
 /** END OF BOOTP EXTENTIONS **/
 extern u8              net_ethaddr[ARP_HLEN];          /* Our ethernet address */
 extern u8              net_server_ethaddr[ARP_HLEN];   /* Boot server enet address */
@@ -550,8 +489,8 @@ extern ushort               net_native_vlan;        /* Our Native VLAN */
 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, UDP
+       BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP, NETCONS,
+       SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI, WGET
 };
 
 extern char    net_boot_file_name[1024];/* Boot File name */
@@ -617,7 +556,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);
 
@@ -627,7 +566,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);
 
@@ -638,7 +577,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);
 
@@ -681,19 +620,36 @@ static inline void net_send_packet(uchar *pkt, int len)
        (void) eth_send(pkt, len);
 }
 
-/*
- * Transmit "net_tx_packet" as UDP packet, performing ARP request if needed
- *  (ether will be populated)
- *
- * @param ether Raw packet buffer
- * @param dest IP address to send the datagram to
- * @param dport Destination UDP port
- * @param sport Source UDP port
- * @param payload_len Length of data after the UDP header
+/**
+ * net_send_ip_packet() - Transmit "net_tx_packet" as UDP or TCP packet,
+ *                        send ARP request if needed (ether will be populated)
+ * @ether: Raw packet buffer
+ * @dest: IP address to send the datagram to
+ * @dport: Destination UDP port
+ * @sport: Source UDP port
+ * @payload_len: Length of data after the UDP header
+ * @action: TCP action to be performed
+ * @tcp_seq_num: TCP sequence number of this transmission
+ * @tcp_ack_num: TCP stream acknolegement number
+ *
+ * Return: 0 on success, other value on failure
  */
 int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport,
                       int payload_len, int proto, u8 action, u32 tcp_seq_num,
                       u32 tcp_ack_num);
+/**
+ * net_send_tcp_packet() - Transmit TCP packet.
+ * @payload_len: length of payload
+ * @dport: Destination TCP port
+ * @sport: Source TCP port
+ * @action: TCP action to be performed
+ * @tcp_seq_num: TCP sequence number of this transmission
+ * @tcp_ack_num: TCP stream acknolegement number
+ *
+ * Return: 0 on success, other value on failure
+ */
+int net_send_tcp_packet(int payload_len, int dport, int sport, u8 action,
+                       u32 tcp_seq_num, u32 tcp_ack_num);
 int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport,
                        int sport, int payload_len);
 
@@ -906,7 +862,7 @@ int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len);
  * @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);
 
@@ -916,7 +872,7 @@ int update_tftp(ulong addr, char *interface, char *devstring);
  * @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
+ * Return: IP address, or 0 if invalid
  */
 static inline struct in_addr env_get_ip(char *var)
 {