i40e_dcb.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 2013 - 2021 Intel Corporation. */
  3. #ifndef _I40E_DCB_H_
  4. #define _I40E_DCB_H_
  5. #include "i40e_type.h"
  6. #define I40E_DCBX_STATUS_NOT_STARTED 0
  7. #define I40E_DCBX_STATUS_IN_PROGRESS 1
  8. #define I40E_DCBX_STATUS_DONE 2
  9. #define I40E_DCBX_STATUS_MULTIPLE_PEERS 3
  10. #define I40E_DCBX_STATUS_DISABLED 7
  11. #define I40E_TLV_TYPE_END 0
  12. #define I40E_TLV_TYPE_ORG 127
  13. #define I40E_IEEE_8021QAZ_OUI 0x0080C2
  14. #define I40E_IEEE_SUBTYPE_ETS_CFG 9
  15. #define I40E_IEEE_SUBTYPE_ETS_REC 10
  16. #define I40E_IEEE_SUBTYPE_PFC_CFG 11
  17. #define I40E_IEEE_SUBTYPE_APP_PRI 12
  18. #define I40E_CEE_DCBX_OUI 0x001b21
  19. #define I40E_CEE_DCBX_TYPE 2
  20. #define I40E_CEE_SUBTYPE_CTRL 1
  21. #define I40E_CEE_SUBTYPE_PG_CFG 2
  22. #define I40E_CEE_SUBTYPE_PFC_CFG 3
  23. #define I40E_CEE_SUBTYPE_APP_PRI 4
  24. #define I40E_CEE_MAX_FEAT_TYPE 3
  25. #define I40E_LLDP_CURRENT_STATUS_XL710_OFFSET 0x2B
  26. #define I40E_LLDP_CURRENT_STATUS_X722_OFFSET 0x31
  27. #define I40E_LLDP_CURRENT_STATUS_OFFSET 1
  28. #define I40E_LLDP_CURRENT_STATUS_SIZE 1
  29. /* Defines for LLDP TLV header */
  30. #define I40E_LLDP_TLV_LEN_SHIFT 0
  31. #define I40E_LLDP_TLV_LEN_MASK (0x01FF << I40E_LLDP_TLV_LEN_SHIFT)
  32. #define I40E_LLDP_TLV_TYPE_SHIFT 9
  33. #define I40E_LLDP_TLV_TYPE_MASK (0x7F << I40E_LLDP_TLV_TYPE_SHIFT)
  34. #define I40E_LLDP_TLV_SUBTYPE_SHIFT 0
  35. #define I40E_LLDP_TLV_SUBTYPE_MASK (0xFF << I40E_LLDP_TLV_SUBTYPE_SHIFT)
  36. #define I40E_LLDP_TLV_OUI_SHIFT 8
  37. #define I40E_LLDP_TLV_OUI_MASK (0xFFFFFFU << I40E_LLDP_TLV_OUI_SHIFT)
  38. /* Defines for IEEE ETS TLV */
  39. #define I40E_IEEE_ETS_MAXTC_SHIFT 0
  40. #define I40E_IEEE_ETS_MAXTC_MASK (0x7 << I40E_IEEE_ETS_MAXTC_SHIFT)
  41. #define I40E_IEEE_ETS_CBS_SHIFT 6
  42. #define I40E_IEEE_ETS_CBS_MASK BIT(I40E_IEEE_ETS_CBS_SHIFT)
  43. #define I40E_IEEE_ETS_WILLING_SHIFT 7
  44. #define I40E_IEEE_ETS_WILLING_MASK BIT(I40E_IEEE_ETS_WILLING_SHIFT)
  45. #define I40E_IEEE_ETS_PRIO_0_SHIFT 0
  46. #define I40E_IEEE_ETS_PRIO_0_MASK (0x7 << I40E_IEEE_ETS_PRIO_0_SHIFT)
  47. #define I40E_IEEE_ETS_PRIO_1_SHIFT 4
  48. #define I40E_IEEE_ETS_PRIO_1_MASK (0x7 << I40E_IEEE_ETS_PRIO_1_SHIFT)
  49. #define I40E_CEE_PGID_PRIO_0_SHIFT 0
  50. #define I40E_CEE_PGID_PRIO_0_MASK (0xF << I40E_CEE_PGID_PRIO_0_SHIFT)
  51. #define I40E_CEE_PGID_PRIO_1_SHIFT 4
  52. #define I40E_CEE_PGID_PRIO_1_MASK (0xF << I40E_CEE_PGID_PRIO_1_SHIFT)
  53. #define I40E_CEE_PGID_STRICT 15
  54. /* Defines for IEEE TSA types */
  55. #define I40E_IEEE_TSA_STRICT 0
  56. #define I40E_IEEE_TSA_ETS 2
  57. /* Defines for IEEE PFC TLV */
  58. #define I40E_DCB_PFC_ENABLED 2
  59. #define I40E_DCB_PFC_FORCED_NUM_TC 2
  60. #define I40E_IEEE_PFC_CAP_SHIFT 0
  61. #define I40E_IEEE_PFC_CAP_MASK (0xF << I40E_IEEE_PFC_CAP_SHIFT)
  62. #define I40E_IEEE_PFC_MBC_SHIFT 6
  63. #define I40E_IEEE_PFC_MBC_MASK BIT(I40E_IEEE_PFC_MBC_SHIFT)
  64. #define I40E_IEEE_PFC_WILLING_SHIFT 7
  65. #define I40E_IEEE_PFC_WILLING_MASK BIT(I40E_IEEE_PFC_WILLING_SHIFT)
  66. /* Defines for IEEE APP TLV */
  67. #define I40E_IEEE_APP_SEL_SHIFT 0
  68. #define I40E_IEEE_APP_SEL_MASK (0x7 << I40E_IEEE_APP_SEL_SHIFT)
  69. #define I40E_IEEE_APP_PRIO_SHIFT 5
  70. #define I40E_IEEE_APP_PRIO_MASK (0x7 << I40E_IEEE_APP_PRIO_SHIFT)
  71. /* TLV definitions for preparing MIB */
  72. #define I40E_TLV_ID_CHASSIS_ID 0
  73. #define I40E_TLV_ID_PORT_ID 1
  74. #define I40E_TLV_ID_TIME_TO_LIVE 2
  75. #define I40E_IEEE_TLV_ID_ETS_CFG 3
  76. #define I40E_IEEE_TLV_ID_ETS_REC 4
  77. #define I40E_IEEE_TLV_ID_PFC_CFG 5
  78. #define I40E_IEEE_TLV_ID_APP_PRI 6
  79. #define I40E_TLV_ID_END_OF_LLDPPDU 7
  80. #define I40E_TLV_ID_START I40E_IEEE_TLV_ID_ETS_CFG
  81. #define I40E_IEEE_TLV_HEADER_LENGTH 2
  82. #define I40E_IEEE_ETS_TLV_LENGTH 25
  83. #define I40E_IEEE_PFC_TLV_LENGTH 6
  84. #define I40E_IEEE_APP_TLV_LENGTH 11
  85. /* Defines for default SW DCB config */
  86. #define I40E_IEEE_DEFAULT_ETS_TCBW 100
  87. #define I40E_IEEE_DEFAULT_ETS_WILLING 1
  88. #define I40E_IEEE_DEFAULT_PFC_WILLING 1
  89. #define I40E_IEEE_DEFAULT_NUM_APPS 1
  90. #define I40E_IEEE_DEFAULT_APP_PRIO 3
  91. #pragma pack(1)
  92. /* IEEE 802.1AB LLDP Organization specific TLV */
  93. struct i40e_lldp_org_tlv {
  94. __be16 typelength;
  95. __be32 ouisubtype;
  96. u8 tlvinfo[1];
  97. };
  98. struct i40e_cee_tlv_hdr {
  99. __be16 typelen;
  100. u8 operver;
  101. u8 maxver;
  102. };
  103. struct i40e_cee_ctrl_tlv {
  104. struct i40e_cee_tlv_hdr hdr;
  105. __be32 seqno;
  106. __be32 ackno;
  107. };
  108. struct i40e_cee_feat_tlv {
  109. struct i40e_cee_tlv_hdr hdr;
  110. u8 en_will_err; /* Bits: |En|Will|Err|Reserved(5)| */
  111. #define I40E_CEE_FEAT_TLV_ENABLE_MASK 0x80
  112. #define I40E_CEE_FEAT_TLV_WILLING_MASK 0x40
  113. #define I40E_CEE_FEAT_TLV_ERR_MASK 0x20
  114. u8 subtype;
  115. u8 tlvinfo[1];
  116. };
  117. struct i40e_cee_app_prio {
  118. __be16 protocol;
  119. u8 upper_oui_sel; /* Bits: |Upper OUI(6)|Selector(2)| */
  120. #define I40E_CEE_APP_SELECTOR_MASK 0x03
  121. __be16 lower_oui;
  122. u8 prio_map;
  123. };
  124. #pragma pack()
  125. enum i40e_get_fw_lldp_status_resp {
  126. I40E_GET_FW_LLDP_STATUS_DISABLED = 0,
  127. I40E_GET_FW_LLDP_STATUS_ENABLED = 1
  128. };
  129. /* Data structures to pass for SW DCBX */
  130. struct i40e_rx_pb_config {
  131. u32 shared_pool_size;
  132. u32 shared_pool_high_wm;
  133. u32 shared_pool_low_wm;
  134. u32 shared_pool_high_thresh[I40E_MAX_TRAFFIC_CLASS];
  135. u32 shared_pool_low_thresh[I40E_MAX_TRAFFIC_CLASS];
  136. u32 tc_pool_size[I40E_MAX_TRAFFIC_CLASS];
  137. u32 tc_pool_high_wm[I40E_MAX_TRAFFIC_CLASS];
  138. u32 tc_pool_low_wm[I40E_MAX_TRAFFIC_CLASS];
  139. };
  140. enum i40e_dcb_arbiter_mode {
  141. I40E_DCB_ARB_MODE_STRICT_PRIORITY = 0,
  142. I40E_DCB_ARB_MODE_ROUND_ROBIN = 1
  143. };
  144. #define I40E_DCB_DEFAULT_MAX_EXPONENT 0xB
  145. #define I40E_DEFAULT_PAUSE_TIME 0xffff
  146. #define I40E_MAX_FRAME_SIZE 4608 /* 4.5 KB */
  147. #define I40E_DEVICE_RPB_SIZE 968000 /* 968 KB */
  148. /* BitTimes (BT) conversion */
  149. #define I40E_BT2KB(BT) (((BT) + (8 * 1024 - 1)) / (8 * 1024))
  150. #define I40E_B2BT(BT) ((BT) * 8)
  151. #define I40E_BT2B(BT) (((BT) + (8 - 1)) / 8)
  152. /* Max Frame(TC) = MFS(max) + MFS(TC) */
  153. #define I40E_MAX_FRAME_TC(mfs_max, mfs_tc) I40E_B2BT((mfs_max) + (mfs_tc))
  154. /* EEE Tx LPI Exit time in Bit Times */
  155. #define I40E_EEE_TX_LPI_EXIT_TIME 142500
  156. /* PCI Round Trip Time in Bit Times */
  157. #define I40E_PCIRTT_LINK_SPEED_10G 20000
  158. #define I40E_PCIRTT_BYTE_LINK_SPEED_20G 40000
  159. #define I40E_PCIRTT_BYTE_LINK_SPEED_40G 80000
  160. /* PFC Frame Delay Bit Times */
  161. #define I40E_PFC_FRAME_DELAY 672
  162. /* Worst case Cable (10GBase-T) Delay Bit Times */
  163. #define I40E_CABLE_DELAY 5556
  164. /* Higher Layer Delay @10G Bit Times */
  165. #define I40E_HIGHER_LAYER_DELAY_10G 6144
  166. /* Interface Delays in Bit Times */
  167. /* TODO: Add for other link speeds 20G/40G/etc. */
  168. #define I40E_INTERFACE_DELAY_10G_MAC_CONTROL 8192
  169. #define I40E_INTERFACE_DELAY_10G_MAC 8192
  170. #define I40E_INTERFACE_DELAY_10G_RS 8192
  171. #define I40E_INTERFACE_DELAY_XGXS 2048
  172. #define I40E_INTERFACE_DELAY_XAUI 2048
  173. #define I40E_INTERFACE_DELAY_10G_BASEX_PCS 2048
  174. #define I40E_INTERFACE_DELAY_10G_BASER_PCS 3584
  175. #define I40E_INTERFACE_DELAY_LX4_PMD 512
  176. #define I40E_INTERFACE_DELAY_CX4_PMD 512
  177. #define I40E_INTERFACE_DELAY_SERIAL_PMA 512
  178. #define I40E_INTERFACE_DELAY_PMD 512
  179. #define I40E_INTERFACE_DELAY_10G_BASET 25600
  180. /* Hardware RX DCB config related defines */
  181. #define I40E_DCB_1_PORT_THRESHOLD 0xF
  182. #define I40E_DCB_1_PORT_FIFO_SIZE 0x10
  183. #define I40E_DCB_2_PORT_THRESHOLD_LOW_NUM_TC 0xF
  184. #define I40E_DCB_2_PORT_FIFO_SIZE_LOW_NUM_TC 0x10
  185. #define I40E_DCB_2_PORT_THRESHOLD_HIGH_NUM_TC 0xC
  186. #define I40E_DCB_2_PORT_FIFO_SIZE_HIGH_NUM_TC 0x8
  187. #define I40E_DCB_4_PORT_THRESHOLD_LOW_NUM_TC 0x9
  188. #define I40E_DCB_4_PORT_FIFO_SIZE_LOW_NUM_TC 0x8
  189. #define I40E_DCB_4_PORT_THRESHOLD_HIGH_NUM_TC 0x6
  190. #define I40E_DCB_4_PORT_FIFO_SIZE_HIGH_NUM_TC 0x4
  191. #define I40E_DCB_WATERMARK_START_FACTOR 0x2
  192. /* delay values for with 10G BaseT in Bit Times */
  193. #define I40E_INTERFACE_DELAY_10G_COPPER \
  194. (I40E_INTERFACE_DELAY_10G_MAC + (2 * I40E_INTERFACE_DELAY_XAUI) \
  195. + I40E_INTERFACE_DELAY_10G_BASET)
  196. #define I40E_DV_TC(mfs_max, mfs_tc) \
  197. ((2 * I40E_MAX_FRAME_TC(mfs_max, mfs_tc)) \
  198. + I40E_PFC_FRAME_DELAY \
  199. + (2 * I40E_CABLE_DELAY) \
  200. + (2 * I40E_INTERFACE_DELAY_10G_COPPER) \
  201. + I40E_HIGHER_LAYER_DELAY_10G)
  202. static inline u32 I40E_STD_DV_TC(u32 mfs_max, u32 mfs_tc)
  203. {
  204. return I40E_DV_TC(mfs_max, mfs_tc) + I40E_B2BT(mfs_max);
  205. }
  206. /* APIs for SW DCBX */
  207. void i40e_dcb_hw_rx_fifo_config(struct i40e_hw *hw,
  208. enum i40e_dcb_arbiter_mode ets_mode,
  209. enum i40e_dcb_arbiter_mode non_ets_mode,
  210. u32 max_exponent, u8 lltc_map);
  211. void i40e_dcb_hw_rx_cmd_monitor_config(struct i40e_hw *hw,
  212. u8 num_tc, u8 num_ports);
  213. void i40e_dcb_hw_pfc_config(struct i40e_hw *hw,
  214. u8 pfc_en, u8 *prio_tc);
  215. void i40e_dcb_hw_set_num_tc(struct i40e_hw *hw, u8 num_tc);
  216. u8 i40e_dcb_hw_get_num_tc(struct i40e_hw *hw);
  217. void i40e_dcb_hw_rx_ets_bw_config(struct i40e_hw *hw, u8 *bw_share,
  218. u8 *mode, u8 *prio_type);
  219. void i40e_dcb_hw_rx_up2tc_config(struct i40e_hw *hw, u8 *prio_tc);
  220. void i40e_dcb_hw_calculate_pool_sizes(struct i40e_hw *hw,
  221. u8 num_ports, bool eee_enabled,
  222. u8 pfc_en, u32 *mfs_tc,
  223. struct i40e_rx_pb_config *pb_cfg);
  224. void i40e_dcb_hw_rx_pb_config(struct i40e_hw *hw,
  225. struct i40e_rx_pb_config *old_pb_cfg,
  226. struct i40e_rx_pb_config *new_pb_cfg);
  227. int i40e_get_dcbx_status(struct i40e_hw *hw,
  228. u16 *status);
  229. int i40e_lldp_to_dcb_config(u8 *lldpmib,
  230. struct i40e_dcbx_config *dcbcfg);
  231. int i40e_aq_get_dcb_config(struct i40e_hw *hw, u8 mib_type,
  232. u8 bridgetype,
  233. struct i40e_dcbx_config *dcbcfg);
  234. int i40e_get_dcb_config(struct i40e_hw *hw);
  235. int i40e_init_dcb(struct i40e_hw *hw,
  236. bool enable_mib_change);
  237. int
  238. i40e_get_fw_lldp_status(struct i40e_hw *hw,
  239. enum i40e_get_fw_lldp_status_resp *lldp_status);
  240. int i40e_set_dcb_config(struct i40e_hw *hw);
  241. int i40e_dcb_config_to_lldp(u8 *lldpmib, u16 *miblen,
  242. struct i40e_dcbx_config *dcbcfg);
  243. #endif /* _I40E_DCB_H_ */