ixgbe_dcb_82598.c 10.0 KB

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