ena.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ============================================================
  3. Linux kernel driver for Elastic Network Adapter (ENA) family
  4. ============================================================
  5. Overview
  6. ========
  7. ENA is a networking interface designed to make good use of modern CPU
  8. features and system architectures.
  9. The ENA device exposes a lightweight management interface with a
  10. minimal set of memory mapped registers and extendible command set
  11. through an Admin Queue.
  12. The driver supports a range of ENA devices, is link-speed independent
  13. (i.e., the same driver is used for 10GbE, 25GbE, 40GbE, etc), and has
  14. a negotiated and extendible feature set.
  15. Some ENA devices support SR-IOV. This driver is used for both the
  16. SR-IOV Physical Function (PF) and Virtual Function (VF) devices.
  17. ENA devices enable high speed and low overhead network traffic
  18. processing by providing multiple Tx/Rx queue pairs (the maximum number
  19. is advertised by the device via the Admin Queue), a dedicated MSI-X
  20. interrupt vector per Tx/Rx queue pair, adaptive interrupt moderation,
  21. and CPU cacheline optimized data placement.
  22. The ENA driver supports industry standard TCP/IP offload features such as
  23. checksum offload. Receive-side scaling (RSS) is supported for multi-core
  24. scaling.
  25. The ENA driver and its corresponding devices implement health
  26. monitoring mechanisms such as watchdog, enabling the device and driver
  27. to recover in a manner transparent to the application, as well as
  28. debug logs.
  29. Some of the ENA devices support a working mode called Low-latency
  30. Queue (LLQ), which saves several more microseconds.
  31. ENA Source Code Directory Structure
  32. ===================================
  33. ================= ======================================================
  34. ena_com.[ch] Management communication layer. This layer is
  35. responsible for the handling all the management
  36. (admin) communication between the device and the
  37. driver.
  38. ena_eth_com.[ch] Tx/Rx data path.
  39. ena_admin_defs.h Definition of ENA management interface.
  40. ena_eth_io_defs.h Definition of ENA data path interface.
  41. ena_common_defs.h Common definitions for ena_com layer.
  42. ena_regs_defs.h Definition of ENA PCI memory-mapped (MMIO) registers.
  43. ena_netdev.[ch] Main Linux kernel driver.
  44. ena_ethtool.c ethtool callbacks.
  45. ena_xdp.[ch] XDP files
  46. ena_pci_id_tbl.h Supported device IDs.
  47. ena_phc.[ch] PTP hardware clock infrastructure (see `PHC`_ for more info)
  48. ena_devlink.[ch] devlink files.
  49. ena_debugfs.[ch] debugfs files.
  50. ================= ======================================================
  51. Management Interface:
  52. =====================
  53. ENA management interface is exposed by means of:
  54. - PCIe Configuration Space
  55. - Device Registers
  56. - Admin Queue (AQ) and Admin Completion Queue (ACQ)
  57. - Asynchronous Event Notification Queue (AENQ)
  58. ENA device MMIO Registers are accessed only during driver
  59. initialization and are not used during further normal device
  60. operation.
  61. AQ is used for submitting management commands, and the
  62. results/responses are reported asynchronously through ACQ.
  63. ENA introduces a small set of management commands with room for
  64. vendor-specific extensions. Most of the management operations are
  65. framed in a generic Get/Set feature command.
  66. The following admin queue commands are supported:
  67. - Create I/O submission queue
  68. - Create I/O completion queue
  69. - Destroy I/O submission queue
  70. - Destroy I/O completion queue
  71. - Get feature
  72. - Set feature
  73. - Configure AENQ
  74. - Get statistics
  75. Refer to ena_admin_defs.h for the list of supported Get/Set Feature
  76. properties.
  77. The Asynchronous Event Notification Queue (AENQ) is a uni-directional
  78. queue used by the ENA device to send to the driver events that cannot
  79. be reported using ACQ. AENQ events are subdivided into groups. Each
  80. group may have multiple syndromes, as shown below
  81. The events are:
  82. ==================== ===============
  83. Group Syndrome
  84. ==================== ===============
  85. Link state change **X**
  86. Fatal error **X**
  87. Notification Suspend traffic
  88. Notification Resume traffic
  89. Keep-Alive **X**
  90. ==================== ===============
  91. ACQ and AENQ share the same MSI-X vector.
  92. Keep-Alive is a special mechanism that allows monitoring the device's health.
  93. A Keep-Alive event is delivered by the device every second.
  94. The driver maintains a watchdog (WD) handler which logs the current state and
  95. statistics. If the keep-alive events aren't delivered as expected the WD resets
  96. the device and the driver.
  97. Data Path Interface
  98. ===================
  99. I/O operations are based on Tx and Rx Submission Queues (Tx SQ and Rx
  100. SQ correspondingly). Each SQ has a completion queue (CQ) associated
  101. with it.
  102. The SQs and CQs are implemented as descriptor rings in contiguous
  103. physical memory.
  104. The ENA driver supports two Queue Operation modes for Tx SQs:
  105. - **Regular mode:**
  106. In this mode the Tx SQs reside in the host's memory. The ENA
  107. device fetches the ENA Tx descriptors and packet data from host
  108. memory.
  109. - **Low Latency Queue (LLQ) mode or "push-mode":**
  110. In this mode the driver pushes the transmit descriptors and the
  111. first 96 bytes of the packet directly to the ENA device memory
  112. space. The rest of the packet payload is fetched by the
  113. device. For this operation mode, the driver uses a dedicated PCI
  114. device memory BAR, which is mapped with write-combine capability.
  115. **Note that** not all ENA devices support LLQ, and this feature is negotiated
  116. with the device upon initialization. If the ENA device does not
  117. support LLQ mode, the driver falls back to the regular mode.
  118. The Rx SQs support only the regular mode.
  119. The driver supports multi-queue for both Tx and Rx. This has various
  120. benefits:
  121. - Reduced CPU/thread/process contention on a given Ethernet interface.
  122. - Cache miss rate on completion is reduced, particularly for data
  123. cache lines that hold the sk_buff structures.
  124. - Increased process-level parallelism when handling received packets.
  125. - Increased data cache hit rate, by steering kernel processing of
  126. packets to the CPU, where the application thread consuming the
  127. packet is running.
  128. - In hardware interrupt re-direction.
  129. Interrupt Modes
  130. ===============
  131. The driver assigns a single MSI-X vector per queue pair (for both Tx
  132. and Rx directions). The driver assigns an additional dedicated MSI-X vector
  133. for management (for ACQ and AENQ).
  134. Management interrupt registration is performed when the Linux kernel
  135. probes the adapter, and it is de-registered when the adapter is
  136. removed. I/O queue interrupt registration is performed when the Linux
  137. interface of the adapter is opened, and it is de-registered when the
  138. interface is closed.
  139. The management interrupt is named::
  140. ena-mgmnt@pci:<PCI domain:bus:slot.function>
  141. and for each queue pair, an interrupt is named::
  142. <interface name>-Tx-Rx-<queue index>
  143. The ENA device operates in auto-mask and auto-clear interrupt
  144. modes. That is, once MSI-X is delivered to the host, its Cause bit is
  145. automatically cleared and the interrupt is masked. The interrupt is
  146. unmasked by the driver after NAPI processing is complete.
  147. Interrupt Moderation
  148. ====================
  149. ENA driver and device can operate in conventional or adaptive interrupt
  150. moderation mode.
  151. **In conventional mode** the driver instructs device to postpone interrupt
  152. posting according to static interrupt delay value. The interrupt delay
  153. value can be configured through `ethtool(8)`. The following `ethtool`
  154. parameters are supported by the driver: ``tx-usecs``, ``rx-usecs``
  155. **In adaptive interrupt** moderation mode the interrupt delay value is
  156. updated by the driver dynamically and adjusted every NAPI cycle
  157. according to the traffic nature.
  158. Adaptive coalescing can be switched on/off through `ethtool(8)`'s
  159. :code:`adaptive_rx on|off` parameter.
  160. More information about Adaptive Interrupt Moderation (DIM) can be found in
  161. Documentation/networking/net_dim.rst
  162. .. _`RX copybreak`:
  163. RX copybreak
  164. ============
  165. The rx_copybreak is initialized by default to ENA_DEFAULT_RX_COPYBREAK
  166. and can be configured by the ETHTOOL_STUNABLE command of the
  167. SIOCETHTOOL ioctl.
  168. This option controls the maximum packet length for which the RX
  169. descriptor it was received on would be recycled. When a packet smaller
  170. than RX copybreak bytes is received, it is copied into a new memory
  171. buffer and the RX descriptor is returned to HW.
  172. .. _`PHC`:
  173. PTP Hardware Clock (PHC)
  174. ========================
  175. .. _`ptp-userspace-api`: https://docs.kernel.org/driver-api/ptp.html#ptp-hardware-clock-user-space-api
  176. .. _`testptp`: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/ptp/testptp.c
  177. ENA Linux driver supports PTP hardware clock providing timestamp reference to achieve nanosecond resolution.
  178. **PHC support**
  179. PHC depends on the PTP module, which needs to be either loaded as a module or compiled into the kernel.
  180. Verify if the PTP module is present:
  181. .. code-block:: shell
  182. grep -w '^CONFIG_PTP_1588_CLOCK=[ym]' /boot/config-`uname -r`
  183. - If no output is provided, the ENA driver cannot be loaded with PHC support.
  184. **PHC activation**
  185. The feature is turned off by default, in order to turn the feature on, the ENA driver
  186. can be loaded in the following way:
  187. - devlink:
  188. .. code-block:: shell
  189. sudo devlink dev param set pci/<domain:bus:slot.function> name enable_phc value true cmode driverinit
  190. sudo devlink dev reload pci/<domain:bus:slot.function>
  191. # for example:
  192. sudo devlink dev param set pci/0000:00:06.0 name enable_phc value true cmode driverinit
  193. sudo devlink dev reload pci/0000:00:06.0
  194. All available PTP clock sources can be tracked here:
  195. .. code-block:: shell
  196. ls /sys/class/ptp
  197. PHC support and capabilities can be verified using ethtool:
  198. .. code-block:: shell
  199. ethtool -T <interface>
  200. **PHC timestamp**
  201. To retrieve PHC timestamp, use `ptp-userspace-api`_, usage example using `testptp`_:
  202. .. code-block:: shell
  203. testptp -d /dev/ptp$(ethtool -T <interface> | awk '/PTP Hardware Clock:/ {print $NF}') -k 1
  204. PHC get time requests should be within reasonable bounds,
  205. avoid excessive utilization to ensure optimal performance and efficiency.
  206. The ENA device restricts the frequency of PHC get time requests to a maximum
  207. of 125 requests per second. If this limit is surpassed, the get time request
  208. will fail, leading to an increment in the phc_err_ts statistic.
  209. **PHC statistics**
  210. PHC can be monitored using debugfs (if mounted):
  211. .. code-block:: shell
  212. sudo cat /sys/kernel/debug/<domain:bus:slot.function>/phc_stats
  213. # for example:
  214. sudo cat /sys/kernel/debug/0000:00:06.0/phc_stats
  215. PHC errors must remain below 1% of all PHC requests to maintain the desired level of accuracy and reliability
  216. ================= ======================================================
  217. **phc_cnt** | Number of successful retrieved timestamps (below expire timeout).
  218. **phc_exp** | Number of expired retrieved timestamps (above expire timeout).
  219. **phc_skp** | Number of skipped get time attempts (during block period).
  220. **phc_err_dv** | Number of failed get time attempts due to device errors (entering into block state).
  221. **phc_err_ts** | Number of failed get time attempts due to timestamp errors (entering into block state),
  222. | This occurs if driver exceeded the request limit or device received an invalid timestamp.
  223. ================= ======================================================
  224. PHC timeouts:
  225. ================= ======================================================
  226. **expire** | Max time for a valid timestamp retrieval, passing this threshold will fail
  227. | the get time request and block new requests until block timeout.
  228. **block** | Blocking period starts once get time request expires or fails,
  229. | all get time requests during block period will be skipped.
  230. ================= ======================================================
  231. Statistics
  232. ==========
  233. The user can obtain ENA device and driver statistics using `ethtool`.
  234. The driver can collect regular or extended statistics (including
  235. per-queue stats) from the device.
  236. In addition the driver logs the stats to syslog upon device reset.
  237. On supported instance types, the statistics will also include the
  238. ENA Express data (fields prefixed with `ena_srd`). For a complete
  239. documentation of ENA Express data refer to
  240. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ena-express.html#ena-express-monitor
  241. MTU
  242. ===
  243. The driver supports an arbitrarily large MTU with a maximum that is
  244. negotiated with the device. The driver configures MTU using the
  245. SetFeature command (ENA_ADMIN_MTU property). The user can change MTU
  246. via `ip(8)` and similar legacy tools.
  247. Stateless Offloads
  248. ==================
  249. The ENA driver supports:
  250. - IPv4 header checksum offload
  251. - TCP/UDP over IPv4/IPv6 checksum offloads
  252. RSS
  253. ===
  254. - The ENA device supports RSS that allows flexible Rx traffic
  255. steering.
  256. - Toeplitz and CRC32 hash functions are supported.
  257. - Different combinations of L2/L3/L4 fields can be configured as
  258. inputs for hash functions.
  259. - The driver configures RSS settings using the AQ SetFeature command
  260. (ENA_ADMIN_RSS_HASH_FUNCTION, ENA_ADMIN_RSS_HASH_INPUT and
  261. ENA_ADMIN_RSS_INDIRECTION_TABLE_CONFIG properties).
  262. - If the NETIF_F_RXHASH flag is set, the 32-bit result of the hash
  263. function delivered in the Rx CQ descriptor is set in the received
  264. SKB.
  265. - The user can provide a hash key, hash function, and configure the
  266. indirection table through `ethtool(8)`.
  267. DEVLINK SUPPORT
  268. ===============
  269. .. _`devlink`: https://www.kernel.org/doc/html/latest/networking/devlink/index.html
  270. `devlink`_ supports reloading the driver and initiating re-negotiation with the ENA device
  271. .. code-block:: shell
  272. sudo devlink dev reload pci/<domain:bus:slot.function>
  273. # for example:
  274. sudo devlink dev reload pci/0000:00:06.0
  275. DATA PATH
  276. =========
  277. Tx
  278. --
  279. :code:`ena_start_xmit()` is called by the stack. This function does the following:
  280. - Maps data buffers (``skb->data`` and frags).
  281. - Populates ``ena_buf`` for the push buffer (if the driver and device are
  282. in push mode).
  283. - Prepares ENA bufs for the remaining frags.
  284. - Allocates a new request ID from the empty ``req_id`` ring. The request
  285. ID is the index of the packet in the Tx info. This is used for
  286. out-of-order Tx completions.
  287. - Adds the packet to the proper place in the Tx ring.
  288. - Calls :code:`ena_com_prepare_tx()`, an ENA communication layer that converts
  289. the ``ena_bufs`` to ENA descriptors (and adds meta ENA descriptors as
  290. needed).
  291. * This function also copies the ENA descriptors and the push buffer
  292. to the Device memory space (if in push mode).
  293. - Writes a doorbell to the ENA device.
  294. - When the ENA device finishes sending the packet, a completion
  295. interrupt is raised.
  296. - The interrupt handler schedules NAPI.
  297. - The :code:`ena_clean_tx_irq()` function is called. This function handles the
  298. completion descriptors generated by the ENA, with a single
  299. completion descriptor per completed packet.
  300. * ``req_id`` is retrieved from the completion descriptor. The ``tx_info`` of
  301. the packet is retrieved via the ``req_id``. The data buffers are
  302. unmapped and ``req_id`` is returned to the empty ``req_id`` ring.
  303. * The function stops when the completion descriptors are completed or
  304. the budget is reached.
  305. Rx
  306. --
  307. - When a packet is received from the ENA device.
  308. - The interrupt handler schedules NAPI.
  309. - The :code:`ena_clean_rx_irq()` function is called. This function calls
  310. :code:`ena_com_rx_pkt()`, an ENA communication layer function, which returns the
  311. number of descriptors used for a new packet, and zero if
  312. no new packet is found.
  313. - :code:`ena_rx_skb()` checks packet length:
  314. * If the packet is small (len < rx_copybreak), the driver allocates
  315. a SKB for the new packet, and copies the packet payload into the
  316. SKB data buffer.
  317. - In this way the original data buffer is not passed to the stack
  318. and is reused for future Rx packets.
  319. * Otherwise the function unmaps the Rx buffer, sets the first
  320. descriptor as `skb`'s linear part and the other descriptors as the
  321. `skb`'s frags.
  322. - The new SKB is updated with the necessary information (protocol,
  323. checksum hw verify result, etc), and then passed to the network
  324. stack, using the NAPI interface function :code:`napi_gro_receive()`.
  325. Dynamic RX Buffers (DRB)
  326. ------------------------
  327. Each RX descriptor in the RX ring is a single memory page (which is either 4KB
  328. or 16KB long depending on system's configurations).
  329. To reduce the memory allocations required when dealing with a high rate of small
  330. packets, the driver tries to reuse the remaining RX descriptor's space if more
  331. than 2KB of this page remain unused.
  332. A simple example of this mechanism is the following sequence of events:
  333. ::
  334. 1. Driver allocates page-sized RX buffer and passes it to hardware
  335. +----------------------+
  336. |4KB RX Buffer |
  337. +----------------------+
  338. 2. A 300Bytes packet is received on this buffer
  339. 3. The driver increases the ref count on this page and returns it back to
  340. HW as an RX buffer of size 4KB - 300Bytes = 3796 Bytes
  341. +----+--------------------+
  342. |****|3796 Bytes RX Buffer|
  343. +----+--------------------+
  344. This mechanism isn't used when an XDP program is loaded, or when the
  345. RX packet is less than rx_copybreak bytes (in which case the packet is
  346. copied out of the RX buffer into the linear part of a new skb allocated
  347. for it and the RX buffer remains the same size, see `RX copybreak`_).