devlink-dpipe.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =============
  3. Devlink DPIPE
  4. =============
  5. Background
  6. ==========
  7. While performing the hardware offloading process, much of the hardware
  8. specifics cannot be presented. These details are useful for debugging, and
  9. ``devlink-dpipe`` provides a standardized way to provide visibility into the
  10. offloading process.
  11. For example, the routing longest prefix match (LPM) algorithm used by the
  12. Linux kernel may differ from the hardware implementation. The pipeline debug
  13. API (DPIPE) is aimed at providing the user visibility into the ASIC's
  14. pipeline in a generic way.
  15. The hardware offload process is expected to be done in a way that the user
  16. should not be able to distinguish between the hardware vs. software
  17. implementation. In this process, hardware specifics are neglected. In
  18. reality those details can have lots of meaning and should be exposed in some
  19. standard way.
  20. This problem is made even more complex when one wishes to offload the
  21. control path of the whole networking stack to a switch ASIC. Due to
  22. differences in the hardware and software models some processes cannot be
  23. represented correctly.
  24. One example is the kernel's LPM algorithm which in many cases differs
  25. greatly to the hardware implementation. The configuration API is the same,
  26. but one cannot rely on the Forward Information Base (FIB) to look like the
  27. Level Path Compression trie (LPC-trie) in hardware.
  28. In many situations trying to analyze systems failure solely based on the
  29. kernel's dump may not be enough. By combining this data with complementary
  30. information about the underlying hardware, this debugging can be made
  31. easier; additionally, the information can be useful when debugging
  32. performance issues.
  33. Overview
  34. ========
  35. The ``devlink-dpipe`` interface closes this gap. The hardware's pipeline is
  36. modeled as a graph of match/action tables. Each table represents a specific
  37. hardware block. This model is not new, first being used by the P4 language.
  38. Traditionally it has been used as an alternative model for hardware
  39. configuration, but the ``devlink-dpipe`` interface uses it for visibility
  40. purposes as a standard complementary tool. The system's view from
  41. ``devlink-dpipe`` should change according to the changes done by the
  42. standard configuration tools.
  43. For example, it’s quite common to implement Access Control Lists (ACL)
  44. using Ternary Content Addressable Memory (TCAM). The TCAM memory can be
  45. divided into TCAM regions. Complex TC filters can have multiple rules with
  46. different priorities and different lookup keys. On the other hand hardware
  47. TCAM regions have a predefined lookup key. Offloading the TC filter rules
  48. using TCAM engine can result in multiple TCAM regions being interconnected
  49. in a chain (which may affect the data path latency). In response to a new TC
  50. filter new tables should be created describing those regions.
  51. Model
  52. =====
  53. The ``DPIPE`` model introduces several objects:
  54. * headers
  55. * tables
  56. * entries
  57. A ``header`` describes packet formats and provides names for fields within
  58. the packet. A ``table`` describes hardware blocks. An ``entry`` describes
  59. the actual content of a specific table.
  60. The hardware pipeline is not port specific, but rather describes the whole
  61. ASIC. Thus it is tied to the top of the ``devlink`` infrastructure.
  62. Drivers can register and unregister tables at run time, in order to support
  63. dynamic behavior. This dynamic behavior is mandatory for describing hardware
  64. blocks like TCAM regions which can be allocated and freed dynamically.
  65. ``devlink-dpipe`` generally is not intended for configuration. The exception
  66. is hardware counting for a specific table.
  67. The following commands are used to obtain the ``dpipe`` objects from
  68. userspace:
  69. * ``table_get``: Receive a table's description.
  70. * ``headers_get``: Receive a device's supported headers.
  71. * ``entries_get``: Receive a table's current entries.
  72. * ``counters_set``: Enable or disable counters on a table.
  73. Table
  74. -----
  75. The driver should implement the following operations for each table:
  76. * ``matches_dump``: Dump the supported matches.
  77. * ``actions_dump``: Dump the supported actions.
  78. * ``entries_dump``: Dump the actual content of the table.
  79. * ``counters_set_update``: Synchronize hardware with counters enabled or
  80. disabled.
  81. Header/Field
  82. ------------
  83. In a similar way to P4 headers and fields are used to describe a table's
  84. behavior. There is a slight difference between the standard protocol headers
  85. and specific ASIC metadata. The protocol headers should be declared in the
  86. ``devlink`` core API. On the other hand ASIC meta data is driver specific
  87. and should be defined in the driver. Additionally, each driver-specific
  88. devlink documentation file should document the driver-specific ``dpipe``
  89. headers it implements. The headers and fields are identified by enumeration.
  90. In order to provide further visibility some ASIC metadata fields could be
  91. mapped to kernel objects. For example, internal router interface indexes can
  92. be directly mapped to the net device ifindex. FIB table indexes used by
  93. different Virtual Routing and Forwarding (VRF) tables can be mapped to
  94. internal routing table indexes.
  95. Match
  96. -----
  97. Matches are kept primitive and close to hardware operation. Match types like
  98. LPM are not supported due to the fact that this is exactly a process we wish
  99. to describe in full detail. Example of matches:
  100. * ``field_exact``: Exact match on a specific field.
  101. * ``field_exact_mask``: Exact match on a specific field after masking.
  102. * ``field_range``: Match on a specific range.
  103. The id's of the header and the field should be specified in order to
  104. identify the specific field. Furthermore, the header index should be
  105. specified in order to distinguish multiple headers of the same type in a
  106. packet (tunneling).
  107. Action
  108. ------
  109. Similar to match, the actions are kept primitive and close to hardware
  110. operation. For example:
  111. * ``field_modify``: Modify the field value.
  112. * ``field_inc``: Increment the field value.
  113. * ``push_header``: Add a header.
  114. * ``pop_header``: Remove a header.
  115. Entry
  116. -----
  117. Entries of a specific table can be dumped on demand. Each eentry is
  118. identified with an index and its properties are described by a list of
  119. match/action values and specific counter. By dumping the tables content the
  120. interactions between tables can be resolved.
  121. Abstraction Example
  122. ===================
  123. The following is an example of the abstraction model of the L3 part of
  124. Mellanox Spectrum ASIC. The blocks are described in the order they appear in
  125. the pipeline. The table sizes in the following examples are not real
  126. hardware sizes and are provided for demonstration purposes.
  127. LPM
  128. ---
  129. The LPM algorithm can be implemented as a list of hash tables. Each hash
  130. table contains routes with the same prefix length. The root of the list is
  131. /32, and in case of a miss the hardware will continue to the next hash
  132. table. The depth of the search will affect the data path latency.
  133. In case of a hit the entry contains information about the next stage of the
  134. pipeline which resolves the MAC address. The next stage can be either local
  135. host table for directly connected routes, or adjacency table for next-hops.
  136. The ``meta.lpm_prefix`` field is used to connect two LPM tables.
  137. .. code::
  138. table lpm_prefix_16 {
  139. size: 4096,
  140. counters_enabled: true,
  141. match: { meta.vr_id: exact,
  142. ipv4.dst_addr: exact_mask,
  143. ipv6.dst_addr: exact_mask,
  144. meta.lpm_prefix: exact },
  145. action: { meta.adj_index: set,
  146. meta.adj_group_size: set,
  147. meta.rif_port: set,
  148. meta.lpm_prefix: set },
  149. }
  150. Local Host
  151. ----------
  152. In the case of local routes the LPM lookup already resolves the egress
  153. router interface (RIF), yet the exact MAC address is not known. The local
  154. host table is a hash table combining the output interface id with
  155. destination IP address as a key. The result is the MAC address.
  156. .. code::
  157. table local_host {
  158. size: 4096,
  159. counters_enabled: true,
  160. match: { meta.rif_port: exact,
  161. ipv4.dst_addr: exact},
  162. action: { ethernet.daddr: set }
  163. }
  164. Adjacency
  165. ---------
  166. In case of remote routes this table does the ECMP. The LPM lookup results in
  167. ECMP group size and index that serves as a global offset into this table.
  168. Concurrently a hash of the packet is generated. Based on the ECMP group size
  169. and the packet's hash a local offset is generated. Multiple LPM entries can
  170. point to the same adjacency group.
  171. .. code::
  172. table adjacency {
  173. size: 4096,
  174. counters_enabled: true,
  175. match: { meta.adj_index: exact,
  176. meta.adj_group_size: exact,
  177. meta.packet_hash_index: exact },
  178. action: { ethernet.daddr: set,
  179. meta.erif: set }
  180. }
  181. ERIF
  182. ----
  183. In case the egress RIF and destination MAC have been resolved by previous
  184. tables this table does multiple operations like TTL decrease and MTU check.
  185. Then the decision of forward/drop is taken and the port L3 statistics are
  186. updated based on the packet's type (broadcast, unicast, multicast).
  187. .. code::
  188. table erif {
  189. size: 800,
  190. counters_enabled: true,
  191. match: { meta.rif_port: exact,
  192. meta.is_l3_unicast: exact,
  193. meta.is_l3_broadcast: exact,
  194. meta.is_l3_multicast, exact },
  195. action: { meta.l3_drop: set,
  196. meta.l3_forward: set }
  197. }