diff --git a/boards/sim/sim/sim/configs/tcploop/defconfig b/boards/sim/sim/sim/configs/tcploop/defconfig index 888c68c77d..00c9d7eae0 100644 --- a/boards/sim/sim/sim/configs/tcploop/defconfig +++ b/boards/sim/sim/sim/configs/tcploop/defconfig @@ -45,6 +45,7 @@ CONFIG_NETDEVICES=y CONFIG_NET_IPv6=y CONFIG_NET_IPv6_NCONF_ENTRIES=4 CONFIG_NET_LOOPBACK=y +CONFIG_NET_LOOPBACK_PKTSIZE=1500 CONFIG_NET_MAX_LISTENPORTS=16 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 88a5d057c3..36ae9f2247 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -108,7 +109,7 @@ struct lo_driver_s ****************************************************************************/ static struct lo_driver_s g_loopback; -static uint8_t g_iobuffer[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE]; +static uint8_t g_iobuffer[NET_LO_PKTSIZE + CONFIG_NET_GUARDSIZE]; /**************************************************************************** * Private Function Prototypes diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index 1fdb71fff9..7ed1dbd055 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -184,9 +184,21 @@ #define MIN_NETDEV_PKTSIZE _MIN_6LOWPAN_PKTSIZE #define MAX_NETDEV_PKTSIZE _MAX_6LOWPAN_PKTSIZE -/* For the loopback device, we will use the largest MTU */ +/* The loopback driver packet buffer should be quite large. The larger the + * loopback packet buffer, the better will be TCP performance of the loopback + * transfers. The Linux loopback device historically used packet buffers of + * size 16Kb, but that was increased in recent Linux versions to 64Kb. Those + * sizes may be excessive for resource constrained MCUs, however. + * + * For the loopback driver, we enforce a lower limit that is the maximum + * packet size of all enabled link layer protocols. + */ +#if CONFIG_NET_LOOPBACK_PKTSIZE < MAX_NETDEV_PKTSIZE # define NET_LO_PKTSIZE MAX_NETDEV_PKTSIZE +#else +# define NET_LO_PKTSIZE CONFIG_NET_LOOPBACK_PKTSIZE +#endif /* Layer 3/4 Configuration Options ******************************************/ @@ -206,7 +218,7 @@ * of the timer is 8-bits. */ -# define CONFIG_NET_TCP_REASS_MAXAGE (20*10) /* 20 seconds */ +# define CONFIG_NET_TCP_REASS_MAXAGE (20 * 10) /* 20 seconds */ # endif #endif diff --git a/net/Kconfig b/net/Kconfig index fffbfa8b27..5019cd5da3 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -132,6 +132,24 @@ config NET_LOOPBACK ---help--- Add support for the local network loopback device, lo. +config NET_LOOPBACK_PKTSIZE + int "Loopback packet buffer size" + default 0 + depends on NET_LOOPBACK + range 0 65535 + ---help--- + The loopback driver packet buffer should be quite large. The larger + the loopback packet buffer, the better will be TCP performance of + the loopback transfers. The Linux loopback device historically used + packet buffers of size 16Kb, but that was increased in recent Linux + versions to 64Kb. Those sizes may be excessive for resource + constrained MCUs, however. + + The network enforces a lower limit that is the maximum packet size + of all enabled link layer protocols. The default value of + CONFIG_NET_LOOPBACK_PKTSIZE is zero, meaning that this maximum + packet size will be used by loopback driver. + menuconfig NET_SLIP bool "SLIP support" select ARCH_HAVE_NETDEV_STATISTICS