ixgbe_dcb_82599.c 10 KB

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