From 5d09d36ddf74da9c5fa87a6dd5bc104fe99bdce6 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Sat, 18 Jan 2025 20:55:43 +0800
Subject: [PATCH] tso: max frags is configurable

---
 src/core/netif.c         | 10 ++++++++++
 src/core/tcp_out.c       |  4 ++--
 src/include/lwip/netif.h |  6 +++++-
 src/include/lwipopts.h   |  5 -----
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/core/netif.c b/src/core/netif.c
index eba9a0b..b79ab57 100644
--- a/src/core/netif.c
+++ b/src/core/netif.c
@@ -1117,6 +1117,16 @@ netif_set_txol_flags(struct netif *netif, u64_t flags)
 {
     netif->txol_flags |= flags;
 }
+
+void netif_set_max_pbuf_frags(struct netif *netif, u8_t max_frags)
+{
+    netif->max_pbuf_frags = max_frags;
+}
+
+void netif_set_min_tso_seglen(struct netif *netif, u16_t min_tso_seglen)
+{
+    netif->min_tso_seglen = min_tso_seglen;
+}
 #endif
 
 #if LWIP_NETIF_LINK_CALLBACK
diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c
index 93ef958..cf93482 100644
--- a/src/core/tcp_out.c
+++ b/src/core/tcp_out.c
@@ -1578,8 +1578,8 @@ tcp_output(struct tcp_pcb *pcb)
         struct tcp_seg *last_seg = NULL;
         u16_t last_seg_len = 0;
         u8_t pbuf_chain_len = 0;
-        while (seg != NULL && seg_seqno - pcb->lastack + seg->len <= wnd && pbuf_chain_len < GAZELLE_TCP_MAX_PBUF_CHAIN_LEN) {
-            if (last_seg_len != 0 && (last_seg_len + seg->len < 1460) && seg->len < GAZELLE_TCP_MIN_TSO_SEG_LEN) {
+        while (seg != NULL && seg_seqno - pcb->lastack + seg->len <= wnd && pbuf_chain_len < netif->max_pbuf_frags) {
+            if (last_seg_len != 0 && (last_seg_len + seg->len < 1460) && seg->len < netif->min_tso_seglen) {
                 break;
             }
 
diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h
index 3deefb0..75157de 100644
--- a/src/include/lwip/netif.h
+++ b/src/include/lwip/netif.h
@@ -372,6 +372,9 @@ struct netif {
   /** vlan id is an attribute of NIC. The variable 'netif_hints' is not used because it is assigned by pcb,
    *  while non transport layers without pcb cannot be enabled */
   u16_t vlan_tci;
+
+  u8_t max_pbuf_frags;
+  u16_t min_tso_seglen;
 #endif
   /** descriptive abbreviation */
   char name[2];
@@ -508,7 +511,8 @@ void netif_set_vlan_tci(struct netif *netif, u16_t vlan_tci);
 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);
-
+void netif_set_min_tso_seglen(struct netif *netif, u16_t min_tso_seglen);
+void netif_set_max_pbuf_frags(struct netif *netif, u8_t max_frags);
 #endif
 
 #if LWIP_NETIF_STATUS_CALLBACK
diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h
index 572d550..2ac48f5 100644
--- a/src/include/lwipopts.h
+++ b/src/include/lwipopts.h
@@ -55,11 +55,6 @@
 
 #define GAZELLE_TCP_NEW_PORT 1
 
-#define GAZELLE_TCP_MAX_PBUF_CHAIN_LEN 40
-
-#define GAZELLE_TCP_MIN_TSO_SEG_LEN 256
-
-
 #define GAZELLE_UDP_ENABLE 1
 #define GAZELLE_UDP_NEW_PORT 1
 
-- 
2.33.0

