bsd_pbf: introduce new driver using FreeBSD /dev/bpf
Subsystems (2)
RFC 1/1 bsd_pbf: introduce new driver using FreeBSD /dev/bpf
The device driver /dev/bpf is the FreeBSD equivalent of Linux AF_PACKET for raw packet access. This was auto generated using Claude AI based on the Linux af_packet PMD.
The naming is unfortunate since the initials BPF get used in so many places already. BPF in pcap, eBPF in DPDK, eBPF in the kernel, etc.
At this point is a proof of concept, not sure if will be useful for anyone. More of a "what can AI do now" experiment.
Signed-off-by Stephen Hemminger <[email protected]>
--- doc/guides/nics/bsd_bpf.rst | 110 +++ doc/guides/nics/features/bsd_bpf.ini | 18 + doc/guides/nics/index.rst | 1 + drivers/net/bsd_bpf/meson.build | 9 + drivers/net/bsd_bpf/rte_eth_bpf.c | 1254 ++++++++++++++++++++++++++ drivers/net/meson.build | 1 + 6 files changed, 1393 insertions(+) create mode 100644 doc/guides/nics/bsd_bpf.rst create mode 100644 doc/guides/nics/features/bsd_bpf.ini create mode 100644 drivers/net/bsd_bpf/meson.build create mode 100644 drivers/net/bsd_bpf/rte_eth_bpf.c
doc/guides/nics/bsd_bpf.rst new file +110 -0
@@ -0,0 +1,110 @@ +.. SPDX-License-Identifier: BSD-3-Clause + Copyright(c) 2024 FreeBSD Foundation + +BPF Poll Mode Driver +==================== + +The BPF PMD (librte_net_bpf) provides poll mode driver support for +FreeBSD's Berkeley Packet Filter (BPF) interface. This allows DPDK +applications to send and receive raw network packets through standard +FreeBSD network interfaces. + +This driver is analogous to the AF_PACKET driver for Linux. + +Features +-------- + +- Works with any FreeBSD network interface +- Multiple queue support (via multiple BPF device instances) +- Zero-copy mode support (on FreeBSD with BIOCSETZBUF support) +- Promiscuous mode support +- Link status detection +- Statistics collection + +Build Configuration +------------------- + +The BPF PMD is only available on FreeBSD systems. It is automatically +enabled when building DPDK on FreeBSD. + +Runtime Configuration +--------------------- + +The PMD is configured via the following devargs: + +- ``iface`` - (Required) The name of the network interface to bind to +- ``qpairs`` - Number of queue pairs (default: 1) +- ``bufsz`` - Size of the receive buffer in bytes (default: 65536) +- ``zerocopy`` - Enable zero-copy mode: 0 or 1 (default: 0) + +Example Usage +------------- + +Start a DPDK application with a BPF-based port bound to em0:: + + ./dpdk-app --vdev=net_bpf,iface=em0 + +Start with multiple queues:: + + ./dpdk-app --vdev=net_bpf,iface=em0,qpairs=2 + +Start with custom buffer size and zero-copy enabled:: + + ./dpdk-app --vdev=net_bpf,iface=em0,bufsz=131072,zerocopy=1 + +Multiple Ports +-------------- + +Multiple BPF ports can be created to capture from different interfaces:: + + ./dpdk-app --vdev=net_bpf0,iface=em0 --vdev=net_bpf1,iface=em1 + +Limitations +----------- + +- The number of queue pairs is limited by the number of available + /dev/bpf devices on the system +- Zero-copy mode requires FreeBSD with BPF zero-copy support +- Each queue pair requires its own BPF device file descriptor +- Write operations are unbuffered (one packet per write) + +Performance Considerations +-------------------------- + +- Zero-copy mode provides better performance by avoiding data copies + between kernel and userspace +- Buffer size should be tuned based on expected packet rates +- Immediate mode (BIOCIMMEDIATE) is enabled by default to minimize latency + +Debugging +--------- + +To enable debug logging for the BPF PMD, use:: + + --log-level=pmd.net.bpf:debug + +System Requirements +------------------- + +- FreeBSD operating system +- Read/write access to /dev/bpf devices (typically requires root or + membership in the appropriate group) +- For promiscuous mode, appropriate privileges are required + +BPF Device Configuration +------------------------ + +The number of available BPF devices can be checked with:: + + ls /dev/bpf* + +The maximum number of BPF devices can be increased via sysctl:: + + sysctl net.bpf.maxbufsize + sysctl net.bpf.bufsize + +See Also +-------- + +- FreeBSD bpf(4) man page +- DPDK AF_PACKET PMD documentation
doc/guides/nics/features/bsd_bpf.ini new file +18 -0
@@ -0,0 +1,18 @@ +; +; Supported features of the 'bpf' network poll mode driver. +; +; Refer to default.ini for the full list of available PMD features. +; +[Features] +Link status = Y +MTU update = Y +Promiscuous mode = Y +Unicast MAC filter = Y +Basic stats = Y +Stats per queue = Y +Multiprocess aware = Y +ARMv7 = Y +ARMv8 = Y +x86-32 = Y +x86-64 = Y +Usage doc = Y
doc/guides/nics/index.rst +1 -0
@@ -19,6 +19,7 @@ Network Interface Controller Drivers axgbe bnx2x bnxt + bsd_bpf cnxk cpfl cxgbe
drivers/net/bsd_bpf/meson.build new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: BSD-3-Clause + +if not is_freebsd + build = false + reason = 'only supported on FreeBSD' + subdir_done() +endif + +sources = files('rte_eth_bpf.c')
drivers/net/bsd_bpf/rte_eth_bpf.c new file +1254 -0
1,254 lines not on this page · raw message
drivers/net/meson.build +1 -0
@@ -9,6 +9,7 @@ drivers = [ 'atlantic', 'avp', 'axgbe', + 'bsd_bpf', 'bnx2x', 'bnxt', 'bonding',
Signature · 1 line
2.51.0