ixgbe_dcb_82599.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2012 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, reg;
  180. u8 max_tc = 0;
  181. for (i = 0; i < MAX_USER_PRIORITY; i++)
  182. if (prio_tc[i] > max_tc)
  183. max_tc = prio_tc[i];
  184. /* Configure PFC Tx thresholds per TC */
  185. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  186. int enabled = 0;
  187. if (i > max_tc) {
  188. reg = 0;
  189. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), reg);
  190. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg);
  191. continue;
  192. }
  193. for (j = 0; j < MAX_USER_PRIORITY; j++) {
  194. if ((prio_tc[j] == i) && (pfc_en & (1 << j))) {
  195. enabled = 1;
  196. break;
  197. }
  198. }
  199. reg = hw->fc.low_water << 10;
  200. if (enabled)
  201. reg |= IXGBE_FCRTL_XONE;
  202. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), reg);
  203. reg = hw->fc.high_water[i] << 10;
  204. if (enabled)
  205. reg |= IXGBE_FCRTH_FCEN;
  206. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg);
  207. }
  208. if (pfc_en) {
  209. /* Configure pause time (2 TCs per register) */
  210. reg = hw->fc.pause_time | (hw->fc.pause_time << 16);
  211. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  212. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  213. /* Configure flow control refresh threshold value */
  214. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  215. reg = IXGBE_FCCFG_TFCE_PRIORITY;
  216. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, reg);
  217. /*
  218. * Enable Receive PFC
  219. * 82599 will always honor XOFF frames we receive when
  220. * we are in PFC mode however X540 only honors enabled
  221. * traffic classes.
  222. */
  223. reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  224. reg &= ~IXGBE_MFLCN_RFCE;
  225. reg |= IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_DPF;
  226. if (hw->mac.type == ixgbe_mac_X540) {
  227. reg &= ~IXGBE_MFLCN_RPFCE_MASK;
  228. reg |= pfc_en << IXGBE_MFLCN_RPFCE_SHIFT;
  229. }
  230. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
  231. } else {
  232. /* X540 devices have a RX bit that should be cleared
  233. * if PFC is disabled on all TCs but PFC features is
  234. * enabled.
  235. */
  236. if (hw->mac.type == ixgbe_mac_X540) {
  237. reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  238. reg &= ~IXGBE_MFLCN_RPFCE_MASK;
  239. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
  240. }
  241. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  242. hw->mac.ops.fc_enable(hw, i);
  243. }
  244. return 0;
  245. }
  246. /**
  247. * ixgbe_dcb_config_tc_stats_82599 - Config traffic class statistics
  248. * @hw: pointer to hardware structure
  249. *
  250. * Configure queue statistics registers, all queues belonging to same traffic
  251. * class uses a single set of queue statistics counters.
  252. */
  253. static s32 ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw *hw)
  254. {
  255. u32 reg = 0;
  256. u8 i = 0;
  257. /*
  258. * Receive Queues stats setting
  259. * 32 RQSMR registers, each configuring 4 queues.
  260. * Set all 16 queues of each TC to the same stat
  261. * with TC 'n' going to stat 'n'.
  262. */
  263. for (i = 0; i < 32; i++) {
  264. reg = 0x01010101 * (i / 4);
  265. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
  266. }
  267. /*
  268. * Transmit Queues stats setting
  269. * 32 TQSM registers, each controlling 4 queues.
  270. * Set all queues of each TC to the same stat
  271. * with TC 'n' going to stat 'n'.
  272. * Tx queues are allocated non-uniformly to TCs:
  273. * 32, 32, 16, 16, 8, 8, 8, 8.
  274. */
  275. for (i = 0; i < 32; i++) {
  276. if (i < 8)
  277. reg = 0x00000000;
  278. else if (i < 16)
  279. reg = 0x01010101;
  280. else if (i < 20)
  281. reg = 0x02020202;
  282. else if (i < 24)
  283. reg = 0x03030303;
  284. else if (i < 26)
  285. reg = 0x04040404;
  286. else if (i < 28)
  287. reg = 0x05050505;
  288. else if (i < 30)
  289. reg = 0x06060606;
  290. else
  291. reg = 0x07070707;
  292. IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), reg);
  293. }
  294. return 0;
  295. }
  296. /**
  297. * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
  298. * @hw: pointer to hardware structure
  299. * @refill: refill credits index by traffic class
  300. * @max: max credits index by traffic class
  301. * @bwg_id: bandwidth grouping indexed by traffic class
  302. * @prio_type: priority type indexed by traffic class
  303. * @pfc_en: enabled pfc bitmask
  304. *
  305. * Configure dcb settings and enable dcb mode.
  306. */
  307. s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill,
  308. u16 *max, u8 *bwg_id, u8 *prio_type, u8 *prio_tc)
  309. {
  310. ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id,
  311. prio_type, prio_tc);
  312. ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
  313. bwg_id, prio_type);
  314. ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max,
  315. bwg_id, prio_type, prio_tc);
  316. ixgbe_dcb_config_pfc_82599(hw, pfc_en, prio_tc);
  317. ixgbe_dcb_config_tc_stats_82599(hw);
  318. return 0;
  319. }