Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: enable driver support for netmem TX

Drivers need to make sure not to pass netmem dma-addrs to the
dma-mapping API in order to support netmem TX.

Add helpers and netmem_dma_*() helpers that enables special handling of
netmem dma-addrs that drivers can use.

Document in netmem.rst what drivers need to do to support netmem TX.

Signed-off-by: Mina Almasry <almasrymina@google.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250508004830.4100853-7-almasrymina@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Mina Almasry and committed by
Paolo Abeni
383faec0 17af8cc0

+49 -2
+1
Documentation/networking/net_cachelines/net_device.rst
··· 10 10 =================================== =========================== =================== =================== =================================================================================== 11 11 unsigned_long:32 priv_flags read_mostly __dev_queue_xmit(tx) 12 12 unsigned_long:1 lltx read_mostly HARD_TX_LOCK,HARD_TX_TRYLOCK,HARD_TX_UNLOCK(tx) 13 + unsigned long:1 netmem_tx:1; read_mostly 13 14 char name[16] 14 15 struct netdev_name_node* name_node 15 16 struct dev_ifalias* ifalias
+5
Documentation/networking/netdev-features.rst
··· 188 188 This should be set for devices which duplicate outgoing HSR (High-availability 189 189 Seamless Redundancy) or PRP (Parallel Redundancy Protocol) tags automatically 190 190 frames in hardware. 191 + 192 + * netmem-tx 193 + 194 + This should be set for devices which support netmem TX. See 195 + Documentation/networking/netmem.rst
+21 -2
Documentation/networking/netmem.rst
··· 19 19 * Simplified Development: Drivers interact with a consistent API, 20 20 regardless of the underlying memory implementation. 21 21 22 - Driver Requirements 23 - =================== 22 + Driver RX Requirements 23 + ====================== 24 24 25 25 1. The driver must support page_pool. 26 26 ··· 77 77 that purpose, but be mindful that some netmem types might have longer 78 78 circulation times, such as when userspace holds a reference in zerocopy 79 79 scenarios. 80 + 81 + Driver TX Requirements 82 + ====================== 83 + 84 + 1. The Driver must not pass the netmem dma_addr to any of the dma-mapping APIs 85 + directly. This is because netmem dma_addrs may come from a source like 86 + dma-buf that is not compatible with the dma-mapping APIs. 87 + 88 + Helpers like netmem_dma_unmap_page_attrs() & netmem_dma_unmap_addr_set() 89 + should be used in lieu of dma_unmap_page[_attrs](), dma_unmap_addr_set(). 90 + The netmem variants will handle netmem dma_addrs correctly regardless of the 91 + source, delegating to the dma-mapping APIs when appropriate. 92 + 93 + Not all dma-mapping APIs have netmem equivalents at the moment. If your 94 + driver relies on a missing netmem API, feel free to add and propose to 95 + netdev@, or reach out to the maintainers and/or almasrymina@google.com for 96 + help adding the netmem API. 97 + 98 + 2. Driver should declare support by setting `netdev->netmem_tx = true`
+2
include/linux/netdevice.h
··· 1772 1772 * @lltx: device supports lockless Tx. Deprecated for real HW 1773 1773 * drivers. Mainly used by logical interfaces, such as 1774 1774 * bonding and tunnels 1775 + * @netmem_tx: device support netmem_tx. 1775 1776 * 1776 1777 * @name: This is the first field of the "visible" part of this structure 1777 1778 * (i.e. as seen by users in the "Space.c" file). It is the name ··· 2088 2087 struct_group(priv_flags_fast, 2089 2088 unsigned long priv_flags:32; 2090 2089 unsigned long lltx:1; 2090 + unsigned long netmem_tx:1; 2091 2091 ); 2092 2092 const struct net_device_ops *netdev_ops; 2093 2093 const struct header_ops *header_ops;
+20
include/net/netmem.h
··· 8 8 #ifndef _NET_NETMEM_H 9 9 #define _NET_NETMEM_H 10 10 11 + #include <linux/dma-mapping.h> 11 12 #include <linux/mm.h> 12 13 #include <net/net_debug.h> 13 14 ··· 276 275 277 276 void get_netmem(netmem_ref netmem); 278 277 void put_netmem(netmem_ref netmem); 278 + 279 + #define netmem_dma_unmap_addr_set(NETMEM, PTR, ADDR_NAME, VAL) \ 280 + do { \ 281 + if (!netmem_is_net_iov(NETMEM)) \ 282 + dma_unmap_addr_set(PTR, ADDR_NAME, VAL); \ 283 + else \ 284 + dma_unmap_addr_set(PTR, ADDR_NAME, 0); \ 285 + } while (0) 286 + 287 + static inline void netmem_dma_unmap_page_attrs(struct device *dev, 288 + dma_addr_t addr, size_t size, 289 + enum dma_data_direction dir, 290 + unsigned long attrs) 291 + { 292 + if (!addr) 293 + return; 294 + 295 + dma_unmap_page_attrs(dev, addr, size, dir, attrs); 296 + } 279 297 280 298 #endif /* _NET_NETMEM_H */