ixgbe_dcb_82599.c 10.0 KB

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