Skip to content

Commit 88eb600

Browse files
rluboskapbh
authored andcommitted
[nrf fromtree] 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 <[email protected]> (cherry picked from commit 78c3996)
1 parent f78658f commit 88eb600

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/zephyr/net/ethernet.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ enum ethernet_config_type {
230230
ETHERNET_CONFIG_TYPE_T1S_PARAM,
231231
ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
232232
ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT,
233-
ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT
233+
ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT,
234+
ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM,
234235
};
235236

236237
enum ethernet_qav_param_type {
@@ -525,6 +526,8 @@ struct ethernet_config {
525526
enum ethernet_checksum_support chksum_support;
526527

527528
struct ethernet_filter filter;
529+
530+
uint16_t extra_tx_pkt_headroom;
528531
};
529532
};
530533

subsys/net/l2/ethernet/ethernet.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,15 @@ static int ethernet_l2_alloc(struct net_if *iface, struct net_pkt *pkt,
884884
size_t size, enum net_ip_protocol proto,
885885
k_timeout_t timeout)
886886
{
887-
return net_pkt_alloc_buffer_with_reserve(pkt, size,
888-
get_reserve_ll_header_size(iface),
887+
size_t reserve = get_reserve_ll_header_size(iface);
888+
struct ethernet_config config;
889+
890+
if (net_eth_get_hw_config(iface, ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM,
891+
&config) == 0) {
892+
reserve += config.extra_tx_pkt_headroom;
893+
}
894+
895+
return net_pkt_alloc_buffer_with_reserve(pkt, size, reserve,
889896
proto, timeout);
890897
}
891898
#else

0 commit comments

Comments
 (0)