ixgbe_dcb_82599.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #include "ixgbe.h"
  4. #include "ixgbe_type.h"
  5. #include "ixgbe_dcb.h"
  6. #include "ixgbe_dcb_82599.h"
  7. /**
  8. * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter
  9. * @hw: pointer to hardware structure
  10. * @refill: refill credits index by traffic class
  11. * @max: max credits index by traffic class
  12. * @bwg_id: bandwidth grouping indexed by traffic class
  13. * @prio_type: priority type indexed by traffic class
  14. * @prio_tc: priority to tc assignments indexed by priority
  15. *
  16. * Configure Rx Packet Arbiter and credits for each traffic class.
  17. */
  18. s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw,
  19. u16 *refill,
  20. u16 *max,
  21. u8 *bwg_id,
  22. u8 *prio_type,
  23. u8 *prio_tc)
  24. {
  25. u32 reg = 0;
  26. u32 credit_refill = 0;
  27. u32 credit_max = 0;
  28. u8 i = 0;
  29. /*
  30. * Disable the arbiter before changing parameters
  31. * (always enable recycle mode; WSP)
  32. */
  33. reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC | IXGBE_RTRPCS_ARBDIS;
  34. IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
  35. /* Map all traffic classes to their UP */
  36. reg = 0;
  37. for (i = 0; i < MAX_USER_PRIORITY; i++)
  38. reg |= (prio_tc[i] << (i * IXGBE_RTRUP2TC_UP_SHIFT));
  39. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  40. /* Configure traffic class credits and priority */
  41. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  42. credit_refill = refill[i];
  43. credit_max = max[i];
  44. reg = credit_refill | (credit_max << IXGBE_RTRPT4C_MCL_SHIFT);
  45. reg |= (u32)(bwg_id[i]) << IXGBE_RTRPT4C_BWG_SHIFT;
  46. if (prio_type[i] == prio_link)
  47. reg |= IXGBE_RTRPT4C_LSP;
  48. IXGBE_WRITE_REG(hw, IXGBE_RTRPT4C(i), reg);
  49. }
  50. /*
  51. * Configure Rx packet plane (recycle mode; WSP) and
  52. * enable arbiter
  53. */
  54. reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC;
  55. IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
  56. return 0;
  57. }
  58. /**
  59. * ixgbe_dcb_config_tx_desc_arbiter_82599 - Config Tx Desc. arbiter
  60. * @hw: pointer to hardware structure
  61. * @refill: refill credits index by traffic class
  62. * @max: max credits index by traffic class
  63. * @bwg_id: bandwidth grouping indexed by traffic class
  64. * @prio_type: priority type indexed by traffic class
  65. *
  66. * Configure Tx Descriptor Arbiter and credits for each traffic class.
  67. */
  68. s32 ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw *hw,
  69. u16 *refill,
  70. u16 *max,
  71. u8 *bwg_id,
  72. u8 *prio_type)
  73. {
  74. u32 reg, max_credits;
  75. u8 i;
  76. /* Clear the per-Tx queue credits; we use per-TC instead */
  77. for (i = 0; i < 128; i++) {
  78. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
  79. IXGBE_WRITE_REG(hw, IXGBE_RTTDT1C, 0);
  80. }
  81. /* Configure traffic class credits and priority */
  82. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  83. max_credits = max[i];
  84. reg = max_credits << IXGBE_RTTDT2C_MCL_SHIFT;
  85. reg |= refill[i];
  86. reg |= (u32)(bwg_id[i]) << IXGBE_RTTDT2C_BWG_SHIFT;
  87. if (prio_type[i] == prio_group)
  88. reg |= IXGBE_RTTDT2C_GSP;
  89. if (prio_type[i] == prio_link)
  90. reg |= IXGBE_RTTDT2C_LSP;
  91. IXGBE_WRITE_REG(hw, IXGBE_RTTDT2C(i), reg);
  92. }
  93. /*
  94. * Configure Tx descriptor plane (recycle mode; WSP) and
  95. * enable arbiter
  96. */
  97. reg = IXGBE_RTTDCS_TDPAC | IXGBE_RTTDCS_TDRM;
  98. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
  99. return 0;
  100. }
  101. /**
  102. * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter
  103. * @hw: pointer to hardware structure
  104. * @refill: refill credits index by traffic class
  105. * @max: max credits index by traffic class
  106. * @bwg_id: bandwidth grouping indexed by traffic class
  107. * @prio_type: priority type indexed by traffic class
  108. * @prio_tc: priority to tc assignments indexed by priority
  109. *
  110. * Configure Tx Packet Arbiter and credits for each traffic class.
  111. */
  112. s32 ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw *hw,
  113. u16 *refill,
  114. u16 *max,
  115. u8 *bwg_id,
  116. u8 *prio_type,
  117. u8 *prio_tc)
  118. {
  119. u32 reg;
  120. u8 i;
  121. /*
  122. * Disable the arbiter before changing parameters
  123. * (always enable recycle mode; SP; arb delay)
  124. */
  125. reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
  126. (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT) |
  127. IXGBE_RTTPCS_ARBDIS;
  128. IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
  129. /* Map all traffic classes to their UP */
  130. reg = 0;
  131. for (i = 0; i < MAX_USER_PRIORITY; i++)
  132. reg |= (prio_tc[i] << (i * IXGBE_RTTUP2TC_UP_SHIFT));
  133. IXGBE_WRITE_REG(hw, IXGBE_RTTUP2TC, reg);
  134. /* Configure traffic class credits and priority */
  135. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  136. reg = refill[i];
  137. reg |= (u32)(max[i]) << IXGBE_RTTPT2C_MCL_SHIFT;
  138. reg |= (u32)(bwg_id[i]) << IXGBE_RTTPT2C_BWG_SHIFT;
  139. if (prio_type[i] == prio_group)
  140. reg |= IXGBE_RTTPT2C_GSP;
  141. if (prio_type[i] == prio_link)
  142. reg |= IXGBE_RTTPT2C_LSP;
  143. IXGBE_WRITE_REG(hw, IXGBE_RTTPT2C(i), reg);
  144. }
  145. /*
  146. * Configure Tx packet plane (recycle mode; SP; arb delay) and
  147. * enable arbiter
  148. */
  149. reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
  150. (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT);
  151. IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
  152. return 0;
  153. }
  154. /**
  155. * ixgbe_dcb_config_pfc_82599 - Configure priority flow control
  156. * @hw: pointer to hardware structure
  157. * @pfc_en: enabled pfc bitmask
  158. * @prio_tc: priority to tc assignments indexed by priority
  159. *
  160. * Configure Priority Flow Control (PFC) for each traffic class.
  161. */
  162. s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw, u8 pfc_en, u8 *prio_tc)
  163. {
  164. u32 i, j, fcrtl, reg;
  165. u8 max_tc = 0;
  166. /* Enable Transmit Priority Flow Control */
  167. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, IXGBE_FCCFG_TFCE_PRIORITY);
  168. /* Enable Receive Priority Flow Control */
  169. reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  170. reg |= IXGBE_MFLCN_DPF;
  171. /*
  172. * X540 & X550 supports per TC Rx priority flow control.
  173. * So clear all TCs and only enable those that should be
  174. * enabled.
  175. */
  176. reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
  177. if (hw->mac.type >= ixgbe_mac_X540)
  178. reg |= pfc_en << IXGBE_MFLCN_RPFCE_SHIFT;
  179. if (pfc_en)
  180. reg |= IXGBE_MFLCN_RPFCE;
  181. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
  182. for (i = 0; i < MAX_USER_PRIORITY; i++) {
  183. if (prio_tc[i] > max_tc)
  184. max_tc = prio_tc[i];
  185. }
  186. /* Configure PFC Tx thresholds per TC */
  187. for (i = 0; i <= max_tc; i++) {
  188. int enabled = 0;
  189. for (j = 0; j < MAX_USER_PRIORITY; j++) {
  190. if ((prio_tc[j] == i) && (pfc_en & BIT(j))) {
  191. enabled = 1;
  192. break;
  193. }
  194. }
  195. if (enabled) {
  196. reg = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
  197. fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
  198. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
  199. } else {
  200. /* In order to prevent Tx hangs when the internal Tx
  201. * switch is enabled we must set the high water mark
  202. * to the Rx packet buffer size - 24KB. This allows
  203. * the Tx switch to function even under heavy Rx
  204. * workloads.
  205. */
  206. reg = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 24576;
  207. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
  208. }
  209. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg);
  210. }
  211. for (; i < MAX_TRAFFIC_CLASS; i++) {
  212. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
  213. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), 0);
  214. }
  215. /* Configure pause time (2 TCs per register) */
  216. reg = hw->fc.pause_time * 0x00010001;
  217. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  218. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  219. /* Configure flow control refresh threshold value */
  220. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  221. return 0;
  222. }
  223. /**
  224. * ixgbe_dcb_config_tc_stats_82599 - Config traffic class statistics
  225. * @hw: pointer to hardware structure
  226. *
  227. * Configure queue statistics registers, all queues belonging to same traffic
  228. * class uses a single set of queue statistics counters.
  229. */
  230. static s32 ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw *hw)
  231. {
  232. u32 reg = 0;
  233. u8 i = 0;
  234. /*
  235. * Receive Queues stats setting
  236. * 32 RQSMR registers, each configuring 4 queues.
  237. * Set all 16 queues of each TC to the same stat
  238. * with TC 'n' going to stat 'n'.
  239. */
  240. for (i = 0; i < 32; i++) {
  241. reg = 0x01010101 * (i / 4);
  242. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
  243. }
  244. /*
  245. * Transmit Queues stats setting
  246. * 32 TQSM registers, each controlling 4 queues.
  247. * Set all queues of each TC to the same stat
  248. * with TC 'n' going to stat 'n'.
  249. * Tx queues are allocated non-uniformly to TCs:
  250. * 32, 32, 16, 16, 8, 8, 8, 8.
  251. */
  252. for (i = 0; i < 32; i++) {
  253. if (i < 8)
  254. reg = 0x00000000;
  255. else if (i < 16)
  256. reg = 0x01010101;
  257. else if (i < 20)
  258. reg = 0x02020202;
  259. else if (i < 24)
  260. reg = 0x03030303;
  261. else if (i < 26)
  262. reg = 0x04040404;
  263. else if (i < 28)
  264. reg = 0x05050505;
  265. else if (i < 30)
  266. reg = 0x06060606;
  267. else
  268. reg = 0x07070707;
  269. IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), reg);
  270. }
  271. return 0;
  272. }
  273. /**
  274. * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
  275. * @hw: pointer to hardware structure
  276. * @pfc_en: enabled pfc bitmask
  277. * @refill: refill credits index by traffic class
  278. * @max: max credits index by traffic class
  279. * @bwg_id: bandwidth grouping indexed by traffic class
  280. * @prio_type: priority type indexed by traffic class
  281. * @prio_tc: priority to tc assignments indexed by priority
  282. *
  283. * Configure dcb settings and enable dcb mode.
  284. */
  285. s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill,
  286. u16 *max, u8 *bwg_id, u8 *prio_type, u8 *prio_tc)
  287. {
  288. ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id,
  289. prio_type, prio_tc);
  290. ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
  291. bwg_id, prio_type);
  292. ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max,
  293. bwg_id, prio_type, prio_tc);
  294. ixgbe_dcb_config_pfc_82599(hw, pfc_en, prio_tc);
  295. ixgbe_dcb_config_tc_stats_82599(hw);
  296. return 0;
  297. }