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 <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2025-01-21 12:39:03 +01:00 committed by Benjamin Cabé
parent e35cb93afa
commit 78c3996b59
2 changed files with 13 additions and 3 deletions

View file

@ -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;
};
};

View file

@ -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