ixgbe_dcb_82599.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include "ixgbe.h"
  21. #include "ixgbe_type.h"
  22. #include "ixgbe_dcb.h"
  23. #include "ixgbe_dcb_82599.h"
  24. /**
  25. * ixgbe_dcb_config_packet_buffers_82599 - Configure DCB packet buffers
  26. * @hw: pointer to hardware structure
  27. * @dcb_config: pointer to ixgbe_dcb_config structure
  28. *
  29. * Configure packet buffers for DCB mode.
  30. */
  31. static s32 ixgbe_dcb_config_packet_buffers_82599(struct ixgbe_hw *hw,
  32. struct ixgbe_dcb_config *dcb_config)
  33. {
  34. s32 ret_val = 0;
  35. u32 value = IXGBE_RXPBSIZE_64KB;
  36. u8 i = 0;
  37. /* Setup Rx packet buffer sizes */
  38. switch (dcb_config->rx_pba_cfg) {
  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_20KB);
  55. IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i),
  56. IXGBE_TXPBTHRESH_DCB);
  57. }
  58. break;
  59. }
  60. return ret_val;
  61. }
  62. /**
  63. * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter
  64. * @hw: pointer to hardware structure
  65. * @dcb_config: pointer to ixgbe_dcb_config structure
  66. *
  67. * Configure Rx Packet Arbiter and credits for each traffic class.
  68. */
  69. static s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw,
  70. struct ixgbe_dcb_config *dcb_config)
  71. {
  72. struct tc_bw_alloc *p;
  73. u32 reg = 0;
  74. u32 credit_refill = 0;
  75. u32 credit_max = 0;
  76. u8 i = 0;
  77. /*
  78. * Disable the arbiter before changing parameters
  79. * (always enable recycle mode; WSP)
  80. */
  81. reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC | IXGBE_RTRPCS_ARBDIS;
  82. IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
  83. /* Map all traffic classes to their UP, 1 to 1 */
  84. reg = 0;
  85. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  86. reg |= (i << (i * IXGBE_RTRUP2TC_UP_SHIFT));
  87. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  88. /* Configure traffic class credits and priority */
  89. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  90. p = &dcb_config->tc_config[i].path[DCB_RX_CONFIG];
  91. credit_refill = p->data_credits_refill;
  92. credit_max = p->data_credits_max;
  93. reg = credit_refill | (credit_max << IXGBE_RTRPT4C_MCL_SHIFT);
  94. reg |= (u32)(p->bwg_id) << IXGBE_RTRPT4C_BWG_SHIFT;
  95. if (p->prio_type == prio_link)
  96. reg |= IXGBE_RTRPT4C_LSP;
  97. IXGBE_WRITE_REG(hw, IXGBE_RTRPT4C(i), reg);
  98. }
  99. /*
  100. * Configure Rx packet plane (recycle mode; WSP) and
  101. * enable arbiter
  102. */
  103. reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC;
  104. IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
  105. return 0;
  106. }
  107. /**
  108. * ixgbe_dcb_config_tx_desc_arbiter_82599 - 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_82599(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. /* Clear the per-Tx queue credits; we use per-TC instead */
  121. for (i = 0; i < 128; i++) {
  122. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
  123. IXGBE_WRITE_REG(hw, IXGBE_RTTDT1C, 0);
  124. }
  125. /* Configure traffic class credits and priority */
  126. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  127. p = &dcb_config->tc_config[i].path[DCB_TX_CONFIG];
  128. max_credits = dcb_config->tc_config[i].desc_credits_max;
  129. reg = max_credits << IXGBE_RTTDT2C_MCL_SHIFT;
  130. reg |= p->data_credits_refill;
  131. reg |= (u32)(p->bwg_id) << IXGBE_RTTDT2C_BWG_SHIFT;
  132. if (p->prio_type == prio_group)
  133. reg |= IXGBE_RTTDT2C_GSP;
  134. if (p->prio_type == prio_link)
  135. reg |= IXGBE_RTTDT2C_LSP;
  136. IXGBE_WRITE_REG(hw, IXGBE_RTTDT2C(i), reg);
  137. }
  138. /*
  139. * Configure Tx descriptor plane (recycle mode; WSP) and
  140. * enable arbiter
  141. */
  142. reg = IXGBE_RTTDCS_TDPAC | IXGBE_RTTDCS_TDRM;
  143. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
  144. return 0;
  145. }
  146. /**
  147. * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter
  148. * @hw: pointer to hardware structure
  149. * @dcb_config: pointer to ixgbe_dcb_config structure
  150. *
  151. * Configure Tx Packet Arbiter and credits for each traffic class.
  152. */
  153. static s32 ixgbe_dcb_config_tx_data_arbiter_82599(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. /*
  160. * Disable the arbiter before changing parameters
  161. * (always enable recycle mode; SP; arb delay)
  162. */
  163. reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
  164. (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT) |
  165. IXGBE_RTTPCS_ARBDIS;
  166. IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
  167. /* Map all traffic classes to their UP, 1 to 1 */
  168. reg = 0;
  169. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  170. reg |= (i << (i * IXGBE_RTTUP2TC_UP_SHIFT));
  171. IXGBE_WRITE_REG(hw, IXGBE_RTTUP2TC, reg);
  172. /* Configure traffic class credits and priority */
  173. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  174. p = &dcb_config->tc_config[i].path[DCB_TX_CONFIG];
  175. reg = p->data_credits_refill;
  176. reg |= (u32)(p->data_credits_max) << IXGBE_RTTPT2C_MCL_SHIFT;
  177. reg |= (u32)(p->bwg_id) << IXGBE_RTTPT2C_BWG_SHIFT;
  178. if (p->prio_type == prio_group)
  179. reg |= IXGBE_RTTPT2C_GSP;
  180. if (p->prio_type == prio_link)
  181. reg |= IXGBE_RTTPT2C_LSP;
  182. IXGBE_WRITE_REG(hw, IXGBE_RTTPT2C(i), reg);
  183. }
  184. /*
  185. * Configure Tx packet plane (recycle mode; SP; arb delay) and
  186. * enable arbiter
  187. */
  188. reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
  189. (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT);
  190. IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
  191. return 0;
  192. }
  193. /**
  194. * ixgbe_dcb_config_pfc_82599 - Configure priority flow control
  195. * @hw: pointer to hardware structure
  196. * @dcb_config: pointer to ixgbe_dcb_config structure
  197. *
  198. * Configure Priority Flow Control (PFC) for each traffic class.
  199. */
  200. s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw,
  201. struct ixgbe_dcb_config *dcb_config)
  202. {
  203. u32 i, reg, rx_pba_size;
  204. /* If PFC is disabled globally then fall back to LFC. */
  205. if (!dcb_config->pfc_mode_enable) {
  206. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  207. hw->mac.ops.fc_enable(hw, i);
  208. goto out;
  209. }
  210. /* Configure PFC Tx thresholds per TC */
  211. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  212. rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
  213. rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
  214. reg = (rx_pba_size - hw->fc.low_water) << 10;
  215. if (dcb_config->tc_config[i].dcb_pfc == pfc_enabled_full ||
  216. dcb_config->tc_config[i].dcb_pfc == pfc_enabled_tx)
  217. reg |= IXGBE_FCRTL_XONE;
  218. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), reg);
  219. reg = (rx_pba_size - hw->fc.high_water) << 10;
  220. if (dcb_config->tc_config[i].dcb_pfc == pfc_enabled_full ||
  221. dcb_config->tc_config[i].dcb_pfc == pfc_enabled_tx)
  222. reg |= IXGBE_FCRTH_FCEN;
  223. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg);
  224. }
  225. /* Configure pause time (2 TCs per register) */
  226. reg = hw->fc.pause_time | (hw->fc.pause_time << 16);
  227. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  228. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  229. /* Configure flow control refresh threshold value */
  230. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  231. /* Enable Transmit PFC */
  232. reg = IXGBE_FCCFG_TFCE_PRIORITY;
  233. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, reg);
  234. /*
  235. * Enable Receive PFC
  236. * We will always honor XOFF frames we receive when
  237. * we are in PFC mode.
  238. */
  239. reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  240. reg &= ~IXGBE_MFLCN_RFCE;
  241. reg |= IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_DPF;
  242. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
  243. out:
  244. return 0;
  245. }
  246. /**
  247. * ixgbe_dcb_config_tc_stats_82599 - Config traffic class statistics
  248. * @hw: pointer to hardware structure
  249. *
  250. * Configure queue statistics registers, all queues belonging to same traffic
  251. * class uses a single set of queue statistics counters.
  252. */
  253. static s32 ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw *hw)
  254. {
  255. u32 reg = 0;
  256. u8 i = 0;
  257. /*
  258. * Receive Queues stats setting
  259. * 32 RQSMR registers, each configuring 4 queues.
  260. * Set all 16 queues of each TC to the same stat
  261. * with TC 'n' going to stat 'n'.
  262. */
  263. for (i = 0; i < 32; i++) {
  264. reg = 0x01010101 * (i / 4);
  265. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
  266. }
  267. /*
  268. * Transmit Queues stats setting
  269. * 32 TQSM registers, each controlling 4 queues.
  270. * Set all queues of each TC to the same stat
  271. * with TC 'n' going to stat 'n'.
  272. * Tx queues are allocated non-uniformly to TCs:
  273. * 32, 32, 16, 16, 8, 8, 8, 8.
  274. */
  275. for (i = 0; i < 32; i++) {
  276. if (i < 8)
  277. reg = 0x00000000;
  278. else if (i < 16)
  279. reg = 0x01010101;
  280. else if (i < 20)
  281. reg = 0x02020202;
  282. else if (i < 24)
  283. reg = 0x03030303;
  284. else if (i < 26)
  285. reg = 0x04040404;
  286. else if (i < 28)
  287. reg = 0x05050505;
  288. else if (i < 30)
  289. reg = 0x06060606;
  290. else
  291. reg = 0x07070707;
  292. IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), reg);
  293. }
  294. return 0;
  295. }
  296. /**
  297. * ixgbe_dcb_config_82599 - Configure general DCB parameters
  298. * @hw: pointer to hardware structure
  299. * @dcb_config: pointer to ixgbe_dcb_config structure
  300. *
  301. * Configure general DCB parameters.
  302. */
  303. static s32 ixgbe_dcb_config_82599(struct ixgbe_hw *hw)
  304. {
  305. u32 reg;
  306. u32 q;
  307. /* Disable the Tx desc arbiter so that MTQC can be changed */
  308. reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  309. reg |= IXGBE_RTTDCS_ARBDIS;
  310. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
  311. /* Enable DCB for Rx with 8 TCs */
  312. reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
  313. switch (reg & IXGBE_MRQC_MRQE_MASK) {
  314. case 0:
  315. case IXGBE_MRQC_RT4TCEN:
  316. /* RSS disabled cases */
  317. reg = (reg & ~IXGBE_MRQC_MRQE_MASK) | IXGBE_MRQC_RT8TCEN;
  318. break;
  319. case IXGBE_MRQC_RSSEN:
  320. case IXGBE_MRQC_RTRSS4TCEN:
  321. /* RSS enabled cases */
  322. reg = (reg & ~IXGBE_MRQC_MRQE_MASK) | IXGBE_MRQC_RTRSS8TCEN;
  323. break;
  324. default:
  325. /* Unsupported value, assume stale data, overwrite no RSS */
  326. reg = (reg & ~IXGBE_MRQC_MRQE_MASK) | IXGBE_MRQC_RT8TCEN;
  327. }
  328. IXGBE_WRITE_REG(hw, IXGBE_MRQC, reg);
  329. /* Enable DCB for Tx with 8 TCs */
  330. reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  331. IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
  332. /* Disable drop for all queues */
  333. for (q = 0; q < 128; q++)
  334. IXGBE_WRITE_REG(hw, IXGBE_QDE, q << IXGBE_QDE_IDX_SHIFT);
  335. /* Enable the Tx desc arbiter */
  336. reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  337. reg &= ~IXGBE_RTTDCS_ARBDIS;
  338. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
  339. /* Enable Security TX Buffer IFG for DCB */
  340. reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
  341. reg |= IXGBE_SECTX_DCB;
  342. IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
  343. return 0;
  344. }
  345. /**
  346. * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
  347. * @hw: pointer to hardware structure
  348. * @dcb_config: pointer to ixgbe_dcb_config structure
  349. *
  350. * Configure dcb settings and enable dcb mode.
  351. */
  352. s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw,
  353. struct ixgbe_dcb_config *dcb_config)
  354. {
  355. ixgbe_dcb_config_packet_buffers_82599(hw, dcb_config);
  356. ixgbe_dcb_config_82599(hw);
  357. ixgbe_dcb_config_rx_arbiter_82599(hw, dcb_config);
  358. ixgbe_dcb_config_tx_desc_arbiter_82599(hw, dcb_config);
  359. ixgbe_dcb_config_tx_data_arbiter_82599(hw, dcb_config);
  360. ixgbe_dcb_config_pfc_82599(hw, dcb_config);
  361. ixgbe_dcb_config_tc_stats_82599(hw);
  362. return 0;
  363. }