ixgbe_dcb.c 11 KB

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