ixgbe_dcb_82599.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 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_get_tc_stats_82599 - Returns status for each traffic class
  26. * @hw: pointer to hardware structure
  27. * @stats: pointer to statistics structure
  28. * @tc_count: Number of elements in bwg_array.
  29. *
  30. * This function returns the status data for each of the Traffic Classes in use.
  31. */
  32. s32 ixgbe_dcb_get_tc_stats_82599(struct ixgbe_hw *hw,
  33. struct ixgbe_hw_stats *stats,
  34. u8 tc_count)
  35. {
  36. int tc;
  37. if (tc_count > MAX_TRAFFIC_CLASS)
  38. return DCB_ERR_PARAM;
  39. /* Statistics pertaining to each traffic class */
  40. for (tc = 0; tc < tc_count; tc++) {
  41. /* Transmitted Packets */
  42. stats->qptc[tc] += IXGBE_READ_REG(hw, IXGBE_QPTC(tc));
  43. /* Transmitted Bytes */
  44. stats->qbtc[tc] += IXGBE_READ_REG(hw, IXGBE_QBTC(tc));
  45. /* Received Packets */
  46. stats->qprc[tc] += IXGBE_READ_REG(hw, IXGBE_QPRC(tc));
  47. /* Received Bytes */
  48. stats->qbrc[tc] += IXGBE_READ_REG(hw, IXGBE_QBRC(tc));
  49. }
  50. return 0;
  51. }
  52. /**
  53. * ixgbe_dcb_get_pfc_stats_82599 - Return CBFC status data
  54. * @hw: pointer to hardware structure
  55. * @stats: pointer to statistics structure
  56. * @tc_count: Number of elements in bwg_array.
  57. *
  58. * This function returns the CBFC status data for each of the Traffic Classes.
  59. */
  60. s32 ixgbe_dcb_get_pfc_stats_82599(struct ixgbe_hw *hw,
  61. struct ixgbe_hw_stats *stats,
  62. u8 tc_count)
  63. {
  64. int tc;
  65. if (tc_count > MAX_TRAFFIC_CLASS)
  66. return DCB_ERR_PARAM;
  67. for (tc = 0; tc < tc_count; tc++) {
  68. /* Priority XOFF Transmitted */
  69. stats->pxofftxc[tc] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(tc));
  70. /* Priority XOFF Received */
  71. stats->pxoffrxc[tc] += IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(tc));
  72. }
  73. return 0;
  74. }
  75. /**
  76. * ixgbe_dcb_config_packet_buffers_82599 - Configure DCB packet buffers
  77. * @hw: pointer to hardware structure
  78. * @dcb_config: pointer to ixgbe_dcb_config structure
  79. *
  80. * Configure packet buffers for DCB mode.
  81. */
  82. s32 ixgbe_dcb_config_packet_buffers_82599(struct ixgbe_hw *hw,
  83. struct ixgbe_dcb_config *dcb_config)
  84. {
  85. s32 ret_val = 0;
  86. u32 value = IXGBE_RXPBSIZE_64KB;
  87. u8 i = 0;
  88. /* Setup Rx packet buffer sizes */
  89. switch (dcb_config->rx_pba_cfg) {
  90. case pba_80_48:
  91. /* Setup the first four at 80KB */
  92. value = IXGBE_RXPBSIZE_80KB;
  93. for (; i < 4; i++)
  94. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), value);
  95. /* Setup the last four at 48KB...don't re-init i */
  96. value = IXGBE_RXPBSIZE_48KB;
  97. /* Fall Through */
  98. case pba_equal:
  99. default:
  100. for (; i < IXGBE_MAX_PACKET_BUFFERS; i++)
  101. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), value);
  102. /* Setup Tx packet buffer sizes */
  103. for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
  104. IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i),
  105. IXGBE_TXPBSIZE_20KB);
  106. IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i),
  107. IXGBE_TXPBTHRESH_DCB);
  108. }
  109. break;
  110. }
  111. return ret_val;
  112. }
  113. /**
  114. * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter
  115. * @hw: pointer to hardware structure
  116. * @dcb_config: pointer to ixgbe_dcb_config structure
  117. *
  118. * Configure Rx Packet Arbiter and credits for each traffic class.
  119. */
  120. s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw,
  121. struct ixgbe_dcb_config *dcb_config)
  122. {
  123. struct tc_bw_alloc *p;
  124. u32 reg = 0;
  125. u32 credit_refill = 0;
  126. u32 credit_max = 0;
  127. u8 i = 0;
  128. /* Disable the arbiter before changing parameters */
  129. IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, IXGBE_RTRPCS_ARBDIS);
  130. /* Map all traffic classes to their UP, 1 to 1 */
  131. reg = 0;
  132. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  133. reg |= (i << (i * IXGBE_RTRUP2TC_UP_SHIFT));
  134. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  135. /* Configure traffic class credits and priority */
  136. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  137. p = &dcb_config->tc_config[i].path[DCB_RX_CONFIG];
  138. credit_refill = p->data_credits_refill;
  139. credit_max = p->data_credits_max;
  140. reg = credit_refill | (credit_max << IXGBE_RTRPT4C_MCL_SHIFT);
  141. reg |= (u32)(p->bwg_id) << IXGBE_RTRPT4C_BWG_SHIFT;
  142. if (p->prio_type == prio_link)
  143. reg |= IXGBE_RTRPT4C_LSP;
  144. IXGBE_WRITE_REG(hw, IXGBE_RTRPT4C(i), reg);
  145. }
  146. /*
  147. * Configure Rx packet plane (recycle mode; WSP) and
  148. * enable arbiter
  149. */
  150. reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC;
  151. IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
  152. return 0;
  153. }
  154. /**
  155. * ixgbe_dcb_config_tx_desc_arbiter_82599 - Config Tx Desc. arbiter
  156. * @hw: pointer to hardware structure
  157. * @dcb_config: pointer to ixgbe_dcb_config structure
  158. *
  159. * Configure Tx Descriptor Arbiter and credits for each traffic class.
  160. */
  161. s32 ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw *hw,
  162. struct ixgbe_dcb_config *dcb_config)
  163. {
  164. struct tc_bw_alloc *p;
  165. u32 reg, max_credits;
  166. u8 i;
  167. /* Disable the arbiter before changing parameters */
  168. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, IXGBE_RTTDCS_ARBDIS);
  169. /* Clear the per-Tx queue credits; we use per-TC instead */
  170. for (i = 0; i < 128; i++) {
  171. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
  172. IXGBE_WRITE_REG(hw, IXGBE_RTTDT1C, 0);
  173. }
  174. /* Configure traffic class credits and priority */
  175. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  176. p = &dcb_config->tc_config[i].path[DCB_TX_CONFIG];
  177. max_credits = dcb_config->tc_config[i].desc_credits_max;
  178. reg = max_credits << IXGBE_RTTDT2C_MCL_SHIFT;
  179. reg |= p->data_credits_refill;
  180. reg |= (u32)(p->bwg_id) << IXGBE_RTTDT2C_BWG_SHIFT;
  181. if (p->prio_type == prio_group)
  182. reg |= IXGBE_RTTDT2C_GSP;
  183. if (p->prio_type == prio_link)
  184. reg |= IXGBE_RTTDT2C_LSP;
  185. IXGBE_WRITE_REG(hw, IXGBE_RTTDT2C(i), reg);
  186. }
  187. /*
  188. * Configure Tx descriptor plane (recycle mode; WSP) and
  189. * enable arbiter
  190. */
  191. reg = IXGBE_RTTDCS_TDPAC | IXGBE_RTTDCS_TDRM;
  192. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
  193. return 0;
  194. }
  195. /**
  196. * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter
  197. * @hw: pointer to hardware structure
  198. * @dcb_config: pointer to ixgbe_dcb_config structure
  199. *
  200. * Configure Tx Packet Arbiter and credits for each traffic class.
  201. */
  202. s32 ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw *hw,
  203. struct ixgbe_dcb_config *dcb_config)
  204. {
  205. struct tc_bw_alloc *p;
  206. u32 reg;
  207. u8 i;
  208. /* Disable the arbiter before changing parameters */
  209. IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, IXGBE_RTTPCS_ARBDIS);
  210. /* Map all traffic classes to their UP, 1 to 1 */
  211. reg = 0;
  212. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  213. reg |= (i << (i * IXGBE_RTTUP2TC_UP_SHIFT));
  214. IXGBE_WRITE_REG(hw, IXGBE_RTTUP2TC, reg);
  215. /* Configure traffic class credits and priority */
  216. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  217. p = &dcb_config->tc_config[i].path[DCB_TX_CONFIG];
  218. reg = p->data_credits_refill;
  219. reg |= (u32)(p->data_credits_max) << IXGBE_RTTPT2C_MCL_SHIFT;
  220. reg |= (u32)(p->bwg_id) << IXGBE_RTTPT2C_BWG_SHIFT;
  221. if (p->prio_type == prio_group)
  222. reg |= IXGBE_RTTPT2C_GSP;
  223. if (p->prio_type == prio_link)
  224. reg |= IXGBE_RTTPT2C_LSP;
  225. IXGBE_WRITE_REG(hw, IXGBE_RTTPT2C(i), reg);
  226. }
  227. /*
  228. * Configure Tx packet plane (recycle mode; SP; arb delay) and
  229. * enable arbiter
  230. */
  231. reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
  232. (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT);
  233. IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
  234. return 0;
  235. }
  236. /**
  237. * ixgbe_dcb_config_pfc_82599 - Configure priority flow control
  238. * @hw: pointer to hardware structure
  239. * @dcb_config: pointer to ixgbe_dcb_config structure
  240. *
  241. * Configure Priority Flow Control (PFC) for each traffic class.
  242. */
  243. s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw,
  244. struct ixgbe_dcb_config *dcb_config)
  245. {
  246. u32 i, reg, rx_pba_size;
  247. /* If PFC is disabled globally then fall back to LFC. */
  248. if (!dcb_config->pfc_mode_enable) {
  249. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  250. hw->mac.ops.setup_fc(hw, i);
  251. goto out;
  252. }
  253. /* Configure PFC Tx thresholds per TC */
  254. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  255. if (dcb_config->rx_pba_cfg == pba_equal)
  256. rx_pba_size = IXGBE_RXPBSIZE_64KB;
  257. else
  258. rx_pba_size = (i < 4) ? IXGBE_RXPBSIZE_80KB
  259. : IXGBE_RXPBSIZE_48KB;
  260. reg = ((rx_pba_size >> 5) & 0xFFE0);
  261. if (dcb_config->tc_config[i].dcb_pfc == pfc_enabled_full ||
  262. dcb_config->tc_config[i].dcb_pfc == pfc_enabled_tx)
  263. reg |= IXGBE_FCRTL_XONE;
  264. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), reg);
  265. reg = ((rx_pba_size >> 2) & 0xFFE0);
  266. if (dcb_config->tc_config[i].dcb_pfc == pfc_enabled_full ||
  267. dcb_config->tc_config[i].dcb_pfc == pfc_enabled_tx)
  268. reg |= IXGBE_FCRTH_FCEN;
  269. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg);
  270. }
  271. /* Configure pause time (2 TCs per register) */
  272. reg = hw->fc.pause_time | (hw->fc.pause_time << 16);
  273. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  274. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  275. /* Configure flow control refresh threshold value */
  276. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  277. /* Enable Transmit PFC */
  278. reg = IXGBE_FCCFG_TFCE_PRIORITY;
  279. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, reg);
  280. /*
  281. * Enable Receive PFC
  282. * We will always honor XOFF frames we receive when
  283. * we are in PFC mode.
  284. */
  285. reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  286. reg &= ~IXGBE_MFLCN_RFCE;
  287. reg |= IXGBE_MFLCN_RPFCE;
  288. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
  289. out:
  290. return 0;
  291. }
  292. /**
  293. * ixgbe_dcb_config_tc_stats_82599 - Config traffic class statistics
  294. * @hw: pointer to hardware structure
  295. *
  296. * Configure queue statistics registers, all queues belonging to same traffic
  297. * class uses a single set of queue statistics counters.
  298. */
  299. s32 ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw *hw)
  300. {
  301. u32 reg = 0;
  302. u8 i = 0;
  303. /*
  304. * Receive Queues stats setting
  305. * 32 RQSMR registers, each configuring 4 queues.
  306. * Set all 16 queues of each TC to the same stat
  307. * with TC 'n' going to stat 'n'.
  308. */
  309. for (i = 0; i < 32; i++) {
  310. reg = 0x01010101 * (i / 4);
  311. IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
  312. }
  313. /*
  314. * Transmit Queues stats setting
  315. * 32 TQSM registers, each controlling 4 queues.
  316. * Set all queues of each TC to the same stat
  317. * with TC 'n' going to stat 'n'.
  318. * Tx queues are allocated non-uniformly to TCs:
  319. * 32, 32, 16, 16, 8, 8, 8, 8.
  320. */
  321. for (i = 0; i < 32; i++) {
  322. if (i < 8)
  323. reg = 0x00000000;
  324. else if (i < 16)
  325. reg = 0x01010101;
  326. else if (i < 20)
  327. reg = 0x02020202;
  328. else if (i < 24)
  329. reg = 0x03030303;
  330. else if (i < 26)
  331. reg = 0x04040404;
  332. else if (i < 28)
  333. reg = 0x05050505;
  334. else if (i < 30)
  335. reg = 0x06060606;
  336. else
  337. reg = 0x07070707;
  338. IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), reg);
  339. }
  340. return 0;
  341. }
  342. /**
  343. * ixgbe_dcb_config_82599 - Configure general DCB parameters
  344. * @hw: pointer to hardware structure
  345. * @dcb_config: pointer to ixgbe_dcb_config structure
  346. *
  347. * Configure general DCB parameters.
  348. */
  349. s32 ixgbe_dcb_config_82599(struct ixgbe_hw *hw)
  350. {
  351. u32 reg;
  352. u32 q;
  353. /* Disable the Tx desc arbiter so that MTQC can be changed */
  354. reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  355. reg |= IXGBE_RTTDCS_ARBDIS;
  356. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
  357. /* Enable DCB for Rx with 8 TCs */
  358. reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
  359. switch (reg & IXGBE_MRQC_MRQE_MASK) {
  360. case 0:
  361. case IXGBE_MRQC_RT4TCEN:
  362. /* RSS disabled cases */
  363. reg = (reg & ~IXGBE_MRQC_MRQE_MASK) | IXGBE_MRQC_RT8TCEN;
  364. break;
  365. case IXGBE_MRQC_RSSEN:
  366. case IXGBE_MRQC_RTRSS4TCEN:
  367. /* RSS enabled cases */
  368. reg = (reg & ~IXGBE_MRQC_MRQE_MASK) | IXGBE_MRQC_RTRSS8TCEN;
  369. break;
  370. default:
  371. /* Unsupported value, assume stale data, overwrite no RSS */
  372. reg = (reg & ~IXGBE_MRQC_MRQE_MASK) | IXGBE_MRQC_RT8TCEN;
  373. }
  374. IXGBE_WRITE_REG(hw, IXGBE_MRQC, reg);
  375. /* Enable DCB for Tx with 8 TCs */
  376. reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  377. IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
  378. /* Disable drop for all queues */
  379. for (q = 0; q < 128; q++)
  380. IXGBE_WRITE_REG(hw, IXGBE_QDE, q << IXGBE_QDE_IDX_SHIFT);
  381. /* Enable the Tx desc arbiter */
  382. reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  383. reg &= ~IXGBE_RTTDCS_ARBDIS;
  384. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
  385. return 0;
  386. }
  387. /**
  388. * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
  389. * @hw: pointer to hardware structure
  390. * @dcb_config: pointer to ixgbe_dcb_config structure
  391. *
  392. * Configure dcb settings and enable dcb mode.
  393. */
  394. s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw,
  395. struct ixgbe_dcb_config *dcb_config)
  396. {
  397. ixgbe_dcb_config_packet_buffers_82599(hw, dcb_config);
  398. ixgbe_dcb_config_82599(hw);
  399. ixgbe_dcb_config_rx_arbiter_82599(hw, dcb_config);
  400. ixgbe_dcb_config_tx_desc_arbiter_82599(hw, dcb_config);
  401. ixgbe_dcb_config_tx_data_arbiter_82599(hw, dcb_config);
  402. ixgbe_dcb_config_pfc_82599(hw, dcb_config);
  403. ixgbe_dcb_config_tc_stats_82599(hw);
  404. return 0;
  405. }