ixgbe_dcb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2016 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. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include "ixgbe.h"
  22. #include "ixgbe_type.h"
  23. #include "ixgbe_dcb.h"
  24. #include "ixgbe_dcb_82598.h"
  25. #include "ixgbe_dcb_82599.h"
  26. /**
  27. * ixgbe_ieee_credits - This calculates the ieee traffic class
  28. * credits from the configured bandwidth percentages. Credits
  29. * are the smallest unit programmable into the underlying
  30. * hardware. The IEEE 802.1Qaz specification do not use bandwidth
  31. * groups so this is much simplified from the CEE case.
  32. */
  33. static s32 ixgbe_ieee_credits(__u8 *bw, __u16 *refill,
  34. __u16 *max, int max_frame)
  35. {
  36. int min_percent = 100;
  37. int min_credit, multiplier;
  38. int i;
  39. min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
  40. DCB_CREDIT_QUANTUM;
  41. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  42. if (bw[i] < min_percent && bw[i])
  43. min_percent = bw[i];
  44. }
  45. multiplier = (min_credit / min_percent) + 1;
  46. /* Find out the hw credits for each TC */
  47. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  48. int val = min(bw[i] * multiplier, MAX_CREDIT_REFILL);
  49. if (val < min_credit)
  50. val = min_credit;
  51. refill[i] = val;
  52. max[i] = bw[i] ? (bw[i] * MAX_CREDIT)/100 : min_credit;
  53. }
  54. return 0;
  55. }
  56. /**
  57. * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits
  58. * @ixgbe_dcb_config: Struct containing DCB settings.
  59. * @direction: Configuring either Tx or Rx.
  60. *
  61. * This function calculates the credits allocated to each traffic class.
  62. * It should be called only after the rules are checked by
  63. * ixgbe_dcb_check_config().
  64. */
  65. s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *hw,
  66. struct ixgbe_dcb_config *dcb_config,
  67. int max_frame, u8 direction)
  68. {
  69. struct tc_bw_alloc *p;
  70. int min_credit;
  71. int min_multiplier;
  72. int min_percent = 100;
  73. /* Initialization values default for Tx settings */
  74. u32 credit_refill = 0;
  75. u32 credit_max = 0;
  76. u16 link_percentage = 0;
  77. u8 bw_percent = 0;
  78. u8 i;
  79. if (!dcb_config)
  80. return DCB_ERR_CONFIG;
  81. min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
  82. DCB_CREDIT_QUANTUM;
  83. /* Find smallest link percentage */
  84. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  85. p = &dcb_config->tc_config[i].path[direction];
  86. bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
  87. link_percentage = p->bwg_percent;
  88. link_percentage = (link_percentage * bw_percent) / 100;
  89. if (link_percentage && link_percentage < min_percent)
  90. min_percent = link_percentage;
  91. }
  92. /*
  93. * The ratio between traffic classes will control the bandwidth
  94. * percentages seen on the wire. To calculate this ratio we use
  95. * a multiplier. It is required that the refill credits must be
  96. * larger than the max frame size so here we find the smallest
  97. * multiplier that will allow all bandwidth percentages to be
  98. * greater than the max frame size.
  99. */
  100. min_multiplier = (min_credit / min_percent) + 1;
  101. /* Find out the link percentage for each TC first */
  102. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  103. p = &dcb_config->tc_config[i].path[direction];
  104. bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
  105. link_percentage = p->bwg_percent;
  106. /* Must be careful of integer division for very small nums */
  107. link_percentage = (link_percentage * bw_percent) / 100;
  108. if (p->bwg_percent > 0 && link_percentage == 0)
  109. link_percentage = 1;
  110. /* Save link_percentage for reference */
  111. p->link_percent = (u8)link_percentage;
  112. /* Calculate credit refill ratio using multiplier */
  113. credit_refill = min(link_percentage * min_multiplier,
  114. MAX_CREDIT_REFILL);
  115. /* Refill at least minimum credit */
  116. if (credit_refill < min_credit)
  117. credit_refill = min_credit;
  118. p->data_credits_refill = (u16)credit_refill;
  119. /* Calculate maximum credit for the TC */
  120. credit_max = (link_percentage * MAX_CREDIT) / 100;
  121. /*
  122. * Adjustment based on rule checking, if the percentage
  123. * of a TC is too small, the maximum credit may not be
  124. * enough to send out a jumbo frame in data plane arbitration.
  125. */
  126. if (credit_max < min_credit)
  127. credit_max = min_credit;
  128. if (direction == DCB_TX_CONFIG) {
  129. /*
  130. * Adjustment based on rule checking, if the
  131. * percentage of a TC is too small, the maximum
  132. * credit may not be enough to send out a TSO
  133. * packet in descriptor plane arbitration.
  134. */
  135. if ((hw->mac.type == ixgbe_mac_82598EB) &&
  136. credit_max &&
  137. (credit_max < MINIMUM_CREDIT_FOR_TSO))
  138. credit_max = MINIMUM_CREDIT_FOR_TSO;
  139. dcb_config->tc_config[i].desc_credits_max =
  140. (u16)credit_max;
  141. }
  142. p->data_credits_max = (u16)credit_max;
  143. }
  144. return 0;
  145. }
  146. void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en)
  147. {
  148. struct tc_configuration *tc_config = &cfg->tc_config[0];
  149. int tc;
  150. for (*pfc_en = 0, tc = 0; tc < MAX_TRAFFIC_CLASS; tc++) {
  151. if (tc_config[tc].dcb_pfc != pfc_disabled)
  152. *pfc_en |= BIT(tc);
  153. }
  154. }
  155. void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *cfg, int direction,
  156. u16 *refill)
  157. {
  158. struct tc_configuration *tc_config = &cfg->tc_config[0];
  159. int tc;
  160. for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
  161. refill[tc] = tc_config[tc].path[direction].data_credits_refill;
  162. }
  163. void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *cfg, u16 *max)
  164. {
  165. struct tc_configuration *tc_config = &cfg->tc_config[0];
  166. int tc;
  167. for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
  168. max[tc] = tc_config[tc].desc_credits_max;
  169. }
  170. void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *cfg, int direction,
  171. u8 *bwgid)
  172. {
  173. struct tc_configuration *tc_config = &cfg->tc_config[0];
  174. int tc;
  175. for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
  176. bwgid[tc] = tc_config[tc].path[direction].bwg_id;
  177. }
  178. void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *cfg, int direction,
  179. u8 *ptype)
  180. {
  181. struct tc_configuration *tc_config = &cfg->tc_config[0];
  182. int tc;
  183. for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
  184. ptype[tc] = tc_config[tc].path[direction].prio_type;
  185. }
  186. u8 ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config *cfg, int direction, u8 up)
  187. {
  188. struct tc_configuration *tc_config = &cfg->tc_config[0];
  189. u8 prio_mask = BIT(up);
  190. u8 tc = cfg->num_tcs.pg_tcs;
  191. /* If tc is 0 then DCB is likely not enabled or supported */
  192. if (!tc)
  193. return 0;
  194. /*
  195. * Test from maximum TC to 1 and report the first match we find. If
  196. * we find no match we can assume that the TC is 0 since the TC must
  197. * be set for all user priorities
  198. */
  199. for (tc--; tc; tc--) {
  200. if (prio_mask & tc_config[tc].path[direction].up_to_tc_bitmap)
  201. break;
  202. }
  203. return tc;
  204. }
  205. void ixgbe_dcb_unpack_map(struct ixgbe_dcb_config *cfg, int direction, u8 *map)
  206. {
  207. u8 up;
  208. for (up = 0; up < MAX_USER_PRIORITY; up++)
  209. map[up] = ixgbe_dcb_get_tc_from_up(cfg, direction, up);
  210. }
  211. /**
  212. * ixgbe_dcb_hw_config - Config and enable DCB
  213. * @hw: pointer to hardware structure
  214. * @dcb_config: pointer to ixgbe_dcb_config structure
  215. *
  216. * Configure dcb settings and enable dcb mode.
  217. */
  218. s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw,
  219. struct ixgbe_dcb_config *dcb_config)
  220. {
  221. u8 pfc_en;
  222. u8 ptype[MAX_TRAFFIC_CLASS];
  223. u8 bwgid[MAX_TRAFFIC_CLASS];
  224. u8 prio_tc[MAX_TRAFFIC_CLASS];
  225. u16 refill[MAX_TRAFFIC_CLASS];
  226. u16 max[MAX_TRAFFIC_CLASS];
  227. /* Unpack CEE standard containers */
  228. ixgbe_dcb_unpack_pfc(dcb_config, &pfc_en);
  229. ixgbe_dcb_unpack_refill(dcb_config, DCB_TX_CONFIG, refill);
  230. ixgbe_dcb_unpack_max(dcb_config, max);
  231. ixgbe_dcb_unpack_bwgid(dcb_config, DCB_TX_CONFIG, bwgid);
  232. ixgbe_dcb_unpack_prio(dcb_config, DCB_TX_CONFIG, ptype);
  233. ixgbe_dcb_unpack_map(dcb_config, DCB_TX_CONFIG, prio_tc);
  234. switch (hw->mac.type) {
  235. case ixgbe_mac_82598EB:
  236. return ixgbe_dcb_hw_config_82598(hw, pfc_en, refill, max,
  237. bwgid, ptype);
  238. case ixgbe_mac_82599EB:
  239. case ixgbe_mac_X540:
  240. case ixgbe_mac_X550:
  241. case ixgbe_mac_X550EM_x:
  242. case ixgbe_mac_x550em_a:
  243. return ixgbe_dcb_hw_config_82599(hw, pfc_en, refill, max,
  244. bwgid, ptype, prio_tc);
  245. default:
  246. break;
  247. }
  248. return 0;
  249. }
  250. /* Helper routines to abstract HW specifics from DCB netlink ops */
  251. s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en, u8 *prio_tc)
  252. {
  253. switch (hw->mac.type) {
  254. case ixgbe_mac_82598EB:
  255. return ixgbe_dcb_config_pfc_82598(hw, pfc_en);
  256. case ixgbe_mac_82599EB:
  257. case ixgbe_mac_X540:
  258. case ixgbe_mac_X550:
  259. case ixgbe_mac_X550EM_x:
  260. case ixgbe_mac_x550em_a:
  261. return ixgbe_dcb_config_pfc_82599(hw, pfc_en, prio_tc);
  262. default:
  263. break;
  264. }
  265. return -EINVAL;
  266. }
  267. s32 ixgbe_dcb_hw_ets(struct ixgbe_hw *hw, struct ieee_ets *ets, int max_frame)
  268. {
  269. __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
  270. __u8 prio_type[IEEE_8021QAZ_MAX_TCS];
  271. int i;
  272. /* naively give each TC a bwg to map onto CEE hardware */
  273. __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
  274. /* Map TSA onto CEE prio type */
  275. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  276. switch (ets->tc_tsa[i]) {
  277. case IEEE_8021QAZ_TSA_STRICT:
  278. prio_type[i] = 2;
  279. break;
  280. case IEEE_8021QAZ_TSA_ETS:
  281. prio_type[i] = 0;
  282. break;
  283. default:
  284. /* Hardware only supports priority strict or
  285. * ETS transmission selection algorithms if
  286. * we receive some other value from dcbnl
  287. * throw an error
  288. */
  289. return -EINVAL;
  290. }
  291. }
  292. ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
  293. return ixgbe_dcb_hw_ets_config(hw, refill, max,
  294. bwg_id, prio_type, ets->prio_tc);
  295. }
  296. s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw,
  297. u16 *refill, u16 *max, u8 *bwg_id,
  298. u8 *prio_type, u8 *prio_tc)
  299. {
  300. switch (hw->mac.type) {
  301. case ixgbe_mac_82598EB:
  302. ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max,
  303. prio_type);
  304. ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
  305. bwg_id, prio_type);
  306. ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
  307. bwg_id, prio_type);
  308. break;
  309. case ixgbe_mac_82599EB:
  310. case ixgbe_mac_X540:
  311. case ixgbe_mac_X550:
  312. case ixgbe_mac_X550EM_x:
  313. case ixgbe_mac_x550em_a:
  314. ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max,
  315. bwg_id, prio_type, prio_tc);
  316. ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
  317. bwg_id, prio_type);
  318. ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id,
  319. prio_type, prio_tc);
  320. break;
  321. default:
  322. break;
  323. }
  324. return 0;
  325. }
  326. static void ixgbe_dcb_read_rtrup2tc_82599(struct ixgbe_hw *hw, u8 *map)
  327. {
  328. u32 reg, i;
  329. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  330. for (i = 0; i < MAX_USER_PRIORITY; i++)
  331. map[i] = IXGBE_RTRUP2TC_UP_MASK &
  332. (reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT));
  333. }
  334. void ixgbe_dcb_read_rtrup2tc(struct ixgbe_hw *hw, u8 *map)
  335. {
  336. switch (hw->mac.type) {
  337. case ixgbe_mac_82599EB:
  338. case ixgbe_mac_X540:
  339. case ixgbe_mac_X550:
  340. case ixgbe_mac_X550EM_x:
  341. case ixgbe_mac_x550em_a:
  342. ixgbe_dcb_read_rtrup2tc_82599(hw, map);
  343. break;
  344. default:
  345. break;
  346. }
  347. }