From b3ee14ea6d233a507a7983ccb5f1328cc8d683c2 Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Mon, 9 Mar 2026 21:06:39 +0000 Subject: net: lwip: Fix PBUF_POOL_BUFSIZE when PROT_TCP_LWIP is disabled The PBUF_POOL_BUFSIZE ends up being only 592 bytes, instead of 1514, when PROT_TCP_LWIP Kconfig option is disabled. This results in a full Ethernet frame requiring three PBUFs instead of just one. This happens because the PBUF_POOL_BUFSIZE constant depends on the value of a TCP_MSS constant, something that defaults to 536 when PROT_TCP_LWIP is disabled. PBUF_POOL_BUFSIZE = LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_HLEN) Ensure that a full Ethernet frame fits inside a single PBUF by moving the define of TCP_MSS outside the PROT_TCP_LWIP ifdef block. Fixes: 1c41a7afaa15 ("net: lwip: build lwIP") Acked-by: Jerome Forissier Signed-off-by: Jonas Karlman --- lib/lwip/u-boot/lwipopts.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/lwip/u-boot/lwipopts.h b/lib/lwip/u-boot/lwipopts.h index e8a2c9d7a0a..1550870fa86 100644 --- a/lib/lwip/u-boot/lwipopts.h +++ b/lib/lwip/u-boot/lwipopts.h @@ -121,9 +121,13 @@ #define LWIP_UDP 0 #endif +/* + * PBUF_POOL_BUFSIZE is derived from TCP_MSS even when + * CONFIG_PROT_TCP_LWIP is not defined + */ +#define TCP_MSS 1460 #if defined(CONFIG_PROT_TCP_LWIP) #define LWIP_TCP 1 -#define TCP_MSS 1460 #define TCP_WND CONFIG_LWIP_TCP_WND #define LWIP_WND_SCALE 1 #define TCP_RCV_SCALE 0x7 -- cgit v1.2.3 From 67586012490a4b2b4db6b79647aaf946f03eb767 Mon Sep 17 00:00:00 2001 From: Pranav Tilak Date: Tue, 10 Mar 2026 18:28:25 +0530 Subject: net: lwip: scale buffer pool size with TFTP block size TFTP transfers fail when tftpblocksize is set to 8192 or larger due to insufficient buffer resources for IP fragment reassembly. Calculate PBUF_POOL_SIZE and IP_REASS_MAX_PBUFS dynamically based on CONFIG_TFTP_BLOCKSIZE using IP fragmentation boundaries (1480 usable bytes per fragment at 1500 MTU). The pool size includes headroom for TX, ARP, and protocol overhead, while ensuring PBUF_POOL_SIZE remains greater than IP_REASS_MAX_PBUFS as required by lwIP. Signed-off-by: Pranav Tilak --- lib/lwip/u-boot/lwipopts.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/lwip/u-boot/lwipopts.h b/lib/lwip/u-boot/lwipopts.h index 1550870fa86..8dae004f1a2 100644 --- a/lib/lwip/u-boot/lwipopts.h +++ b/lib/lwip/u-boot/lwipopts.h @@ -65,7 +65,21 @@ #define MEM_ALIGNMENT 8 #define MEMP_NUM_TCP_SEG 16 + +/* IP fragmentation parameters for TFTP reassembly */ +#define IP_FRAG_MTU_USABLE 1480 +#define PBUF_POOL_HEADROOM 6 +#define PBUF_POOL_RESERVE 4 +#define TFTP_BLOCKSIZE_THRESHOLD 4096 + +#if defined(CONFIG_TFTP_BLOCKSIZE) && (CONFIG_TFTP_BLOCKSIZE > TFTP_BLOCKSIZE_THRESHOLD) +#define PBUF_POOL_SIZE (((CONFIG_TFTP_BLOCKSIZE + (IP_FRAG_MTU_USABLE - 1)) / \ + IP_FRAG_MTU_USABLE) + PBUF_POOL_HEADROOM) +#define IP_REASS_MAX_PBUFS (PBUF_POOL_SIZE - PBUF_POOL_RESERVE) +#else #define PBUF_POOL_SIZE 8 +#define IP_REASS_MAX_PBUFS 4 +#endif #define LWIP_ARP 1 #define ARP_TABLE_SIZE 4 @@ -76,7 +90,7 @@ #define IP_REASSEMBLY 1 #define IP_FRAG 1 #define IP_REASS_MAXAGE 3 -#define IP_REASS_MAX_PBUFS 4 + #define IP_FRAG_USES_STATIC_BUF 0 #define IP_DEFAULT_TTL 255 -- cgit v1.2.3