ixgbe_dcb_82598.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. 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. /* Enable DFP and Recycle mode */
  90. reg |= (IXGBE_DPMCS_TDPAC | IXGBE_DPMCS_TRM);
  91. reg |= IXGBE_DPMCS_TSOEF;
  92. /* Configure Max TSO packet size 34KB including payload and headers */
  93. reg |= (0x4 << IXGBE_DPMCS_MTSOS_SHIFT);
  94. IXGBE_WRITE_REG(hw, IXGBE_DPMCS, reg);
  95. /* Configure traffic class credits and priority */
  96. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  97. max_credits = max[i];
  98. reg = max_credits << IXGBE_TDTQ2TCCR_MCL_SHIFT;
  99. reg |= refill[i];
  100. reg |= (u32)(bwg_id[i]) << IXGBE_TDTQ2TCCR_BWG_SHIFT;
  101. if (prio_type[i] == prio_group)
  102. reg |= IXGBE_TDTQ2TCCR_GSP;
  103. if (prio_type[i] == prio_link)
  104. reg |= IXGBE_TDTQ2TCCR_LSP;
  105. IXGBE_WRITE_REG(hw, IXGBE_TDTQ2TCCR(i), reg);
  106. }
  107. return 0;
  108. }
  109. /**
  110. * ixgbe_dcb_config_tx_data_arbiter_82598 - Config Tx data arbiter
  111. * @hw: pointer to hardware structure
  112. * @dcb_config: pointer to ixgbe_dcb_config structure
  113. *
  114. * Configure Tx Data Arbiter and credits for each traffic class.
  115. */
  116. s32 ixgbe_dcb_config_tx_data_arbiter_82598(struct ixgbe_hw *hw,
  117. u16 *refill,
  118. u16 *max,
  119. u8 *bwg_id,
  120. u8 *prio_type)
  121. {
  122. u32 reg;
  123. u8 i;
  124. reg = IXGBE_READ_REG(hw, IXGBE_PDPMCS);
  125. /* Enable Data Plane Arbiter */
  126. reg &= ~IXGBE_PDPMCS_ARBDIS;
  127. /* Enable DFP and Transmit Recycle Mode */
  128. reg |= (IXGBE_PDPMCS_TPPAC | IXGBE_PDPMCS_TRM);
  129. IXGBE_WRITE_REG(hw, IXGBE_PDPMCS, reg);
  130. /* Configure traffic class credits and priority */
  131. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  132. reg = refill[i];
  133. reg |= (u32)(max[i]) << IXGBE_TDPT2TCCR_MCL_SHIFT;
  134. reg |= (u32)(bwg_id[i]) << IXGBE_TDPT2TCCR_BWG_SHIFT;
  135. if (prio_type[i] == prio_group)
  136. reg |= IXGBE_TDPT2TCCR_GSP;
  137. if (prio_type[i] == prio_link)
  138. reg |= IXGBE_TDPT2TCCR_LSP;
  139. IXGBE_WRITE_REG(hw, IXGBE_TDPT2TCCR(i), reg);
  140. }
  141. /* Enable Tx packet buffer division */
  142. reg = IXGBE_READ_REG(hw, IXGBE_DTXCTL);
  143. reg |= IXGBE_DTXCTL_ENDBUBD;
  144. IXGBE_WRITE_REG(hw, IXGBE_DTXCTL, reg);
  145. return 0;
  146. }
  147. /**
  148. * ixgbe_dcb_config_pfc_82598 - Config priority flow control
  149. * @hw: pointer to hardware structure
  150. * @dcb_config: pointer to ixgbe_dcb_config structure
  151. *
  152. * Configure Priority Flow Control for each traffic class.
  153. */
  154. s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *hw, u8 pfc_en)
  155. {
  156. u32 reg;
  157. u8 i;
  158. if (pfc_en) {
  159. /* Enable Transmit Priority Flow Control */
  160. reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  161. reg &= ~IXGBE_RMCS_TFCE_802_3X;
  162. /* correct the reporting of our flow control status */
  163. reg |= IXGBE_RMCS_TFCE_PRIORITY;
  164. IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
  165. /* Enable Receive Priority Flow Control */
  166. reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  167. reg &= ~IXGBE_FCTRL_RFCE;
  168. reg |= IXGBE_FCTRL_RPFCE;
  169. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg);
  170. /* Configure pause time */
  171. for (i = 0; i < (MAX_TRAFFIC_CLASS >> 1); i++)
  172. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), 0x68006800);
  173. /* Configure flow control refresh threshold value */
  174. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, 0x3400);
  175. }
  176. /*
  177. * Configure flow control thresholds and enable priority flow control
  178. * for each traffic class.
  179. */
  180. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  181. int enabled = pfc_en & (1 << i);
  182. reg = hw->fc.low_water << 10;
  183. if (enabled == pfc_enabled_tx ||
  184. enabled == pfc_enabled_full)
  185. reg |= IXGBE_FCRTL_XONE;
  186. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), reg);
  187. reg = hw->fc.high_water[i] << 10;
  188. if (enabled == pfc_enabled_tx ||
  189. enabled == pfc_enabled_full)
  190. reg |= IXGBE_FCRTH_FCEN;
  191. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), reg);
  192. }
  193. return 0;
  194. }
  195. /**
  196. * ixgbe_dcb_config_tc_stats_82598 - Configure traffic class statistics
  197. * @hw: pointer to hardware structure
  198. *
  199. * Configure queue statistics registers, all queues belonging to same traffic
  200. * class uses a single set of queue statistics counters.
  201. */
  202. static s32 ixgbe_dcb_config_tc_stats_82598(struct ixgbe_hw *hw)
  203. {
  204. u32 reg = 0;
  205. u8 i = 0;
  206. u8 j = 0;
  207. /* Receive Queues stats setting - 8 queues per statistics reg */
  208. for (i = 0, j = 0; i < 15 && j < 8; i = i + 2, j++) {
  209. reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i));
  210. reg |= ((0x1010101) * j);
  211. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
  212. reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i + 1));
  213. reg |= ((0x1010101) * j);
  214. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i + 1), reg);
  215. }
  216. /* Transmit Queues stats setting - 4 queues per statistics reg */
  217. for (i = 0; i < 8; i++) {
  218. reg = IXGBE_READ_REG(hw, IXGBE_TQSMR(i));
  219. reg |= ((0x1010101) * i);
  220. IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i), reg);
  221. }
  222. return 0;
  223. }
  224. /**
  225. * ixgbe_dcb_hw_config_82598 - Config and enable DCB
  226. * @hw: pointer to hardware structure
  227. * @dcb_config: pointer to ixgbe_dcb_config structure
  228. *
  229. * Configure dcb settings and enable dcb mode.
  230. */
  231. s32 ixgbe_dcb_hw_config_82598(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill,
  232. u16 *max, u8 *bwg_id, u8 *prio_type)
  233. {
  234. ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, prio_type);
  235. ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
  236. bwg_id, prio_type);
  237. ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
  238. bwg_id, prio_type);
  239. ixgbe_dcb_config_pfc_82598(hw, pfc_en);
  240. ixgbe_dcb_config_tc_stats_82598(hw);
  241. return 0;
  242. }