Skip to content

Commit 8b0f48b

Browse files
Robert LubosChromeos LUCI
authored andcommitted
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. (cherry picked from commit 78c3996) Original-Signed-off-by: Robert Lubos <[email protected]> GitOrigin-RevId: 78c3996 Cr-Build-Id: 8724909411128659441 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8724909411128659441 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: I9f53462110aae6f48b567a4ae139bd5cc774b2bb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6196364 Tested-by: ChromeOS Prod (Robot) <[email protected]> Commit-Queue: ChromeOS Prod (Robot) <[email protected]> Bot-Commit: ChromeOS Prod (Robot) <[email protected]>
1 parent eb68dc0 commit 8b0f48b

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
@@ -234,7 +234,8 @@ enum ethernet_config_type {
234234
ETHERNET_CONFIG_TYPE_T1S_PARAM,
235235
ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
236236
ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT,
237-
ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT
237+
ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT,
238+
ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM,
238239
};
239240

240241
enum ethernet_qav_param_type {
@@ -529,6 +530,8 @@ struct ethernet_config {
529530
enum ethernet_checksum_support chksum_support;
530531

531532
struct ethernet_filter filter;
533+
534+
uint16_t extra_tx_pkt_headroom;
532535
};
533536
};
534537

subsys/net/l2/ethernet/ethernet.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,15 @@ static int ethernet_l2_alloc(struct net_if *iface, struct net_pkt *pkt,
862862
size_t size, enum net_ip_protocol proto,
863863
k_timeout_t timeout)
864864
{
865-
return net_pkt_alloc_buffer_with_reserve(pkt, size,
866-
get_reserve_ll_header_size(iface),
865+
size_t reserve = get_reserve_ll_header_size(iface);
866+
struct ethernet_config config;
867+
868+
if (net_eth_get_hw_config(iface, ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM,
869+
&config) == 0) {
870+
reserve += config.extra_tx_pkt_headroom;
871+
}
872+
873+
return net_pkt_alloc_buffer_with_reserve(pkt, size, reserve,
867874
proto, timeout);
868875
}
869876
#else

0 commit comments

Comments
 (0)