summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2022-11-28 13:12:40 -0500
committerTom Rini <[email protected]>2022-11-28 13:12:40 -0500
commit39b81955d38c11254b455322b9d98e07010049d6 (patch)
treeef486924750d138effb1ecd24081cb6bf28820d4 /include
parent597e7b784dbfec29fd8d6c450bc9a3a607c4feae (diff)
parent5e6c069b2c6b37083da685f39fa56ab5137dbdf9 (diff)
Merge branch '2022-11-28-networking-updates-and-improvements'
- LiteX Ethernet support, dwc_eth_qos fixes, re-work fixing CVE-2022-{30790,30552}, macb race fix, Intel XWAY PHY support and add wget command and TCP support.
Diffstat (limited to 'include')
-rw-r--r--include/linux/litex.h84
-rw-r--r--include/net.h38
-rw-r--r--include/net/tcp.h299
-rw-r--r--include/net/wget.h22
-rw-r--r--include/phy.h1
5 files changed, 434 insertions, 10 deletions
diff --git a/include/linux/litex.h b/include/linux/litex.h
new file mode 100644
index 00000000000..5e91db41fdc
--- /dev/null
+++ b/include/linux/litex.h
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Common LiteX header providing
+ * helper functions for accessing CSRs.
+ *
+ * Copyright (C) 2019-2020 Antmicro <www.antmicro.com>
+ */
+
+#ifndef _LINUX_LITEX_H
+#define _LINUX_LITEX_H
+
+#include <linux/io.h>
+#include <asm/byteorder.h>
+
+static inline void _write_litex_subregister(u32 val, void __iomem *addr)
+{
+ writel((u32 __force)cpu_to_le32(val), addr);
+}
+
+static inline u32 _read_litex_subregister(void __iomem *addr)
+{
+ return le32_to_cpu((__le32 __force)readl(addr));
+}
+
+/*
+ * LiteX SoC Generator, depending on the configuration, can split a single
+ * logical CSR (Control&Status Register) into a series of consecutive physical
+ * registers.
+ *
+ * For example, in the configuration with 8-bit CSR Bus, a 32-bit aligned,
+ * 32-bit wide logical CSR will be laid out as four 32-bit physical
+ * subregisters, each one containing one byte of meaningful data.
+ *
+ * For Linux support, upstream LiteX enforces a 32-bit wide CSR bus, which
+ * means that only larger-than-32-bit CSRs will be split across multiple
+ * subregisters (e.g., a 64-bit CSR will be spread across two consecutive
+ * 32-bit subregisters).
+ *
+ * For details see: https://github.com/enjoy-digital/litex/wiki/CSR-Bus
+ */
+
+static inline void litex_write8(void __iomem *reg, u8 val)
+{
+ _write_litex_subregister(val, reg);
+}
+
+static inline void litex_write16(void __iomem *reg, u16 val)
+{
+ _write_litex_subregister(val, reg);
+}
+
+static inline void litex_write32(void __iomem *reg, u32 val)
+{
+ _write_litex_subregister(val, reg);
+}
+
+static inline void litex_write64(void __iomem *reg, u64 val)
+{
+ _write_litex_subregister(val >> 32, reg);
+ _write_litex_subregister(val, reg + 4);
+}
+
+static inline u8 litex_read8(void __iomem *reg)
+{
+ return _read_litex_subregister(reg);
+}
+
+static inline u16 litex_read16(void __iomem *reg)
+{
+ return _read_litex_subregister(reg);
+}
+
+static inline u32 litex_read32(void __iomem *reg)
+{
+ return _read_litex_subregister(reg);
+}
+
+static inline u64 litex_read64(void __iomem *reg)
+{
+ return ((u64)_read_litex_subregister(reg) << 32) |
+ _read_litex_subregister(reg + 4);
+}
+
+#endif /* _LINUX_LITEX_H */
diff --git a/include/net.h b/include/net.h
index 32364ed0ced..e0c78048274 100644
--- a/include/net.h
+++ b/include/net.h
@@ -365,6 +365,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 */
/*
@@ -560,7 +561,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, UDP, NCSI
+ TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI, WGET
};
extern char net_boot_file_name[1024];/* Boot File name */
@@ -690,19 +691,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);
diff --git a/include/net/tcp.h b/include/net/tcp.h
new file mode 100644
index 00000000000..322551694f5
--- /dev/null
+++ b/include/net/tcp.h
@@ -0,0 +1,299 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * TCP Support with SACK for file transfer.
+ *
+ * Copyright 2017 Duncan Hare, All rights reserved.
+ */
+
+#define TCP_ACTIVITY 127 /* Number of packets received */
+ /* before console progress mark */
+/**
+ * struct ip_tcp_hdr - IP and TCP header
+ * @ip_hl_v: header length and version
+ * @ip_tos: type of service
+ * @ip_len: total length
+ * @ip_id: identification
+ * @ip_off: fragment offset field
+ * @ip_ttl: time to live
+ * @ip_p: protocol
+ * @ip_sum: checksum
+ * @ip_src: Source IP address
+ * @ip_dst: Destination IP address
+ * @tcp_src: TCP source port
+ * @tcp_dst: TCP destination port
+ * @tcp_seq: TCP sequence number
+ * @tcp_ack: TCP Acknowledgment number
+ * @tcp_hlen: 4 bits TCP header Length/4, 4 bits reserved, 2 more bits reserved
+ * @tcp_flag: flags of TCP
+ * @tcp_win: TCP windows size
+ * @tcp_xsum: Checksum
+ * @tcp_ugr: Pointer to urgent data
+ */
+struct ip_tcp_hdr {
+ u8 ip_hl_v;
+ u8 ip_tos;
+ u16 ip_len;
+ u16 ip_id;
+ u16 ip_off;
+ u8 ip_ttl;
+ u8 ip_p;
+ u16 ip_sum;
+ struct in_addr ip_src;
+ struct in_addr ip_dst;
+ u16 tcp_src;
+ u16 tcp_dst;
+ u32 tcp_seq;
+ u32 tcp_ack;
+ u8 tcp_hlen;
+ u8 tcp_flags;
+ u16 tcp_win;
+ u16 tcp_xsum;
+ u16 tcp_ugr;
+} __packed;
+
+#define IP_TCP_HDR_SIZE (sizeof(struct ip_tcp_hdr))
+#define TCP_HDR_SIZE (IP_TCP_HDR_SIZE - IP_HDR_SIZE)
+
+#define TCP_DATA 0x00 /* Data Packet - internal use only */
+#define TCP_FIN 0x01 /* Finish flag */
+#define TCP_SYN 0x02 /* Synch (start) flag */
+#define TCP_RST 0x04 /* reset flag */
+#define TCP_PUSH 0x08 /* Push - Notify app */
+#define TCP_ACK 0x10 /* Acknowledgment of data received */
+#define TCP_URG 0x20 /* Urgent */
+#define TCP_ECE 0x40 /* Congestion control */
+#define TCP_CWR 0x80 /* Congestion Control */
+
+/*
+ * TCP header options, Seq, MSS, and SACK
+ */
+
+#define TCP_SACK 32 /* Number of packets analyzed */
+ /* on leading edge of stream */
+
+#define TCP_O_END 0x00 /* End of option list */
+#define TCP_1_NOP 0x01 /* Single padding NOP */
+#define TCP_O_NOP 0x01010101 /* NOPs pad to 32 bit boundary */
+#define TCP_O_MSS 0x02 /* MSS Size option */
+#define TCP_O_SCL 0x03 /* Window Scale option */
+#define TCP_P_SACK 0x04 /* SACK permitted */
+#define TCP_V_SACK 0x05 /* SACK values */
+#define TCP_O_TS 0x08 /* Timestamp option */
+#define TCP_OPT_LEN_2 0x02
+#define TCP_OPT_LEN_3 0x03
+#define TCP_OPT_LEN_4 0x04
+#define TCP_OPT_LEN_6 0x06
+#define TCP_OPT_LEN_8 0x08
+#define TCP_OPT_LEN_A 0x0a /* Timestamp Length */
+#define TCP_MSS 1460 /* Max segment size */
+#define TCP_SCALE 0x01 /* Scale */
+
+/**
+ * struct tcp_mss - TCP option structure for MSS (Max segment size)
+ * @kind: Field ID
+ * @len: Field length
+ * @mss: Segment size value
+ */
+struct tcp_mss {
+ u8 kind;
+ u8 len;
+ u16 mss;
+} __packed;
+
+/**
+ * struct tcp_scale - TCP option structure for Windows scale
+ * @kind: Field ID
+ * @len: Field length
+ * @scale: windows shift value used for networks with many hops.
+ * Typically 4 or more hops
+ */
+struct tcp_scale {
+ u8 kind;
+ u8 len;
+ u8 scale;
+} __packed;
+
+/**
+ * struct tcp_sack_p - TCP option structure for SACK permitted
+ * @kind: Field ID
+ * @len: Field length
+ */
+struct tcp_sack_p {
+ u8 kind;
+ u8 len;
+} __packed;
+
+/**
+ * struct sack_edges - structure for SACK edges
+ * @l: Left edge of stream
+ * @r: right edge of stream
+ */
+struct sack_edges {
+ u32 l;
+ u32 r;
+} __packed;
+
+#define TCP_SACK_SIZE (sizeof(struct sack_edges))
+
+/*
+ * A TCP stream has holes when packets are missing or disordered.
+ * A hill is the inverse of a hole, and is data received.
+ * TCP received hills (a sequence of data), and inferrs Holes
+ * from the "hills" or packets received.
+ */
+
+#define TCP_SACK_HILLS 4
+
+/**
+ * struct tcp_sack_v - TCP option structure for SACK
+ * @kind: Field ID
+ * @len: Field length
+ * @hill: L & R window edges
+ */
+struct tcp_sack_v {
+ u8 kind;
+ u8 len;
+ struct sack_edges hill[TCP_SACK_HILLS];
+} __packed;
+
+/**
+ * struct tcp_t_opt - TCP option structure for time stamps
+ * @kind: Field ID
+ * @len: Field length
+ * @t_snd: Sender timestamp
+ * @t_rcv: Receiver timestamp
+ */
+struct tcp_t_opt {
+ u8 kind;
+ u8 len;
+ u32 t_snd;
+ u32 t_rcv;
+} __packed;
+
+#define TCP_TSOPT_SIZE (sizeof(struct tcp_t_opt))
+
+/*
+ * ip tcp structure with options
+ */
+
+/**
+ * struct ip_tcp_hdr_o - IP + TCP header + TCP options
+ * @hdr: IP + TCP header
+ * @mss: TCP MSS Option
+ * @scale: TCP Windows Scale Option
+ * @sack_p: TCP Sack-Permitted Option
+ * @t_opt: TCP Timestamp Option
+ * @end: end of options
+ */
+struct ip_tcp_hdr_o {
+ struct ip_tcp_hdr hdr;
+ struct tcp_mss mss;
+ struct tcp_scale scale;
+ struct tcp_sack_p sack_p;
+ struct tcp_t_opt t_opt;
+ u8 end;
+} __packed;
+
+#define IP_TCP_O_SIZE (sizeof(struct ip_tcp_hdr_o))
+
+/**
+ * struct ip_tcp_hdr_s - IP + TCP header + TCP options
+ * @hdr: IP + TCP header
+ * @t_opt: TCP Timestamp Option
+ * @sack_v: TCP SACK Option
+ * @end: end of options
+ */
+struct ip_tcp_hdr_s {
+ struct ip_tcp_hdr hdr;
+ struct tcp_t_opt t_opt;
+ struct tcp_sack_v sack_v;
+ u8 end;
+} __packed;
+
+#define IP_TCP_SACK_SIZE (sizeof(struct ip_tcp_hdr_s))
+
+/*
+ * TCP pseudo header definitions
+ */
+#define PSEUDO_PAD_SIZE 8
+
+/**
+ * struct pseudo_hdr - Pseudo Header
+ * @padding: pseudo hdr size = ip_tcp hdr size
+ * @p_src: Source IP address
+ * @p_dst: Destination IP address
+ * @rsvd: reserved
+ * @p: protocol
+ * @len: length of header
+ */
+struct pseudo_hdr {
+ u8 padding[PSEUDO_PAD_SIZE];
+ struct in_addr p_src;
+ struct in_addr p_dst;
+ u8 rsvd;
+ u8 p;
+ u16 len;
+} __packed;
+
+#define PSEUDO_HDR_SIZE (sizeof(struct pseudo_hdr)) - PSEUDO_PAD_SIZE
+
+/**
+ * union tcp_build_pkt - union for building TCP/IP packet.
+ * @ph: pseudo header
+ * @ip: IP and TCP header plus TCP options
+ * @sack: IP and TCP header plus SACK options
+ * @raw: buffer
+ *
+ * Build Pseudo header in packed buffer
+ * first, calculate TCP checksum, then build IP header in packed buffer.
+ *
+ */
+union tcp_build_pkt {
+ struct pseudo_hdr ph;
+ struct ip_tcp_hdr_o ip;
+ struct ip_tcp_hdr_s sack;
+ uchar raw[1600];
+} __packed;
+
+/**
+ * enum tcp_state - TCP State machine states for connection
+ * @TCP_CLOSED: Need to send SYN to connect
+ * @TCP_SYN_SENT: Trying to connect, waiting for SYN ACK
+ * @TCP_ESTABLISHED: both server & client have a connection
+ * @TCP_CLOSE_WAIT: Rec FIN, passed to app for FIN, ACK rsp
+ * @TCP_CLOSING: Rec FIN, sent FIN, ACK waiting for ACK
+ * @TCP_FIN_WAIT_1: Sent FIN waiting for response
+ * @TCP_FIN_WAIT_2: Rec ACK from FIN sent, waiting for FIN
+ */
+enum tcp_state {
+ TCP_CLOSED,
+ TCP_SYN_SENT,
+ TCP_ESTABLISHED,
+ TCP_CLOSE_WAIT,
+ TCP_CLOSING,
+ TCP_FIN_WAIT_1,
+ TCP_FIN_WAIT_2
+};
+
+enum tcp_state tcp_get_tcp_state(void);
+void tcp_set_tcp_state(enum tcp_state new_state);
+int tcp_set_tcp_header(uchar *pkt, int dport, int sport, int payload_len,
+ u8 action, u32 tcp_seq_num, u32 tcp_ack_num);
+
+/**
+ * rxhand_tcp() - An incoming packet handler.
+ * @pkt: pointer to the application packet
+ * @dport: destination UDP port
+ * @sip: source IP address
+ * @sport: source UDP port
+ * @len: packet length
+ */
+typedef void rxhand_tcp(uchar *pkt, unsigned int dport,
+ struct in_addr sip, unsigned int sport,
+ unsigned int len);
+void tcp_set_tcp_handler(rxhand_tcp *f);
+
+void rxhand_tcp_f(union tcp_build_pkt *b, unsigned int len);
+
+u16 tcp_set_pseudo_header(uchar *pkt, struct in_addr src, struct in_addr dest,
+ int tcp_len, int pkt_len);
diff --git a/include/net/wget.h b/include/net/wget.h
new file mode 100644
index 00000000000..da0920de118
--- /dev/null
+++ b/include/net/wget.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Duncan Hare Copyright 2017
+ */
+
+/**
+ * wget_start() - begin wget
+ */
+void wget_start(void);
+
+enum wget_state {
+ WGET_CLOSED,
+ WGET_CONNECTING,
+ WGET_CONNECTED,
+ WGET_TRANSFERRING,
+ WGET_TRANSFERRED
+};
+
+#define DEBUG_WGET 0 /* Set to 1 for debug messages */
+#define SERVER_PORT 80
+#define WGET_RETRY_COUNT 30
+#define WGET_TIMEOUT 2000UL
diff --git a/include/phy.h b/include/phy.h
index 0737c4e8f9a..ff69536fca7 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -380,6 +380,7 @@ int phy_teranetics_init(void);
int phy_ti_init(void);
int phy_vitesse_init(void);
int phy_xilinx_init(void);
+int phy_xway_init(void);
int phy_mscc_init(void);
int phy_fixed_init(void);
int phy_ncsi_init(void);