ixgbe_dcb_82599.c 13 KB

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