ixgbe_dcb_82599.c 10 KB

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