ixgbe_dcb_82599.c 12 KB

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