ixgbe_dcb_82599.c 12 KB

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