1From cc35c455bb52f78546d7b7216b30203863c017fb Mon Sep 17 00:00:00 2001 2From: jiangheng <jiangheng14@huawei.com> 3Date: Tue, 24 Oct 2023 17:32:17 +0800 4Subject: [PATCH] gazelle offloads are registered to lwip 5 6--- 7 src/core/ipv4/icmp.c | 2 +- 8 src/core/ipv4/ip4.c | 6 +++--- 9 src/core/ipv4/ip4_frag.c | 4 ++-- 10 src/core/netif.c | 20 ++++++++++++++++++++ 11 src/core/tcp_in.c | 2 +- 12 src/core/tcp_out.c | 6 +++--- 13 src/core/udp.c | 4 ++-- 14 src/include/dpdk_cksum.h | 2 -- 15 src/include/lwip/netif.h | 20 ++++++++++++++++++++ 16 9 files changed, 52 insertions(+), 14 deletions(-) 17 18diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c 19index 402ba69..c3a877c 100644 20--- a/src/core/ipv4/icmp.c 21+++ b/src/core/ipv4/icmp.c 22@@ -241,7 +241,7 @@ icmp_input(struct pbuf *p, struct netif *inp) 23 #if CHECKSUM_GEN_IP 24 IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_IP) { 25 #if CHECKSUM_GEN_IP_HW 26- if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { 27+ if (netif_get_txol_flags(inp) & DEV_TX_OFFLOAD_IPV4_CKSUM) { 28 iph_cksum_set(p, hlen, 1); 29 } else { 30 iph_cksum_set(p, hlen, 0); 31diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c 32index 1b70bb5..1e3690f 100644 33--- a/src/core/ipv4/ip4.c 34+++ b/src/core/ipv4/ip4.c 35@@ -509,7 +509,7 @@ ip4_input(struct pbuf *p, struct netif *inp) 36 IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_IP) { 37 #if CHECKSUM_CHECK_IP_HW 38 u64_t ret; 39- if (get_eth_params_rx_ol() & DEV_RX_OFFLOAD_IPV4_CKSUM) { 40+ if (netif_get_rxol_flags(inp) & DEV_RX_OFFLOAD_IPV4_CKSUM) { 41 ret = is_cksum_ipbad(p); 42 } else { 43 ret = (u64_t)inet_chksum(iphdr, iphdr_hlen); 44@@ -986,7 +986,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d 45 #if CHECKSUM_GEN_IP 46 IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { 47 #if CHECKSUM_GEN_IP_HW 48- if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { 49+ if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_IPV4_CKSUM) { 50 iph_cksum_set(p, ip_hlen, 1); 51 } else { 52 iph_cksum_set(p, ip_hlen, 0); 53@@ -1035,7 +1035,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d 54 #if IP_FRAG 55 /* don't fragment if interface has mtu set to 0 [loopif] */ 56 #if GAZELLE_ENABLE 57- if (!(get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_TSO)) { 58+ if (!(netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_TCP_TSO)) { 59 #endif 60 if (netif->mtu && (p->tot_len > netif->mtu)) { 61 return ip4_frag(p, netif, dest); 62diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c 63index e01ea51..f63a99e 100644 64--- a/src/core/ipv4/ip4_frag.c 65+++ b/src/core/ipv4/ip4_frag.c 66@@ -642,7 +642,7 @@ ip4_reass(struct pbuf *p) 67 #if CHECKSUM_GEN_IP 68 IF__NETIF_CHECKSUM_ENABLED(ip_current_input_netif(), NETIF_CHECKSUM_GEN_IP) { 69 #if CHECKSUM_GEN_IP_HW 70- if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { 71+ if (netif_get_txol_flags(ip_current_input_netif()) & DEV_TX_OFFLOAD_IPV4_CKSUM) { 72 iph_cksum_set(p, IP_HLEN, 1); 73 } else { 74 iph_cksum_set(p, IP_HLEN, 0); 75@@ -885,7 +885,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) 76 #if CHECKSUM_GEN_IP 77 IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { 78 #if CHECKSUM_GEN_IP_HW 79- if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { 80+ if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_IPV4_CKSUM) { 81 iph_cksum_set(p, IP_HLEN, 1); 82 } else { 83 iph_cksum_set(p, IP_HLEN, 0); 84diff --git a/src/core/netif.c b/src/core/netif.c 85index 86b74a0..eb59fbc 100644 86--- a/src/core/netif.c 87+++ b/src/core/netif.c 88@@ -1049,6 +1049,26 @@ netif_set_link_down(struct netif *netif) 89 } 90 } 91 92+#if GAZELLE_ENABLE 93+void 94+netif_set_rtc_mode(struct netif *netif) 95+{ 96+ if (!(netif->flags & NETIF_FLAG_RTC_MODE)) { 97+ netif_set_flags(netif, NETIF_FLAG_RTC_MODE); 98+ } 99+} 100+void 101+netif_set_rxol_flags(struct netif *netif, u64_t flags) 102+{ 103+ netif->rxol_flags |= flags; 104+} 105+void 106+netif_set_txol_flags(struct netif *netif, u64_t flags) 107+{ 108+ netif->txol_flags |= flags; 109+} 110+#endif 111+ 112 #if LWIP_NETIF_LINK_CALLBACK 113 /** 114 * @ingroup netif 115diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c 116index 736845c..07203e5 100644 117--- a/src/core/tcp_in.c 118+++ b/src/core/tcp_in.c 119@@ -209,7 +209,7 @@ tcp_input(struct pbuf *p, struct netif *inp) 120 /* Verify TCP checksum. */ 121 #if CHECKSUM_CHECK_TCP_HW 122 u64_t ret; 123- if (get_eth_params_rx_ol() & DEV_RX_OFFLOAD_TCP_CKSUM) { 124+ if (netif_get_rxol_flags(inp) & DEV_RX_OFFLOAD_TCP_CKSUM) { 125 ret = is_cksum_bad(p); 126 } else { 127 ret = (u64_t)ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, 128diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c 129index 547d01e..e2c9d63 100644 130--- a/src/core/tcp_out.c 131+++ b/src/core/tcp_out.c 132@@ -1448,7 +1448,7 @@ tcp_output(struct tcp_pcb *pcb) 133 134 /* data available and window allows it to be sent? */ 135 #if GAZELLE_ENABLE 136- if ((get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_TSO) && pcb->need_tso_send) { 137+ if ((netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_TCP_TSO) && pcb->need_tso_send) { 138 uint16_t send_pkt = 0; 139 140 do { 141@@ -1831,7 +1831,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif 142 #if CHECKSUM_GEN_TCP 143 IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { 144 #if CHECKSUM_GEN_TCP_HW 145- if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_CKSUM) { 146+ if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_TCP_CKSUM) { 147 tcph_cksum_set(seg->p, TCPH_HDRLEN_BYTES(seg->tcphdr)); 148 seg->tcphdr->chksum = ip_chksum_pseudo_offload(IP_PROTO_TCP,seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); 149 } else { 150@@ -2273,7 +2273,7 @@ tcp_output_control_segment(struct tcp_pcb *pcb, struct pbuf *p, 151 IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { 152 struct tcp_hdr *tcphdr = (struct tcp_hdr *)p->payload; 153 #if CHECKSUM_GEN_TCP_HW 154- if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_CKSUM) { 155+ if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_TCP_CKSUM) { 156 tcph_cksum_set(p, TCPH_HDRLEN_BYTES(tcphdr)); 157 tcphdr->chksum = ip_chksum_pseudo_offload(IP_PROTO_TCP, p->tot_len, src, dst); 158 } else { 159diff --git a/src/core/udp.c b/src/core/udp.c 160index 5c6dadb..937a045 100644 161--- a/src/core/udp.c 162+++ b/src/core/udp.c 163@@ -414,7 +414,7 @@ udp_input(struct pbuf *p, struct netif *inp) 164 if (udphdr->chksum != 0) { 165 #if CHECKSUM_CHECK_UDP_HW 166 u64_t ret = 0; 167- if (get_eth_params_rx_ol() & DEV_RX_OFFLOAD_UDP_CKSUM) { 168+ if (netif_get_txol_flags(inp) & DEV_RX_OFFLOAD_UDP_CKSUM) { 169 ret = is_cksum_bad(p); 170 } else { 171 ret = ip_chksum_pseudo(p, IP_PROTO_UDP, p->tot_len, 172@@ -983,7 +983,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d 173 #endif /* LWIP_CHECKSUM_ON_COPY */ 174 { 175 #if CHECKSUM_GEN_UDP_HW 176- if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_UDP_CKSUM) { 177+ if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_UDP_CKSUM) { 178 udph_cksum_set(q, UDP_HLEN); 179 udpchksum = ip_chksum_pseudo_offload(IP_PROTO_UDP, q->tot_len, &pcb->local_ip, &pcb->remote_ip); 180 } else { 181diff --git a/src/include/dpdk_cksum.h b/src/include/dpdk_cksum.h 182index 5b1b6f6..b8056f9 100644 183--- a/src/include/dpdk_cksum.h 184+++ b/src/include/dpdk_cksum.h 185@@ -45,8 +45,6 @@ 186 #include "lwip/pbuf.h" 187 #endif 188 189-extern uint64_t get_eth_params_rx_ol(void); 190-extern uint64_t get_eth_params_tx_ol(void); 191 #if CHECKSUM_CHECK_IP_HW 192 // for ip4_input 193 static inline u64_t is_cksum_ipbad(struct pbuf *p) { 194diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h 195index 057c51f..75f8d50 100644 196--- a/src/include/lwip/netif.h 197+++ b/src/include/lwip/netif.h 198@@ -106,6 +106,11 @@ extern "C" { 199 * Set by the netif driver in its init function. */ 200 #define NETIF_FLAG_MLD6 0x40U 201 202+#if GAZELLE_ENABLE 203+/** If set, use run to completion mode */ 204+#define NETIF_FLAG_RTC_MODE 0x80U 205+#endif 206+ 207 /** 208 * @} 209 */ 210@@ -343,6 +348,10 @@ struct netif { 211 u8_t hwaddr_len; 212 /** flags (@see @ref netif_flags) */ 213 u8_t flags; 214+#if GAZELLE_ENABLE 215+ u64_t rxol_flags; 216+ u64_t txol_flags; 217+#endif 218 /** descriptive abbreviation */ 219 char name[2]; 220 /** number of this interface. Used for @ref if_api and @ref netifapi_netif, 221@@ -464,6 +473,17 @@ void netif_set_down(struct netif *netif); 222 */ 223 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) 224 225+#if GAZELLE_ENABLE 226+#define netif_is_rtc_mode(netif) (((netif)->flags & NETIF_FLAG_RTC_MODE) ? (u8_t)1 : (u8_t)0) 227+#define netif_get_rxol_flags(netif) ((netif)->rxol_flags) 228+#define netif_get_txol_flags(netif) ((netif)->txol_flags) 229+ 230+void netif_set_rtc_mode(struct netif *netif); 231+void netif_set_rxol_flags(struct netif *netif, u64_t flags); 232+void netif_set_txol_flags(struct netif *netif, u64_t flags); 233+ 234+#endif 235+ 236 #if LWIP_NETIF_STATUS_CALLBACK 237 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); 238 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 239-- 2402.27.0 241 242