ixgbe_dcb_82598.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2011 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_packet_buffers_82598 - Configure packet buffers
  27. * @hw: pointer to hardware structure
  28. * @dcb_config: pointer to ixgbe_dcb_config structure
  29. *
  30. * Configure packet buffers for DCB mode.
  31. */
  32. static s32 ixgbe_dcb_config_packet_buffers_82598(struct ixgbe_hw *hw, u8 rx_pba)
  33. {
  34. s32 ret_val = 0;
  35. u32 value = IXGBE_RXPBSIZE_64KB;
  36. u8 i = 0;
  37. /* Setup Rx packet buffer sizes */
  38. switch (rx_pba) {
  39. case pba_80_48:
  40. /* Setup the first four at 80KB */
  41. value = IXGBE_RXPBSIZE_80KB;
  42. for (; i < 4; i++)
  43. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), value);
  44. /* Setup the last four at 48KB...don't re-init i */
  45. value = IXGBE_RXPBSIZE_48KB;
  46. /* Fall Through */
  47. case pba_equal:
  48. default:
  49. for (; i < IXGBE_MAX_PACKET_BUFFERS; i++)
  50. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), value);
  51. /* Setup Tx packet buffer sizes */
  52. for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
  53. IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i),
  54. IXGBE_TXPBSIZE_40KB);
  55. }
  56. break;
  57. }
  58. return ret_val;
  59. }
  60. /**
  61. * ixgbe_dcb_config_rx_arbiter_82598 - Config Rx data arbiter
  62. * @hw: pointer to hardware structure
  63. * @dcb_config: pointer to ixgbe_dcb_config structure
  64. *
  65. * Configure Rx Data Arbiter and credits for each traffic class.
  66. */
  67. s32 ixgbe_dcb_config_rx_arbiter_82598(struct ixgbe_hw *hw,
  68. u16 *refill,
  69. u16 *max,
  70. u8 *prio_type)
  71. {
  72. u32 reg = 0;
  73. u32 credit_refill = 0;
  74. u32 credit_max = 0;
  75. u8 i = 0;
  76. reg = IXGBE_READ_REG(hw, IXGBE_RUPPBMR) | IXGBE_RUPPBMR_MQA;
  77. IXGBE_WRITE_REG(hw, IXGBE_RUPPBMR, reg);
  78. reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  79. /* Enable Arbiter */
  80. reg &= ~IXGBE_RMCS_ARBDIS;
  81. /* Enable Receive Recycle within the BWG */
  82. reg |= IXGBE_RMCS_RRM;
  83. /* Enable Deficit Fixed Priority arbitration*/
  84. reg |= IXGBE_RMCS_DFP;
  85. IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
  86. /* Configure traffic class credits and priority */
  87. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  88. credit_refill = refill[i];
  89. credit_max = max[i];
  90. reg = credit_refill | (credit_max << IXGBE_RT2CR_MCL_SHIFT);
  91. if (prio_type[i] == prio_link)
  92. reg |= IXGBE_RT2CR_LSP;
  93. IXGBE_WRITE_REG(hw, IXGBE_RT2CR(i), reg);
  94. }
  95. reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  96. reg |= IXGBE_RDRXCTL_RDMTS_1_2;
  97. reg |= IXGBE_RDRXCTL_MPBEN;
  98. reg |= IXGBE_RDRXCTL_MCEN;
  99. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg);
  100. reg = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  101. /* Make sure there is enough descriptors before arbitration */
  102. reg &= ~IXGBE_RXCTRL_DMBYPS;
  103. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg);
  104. return 0;
  105. }
  106. /**
  107. * ixgbe_dcb_config_tx_desc_arbiter_82598 - Config Tx Desc. arbiter
  108. * @hw: pointer to hardware structure
  109. * @dcb_config: pointer to ixgbe_dcb_config structure
  110. *
  111. * Configure Tx Descriptor Arbiter and credits for each traffic class.
  112. */
  113. s32 ixgbe_dcb_config_tx_desc_arbiter_82598(struct ixgbe_hw *hw,
  114. u16 *refill,
  115. u16 *max,
  116. u8 *bwg_id,
  117. u8 *prio_type)
  118. {
  119. u32 reg, max_credits;
  120. u8 i;
  121. reg = IXGBE_READ_REG(hw, IXGBE_DPMCS);
  122. /* Enable arbiter */
  123. reg &= ~IXGBE_DPMCS_ARBDIS;
  124. /* Enable DFP and Recycle mode */
  125. reg |= (IXGBE_DPMCS_TDPAC | IXGBE_DPMCS_TRM);
  126. reg |= IXGBE_DPMCS_TSOEF;
  127. /* Configure Max TSO packet size 34KB including payload and headers */
  128. reg |= (0x4 << IXGBE_DPMCS_MTSOS_SHIFT);
  129. IXGBE_WRITE_REG(hw, IXGBE_DPMCS, reg);
  130. /* Configure traffic class credits and priority */
  131. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  132. max_credits = max[i];
  133. reg = max_credits << IXGBE_TDTQ2TCCR_MCL_SHIFT;
  134. reg |= refill[i];
  135. reg |= (u32)(bwg_id[i]) << IXGBE_TDTQ2TCCR_BWG_SHIFT;
  136. if (prio_type[i] == prio_group)
  137. reg |= IXGBE_TDTQ2TCCR_GSP;
  138. if (prio_type[i] == prio_link)
  139. reg |= IXGBE_TDTQ2TCCR_LSP;
  140. IXGBE_WRITE_REG(hw, IXGBE_TDTQ2TCCR(i), reg);
  141. }
  142. return 0;
  143. }
  144. /**
  145. * ixgbe_dcb_config_tx_data_arbiter_82598 - Config Tx data arbiter
  146. * @hw: pointer to hardware structure
  147. * @dcb_config: pointer to ixgbe_dcb_config structure
  148. *
  149. * Configure Tx Data Arbiter and credits for each traffic class.
  150. */
  151. s32 ixgbe_dcb_config_tx_data_arbiter_82598(struct ixgbe_hw *hw,
  152. u16 *refill,
  153. u16 *max,
  154. u8 *bwg_id,
  155. u8 *prio_type)
  156. {
  157. u32 reg;
  158. u8 i;
  159. reg = IXGBE_READ_REG(hw, IXGBE_PDPMCS);
  160. /* Enable Data Plane Arbiter */
  161. reg &= ~IXGBE_PDPMCS_ARBDIS;
  162. /* Enable DFP and Transmit Recycle Mode */
  163. reg |= (IXGBE_PDPMCS_TPPAC | IXGBE_PDPMCS_TRM);
  164. IXGBE_WRITE_REG(hw, IXGBE_PDPMCS, reg);
  165. /* Configure traffic class credits and priority */
  166. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  167. reg = refill[i];
  168. reg |= (u32)(max[i]) << IXGBE_TDPT2TCCR_MCL_SHIFT;
  169. reg |= (u32)(bwg_id[i]) << IXGBE_TDPT2TCCR_BWG_SHIFT;
  170. if (prio_type[i] == prio_group)
  171. reg |= IXGBE_TDPT2TCCR_GSP;
  172. if (prio_type[i] == prio_link)
  173. reg |= IXGBE_TDPT2TCCR_LSP;
  174. IXGBE_WRITE_REG(hw, IXGBE_TDPT2TCCR(i), reg);
  175. }
  176. /* Enable Tx packet buffer division */
  177. reg = IXGBE_READ_REG(hw, IXGBE_DTXCTL);
  178. reg |= IXGBE_DTXCTL_ENDBUBD;
  179. IXGBE_WRITE_REG(hw, IXGBE_DTXCTL, reg);
  180. return 0;
  181. }
  182. /**
  183. * ixgbe_dcb_config_pfc_82598 - Config priority flow control
  184. * @hw: pointer to hardware structure
  185. * @dcb_config: pointer to ixgbe_dcb_config structure
  186. *
  187. * Configure Priority Flow Control for each traffic class.
  188. */
  189. s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *hw, u8 pfc_en)
  190. {
  191. u32 reg, rx_pba_size;
  192. u8 i;
  193. if (pfc_en) {
  194. /* Enable Transmit Priority Flow Control */
  195. reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  196. reg &= ~IXGBE_RMCS_TFCE_802_3X;
  197. /* correct the reporting of our flow control status */
  198. reg |= IXGBE_RMCS_TFCE_PRIORITY;
  199. IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
  200. /* Enable Receive Priority Flow Control */
  201. reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  202. reg &= ~IXGBE_FCTRL_RFCE;
  203. reg |= IXGBE_FCTRL_RPFCE;
  204. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg);
  205. /* Configure pause time */
  206. for (i = 0; i < (MAX_TRAFFIC_CLASS >> 1); i++)
  207. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), 0x68006800);
  208. /* Configure flow control refresh threshold value */
  209. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, 0x3400);
  210. }
  211. /*
  212. * Configure flow control thresholds and enable priority flow control
  213. * for each traffic class.
  214. */
  215. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  216. int enabled = pfc_en & (1 << i);
  217. rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
  218. rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
  219. reg = (rx_pba_size - hw->fc.low_water) << 10;
  220. if (enabled == pfc_enabled_tx ||
  221. enabled == pfc_enabled_full)
  222. reg |= IXGBE_FCRTL_XONE;
  223. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), reg);
  224. reg = (rx_pba_size - hw->fc.high_water) << 10;
  225. if (enabled == pfc_enabled_tx ||
  226. enabled == pfc_enabled_full)
  227. reg |= IXGBE_FCRTH_FCEN;
  228. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), reg);
  229. }
  230. return 0;
  231. }
  232. /**
  233. * ixgbe_dcb_config_tc_stats_82598 - Configure traffic class statistics
  234. * @hw: pointer to hardware structure
  235. *
  236. * Configure queue statistics registers, all queues belonging to same traffic
  237. * class uses a single set of queue statistics counters.
  238. */
  239. static s32 ixgbe_dcb_config_tc_stats_82598(struct ixgbe_hw *hw)
  240. {
  241. u32 reg = 0;
  242. u8 i = 0;
  243. u8 j = 0;
  244. /* Receive Queues stats setting - 8 queues per statistics reg */
  245. for (i = 0, j = 0; i < 15 && j < 8; i = i + 2, j++) {
  246. reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i));
  247. reg |= ((0x1010101) * j);
  248. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
  249. reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i + 1));
  250. reg |= ((0x1010101) * j);
  251. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i + 1), reg);
  252. }
  253. /* Transmit Queues stats setting - 4 queues per statistics reg */
  254. for (i = 0; i < 8; i++) {
  255. reg = IXGBE_READ_REG(hw, IXGBE_TQSMR(i));
  256. reg |= ((0x1010101) * i);
  257. IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i), reg);
  258. }
  259. return 0;
  260. }
  261. /**
  262. * ixgbe_dcb_hw_config_82598 - Config and enable DCB
  263. * @hw: pointer to hardware structure
  264. * @dcb_config: pointer to ixgbe_dcb_config structure
  265. *
  266. * Configure dcb settings and enable dcb mode.
  267. */
  268. s32 ixgbe_dcb_hw_config_82598(struct ixgbe_hw *hw,
  269. u8 rx_pba, u8 pfc_en, u16 *refill,
  270. u16 *max, u8 *bwg_id, u8 *prio_type)
  271. {
  272. ixgbe_dcb_config_packet_buffers_82598(hw, rx_pba);
  273. ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, prio_type);
  274. ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
  275. bwg_id, prio_type);
  276. ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
  277. bwg_id, prio_type);
  278. ixgbe_dcb_config_pfc_82598(hw, pfc_en);
  279. ixgbe_dcb_config_tc_stats_82598(hw);
  280. return 0;
  281. }