From cc35c455bb52f78546d7b7216b30203863c017fb Mon Sep 17 00:00:00 2001 From: jiangheng Date: Tue, 24 Oct 2023 17:32:17 +0800 Subject: [PATCH] gazelle offloads are registered to lwip --- src/core/ipv4/icmp.c | 2 +- src/core/ipv4/ip4.c | 6 +++--- src/core/ipv4/ip4_frag.c | 4 ++-- src/core/netif.c | 20 ++++++++++++++++++++ src/core/tcp_in.c | 2 +- src/core/tcp_out.c | 6 +++--- src/core/udp.c | 4 ++-- src/include/dpdk_cksum.h | 2 -- src/include/lwip/netif.h | 20 ++++++++++++++++++++ 9 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c index 402ba69..c3a877c 100644 --- a/src/core/ipv4/icmp.c +++ b/src/core/ipv4/icmp.c @@ -241,7 +241,7 @@ icmp_input(struct pbuf *p, struct netif *inp) #if CHECKSUM_GEN_IP IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_IP) { #if CHECKSUM_GEN_IP_HW - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { + if (netif_get_txol_flags(inp) & DEV_TX_OFFLOAD_IPV4_CKSUM) { iph_cksum_set(p, hlen, 1); } else { iph_cksum_set(p, hlen, 0); diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 1b70bb5..1e3690f 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -509,7 +509,7 @@ ip4_input(struct pbuf *p, struct netif *inp) IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_IP) { #if CHECKSUM_CHECK_IP_HW u64_t ret; - if (get_eth_params_rx_ol() & DEV_RX_OFFLOAD_IPV4_CKSUM) { + if (netif_get_rxol_flags(inp) & DEV_RX_OFFLOAD_IPV4_CKSUM) { ret = is_cksum_ipbad(p); } else { ret = (u64_t)inet_chksum(iphdr, iphdr_hlen); @@ -986,7 +986,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d #if CHECKSUM_GEN_IP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { #if CHECKSUM_GEN_IP_HW - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { + if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_IPV4_CKSUM) { iph_cksum_set(p, ip_hlen, 1); } else { iph_cksum_set(p, ip_hlen, 0); @@ -1035,7 +1035,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d #if IP_FRAG /* don't fragment if interface has mtu set to 0 [loopif] */ #if GAZELLE_ENABLE - if (!(get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_TSO)) { + if (!(netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_TCP_TSO)) { #endif if (netif->mtu && (p->tot_len > netif->mtu)) { return ip4_frag(p, netif, dest); diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index e01ea51..f63a99e 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -642,7 +642,7 @@ ip4_reass(struct pbuf *p) #if CHECKSUM_GEN_IP IF__NETIF_CHECKSUM_ENABLED(ip_current_input_netif(), NETIF_CHECKSUM_GEN_IP) { #if CHECKSUM_GEN_IP_HW - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { + if (netif_get_txol_flags(ip_current_input_netif()) & DEV_TX_OFFLOAD_IPV4_CKSUM) { iph_cksum_set(p, IP_HLEN, 1); } else { iph_cksum_set(p, IP_HLEN, 0); @@ -885,7 +885,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) #if CHECKSUM_GEN_IP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { #if CHECKSUM_GEN_IP_HW - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { + if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_IPV4_CKSUM) { iph_cksum_set(p, IP_HLEN, 1); } else { iph_cksum_set(p, IP_HLEN, 0); diff --git a/src/core/netif.c b/src/core/netif.c index 86b74a0..eb59fbc 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -1049,6 +1049,26 @@ netif_set_link_down(struct netif *netif) } } +#if GAZELLE_ENABLE +void +netif_set_rtc_mode(struct netif *netif) +{ + if (!(netif->flags & NETIF_FLAG_RTC_MODE)) { + netif_set_flags(netif, NETIF_FLAG_RTC_MODE); + } +} +void +netif_set_rxol_flags(struct netif *netif, u64_t flags) +{ + netif->rxol_flags |= flags; +} +void +netif_set_txol_flags(struct netif *netif, u64_t flags) +{ + netif->txol_flags |= flags; +} +#endif + #if LWIP_NETIF_LINK_CALLBACK /** * @ingroup netif diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 736845c..07203e5 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -209,7 +209,7 @@ tcp_input(struct pbuf *p, struct netif *inp) /* Verify TCP checksum. */ #if CHECKSUM_CHECK_TCP_HW u64_t ret; - if (get_eth_params_rx_ol() & DEV_RX_OFFLOAD_TCP_CKSUM) { + if (netif_get_rxol_flags(inp) & DEV_RX_OFFLOAD_TCP_CKSUM) { ret = is_cksum_bad(p); } else { ret = (u64_t)ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 547d01e..e2c9d63 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1448,7 +1448,7 @@ tcp_output(struct tcp_pcb *pcb) /* data available and window allows it to be sent? */ #if GAZELLE_ENABLE - if ((get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_TSO) && pcb->need_tso_send) { + if ((netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_TCP_TSO) && pcb->need_tso_send) { uint16_t send_pkt = 0; do { @@ -1831,7 +1831,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif #if CHECKSUM_GEN_TCP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { #if CHECKSUM_GEN_TCP_HW - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_CKSUM) { + if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_TCP_CKSUM) { tcph_cksum_set(seg->p, TCPH_HDRLEN_BYTES(seg->tcphdr)); seg->tcphdr->chksum = ip_chksum_pseudo_offload(IP_PROTO_TCP,seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); } else { @@ -2273,7 +2273,7 @@ tcp_output_control_segment(struct tcp_pcb *pcb, struct pbuf *p, IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { struct tcp_hdr *tcphdr = (struct tcp_hdr *)p->payload; #if CHECKSUM_GEN_TCP_HW - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_CKSUM) { + if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_TCP_CKSUM) { tcph_cksum_set(p, TCPH_HDRLEN_BYTES(tcphdr)); tcphdr->chksum = ip_chksum_pseudo_offload(IP_PROTO_TCP, p->tot_len, src, dst); } else { diff --git a/src/core/udp.c b/src/core/udp.c index 5c6dadb..937a045 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -414,7 +414,7 @@ udp_input(struct pbuf *p, struct netif *inp) if (udphdr->chksum != 0) { #if CHECKSUM_CHECK_UDP_HW u64_t ret = 0; - if (get_eth_params_rx_ol() & DEV_RX_OFFLOAD_UDP_CKSUM) { + if (netif_get_txol_flags(inp) & DEV_RX_OFFLOAD_UDP_CKSUM) { ret = is_cksum_bad(p); } else { ret = ip_chksum_pseudo(p, IP_PROTO_UDP, p->tot_len, @@ -983,7 +983,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d #endif /* LWIP_CHECKSUM_ON_COPY */ { #if CHECKSUM_GEN_UDP_HW - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_UDP_CKSUM) { + if (netif_get_txol_flags(netif) & DEV_TX_OFFLOAD_UDP_CKSUM) { udph_cksum_set(q, UDP_HLEN); udpchksum = ip_chksum_pseudo_offload(IP_PROTO_UDP, q->tot_len, &pcb->local_ip, &pcb->remote_ip); } else { diff --git a/src/include/dpdk_cksum.h b/src/include/dpdk_cksum.h index 5b1b6f6..b8056f9 100644 --- a/src/include/dpdk_cksum.h +++ b/src/include/dpdk_cksum.h @@ -45,8 +45,6 @@ #include "lwip/pbuf.h" #endif -extern uint64_t get_eth_params_rx_ol(void); -extern uint64_t get_eth_params_tx_ol(void); #if CHECKSUM_CHECK_IP_HW // for ip4_input static inline u64_t is_cksum_ipbad(struct pbuf *p) { diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 057c51f..75f8d50 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -106,6 +106,11 @@ extern "C" { * Set by the netif driver in its init function. */ #define NETIF_FLAG_MLD6 0x40U +#if GAZELLE_ENABLE +/** If set, use run to completion mode */ +#define NETIF_FLAG_RTC_MODE 0x80U +#endif + /** * @} */ @@ -343,6 +348,10 @@ struct netif { u8_t hwaddr_len; /** flags (@see @ref netif_flags) */ u8_t flags; +#if GAZELLE_ENABLE + u64_t rxol_flags; + u64_t txol_flags; +#endif /** descriptive abbreviation */ char name[2]; /** number of this interface. Used for @ref if_api and @ref netifapi_netif, @@ -464,6 +473,17 @@ void netif_set_down(struct netif *netif); */ #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) +#if GAZELLE_ENABLE +#define netif_is_rtc_mode(netif) (((netif)->flags & NETIF_FLAG_RTC_MODE) ? (u8_t)1 : (u8_t)0) +#define netif_get_rxol_flags(netif) ((netif)->rxol_flags) +#define netif_get_txol_flags(netif) ((netif)->txol_flags) + +void netif_set_rtc_mode(struct netif *netif); +void netif_set_rxol_flags(struct netif *netif, u64_t flags); +void netif_set_txol_flags(struct netif *netif, u64_t flags); + +#endif + #if LWIP_NETIF_STATUS_CALLBACK void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); #endif /* LWIP_NETIF_STATUS_CALLBACK */ -- 2.27.0