16ef75e40STiago Lam.. SPDX-License-Identifier: BSD-3-Clause 26ef75e40STiago Lam Copyright(c) 2018 Intel Corporation. 36ef75e40STiago Lam 46ef75e40STiago LamAF_PACKET Poll Mode Driver 56ef75e40STiago Lam========================== 66ef75e40STiago Lam 76ef75e40STiago LamThe AF_PACKET socket in Linux allows an application to receive and send raw 8f8dbaebbSSean Morrisseypackets. This Linux-specific PMD binds to an AF_PACKET socket and allows 96ef75e40STiago Lama DPDK application to send and receive raw packets through the Kernel. 106ef75e40STiago Lam 116ef75e40STiago LamIn order to improve Rx and Tx performance this implementation makes use of 127be78d02SJosh SorefPACKET_MMAP, which provides a mmapped ring buffer, shared between user space 136ef75e40STiago Lamand kernel, that's used to send and receive packets. This helps reducing system 146ef75e40STiago Lamcalls and the copies needed between user space and Kernel. 156ef75e40STiago Lam 166ef75e40STiago LamOptions and inherent limitations 176ef75e40STiago Lam-------------------------------- 186ef75e40STiago Lam 196ef75e40STiago LamThe following options can be provided to set up an af_packet port in DPDK. 20d629b7b5SJohn McNamaraSome of these, in turn, will be used to configure the PACKET_MMAP settings. 216ef75e40STiago Lam 226ef75e40STiago Lam* ``iface`` - name of the Kernel interface to attach to (required); 236ef75e40STiago Lam* ``qpairs`` - number of Rx and Tx queues (optional, default 1); 246ef75e40STiago Lam* ``qdisc_bypass`` - set PACKET_QDISC_BYPASS option in AF_PACKET (optional, 256ef75e40STiago Lam disabled by default); 26*d3bc77abSTudor Cornea* ``fanout_mode`` - set fanout algorithm. 27*d3bc77abSTudor Cornea Possible choices: hash, lb, cpu, rollover, rnd, qm (optional, default hash); 286ef75e40STiago Lam* ``blocksz`` - PACKET_MMAP block size (optional, default 4096); 296ef75e40STiago Lam* ``framesz`` - PACKET_MMAP frame size (optional, default 2048B; Note: multiple 306ef75e40STiago Lam of 16B); 316ef75e40STiago Lam* ``framecnt`` - PACKET_MMAP frame count (optional, default 512). 326ef75e40STiago Lam 33*d3bc77abSTudor CorneaFor details regarding ``fanout_mode`` argument, you can consult the 34*d3bc77abSTudor Cornea`PACKET_FANOUT documentation <https://www.man7.org/linux/man-pages/man7/packet.7.html>`_. 35*d3bc77abSTudor Cornea 36*d3bc77abSTudor CorneaAs an example, when ``fanout_mode=cpu`` is selected, the PACKET_FANOUT_CPU mode 37*d3bc77abSTudor Corneawill be set on the sockets, so that on frame reception, 38*d3bc77abSTudor Corneathe socket will be selected based on the CPU on which the packet arrived. 39*d3bc77abSTudor Cornea 40*d3bc77abSTudor CorneaOnly one ``fanout_mode`` can be chosen. 41*d3bc77abSTudor CorneaIf left unspecified, the default is to use the ``PACKET_FANOUT_HASH`` behavior 42*d3bc77abSTudor Corneaof AF_PACKET for frame reception. 43*d3bc77abSTudor Cornea 446ef75e40STiago LamBecause this implementation is based on PACKET_MMAP, and PACKET_MMAP has its 456ef75e40STiago Lamown pre-requisites, it should be noted that the inner workings of PACKET_MMAP 466ef75e40STiago Lamshould be carefully considered before modifying some of these options (namely, 476ef75e40STiago Lam``blocksz``, ``framesz`` and ``framecnt`` above). 486ef75e40STiago Lam 496ef75e40STiago LamAs an example, if one changes ``framesz`` to be 1024B, it is expected that 506ef75e40STiago Lam``blocksz`` is set to at least 1024B as well (although 2048B in this case would 516ef75e40STiago Lamallow two "frames" per "block"). 526ef75e40STiago Lam 536ef75e40STiago LamThis restriction happens because PACKET_MMAP expects each single "frame" to fit 546ef75e40STiago Laminside of a "block". And although multiple "frames" can fit inside of a single 556ef75e40STiago Lam"block", a "frame" may not span across two "blocks". 566ef75e40STiago Lam 576ef75e40STiago LamFor the full details behind PACKET_MMAP's structures and settings, consider 586ef75e40STiago Lamreading the `PACKET_MMAP documentation in the Kernel 596ef75e40STiago Lam<https://www.kernel.org/doc/Documentation/networking/packet_mmap.txt>`_. 606ef75e40STiago Lam 616ef75e40STiago LamPrerequisites 626ef75e40STiago Lam------------- 636ef75e40STiago Lam 646ef75e40STiago LamThis is a Linux-specific PMD, thus the following prerequisites apply: 656ef75e40STiago Lam 666ef75e40STiago Lam* A Linux Kernel; 676ef75e40STiago Lam* A Kernel bound interface to attach to (e.g. a tap interface). 686ef75e40STiago Lam 696ef75e40STiago LamSet up an af_packet interface 706ef75e40STiago Lam----------------------------- 716ef75e40STiago Lam 726ef75e40STiago LamThe following example will set up an af_packet interface in DPDK with the 736ef75e40STiago Lamdefault options described above (blocksz=4096B, framesz=2048B and 746ef75e40STiago Lamframecnt=512): 756ef75e40STiago Lam 766ef75e40STiago Lam.. code-block:: console 776ef75e40STiago Lam 78*d3bc77abSTudor Cornea --vdev=eth_af_packet0,iface=tap0,blocksz=4096,framesz=2048,framecnt=512,qpairs=1,qdisc_bypass=0,fanout_mode=hash 79d41d39bcSTudor Cornea 80d41d39bcSTudor CorneaFeatures and Limitations 81d41d39bcSTudor Cornea------------------------ 82d41d39bcSTudor Cornea 83be10211cSStefan Laesser* The PMD will re-insert the VLAN tag transparently to the packet if the kernel 84295968d1SFerruh Yigit strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the 85d41d39bcSTudor Cornea application. 86be10211cSStefan Laesser* The PMD will add the kernel packet timestamp with nanoseconds resolution and 87be10211cSStefan Laesser UNIX origo, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled. 88