ixgbe_dcb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2014 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. p->data_credits_refill = (u16)credit_refill;
  116. /* Calculate maximum credit for the TC */
  117. credit_max = (link_percentage * MAX_CREDIT) / 100;
  118. /*
  119. * Adjustment based on rule checking, if the percentage
  120. * of a TC is too small, the maximum credit may not be
  121. * enough to send out a jumbo frame in data plane arbitration.
  122. */
  123. if (credit_max && (credit_max < min_credit))
  124. credit_max = min_credit;
  125. if (direction == DCB_TX_CONFIG) {
  126. /*
  127. * Adjustment based on rule checking, if the
  128. * percentage of a TC is too small, the maximum
  129. * credit may not be enough to send out a TSO
  130. * packet in descriptor plane arbitration.
  131. */
  132. if ((hw->mac.type == ixgbe_mac_82598EB) &&
  133. credit_max &&
  134. (credit_max < MINIMUM_CREDIT_FOR_TSO))
  135. credit_max = MINIMUM_CREDIT_FOR_TSO;
  136. dcb_config->tc_config[i].desc_credits_max =
  137. (u16)credit_max;
  138. }
  139. p->data_credits_max = (u16)credit_max;
  140. }
  141. return 0;
  142. }
  143. void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en)
  144. {
  145. struct tc_configuration *tc_config = &cfg->tc_config[0];
  146. int tc;
  147. for (*pfc_en = 0, tc = 0; tc < MAX_TRAFFIC_CLASS; tc++) {
  148. if (tc_config[tc].dcb_pfc != pfc_disabled)
  149. *pfc_en |= 1 << tc;
  150. }
  151. }
  152. void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *cfg, int direction,
  153. u16 *refill)
  154. {
  155. struct tc_configuration *tc_config = &cfg->tc_config[0];
  156. int tc;
  157. for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
  158. refill[tc] = tc_config[tc].path[direction].data_credits_refill;
  159. }
  160. void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *cfg, u16 *max)
  161. {
  162. struct tc_configuration *tc_config = &cfg->tc_config[0];
  163. int tc;
  164. for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
  165. max[tc] = tc_config[tc].desc_credits_max;
  166. }
  167. void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *cfg, int direction,
  168. u8 *bwgid)
  169. {
  170. struct tc_configuration *tc_config = &cfg->tc_config[0];
  171. int tc;
  172. for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
  173. bwgid[tc] = tc_config[tc].path[direction].bwg_id;
  174. }
  175. void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *cfg, int direction,
  176. u8 *ptype)
  177. {
  178. struct tc_configuration *tc_config = &cfg->tc_config[0];
  179. int tc;
  180. for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
  181. ptype[tc] = tc_config[tc].path[direction].prio_type;
  182. }
  183. u8 ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config *cfg, int direction, u8 up)
  184. {
  185. struct tc_configuration *tc_config = &cfg->tc_config[0];
  186. u8 prio_mask = 1 << up;
  187. u8 tc = cfg->num_tcs.pg_tcs;
  188. /* If tc is 0 then DCB is likely not enabled or supported */
  189. if (!tc)
  190. return 0;
  191. /*
  192. * Test from maximum TC to 1 and report the first match we find. If
  193. * we find no match we can assume that the TC is 0 since the TC must
  194. * be set for all user priorities
  195. */
  196. for (tc--; tc; tc--) {
  197. if (prio_mask & tc_config[tc].path[direction].up_to_tc_bitmap)
  198. break;
  199. }
  200. return tc;
  201. }
  202. void ixgbe_dcb_unpack_map(struct ixgbe_dcb_config *cfg, int direction, u8 *map)
  203. {
  204. u8 up;
  205. for (up = 0; up < MAX_USER_PRIORITY; up++)
  206. map[up] = ixgbe_dcb_get_tc_from_up(cfg, direction, up);
  207. }
  208. /**
  209. * ixgbe_dcb_hw_config - Config and enable DCB
  210. * @hw: pointer to hardware structure
  211. * @dcb_config: pointer to ixgbe_dcb_config structure
  212. *
  213. * Configure dcb settings and enable dcb mode.
  214. */
  215. s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw,
  216. struct ixgbe_dcb_config *dcb_config)
  217. {
  218. u8 pfc_en;
  219. u8 ptype[MAX_TRAFFIC_CLASS];
  220. u8 bwgid[MAX_TRAFFIC_CLASS];
  221. u8 prio_tc[MAX_TRAFFIC_CLASS];
  222. u16 refill[MAX_TRAFFIC_CLASS];
  223. u16 max[MAX_TRAFFIC_CLASS];
  224. /* Unpack CEE standard containers */
  225. ixgbe_dcb_unpack_pfc(dcb_config, &pfc_en);
  226. ixgbe_dcb_unpack_refill(dcb_config, DCB_TX_CONFIG, refill);
  227. ixgbe_dcb_unpack_max(dcb_config, max);
  228. ixgbe_dcb_unpack_bwgid(dcb_config, DCB_TX_CONFIG, bwgid);
  229. ixgbe_dcb_unpack_prio(dcb_config, DCB_TX_CONFIG, ptype);
  230. ixgbe_dcb_unpack_map(dcb_config, DCB_TX_CONFIG, prio_tc);
  231. switch (hw->mac.type) {
  232. case ixgbe_mac_82598EB:
  233. return ixgbe_dcb_hw_config_82598(hw, pfc_en, refill, max,
  234. bwgid, ptype);
  235. case ixgbe_mac_82599EB:
  236. case ixgbe_mac_X540:
  237. case ixgbe_mac_X550:
  238. case ixgbe_mac_X550EM_x:
  239. return ixgbe_dcb_hw_config_82599(hw, pfc_en, refill, max,
  240. bwgid, ptype, prio_tc);
  241. default:
  242. break;
  243. }
  244. return 0;
  245. }
  246. /* Helper routines to abstract HW specifics from DCB netlink ops */
  247. s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en, u8 *prio_tc)
  248. {
  249. switch (hw->mac.type) {
  250. case ixgbe_mac_82598EB:
  251. return ixgbe_dcb_config_pfc_82598(hw, pfc_en);
  252. case ixgbe_mac_82599EB:
  253. case ixgbe_mac_X540:
  254. case ixgbe_mac_X550:
  255. case ixgbe_mac_X550EM_x:
  256. return ixgbe_dcb_config_pfc_82599(hw, pfc_en, prio_tc);
  257. default:
  258. break;
  259. }
  260. return -EINVAL;
  261. }
  262. s32 ixgbe_dcb_hw_ets(struct ixgbe_hw *hw, struct ieee_ets *ets, int max_frame)
  263. {
  264. __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
  265. __u8 prio_type[IEEE_8021QAZ_MAX_TCS];
  266. int i;
  267. /* naively give each TC a bwg to map onto CEE hardware */
  268. __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
  269. /* Map TSA onto CEE prio type */
  270. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  271. switch (ets->tc_tsa[i]) {
  272. case IEEE_8021QAZ_TSA_STRICT:
  273. prio_type[i] = 2;
  274. break;
  275. case IEEE_8021QAZ_TSA_ETS:
  276. prio_type[i] = 0;
  277. break;
  278. default:
  279. /* Hardware only supports priority strict or
  280. * ETS transmission selection algorithms if
  281. * we receive some other value from dcbnl
  282. * throw an error
  283. */
  284. return -EINVAL;
  285. }
  286. }
  287. ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
  288. return ixgbe_dcb_hw_ets_config(hw, refill, max,
  289. bwg_id, prio_type, ets->prio_tc);
  290. }
  291. s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw,
  292. u16 *refill, u16 *max, u8 *bwg_id,
  293. u8 *prio_type, u8 *prio_tc)
  294. {
  295. switch (hw->mac.type) {
  296. case ixgbe_mac_82598EB:
  297. ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max,
  298. prio_type);
  299. ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
  300. bwg_id, prio_type);
  301. ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
  302. bwg_id, prio_type);
  303. break;
  304. case ixgbe_mac_82599EB:
  305. case ixgbe_mac_X540:
  306. case ixgbe_mac_X550:
  307. case ixgbe_mac_X550EM_x:
  308. ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max,
  309. bwg_id, prio_type, prio_tc);
  310. ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
  311. bwg_id, prio_type);
  312. ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id,
  313. prio_type, prio_tc);
  314. break;
  315. default:
  316. break;
  317. }
  318. return 0;
  319. }
  320. static void ixgbe_dcb_read_rtrup2tc_82599(struct ixgbe_hw *hw, u8 *map)
  321. {
  322. u32 reg, i;
  323. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  324. for (i = 0; i < MAX_USER_PRIORITY; i++)
  325. map[i] = IXGBE_RTRUP2TC_UP_MASK &
  326. (reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT));
  327. }
  328. void ixgbe_dcb_read_rtrup2tc(struct ixgbe_hw *hw, u8 *map)
  329. {
  330. switch (hw->mac.type) {
  331. case ixgbe_mac_82599EB:
  332. case ixgbe_mac_X540:
  333. case ixgbe_mac_X550:
  334. case ixgbe_mac_X550EM_x:
  335. ixgbe_dcb_read_rtrup2tc_82599(hw, map);
  336. break;
  337. default:
  338. break;
  339. }
  340. }