mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-17 02:36:21 +00:00
xsk: Document tx_metadata_len layout
- how to use - how to query features - pointers to the examples Signed-off-by: Stanislav Fomichev <sdf@google.com> Link: https://lore.kernel.org/r/20231127190319.1190813-7-sdf@google.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
1347b41931
commit
9620e956d5
@ -123,6 +123,7 @@ Contents:
|
|||||||
xfrm_sync
|
xfrm_sync
|
||||||
xfrm_sysctl
|
xfrm_sysctl
|
||||||
xdp-rx-metadata
|
xdp-rx-metadata
|
||||||
|
xsk-tx-metadata
|
||||||
|
|
||||||
.. only:: subproject and html
|
.. only:: subproject and html
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
.. SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
||||||
===============
|
===============
|
||||||
XDP RX Metadata
|
XDP RX Metadata
|
||||||
===============
|
===============
|
||||||
|
70
Documentation/networking/xsk-tx-metadata.rst
Normal file
70
Documentation/networking/xsk-tx-metadata.rst
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
==================
|
||||||
|
AF_XDP TX Metadata
|
||||||
|
==================
|
||||||
|
|
||||||
|
This document describes how to enable offloads when transmitting packets
|
||||||
|
via :doc:`af_xdp`. Refer to :doc:`xdp-rx-metadata` on how to access similar
|
||||||
|
metadata on the receive side.
|
||||||
|
|
||||||
|
General Design
|
||||||
|
==============
|
||||||
|
|
||||||
|
The headroom for the metadata is reserved via ``tx_metadata_len`` in
|
||||||
|
``struct xdp_umem_reg``. The metadata length is therefore the same for
|
||||||
|
every socket that shares the same umem. The metadata layout is a fixed UAPI,
|
||||||
|
refer to ``union xsk_tx_metadata`` in ``include/uapi/linux/if_xdp.h``.
|
||||||
|
Thus, generally, the ``tx_metadata_len`` field above should contain
|
||||||
|
``sizeof(union xsk_tx_metadata)``.
|
||||||
|
|
||||||
|
The headroom and the metadata itself should be located right before
|
||||||
|
``xdp_desc->addr`` in the umem frame. Within a frame, the metadata
|
||||||
|
layout is as follows::
|
||||||
|
|
||||||
|
tx_metadata_len
|
||||||
|
/ \
|
||||||
|
+-----------------+---------+----------------------------+
|
||||||
|
| xsk_tx_metadata | padding | payload |
|
||||||
|
+-----------------+---------+----------------------------+
|
||||||
|
^
|
||||||
|
|
|
||||||
|
xdp_desc->addr
|
||||||
|
|
||||||
|
An AF_XDP application can request headrooms larger than ``sizeof(struct
|
||||||
|
xsk_tx_metadata)``. The kernel will ignore the padding (and will still
|
||||||
|
use ``xdp_desc->addr - tx_metadata_len`` to locate
|
||||||
|
the ``xsk_tx_metadata``). For the frames that shouldn't carry
|
||||||
|
any metadata (i.e., the ones that don't have ``XDP_TX_METADATA`` option),
|
||||||
|
the metadata area is ignored by the kernel as well.
|
||||||
|
|
||||||
|
The flags field enables the particular offload:
|
||||||
|
|
||||||
|
- ``XDP_TXMD_FLAGS_TIMESTAMP``: requests the device to put transmission
|
||||||
|
timestamp into ``tx_timestamp`` field of ``union xsk_tx_metadata``.
|
||||||
|
- ``XDP_TXMD_FLAGS_CHECKSUM``: requests the device to calculate L4
|
||||||
|
checksum. ``csum_start`` specifies byte offset of where the checksumming
|
||||||
|
should start and ``csum_offset`` specifies byte offset where the
|
||||||
|
device should store the computed checksum.
|
||||||
|
|
||||||
|
Besides the flags above, in order to trigger the offloads, the first
|
||||||
|
packet's ``struct xdp_desc`` descriptor should set ``XDP_TX_METADATA``
|
||||||
|
bit in the ``options`` field. Also note that in a multi-buffer packet
|
||||||
|
only the first chunk should carry the metadata.
|
||||||
|
|
||||||
|
Querying Device Capabilities
|
||||||
|
============================
|
||||||
|
|
||||||
|
Every devices exports its offloads capabilities via netlink netdev family.
|
||||||
|
Refer to ``xsk-flags`` features bitmask in
|
||||||
|
``Documentation/netlink/specs/netdev.yaml``.
|
||||||
|
|
||||||
|
- ``tx-timestamp``: device supports ``XDP_TXMD_FLAGS_TIMESTAMP``
|
||||||
|
- ``tx-checksum``: device supports ``XDP_TXMD_FLAGS_CHECKSUM``
|
||||||
|
|
||||||
|
See ``tools/net/ynl/samples/netdev.c`` on how to query this information.
|
||||||
|
|
||||||
|
Example
|
||||||
|
=======
|
||||||
|
|
||||||
|
See ``tools/testing/selftests/bpf/xdp_hw_metadata.c`` for an example
|
||||||
|
program that handles TX metadata. Also see https://github.com/fomichev/xskgen
|
||||||
|
for a more bare-bones example.
|
Loading…
x
Reference in New Issue
Block a user