ixgbe_dcb_82598.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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_82598.h"
  25. /**
  26. * ixgbe_dcb_config_rx_arbiter_82598 - Config Rx data arbiter
  27. * @hw: pointer to hardware structure
  28. * @dcb_config: pointer to ixgbe_dcb_config structure
  29. *
  30. * Configure Rx Data Arbiter and credits for each traffic class.
  31. */
  32. s32 ixgbe_dcb_config_rx_arbiter_82598(struct ixgbe_hw *hw,
  33. u16 *refill,
  34. u16 *max,
  35. u8 *prio_type)
  36. {
  37. u32 reg = 0;
  38. u32 credit_refill = 0;
  39. u32 credit_max = 0;
  40. u8 i = 0;
  41. reg = IXGBE_READ_REG(hw, IXGBE_RUPPBMR) | IXGBE_RUPPBMR_MQA;
  42. IXGBE_WRITE_REG(hw, IXGBE_RUPPBMR, reg);
  43. reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  44. /* Enable Arbiter */
  45. reg &= ~IXGBE_RMCS_ARBDIS;
  46. /* Enable Receive Recycle within the BWG */
  47. reg |= IXGBE_RMCS_RRM;
  48. /* Enable Deficit Fixed Priority arbitration*/
  49. reg |= IXGBE_RMCS_DFP;
  50. IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
  51. /* Configure traffic class credits and priority */
  52. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  53. credit_refill = refill[i];
  54. credit_max = max[i];
  55. reg = credit_refill | (credit_max << IXGBE_RT2CR_MCL_SHIFT);
  56. if (prio_type[i] == prio_link)
  57. reg |= IXGBE_RT2CR_LSP;
  58. IXGBE_WRITE_REG(hw, IXGBE_RT2CR(i), reg);
  59. }
  60. reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  61. reg |= IXGBE_RDRXCTL_RDMTS_1_2;
  62. reg |= IXGBE_RDRXCTL_MPBEN;
  63. reg |= IXGBE_RDRXCTL_MCEN;
  64. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg);
  65. reg = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  66. /* Make sure there is enough descriptors before arbitration */
  67. reg &= ~IXGBE_RXCTRL_DMBYPS;
  68. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg);
  69. return 0;
  70. }
  71. /**
  72. * ixgbe_dcb_config_tx_desc_arbiter_82598 - Config Tx Desc. arbiter
  73. * @hw: pointer to hardware structure
  74. * @dcb_config: pointer to ixgbe_dcb_config structure
  75. *
  76. * Configure Tx Descriptor Arbiter and credits for each traffic class.
  77. */
  78. s32 ixgbe_dcb_config_tx_desc_arbiter_82598(struct ixgbe_hw *hw,
  79. u16 *refill,
  80. u16 *max,
  81. u8 *bwg_id,
  82. u8 *prio_type)
  83. {
  84. u32 reg, max_credits;
  85. u8 i;
  86. reg = IXGBE_READ_REG(hw, IXGBE_DPMCS);
  87. /* Enable arbiter */
  88. reg &= ~IXGBE_DPMCS_ARBDIS;
  89. reg |= IXGBE_DPMCS_TSOEF;
  90. /* Configure Max TSO packet size 34KB including payload and headers */
  91. reg |= (0x4 << IXGBE_DPMCS_MTSOS_SHIFT);
  92. IXGBE_WRITE_REG(hw, IXGBE_DPMCS, reg);
  93. /* Configure traffic class credits and priority */
  94. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  95. max_credits = max[i];
  96. reg = max_credits << IXGBE_TDTQ2TCCR_MCL_SHIFT;
  97. reg |= refill[i];
  98. reg |= (u32)(bwg_id[i]) << IXGBE_TDTQ2TCCR_BWG_SHIFT;
  99. if (prio_type[i] == prio_group)
  100. reg |= IXGBE_TDTQ2TCCR_GSP;
  101. if (prio_type[i] == prio_link)
  102. reg |= IXGBE_TDTQ2TCCR_LSP;
  103. IXGBE_WRITE_REG(hw, IXGBE_TDTQ2TCCR(i), reg);
  104. }
  105. return 0;
  106. }
  107. /**
  108. * ixgbe_dcb_config_tx_data_arbiter_82598 - Config Tx data arbiter
  109. * @hw: pointer to hardware structure
  110. * @dcb_config: pointer to ixgbe_dcb_config structure
  111. *
  112. * Configure Tx Data Arbiter and credits for each traffic class.
  113. */
  114. s32 ixgbe_dcb_config_tx_data_arbiter_82598(struct ixgbe_hw *hw,
  115. u16 *refill,
  116. u16 *max,
  117. u8 *bwg_id,
  118. u8 *prio_type)
  119. {
  120. u32 reg;
  121. u8 i;
  122. reg = IXGBE_READ_REG(hw, IXGBE_PDPMCS);
  123. /* Enable Data Plane Arbiter */
  124. reg &= ~IXGBE_PDPMCS_ARBDIS;
  125. /* Enable DFP and Transmit Recycle Mode */
  126. reg |= (IXGBE_PDPMCS_TPPAC | IXGBE_PDPMCS_TRM);
  127. IXGBE_WRITE_REG(hw, IXGBE_PDPMCS, reg);
  128. /* Configure traffic class credits and priority */
  129. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  130. reg = refill[i];
  131. reg |= (u32)(max[i]) << IXGBE_TDPT2TCCR_MCL_SHIFT;
  132. reg |= (u32)(bwg_id[i]) << IXGBE_TDPT2TCCR_BWG_SHIFT;
  133. if (prio_type[i] == prio_group)
  134. reg |= IXGBE_TDPT2TCCR_GSP;
  135. if (prio_type[i] == prio_link)
  136. reg |= IXGBE_TDPT2TCCR_LSP;
  137. IXGBE_WRITE_REG(hw, IXGBE_TDPT2TCCR(i), reg);
  138. }
  139. /* Enable Tx packet buffer division */
  140. reg = IXGBE_READ_REG(hw, IXGBE_DTXCTL);
  141. reg |= IXGBE_DTXCTL_ENDBUBD;
  142. IXGBE_WRITE_REG(hw, IXGBE_DTXCTL, reg);
  143. return 0;
  144. }
  145. /**
  146. * ixgbe_dcb_config_pfc_82598 - Config priority flow control
  147. * @hw: pointer to hardware structure
  148. * @dcb_config: pointer to ixgbe_dcb_config structure
  149. *
  150. * Configure Priority Flow Control for each traffic class.
  151. */
  152. s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *hw, u8 pfc_en)
  153. {
  154. u32 fcrtl, reg;
  155. u8 i;
  156. /* Enable Transmit Priority Flow Control */
  157. reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  158. reg &= ~IXGBE_RMCS_TFCE_802_3X;
  159. reg |= IXGBE_RMCS_TFCE_PRIORITY;
  160. IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
  161. /* Enable Receive Priority Flow Control */
  162. reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  163. reg &= ~(IXGBE_FCTRL_RPFCE | IXGBE_FCTRL_RFCE);
  164. if (pfc_en)
  165. reg |= IXGBE_FCTRL_RPFCE;
  166. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg);
  167. /* Configure PFC Tx thresholds per TC */
  168. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  169. if (!(pfc_en & BIT(i))) {
  170. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), 0);
  171. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), 0);
  172. continue;
  173. }
  174. fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
  175. reg = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
  176. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), fcrtl);
  177. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), reg);
  178. }
  179. /* Configure pause time */
  180. reg = hw->fc.pause_time * 0x00010001;
  181. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  182. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  183. /* Configure flow control refresh threshold value */
  184. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  185. return 0;
  186. }
  187. /**
  188. * ixgbe_dcb_config_tc_stats_82598 - Configure traffic class statistics
  189. * @hw: pointer to hardware structure
  190. *
  191. * Configure queue statistics registers, all queues belonging to same traffic
  192. * class uses a single set of queue statistics counters.
  193. */
  194. static s32 ixgbe_dcb_config_tc_stats_82598(struct ixgbe_hw *hw)
  195. {
  196. u32 reg = 0;
  197. u8 i = 0;
  198. u8 j = 0;
  199. /* Receive Queues stats setting - 8 queues per statistics reg */
  200. for (i = 0, j = 0; i < 15 && j < 8; i = i + 2, j++) {
  201. reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i));
  202. reg |= ((0x1010101) * j);
  203. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
  204. reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i + 1));
  205. reg |= ((0x1010101) * j);
  206. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i + 1), reg);
  207. }
  208. /* Transmit Queues stats setting - 4 queues per statistics reg */
  209. for (i = 0; i < 8; i++) {
  210. reg = IXGBE_READ_REG(hw, IXGBE_TQSMR(i));
  211. reg |= ((0x1010101) * i);
  212. IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i), reg);
  213. }
  214. return 0;
  215. }
  216. /**
  217. * ixgbe_dcb_hw_config_82598 - Config and enable DCB
  218. * @hw: pointer to hardware structure
  219. * @dcb_config: pointer to ixgbe_dcb_config structure
  220. *
  221. * Configure dcb settings and enable dcb mode.
  222. */
  223. s32 ixgbe_dcb_hw_config_82598(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill,
  224. u16 *max, u8 *bwg_id, u8 *prio_type)
  225. {
  226. ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, prio_type);
  227. ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
  228. bwg_id, prio_type);
  229. ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
  230. bwg_id, prio_type);
  231. ixgbe_dcb_config_pfc_82598(hw, pfc_en);
  232. ixgbe_dcb_config_tc_stats_82598(hw);
  233. return 0;
  234. }