ixgbe_dcb_82598.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*******************************************************************************
  3. Intel 10 Gigabit PCI Express Linux driver
  4. Copyright(c) 1999 - 2013 Intel Corporation.
  5. This program is free software; you can redistribute it and/or modify it
  6. under the terms and conditions of the GNU General Public License,
  7. version 2, as published by the Free Software Foundation.
  8. This program is distributed in the hope it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. You should have received a copy of the GNU General Public License along with
  13. this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  15. The full GNU General Public License is included in this distribution in
  16. the file called "COPYING".
  17. Contact Information:
  18. Linux NICS <linux.nics@intel.com>
  19. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  20. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  21. *******************************************************************************/
  22. #include "ixgbe.h"
  23. #include "ixgbe_type.h"
  24. #include "ixgbe_dcb.h"
  25. #include "ixgbe_dcb_82598.h"
  26. /**
  27. * ixgbe_dcb_config_rx_arbiter_82598 - Config Rx data arbiter
  28. * @hw: pointer to hardware structure
  29. * @refill: refill credits index by traffic class
  30. * @max: max credits index by traffic class
  31. * @prio_type: priority type indexed by traffic class
  32. *
  33. * Configure Rx Data Arbiter and credits for each traffic class.
  34. */
  35. s32 ixgbe_dcb_config_rx_arbiter_82598(struct ixgbe_hw *hw,
  36. u16 *refill,
  37. u16 *max,
  38. u8 *prio_type)
  39. {
  40. u32 reg = 0;
  41. u32 credit_refill = 0;
  42. u32 credit_max = 0;
  43. u8 i = 0;
  44. reg = IXGBE_READ_REG(hw, IXGBE_RUPPBMR) | IXGBE_RUPPBMR_MQA;
  45. IXGBE_WRITE_REG(hw, IXGBE_RUPPBMR, reg);
  46. reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  47. /* Enable Arbiter */
  48. reg &= ~IXGBE_RMCS_ARBDIS;
  49. /* Enable Receive Recycle within the BWG */
  50. reg |= IXGBE_RMCS_RRM;
  51. /* Enable Deficit Fixed Priority arbitration*/
  52. reg |= IXGBE_RMCS_DFP;
  53. IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
  54. /* Configure traffic class credits and priority */
  55. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  56. credit_refill = refill[i];
  57. credit_max = max[i];
  58. reg = credit_refill | (credit_max << IXGBE_RT2CR_MCL_SHIFT);
  59. if (prio_type[i] == prio_link)
  60. reg |= IXGBE_RT2CR_LSP;
  61. IXGBE_WRITE_REG(hw, IXGBE_RT2CR(i), reg);
  62. }
  63. reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  64. reg |= IXGBE_RDRXCTL_RDMTS_1_2;
  65. reg |= IXGBE_RDRXCTL_MPBEN;
  66. reg |= IXGBE_RDRXCTL_MCEN;
  67. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg);
  68. reg = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  69. /* Make sure there is enough descriptors before arbitration */
  70. reg &= ~IXGBE_RXCTRL_DMBYPS;
  71. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg);
  72. return 0;
  73. }
  74. /**
  75. * ixgbe_dcb_config_tx_desc_arbiter_82598 - 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_82598(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. reg = IXGBE_READ_REG(hw, IXGBE_DPMCS);
  93. /* Enable arbiter */
  94. reg &= ~IXGBE_DPMCS_ARBDIS;
  95. reg |= IXGBE_DPMCS_TSOEF;
  96. /* Configure Max TSO packet size 34KB including payload and headers */
  97. reg |= (0x4 << IXGBE_DPMCS_MTSOS_SHIFT);
  98. IXGBE_WRITE_REG(hw, IXGBE_DPMCS, reg);
  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_TDTQ2TCCR_MCL_SHIFT;
  103. reg |= refill[i];
  104. reg |= (u32)(bwg_id[i]) << IXGBE_TDTQ2TCCR_BWG_SHIFT;
  105. if (prio_type[i] == prio_group)
  106. reg |= IXGBE_TDTQ2TCCR_GSP;
  107. if (prio_type[i] == prio_link)
  108. reg |= IXGBE_TDTQ2TCCR_LSP;
  109. IXGBE_WRITE_REG(hw, IXGBE_TDTQ2TCCR(i), reg);
  110. }
  111. return 0;
  112. }
  113. /**
  114. * ixgbe_dcb_config_tx_data_arbiter_82598 - Config Tx data arbiter
  115. * @hw: pointer to hardware structure
  116. * @refill: refill credits index by traffic class
  117. * @max: max credits index by traffic class
  118. * @bwg_id: bandwidth grouping indexed by traffic class
  119. * @prio_type: priority type indexed by traffic class
  120. *
  121. * Configure Tx Data Arbiter and credits for each traffic class.
  122. */
  123. s32 ixgbe_dcb_config_tx_data_arbiter_82598(struct ixgbe_hw *hw,
  124. u16 *refill,
  125. u16 *max,
  126. u8 *bwg_id,
  127. u8 *prio_type)
  128. {
  129. u32 reg;
  130. u8 i;
  131. reg = IXGBE_READ_REG(hw, IXGBE_PDPMCS);
  132. /* Enable Data Plane Arbiter */
  133. reg &= ~IXGBE_PDPMCS_ARBDIS;
  134. /* Enable DFP and Transmit Recycle Mode */
  135. reg |= (IXGBE_PDPMCS_TPPAC | IXGBE_PDPMCS_TRM);
  136. IXGBE_WRITE_REG(hw, IXGBE_PDPMCS, reg);
  137. /* Configure traffic class credits and priority */
  138. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  139. reg = refill[i];
  140. reg |= (u32)(max[i]) << IXGBE_TDPT2TCCR_MCL_SHIFT;
  141. reg |= (u32)(bwg_id[i]) << IXGBE_TDPT2TCCR_BWG_SHIFT;
  142. if (prio_type[i] == prio_group)
  143. reg |= IXGBE_TDPT2TCCR_GSP;
  144. if (prio_type[i] == prio_link)
  145. reg |= IXGBE_TDPT2TCCR_LSP;
  146. IXGBE_WRITE_REG(hw, IXGBE_TDPT2TCCR(i), reg);
  147. }
  148. /* Enable Tx packet buffer division */
  149. reg = IXGBE_READ_REG(hw, IXGBE_DTXCTL);
  150. reg |= IXGBE_DTXCTL_ENDBUBD;
  151. IXGBE_WRITE_REG(hw, IXGBE_DTXCTL, reg);
  152. return 0;
  153. }
  154. /**
  155. * ixgbe_dcb_config_pfc_82598 - Config priority flow control
  156. * @hw: pointer to hardware structure
  157. * @pfc_en: enabled pfc bitmask
  158. *
  159. * Configure Priority Flow Control for each traffic class.
  160. */
  161. s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *hw, u8 pfc_en)
  162. {
  163. u32 fcrtl, reg;
  164. u8 i;
  165. /* Enable Transmit Priority Flow Control */
  166. reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  167. reg &= ~IXGBE_RMCS_TFCE_802_3X;
  168. reg |= IXGBE_RMCS_TFCE_PRIORITY;
  169. IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
  170. /* Enable Receive Priority Flow Control */
  171. reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  172. reg &= ~(IXGBE_FCTRL_RPFCE | IXGBE_FCTRL_RFCE);
  173. if (pfc_en)
  174. reg |= IXGBE_FCTRL_RPFCE;
  175. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg);
  176. /* Configure PFC Tx thresholds per TC */
  177. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  178. if (!(pfc_en & BIT(i))) {
  179. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), 0);
  180. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), 0);
  181. continue;
  182. }
  183. fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
  184. reg = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
  185. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), fcrtl);
  186. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), reg);
  187. }
  188. /* Configure pause time */
  189. reg = hw->fc.pause_time * 0x00010001;
  190. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  191. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  192. /* Configure flow control refresh threshold value */
  193. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  194. return 0;
  195. }
  196. /**
  197. * ixgbe_dcb_config_tc_stats_82598 - Configure traffic class statistics
  198. * @hw: pointer to hardware structure
  199. *
  200. * Configure queue statistics registers, all queues belonging to same traffic
  201. * class uses a single set of queue statistics counters.
  202. */
  203. static s32 ixgbe_dcb_config_tc_stats_82598(struct ixgbe_hw *hw)
  204. {
  205. u32 reg = 0;
  206. u8 i = 0;
  207. u8 j = 0;
  208. /* Receive Queues stats setting - 8 queues per statistics reg */
  209. for (i = 0, j = 0; i < 15 && j < 8; i = i + 2, j++) {
  210. reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i));
  211. reg |= ((0x1010101) * j);
  212. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
  213. reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i + 1));
  214. reg |= ((0x1010101) * j);
  215. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i + 1), reg);
  216. }
  217. /* Transmit Queues stats setting - 4 queues per statistics reg */
  218. for (i = 0; i < 8; i++) {
  219. reg = IXGBE_READ_REG(hw, IXGBE_TQSMR(i));
  220. reg |= ((0x1010101) * i);
  221. IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i), reg);
  222. }
  223. return 0;
  224. }
  225. /**
  226. * ixgbe_dcb_hw_config_82598 - Config and enable DCB
  227. * @hw: pointer to hardware structure
  228. * @pfc_en: enabled pfc bitmask
  229. * @refill: refill credits index by traffic class
  230. * @max: max credits index by traffic class
  231. * @bwg_id: bandwidth grouping indexed by traffic class
  232. * @prio_type: priority type indexed by traffic class
  233. *
  234. * Configure dcb settings and enable dcb mode.
  235. */
  236. s32 ixgbe_dcb_hw_config_82598(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill,
  237. u16 *max, u8 *bwg_id, u8 *prio_type)
  238. {
  239. ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, prio_type);
  240. ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
  241. bwg_id, prio_type);
  242. ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
  243. bwg_id, prio_type);
  244. ixgbe_dcb_config_pfc_82598(hw, pfc_en);
  245. ixgbe_dcb_config_tc_stats_82598(hw);
  246. return 0;
  247. }