ena.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. Linux kernel driver for Elastic Network Adapter (ENA) family:
  2. =============================================================
  3. Overview:
  4. =========
  5. ENA is a networking interface designed to make good use of modern CPU
  6. features and system architectures.
  7. The ENA device exposes a lightweight management interface with a
  8. minimal set of memory mapped registers and extendable command set
  9. through an Admin Queue.
  10. The driver supports a range of ENA devices, is link-speed independent
  11. (i.e., the same driver is used for 10GbE, 25GbE, 40GbE, etc.), and has
  12. a negotiated and extendable feature set.
  13. Some ENA devices support SR-IOV. This driver is used for both the
  14. SR-IOV Physical Function (PF) and Virtual Function (VF) devices.
  15. ENA devices enable high speed and low overhead network traffic
  16. processing by providing multiple Tx/Rx queue pairs (the maximum number
  17. is advertised by the device via the Admin Queue), a dedicated MSI-X
  18. interrupt vector per Tx/Rx queue pair, adaptive interrupt moderation,
  19. and CPU cacheline optimized data placement.
  20. The ENA driver supports industry standard TCP/IP offload features such
  21. as checksum offload and TCP transmit segmentation offload (TSO).
  22. Receive-side scaling (RSS) is supported for multi-core scaling.
  23. The ENA driver and its corresponding devices implement health
  24. monitoring mechanisms such as watchdog, enabling the device and driver
  25. to recover in a manner transparent to the application, as well as
  26. debug logs.
  27. Some of the ENA devices support a working mode called Low-latency
  28. Queue (LLQ), which saves several more microseconds.
  29. Supported PCI vendor ID/device IDs:
  30. ===================================
  31. 1d0f:0ec2 - ENA PF
  32. 1d0f:1ec2 - ENA PF with LLQ support
  33. 1d0f:ec20 - ENA VF
  34. 1d0f:ec21 - ENA VF with LLQ support
  35. ENA Source Code Directory Structure:
  36. ====================================
  37. ena_com.[ch] - Management communication layer. This layer is
  38. responsible for the handling all the management
  39. (admin) communication between the device and the
  40. driver.
  41. ena_eth_com.[ch] - Tx/Rx data path.
  42. ena_admin_defs.h - Definition of ENA management interface.
  43. ena_eth_io_defs.h - Definition of ENA data path interface.
  44. ena_common_defs.h - Common definitions for ena_com layer.
  45. ena_regs_defs.h - Definition of ENA PCI memory-mapped (MMIO) registers.
  46. ena_netdev.[ch] - Main Linux kernel driver.
  47. ena_syfsfs.[ch] - Sysfs files.
  48. ena_ethtool.c - ethtool callbacks.
  49. ena_pci_id_tbl.h - Supported device IDs.
  50. Management Interface:
  51. =====================
  52. ENA management interface is exposed by means of:
  53. - PCIe Configuration Space
  54. - Device Registers
  55. - Admin Queue (AQ) and Admin Completion Queue (ACQ)
  56. - Asynchronous Event Notification Queue (AENQ)
  57. ENA device MMIO Registers are accessed only during driver
  58. initialization and are not involved in further normal device
  59. operation.
  60. AQ is used for submitting management commands, and the
  61. results/responses are reported asynchronously through ACQ.
  62. ENA introduces a very small set of management commands with room for
  63. vendor-specific extensions. Most of the management operations are
  64. framed in a generic Get/Set feature command.
  65. The following admin queue commands are supported:
  66. - Create I/O submission queue
  67. - Create I/O completion queue
  68. - Destroy I/O submission queue
  69. - Destroy I/O completion queue
  70. - Get feature
  71. - Set feature
  72. - Configure AENQ
  73. - Get statistics
  74. Refer to ena_admin_defs.h for the list of supported Get/Set Feature
  75. properties.
  76. The Asynchronous Event Notification Queue (AENQ) is a uni-directional
  77. queue used by the ENA device to send to the driver events that cannot
  78. be reported using ACQ. AENQ events are subdivided into groups. Each
  79. group may have multiple syndromes, as shown below
  80. The events are:
  81. Group Syndrome
  82. Link state change - X -
  83. Fatal error - X -
  84. Notification Suspend traffic
  85. Notification Resume traffic
  86. Keep-Alive - X -
  87. ACQ and AENQ share the same MSI-X vector.
  88. Keep-Alive is a special mechanism that allows monitoring of the
  89. device's health. The driver maintains a watchdog (WD) handler which,
  90. if fired, logs the current state and statistics then resets and
  91. restarts the ENA device and driver. A Keep-Alive event is delivered by
  92. the device every second. The driver re-arms the WD upon reception of a
  93. Keep-Alive event. A missed Keep-Alive event causes the WD handler to
  94. fire.
  95. Data Path Interface:
  96. ====================
  97. I/O operations are based on Tx and Rx Submission Queues (Tx SQ and Rx
  98. SQ correspondingly). Each SQ has a completion queue (CQ) associated
  99. with it.
  100. The SQs and CQs are implemented as descriptor rings in contiguous
  101. physical memory.
  102. The ENA driver supports two Queue Operation modes for Tx SQs:
  103. - Regular mode
  104. * In this mode the Tx SQs reside in the host's memory. The ENA
  105. device fetches the ENA Tx descriptors and packet data from host
  106. memory.
  107. - Low Latency Queue (LLQ) mode or "push-mode".
  108. * In this mode the driver pushes the transmit descriptors and the
  109. first 128 bytes of the packet directly to the ENA device memory
  110. space. The rest of the packet payload is fetched by the
  111. device. For this operation mode, the driver uses a dedicated PCI
  112. device memory BAR, which is mapped with write-combine capability.
  113. The Rx SQs support only the regular mode.
  114. Note: Not all ENA devices support LLQ, and this feature is negotiated
  115. with the device upon initialization. If the ENA device does not
  116. support LLQ mode, the driver falls back to the regular mode.
  117. The driver supports multi-queue for both Tx and Rx. This has various
  118. benefits:
  119. - Reduced CPU/thread/process contention on a given Ethernet interface.
  120. - Cache miss rate on completion is reduced, particularly for data
  121. cache lines that hold the sk_buff structures.
  122. - Increased process-level parallelism when handling received packets.
  123. - Increased data cache hit rate, by steering kernel processing of
  124. packets to the CPU, where the application thread consuming the
  125. packet is running.
  126. - In hardware interrupt re-direction.
  127. Interrupt Modes:
  128. ================
  129. The driver assigns a single MSI-X vector per queue pair (for both Tx
  130. and Rx directions). The driver assigns an additional dedicated MSI-X vector
  131. for management (for ACQ and AENQ).
  132. Management interrupt registration is performed when the Linux kernel
  133. probes the adapter, and it is de-registered when the adapter is
  134. removed. I/O queue interrupt registration is performed when the Linux
  135. interface of the adapter is opened, and it is de-registered when the
  136. interface is closed.
  137. The management interrupt is named:
  138. ena-mgmnt@pci:<PCI domain:bus:slot.function>
  139. and for each queue pair, an interrupt is named:
  140. <interface name>-Tx-Rx-<queue index>
  141. The ENA device operates in auto-mask and auto-clear interrupt
  142. modes. That is, once MSI-X is delivered to the host, its Cause bit is
  143. automatically cleared and the interrupt is masked. The interrupt is
  144. unmasked by the driver after NAPI processing is complete.
  145. Interrupt Moderation:
  146. =====================
  147. ENA driver and device can operate in conventional or adaptive interrupt
  148. moderation mode.
  149. In conventional mode the driver instructs device to postpone interrupt
  150. posting according to static interrupt delay value. The interrupt delay
  151. value can be configured through ethtool(8). The following ethtool
  152. parameters are supported by the driver: tx-usecs, rx-usecs
  153. In adaptive interrupt moderation mode the interrupt delay value is
  154. updated by the driver dynamically and adjusted every NAPI cycle
  155. according to the traffic nature.
  156. By default ENA driver applies adaptive coalescing on Rx traffic and
  157. conventional coalescing on Tx traffic.
  158. Adaptive coalescing can be switched on/off through ethtool(8)
  159. adaptive_rx on|off parameter.
  160. The driver chooses interrupt delay value according to the number of
  161. bytes and packets received between interrupt unmasking and interrupt
  162. posting. The driver uses interrupt delay table that subdivides the
  163. range of received bytes/packets into 5 levels and assigns interrupt
  164. delay value to each level.
  165. The user can enable/disable adaptive moderation, modify the interrupt
  166. delay table and restore its default values through sysfs.
  167. The rx_copybreak is initialized by default to ENA_DEFAULT_RX_COPYBREAK
  168. and can be configured by the ETHTOOL_STUNABLE command of the
  169. SIOCETHTOOL ioctl.
  170. SKB:
  171. The driver-allocated SKB for frames received from Rx handling using
  172. NAPI context. The allocation method depends on the size of the packet.
  173. If the frame length is larger than rx_copybreak, napi_get_frags()
  174. is used, otherwise netdev_alloc_skb_ip_align() is used, the buffer
  175. content is copied (by CPU) to the SKB, and the buffer is recycled.
  176. Statistics:
  177. ===========
  178. The user can obtain ENA device and driver statistics using ethtool.
  179. The driver can collect regular or extended statistics (including
  180. per-queue stats) from the device.
  181. In addition the driver logs the stats to syslog upon device reset.
  182. MTU:
  183. ====
  184. The driver supports an arbitrarily large MTU with a maximum that is
  185. negotiated with the device. The driver configures MTU using the
  186. SetFeature command (ENA_ADMIN_MTU property). The user can change MTU
  187. via ip(8) and similar legacy tools.
  188. Stateless Offloads:
  189. ===================
  190. The ENA driver supports:
  191. - TSO over IPv4/IPv6
  192. - TSO with ECN
  193. - IPv4 header checksum offload
  194. - TCP/UDP over IPv4/IPv6 checksum offloads
  195. RSS:
  196. ====
  197. - The ENA device supports RSS that allows flexible Rx traffic
  198. steering.
  199. - Toeplitz and CRC32 hash functions are supported.
  200. - Different combinations of L2/L3/L4 fields can be configured as
  201. inputs for hash functions.
  202. - The driver configures RSS settings using the AQ SetFeature command
  203. (ENA_ADMIN_RSS_HASH_FUNCTION, ENA_ADMIN_RSS_HASH_INPUT and
  204. ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG properties).
  205. - If the NETIF_F_RXHASH flag is set, the 32-bit result of the hash
  206. function delivered in the Rx CQ descriptor is set in the received
  207. SKB.
  208. - The user can provide a hash key, hash function, and configure the
  209. indirection table through ethtool(8).
  210. DATA PATH:
  211. ==========
  212. Tx:
  213. ---
  214. end_start_xmit() is called by the stack. This function does the following:
  215. - Maps data buffers (skb->data and frags).
  216. - Populates ena_buf for the push buffer (if the driver and device are
  217. in push mode.)
  218. - Prepares ENA bufs for the remaining frags.
  219. - Allocates a new request ID from the empty req_id ring. The request
  220. ID is the index of the packet in the Tx info. This is used for
  221. out-of-order TX completions.
  222. - Adds the packet to the proper place in the Tx ring.
  223. - Calls ena_com_prepare_tx(), an ENA communication layer that converts
  224. the ena_bufs to ENA descriptors (and adds meta ENA descriptors as
  225. needed.)
  226. * This function also copies the ENA descriptors and the push buffer
  227. to the Device memory space (if in push mode.)
  228. - Writes doorbell to the ENA device.
  229. - When the ENA device finishes sending the packet, a completion
  230. interrupt is raised.
  231. - The interrupt handler schedules NAPI.
  232. - The ena_clean_tx_irq() function is called. This function handles the
  233. completion descriptors generated by the ENA, with a single
  234. completion descriptor per completed packet.
  235. * req_id is retrieved from the completion descriptor. The tx_info of
  236. the packet is retrieved via the req_id. The data buffers are
  237. unmapped and req_id is returned to the empty req_id ring.
  238. * The function stops when the completion descriptors are completed or
  239. the budget is reached.
  240. Rx:
  241. ---
  242. - When a packet is received from the ENA device.
  243. - The interrupt handler schedules NAPI.
  244. - The ena_clean_rx_irq() function is called. This function calls
  245. ena_rx_pkt(), an ENA communication layer function, which returns the
  246. number of descriptors used for a new unhandled packet, and zero if
  247. no new packet is found.
  248. - Then it calls the ena_clean_rx_irq() function.
  249. - ena_eth_rx_skb() checks packet length:
  250. * If the packet is small (len < rx_copybreak), the driver allocates
  251. a SKB for the new packet, and copies the packet payload into the
  252. SKB data buffer.
  253. - In this way the original data buffer is not passed to the stack
  254. and is reused for future Rx packets.
  255. * Otherwise the function unmaps the Rx buffer, then allocates the
  256. new SKB structure and hooks the Rx buffer to the SKB frags.
  257. - The new SKB is updated with the necessary information (protocol,
  258. checksum hw verify result, etc.), and then passed to the network
  259. stack, using the NAPI interface function napi_gro_receive().