From 3fe8eb09a2f17c9c1f7a64b14f1c31dea06f76ce Mon Sep 17 00:00:00 2001 From: Marco Schlumpp Date: Wed, 8 Mar 2023 14:02:56 +0100 Subject: [PATCH] lib/uknetdev: Add interface for IPv4/TCP segmentation offload MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This allows network device to advertise support for TSO on IPv4 and clients to send large packets that are split by the hardware. Signed-off-by: Marco Schlumpp Reviewed-by: Eduard Vintilă Reviewed-by: Andrei Tatar Approved-by: Razvan Deaconescu GitHub-Closes: #1088 --- lib/uknetdev/include/uk/netbuf.h | 14 ++++++++++++++ lib/uknetdev/include/uk/netdev_core.h | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/uknetdev/include/uk/netbuf.h b/lib/uknetdev/include/uk/netbuf.h index 853952dc9..0306ad645 100644 --- a/lib/uknetdev/include/uk/netbuf.h +++ b/lib/uknetdev/include/uk/netbuf.h @@ -123,6 +123,12 @@ typedef void (*uk_netbuf_dtor_t)(struct uk_netbuf *); #define UK_NETBUF_F_PARTIAL_CSUM_BIT 1 #define UK_NETBUF_F_PARTIAL_CSUM (1 << UK_NETBUF_F_PARTIAL_CSUM_BIT) +/* Indicates the packet should be sent with the help of TCP Segmentation + * Offloading. This requires that the device supports this. + */ +#define UK_NETBUF_F_GSO_TCPV4_BIT 2 +#define UK_NETBUF_F_GSO_TCPV4 (1 << UK_NETBUF_F_GSO_TCPV4_BIT) + struct uk_netbuf { struct uk_netbuf *next; struct uk_netbuf *prev; @@ -147,6 +153,14 @@ struct uk_netbuf { * pointing to the checksum field */ + uint16_t header_len; /**< Used if UK_NETBUF_F_GSO_* is set; + * Number of bytes to copy into each split + * packet as a header + */ + uint16_t gso_size; /**< Used if UK_NETBUF_F_GSO_* is set; + * Maximum size of each packet beyond the header + */ + uk_netbuf_dtor_t dtor; /**< Destructor callback */ struct uk_alloc *_a; /**< @internal Allocator for free'ing */ void *_b; /**< @internal Base address for free'ing */ diff --git a/lib/uknetdev/include/uk/netdev_core.h b/lib/uknetdev/include/uk/netdev_core.h index b31e2e780..75022ec67 100644 --- a/lib/uknetdev/include/uk/netdev_core.h +++ b/lib/uknetdev/include/uk/netdev_core.h @@ -142,13 +142,19 @@ struct uk_hwaddr { #define UK_NETDEV_F_PARTIAL_CSUM_BIT 2 #define UK_NETDEV_F_PARTIAL_CSUM (1UL << UK_NETDEV_F_PARTIAL_CSUM_BIT) +/* Indicates that the network device supports sending netbufs with the + * UK_NETBUF_F_GSO_TCPV4 bit set. */ +#define UK_NETDEV_F_TSO4_BIT 3 +#define UK_NETDEV_F_TSO4 (1UL << UK_NETDEV_F_TSO4_BIT) + #define uk_netdev_rxintr_supported(feature) \ (feature & (UK_NETDEV_F_RXQ_INTR)) #define uk_netdev_txintr_supported(feature) \ (feature & (UK_NETDEV_F_TXQ_INTR)) #define uk_netdev_partial_csum_supported(feature) \ (feature & (UK_NETDEV_F_PARTIAL_CSUM)) - +#define uk_netdev_tso4_supported(feature) \ + (feature & (UK_NETDEV_F_TSO4)) /** * A structure used to describe network device capabilities. */ -- 2.39.5