364 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3============================================================4Linux kernel driver for Elastic Network Adapter (ENA) family5============================================================6 7Overview8========9 10ENA is a networking interface designed to make good use of modern CPU11features and system architectures.12 13The ENA device exposes a lightweight management interface with a14minimal set of memory mapped registers and extendible command set15through an Admin Queue.16 17The driver supports a range of ENA devices, is link-speed independent18(i.e., the same driver is used for 10GbE, 25GbE, 40GbE, etc), and has19a negotiated and extendible feature set.20 21Some ENA devices support SR-IOV. This driver is used for both the22SR-IOV Physical Function (PF) and Virtual Function (VF) devices.23 24ENA devices enable high speed and low overhead network traffic25processing by providing multiple Tx/Rx queue pairs (the maximum number26is advertised by the device via the Admin Queue), a dedicated MSI-X27interrupt vector per Tx/Rx queue pair, adaptive interrupt moderation,28and CPU cacheline optimized data placement.29 30The ENA driver supports industry standard TCP/IP offload features such as31checksum offload. Receive-side scaling (RSS) is supported for multi-core32scaling.33 34The ENA driver and its corresponding devices implement health35monitoring mechanisms such as watchdog, enabling the device and driver36to recover in a manner transparent to the application, as well as37debug logs.38 39Some of the ENA devices support a working mode called Low-latency40Queue (LLQ), which saves several more microseconds.41 42ENA Source Code Directory Structure43===================================44 45================= ======================================================46ena_com.[ch] Management communication layer. This layer is47 responsible for the handling all the management48 (admin) communication between the device and the49 driver.50ena_eth_com.[ch] Tx/Rx data path.51ena_admin_defs.h Definition of ENA management interface.52ena_eth_io_defs.h Definition of ENA data path interface.53ena_common_defs.h Common definitions for ena_com layer.54ena_regs_defs.h Definition of ENA PCI memory-mapped (MMIO) registers.55ena_netdev.[ch] Main Linux kernel driver.56ena_ethtool.c ethtool callbacks.57ena_xdp.[ch] XDP files58ena_pci_id_tbl.h Supported device IDs.59================= ======================================================60 61Management Interface:62=====================63 64ENA management interface is exposed by means of:65 66- PCIe Configuration Space67- Device Registers68- Admin Queue (AQ) and Admin Completion Queue (ACQ)69- Asynchronous Event Notification Queue (AENQ)70 71ENA device MMIO Registers are accessed only during driver72initialization and are not used during further normal device73operation.74 75AQ is used for submitting management commands, and the76results/responses are reported asynchronously through ACQ.77 78ENA introduces a small set of management commands with room for79vendor-specific extensions. Most of the management operations are80framed in a generic Get/Set feature command.81 82The following admin queue commands are supported:83 84- Create I/O submission queue85- Create I/O completion queue86- Destroy I/O submission queue87- Destroy I/O completion queue88- Get feature89- Set feature90- Configure AENQ91- Get statistics92 93Refer to ena_admin_defs.h for the list of supported Get/Set Feature94properties.95 96The Asynchronous Event Notification Queue (AENQ) is a uni-directional97queue used by the ENA device to send to the driver events that cannot98be reported using ACQ. AENQ events are subdivided into groups. Each99group may have multiple syndromes, as shown below100 101The events are:102 103==================== ===============104Group Syndrome105==================== ===============106Link state change **X**107Fatal error **X**108Notification Suspend traffic109Notification Resume traffic110Keep-Alive **X**111==================== ===============112 113ACQ and AENQ share the same MSI-X vector.114 115Keep-Alive is a special mechanism that allows monitoring the device's health.116A Keep-Alive event is delivered by the device every second.117The driver maintains a watchdog (WD) handler which logs the current state and118statistics. If the keep-alive events aren't delivered as expected the WD resets119the device and the driver.120 121Data Path Interface122===================123 124I/O operations are based on Tx and Rx Submission Queues (Tx SQ and Rx125SQ correspondingly). Each SQ has a completion queue (CQ) associated126with it.127 128The SQs and CQs are implemented as descriptor rings in contiguous129physical memory.130 131The ENA driver supports two Queue Operation modes for Tx SQs:132 133- **Regular mode:**134 In this mode the Tx SQs reside in the host's memory. The ENA135 device fetches the ENA Tx descriptors and packet data from host136 memory.137 138- **Low Latency Queue (LLQ) mode or "push-mode":**139 In this mode the driver pushes the transmit descriptors and the140 first 96 bytes of the packet directly to the ENA device memory141 space. The rest of the packet payload is fetched by the142 device. For this operation mode, the driver uses a dedicated PCI143 device memory BAR, which is mapped with write-combine capability.144 145 **Note that** not all ENA devices support LLQ, and this feature is negotiated146 with the device upon initialization. If the ENA device does not147 support LLQ mode, the driver falls back to the regular mode.148 149The Rx SQs support only the regular mode.150 151The driver supports multi-queue for both Tx and Rx. This has various152benefits:153 154- Reduced CPU/thread/process contention on a given Ethernet interface.155- Cache miss rate on completion is reduced, particularly for data156 cache lines that hold the sk_buff structures.157- Increased process-level parallelism when handling received packets.158- Increased data cache hit rate, by steering kernel processing of159 packets to the CPU, where the application thread consuming the160 packet is running.161- In hardware interrupt re-direction.162 163Interrupt Modes164===============165 166The driver assigns a single MSI-X vector per queue pair (for both Tx167and Rx directions). The driver assigns an additional dedicated MSI-X vector168for management (for ACQ and AENQ).169 170Management interrupt registration is performed when the Linux kernel171probes the adapter, and it is de-registered when the adapter is172removed. I/O queue interrupt registration is performed when the Linux173interface of the adapter is opened, and it is de-registered when the174interface is closed.175 176The management interrupt is named::177 178 ena-mgmnt@pci:<PCI domain:bus:slot.function>179 180and for each queue pair, an interrupt is named::181 182 <interface name>-Tx-Rx-<queue index>183 184The ENA device operates in auto-mask and auto-clear interrupt185modes. That is, once MSI-X is delivered to the host, its Cause bit is186automatically cleared and the interrupt is masked. The interrupt is187unmasked by the driver after NAPI processing is complete.188 189Interrupt Moderation190====================191 192ENA driver and device can operate in conventional or adaptive interrupt193moderation mode.194 195**In conventional mode** the driver instructs device to postpone interrupt196posting according to static interrupt delay value. The interrupt delay197value can be configured through `ethtool(8)`. The following `ethtool`198parameters are supported by the driver: ``tx-usecs``, ``rx-usecs``199 200**In adaptive interrupt** moderation mode the interrupt delay value is201updated by the driver dynamically and adjusted every NAPI cycle202according to the traffic nature.203 204Adaptive coalescing can be switched on/off through `ethtool(8)`'s205:code:`adaptive_rx on|off` parameter.206 207More information about Adaptive Interrupt Moderation (DIM) can be found in208Documentation/networking/net_dim.rst209 210.. _`RX copybreak`:211 212RX copybreak213============214 215The rx_copybreak is initialized by default to ENA_DEFAULT_RX_COPYBREAK216and can be configured by the ETHTOOL_STUNABLE command of the217SIOCETHTOOL ioctl.218 219This option controls the maximum packet length for which the RX220descriptor it was received on would be recycled. When a packet smaller221than RX copybreak bytes is received, it is copied into a new memory222buffer and the RX descriptor is returned to HW.223 224Statistics225==========226 227The user can obtain ENA device and driver statistics using `ethtool`.228The driver can collect regular or extended statistics (including229per-queue stats) from the device.230 231In addition the driver logs the stats to syslog upon device reset.232 233On supported instance types, the statistics will also include the234ENA Express data (fields prefixed with `ena_srd`). For a complete235documentation of ENA Express data refer to236https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ena-express.html#ena-express-monitor237 238MTU239===240 241The driver supports an arbitrarily large MTU with a maximum that is242negotiated with the device. The driver configures MTU using the243SetFeature command (ENA_ADMIN_MTU property). The user can change MTU244via `ip(8)` and similar legacy tools.245 246Stateless Offloads247==================248 249The ENA driver supports:250 251- IPv4 header checksum offload252- TCP/UDP over IPv4/IPv6 checksum offloads253 254RSS255===256 257- The ENA device supports RSS that allows flexible Rx traffic258 steering.259- Toeplitz and CRC32 hash functions are supported.260- Different combinations of L2/L3/L4 fields can be configured as261 inputs for hash functions.262- The driver configures RSS settings using the AQ SetFeature command263 (ENA_ADMIN_RSS_HASH_FUNCTION, ENA_ADMIN_RSS_HASH_INPUT and264 ENA_ADMIN_RSS_INDIRECTION_TABLE_CONFIG properties).265- If the NETIF_F_RXHASH flag is set, the 32-bit result of the hash266 function delivered in the Rx CQ descriptor is set in the received267 SKB.268- The user can provide a hash key, hash function, and configure the269 indirection table through `ethtool(8)`.270 271DATA PATH272=========273 274Tx275--276 277:code:`ena_start_xmit()` is called by the stack. This function does the following:278 279- Maps data buffers (``skb->data`` and frags).280- Populates ``ena_buf`` for the push buffer (if the driver and device are281 in push mode).282- Prepares ENA bufs for the remaining frags.283- Allocates a new request ID from the empty ``req_id`` ring. The request284 ID is the index of the packet in the Tx info. This is used for285 out-of-order Tx completions.286- Adds the packet to the proper place in the Tx ring.287- Calls :code:`ena_com_prepare_tx()`, an ENA communication layer that converts288 the ``ena_bufs`` to ENA descriptors (and adds meta ENA descriptors as289 needed).290 291 * This function also copies the ENA descriptors and the push buffer292 to the Device memory space (if in push mode).293 294- Writes a doorbell to the ENA device.295- When the ENA device finishes sending the packet, a completion296 interrupt is raised.297- The interrupt handler schedules NAPI.298- The :code:`ena_clean_tx_irq()` function is called. This function handles the299 completion descriptors generated by the ENA, with a single300 completion descriptor per completed packet.301 302 * ``req_id`` is retrieved from the completion descriptor. The ``tx_info`` of303 the packet is retrieved via the ``req_id``. The data buffers are304 unmapped and ``req_id`` is returned to the empty ``req_id`` ring.305 * The function stops when the completion descriptors are completed or306 the budget is reached.307 308Rx309--310 311- When a packet is received from the ENA device.312- The interrupt handler schedules NAPI.313- The :code:`ena_clean_rx_irq()` function is called. This function calls314 :code:`ena_com_rx_pkt()`, an ENA communication layer function, which returns the315 number of descriptors used for a new packet, and zero if316 no new packet is found.317- :code:`ena_rx_skb()` checks packet length:318 319 * If the packet is small (len < rx_copybreak), the driver allocates320 a SKB for the new packet, and copies the packet payload into the321 SKB data buffer.322 323 - In this way the original data buffer is not passed to the stack324 and is reused for future Rx packets.325 326 * Otherwise the function unmaps the Rx buffer, sets the first327 descriptor as `skb`'s linear part and the other descriptors as the328 `skb`'s frags.329 330- The new SKB is updated with the necessary information (protocol,331 checksum hw verify result, etc), and then passed to the network332 stack, using the NAPI interface function :code:`napi_gro_receive()`.333 334Dynamic RX Buffers (DRB)335------------------------336 337Each RX descriptor in the RX ring is a single memory page (which is either 4KB338or 16KB long depending on system's configurations).339To reduce the memory allocations required when dealing with a high rate of small340packets, the driver tries to reuse the remaining RX descriptor's space if more341than 2KB of this page remain unused.342 343A simple example of this mechanism is the following sequence of events:344 345::346 347 1. Driver allocates page-sized RX buffer and passes it to hardware348 +----------------------+349 |4KB RX Buffer |350 +----------------------+351 352 2. A 300Bytes packet is received on this buffer353 354 3. The driver increases the ref count on this page and returns it back to355 HW as an RX buffer of size 4KB - 300Bytes = 3796 Bytes356 +----+--------------------+357 |****|3796 Bytes RX Buffer|358 +----+--------------------+359 360This mechanism isn't used when an XDP program is loaded, or when the361RX packet is less than rx_copybreak bytes (in which case the packet is362copied out of the RX buffer into the linear part of a new skb allocated363for it and the RX buffer remains the same size, see `RX copybreak`_).364