From 78c3996b593a7115cdb6e3d6f6200ff7b1f7e9b1 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 21 Jan 2025 12:39:03 +0100 Subject: [PATCH] net: ethernet: Allow drivers to reserve net_pkt headroom Add new Ethernet driver config option, ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM, which allows Ethernet drivers to inform L2 about the extra net_pkt headroom they need to be allocated. This is only supported when CONFIG_NET_L2_ETHERNET_RESERVE_HEADER is enabled, so that it's possible to fit entire packet into a single net_buf, which is needed for zero-copy transmission. Signed-off-by: Robert Lubos --- include/zephyr/net/ethernet.h | 5 ++++- subsys/net/l2/ethernet/ethernet.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/zephyr/net/ethernet.h b/include/zephyr/net/ethernet.h index 3e361cb8703..ce7c99de803 100644 --- a/include/zephyr/net/ethernet.h +++ b/include/zephyr/net/ethernet.h @@ -234,7 +234,8 @@ enum ethernet_config_type { ETHERNET_CONFIG_TYPE_T1S_PARAM, ETHERNET_CONFIG_TYPE_TXINJECTION_MODE, ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT, - ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT + ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT, + ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM, }; enum ethernet_qav_param_type { @@ -529,6 +530,8 @@ struct ethernet_config { enum ethernet_checksum_support chksum_support; struct ethernet_filter filter; + + uint16_t extra_tx_pkt_headroom; }; }; diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index 86825f4ff08..fc34251a6a1 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -862,8 +862,15 @@ static int ethernet_l2_alloc(struct net_if *iface, struct net_pkt *pkt, size_t size, enum net_ip_protocol proto, k_timeout_t timeout) { - return net_pkt_alloc_buffer_with_reserve(pkt, size, - get_reserve_ll_header_size(iface), + size_t reserve = get_reserve_ll_header_size(iface); + struct ethernet_config config; + + if (net_eth_get_hw_config(iface, ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM, + &config) == 0) { + reserve += config.extra_tx_pkt_headroom; + } + + return net_pkt_alloc_buffer_with_reserve(pkt, size, reserve, proto, timeout); } #else