ixgbe_dcb.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. 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. s32 ixgbe_ieee_credits(__u8 *bw, __u16 *refill, __u16 *max, int max_frame)
  34. {
  35. int min_percent = 100;
  36. int min_credit, multiplier;
  37. int i;
  38. min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
  39. DCB_CREDIT_QUANTUM;
  40. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  41. if (bw[i] < min_percent && bw[i])
  42. min_percent = bw[i];
  43. }
  44. multiplier = (min_credit / min_percent) + 1;
  45. /* Find out the hw credits for each TC */
  46. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  47. int val = min(bw[i] * multiplier, MAX_CREDIT_REFILL);
  48. if (val < min_credit)
  49. val = min_credit;
  50. refill[i] = val;
  51. max[i] = bw[i] ? (bw[i] * MAX_CREDIT)/100 : min_credit;
  52. }
  53. return 0;
  54. }
  55. /**
  56. * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits
  57. * @ixgbe_dcb_config: Struct containing DCB settings.
  58. * @direction: Configuring either Tx or Rx.
  59. *
  60. * This function calculates the credits allocated to each traffic class.
  61. * It should be called only after the rules are checked by
  62. * ixgbe_dcb_check_config().
  63. */
  64. s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *hw,
  65. struct ixgbe_dcb_config *dcb_config,
  66. int max_frame, u8 direction)
  67. {
  68. struct tc_bw_alloc *p;
  69. int min_credit;
  70. int min_multiplier;
  71. int min_percent = 100;
  72. s32 ret_val = 0;
  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 == NULL) {
  80. ret_val = DCB_ERR_CONFIG;
  81. goto out;
  82. }
  83. min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
  84. DCB_CREDIT_QUANTUM;
  85. /* Find smallest link percentage */
  86. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  87. p = &dcb_config->tc_config[i].path[direction];
  88. bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
  89. link_percentage = p->bwg_percent;
  90. link_percentage = (link_percentage * bw_percent) / 100;
  91. if (link_percentage && link_percentage < min_percent)
  92. min_percent = link_percentage;
  93. }
  94. /*
  95. * The ratio between traffic classes will control the bandwidth
  96. * percentages seen on the wire. To calculate this ratio we use
  97. * a multiplier. It is required that the refill credits must be
  98. * larger than the max frame size so here we find the smallest
  99. * multiplier that will allow all bandwidth percentages to be
  100. * greater than the max frame size.
  101. */
  102. min_multiplier = (min_credit / min_percent) + 1;
  103. /* Find out the link percentage for each TC first */
  104. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  105. p = &dcb_config->tc_config[i].path[direction];
  106. bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
  107. link_percentage = p->bwg_percent;
  108. /* Must be careful of integer division for very small nums */
  109. link_percentage = (link_percentage * bw_percent) / 100;
  110. if (p->bwg_percent > 0 && link_percentage == 0)
  111. link_percentage = 1;
  112. /* Save link_percentage for reference */
  113. p->link_percent = (u8)link_percentage;
  114. /* Calculate credit refill ratio using multiplier */
  115. credit_refill = min(link_percentage * min_multiplier,
  116. MAX_CREDIT_REFILL);
  117. p->data_credits_refill = (u16)credit_refill;
  118. /* Calculate maximum credit for the TC */
  119. credit_max = (link_percentage * MAX_CREDIT) / 100;
  120. /*
  121. * Adjustment based on rule checking, if the percentage
  122. * of a TC is too small, the maximum credit may not be
  123. * enough to send out a jumbo frame in data plane arbitration.
  124. */
  125. if (credit_max && (credit_max < min_credit))
  126. credit_max = min_credit;
  127. if (direction == DCB_TX_CONFIG) {
  128. /*
  129. * Adjustment based on rule checking, if the
  130. * percentage of a TC is too small, the maximum
  131. * credit may not be enough to send out a TSO
  132. * packet in descriptor plane arbitration.
  133. */
  134. if ((hw->mac.type == ixgbe_mac_82598EB) &&
  135. credit_max &&
  136. (credit_max < MINIMUM_CREDIT_FOR_TSO))
  137. credit_max = MINIMUM_CREDIT_FOR_TSO;
  138. dcb_config->tc_config[i].desc_credits_max =
  139. (u16)credit_max;
  140. }
  141. p->data_credits_max = (u16)credit_max;
  142. }
  143. out:
  144. return ret_val;
  145. }
  146. void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en)
  147. {
  148. int i;
  149. *pfc_en = 0;
  150. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  151. *pfc_en |= (cfg->tc_config[i].dcb_pfc & 0xF) << i;
  152. }
  153. void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *cfg, int direction,
  154. u16 *refill)
  155. {
  156. struct tc_bw_alloc *p;
  157. int i;
  158. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  159. p = &cfg->tc_config[i].path[direction];
  160. refill[i] = p->data_credits_refill;
  161. }
  162. }
  163. void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *cfg, u16 *max)
  164. {
  165. int i;
  166. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  167. max[i] = cfg->tc_config[i].desc_credits_max;
  168. }
  169. void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *cfg, int direction,
  170. u8 *bwgid)
  171. {
  172. struct tc_bw_alloc *p;
  173. int i;
  174. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  175. p = &cfg->tc_config[i].path[direction];
  176. bwgid[i] = p->bwg_id;
  177. }
  178. }
  179. void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *cfg, int direction,
  180. u8 *ptype)
  181. {
  182. struct tc_bw_alloc *p;
  183. int i;
  184. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  185. p = &cfg->tc_config[i].path[direction];
  186. ptype[i] = p->prio_type;
  187. }
  188. }
  189. /**
  190. * ixgbe_dcb_hw_config - Config and enable DCB
  191. * @hw: pointer to hardware structure
  192. * @dcb_config: pointer to ixgbe_dcb_config structure
  193. *
  194. * Configure dcb settings and enable dcb mode.
  195. */
  196. s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw,
  197. struct ixgbe_dcb_config *dcb_config)
  198. {
  199. s32 ret = 0;
  200. u8 pfc_en;
  201. u8 ptype[MAX_TRAFFIC_CLASS];
  202. u8 bwgid[MAX_TRAFFIC_CLASS];
  203. u16 refill[MAX_TRAFFIC_CLASS];
  204. u16 max[MAX_TRAFFIC_CLASS];
  205. /* CEE does not define a priority to tc mapping so map 1:1 */
  206. u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7};
  207. /* Unpack CEE standard containers */
  208. ixgbe_dcb_unpack_pfc(dcb_config, &pfc_en);
  209. ixgbe_dcb_unpack_refill(dcb_config, DCB_TX_CONFIG, refill);
  210. ixgbe_dcb_unpack_max(dcb_config, max);
  211. ixgbe_dcb_unpack_bwgid(dcb_config, DCB_TX_CONFIG, bwgid);
  212. ixgbe_dcb_unpack_prio(dcb_config, DCB_TX_CONFIG, ptype);
  213. switch (hw->mac.type) {
  214. case ixgbe_mac_82598EB:
  215. ret = ixgbe_dcb_hw_config_82598(hw, dcb_config->rx_pba_cfg,
  216. pfc_en, refill, max, bwgid,
  217. ptype);
  218. break;
  219. case ixgbe_mac_82599EB:
  220. case ixgbe_mac_X540:
  221. ret = ixgbe_dcb_hw_config_82599(hw, dcb_config->rx_pba_cfg,
  222. pfc_en, refill, max, bwgid,
  223. ptype, prio_tc);
  224. break;
  225. default:
  226. break;
  227. }
  228. return ret;
  229. }
  230. /* Helper routines to abstract HW specifics from DCB netlink ops */
  231. s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en)
  232. {
  233. int ret = -EINVAL;
  234. switch (hw->mac.type) {
  235. case ixgbe_mac_82598EB:
  236. ret = ixgbe_dcb_config_pfc_82598(hw, pfc_en);
  237. break;
  238. case ixgbe_mac_82599EB:
  239. case ixgbe_mac_X540:
  240. ret = ixgbe_dcb_config_pfc_82599(hw, pfc_en);
  241. break;
  242. default:
  243. break;
  244. }
  245. return ret;
  246. }
  247. s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw,
  248. u16 *refill, u16 *max, u8 *bwg_id,
  249. u8 *prio_type, u8 *prio_tc)
  250. {
  251. switch (hw->mac.type) {
  252. case ixgbe_mac_82598EB:
  253. ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max,
  254. prio_type);
  255. ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
  256. bwg_id, prio_type);
  257. ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
  258. bwg_id, prio_type);
  259. break;
  260. case ixgbe_mac_82599EB:
  261. case ixgbe_mac_X540:
  262. ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max,
  263. bwg_id, prio_type, prio_tc);
  264. ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
  265. bwg_id, prio_type);
  266. ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id,
  267. prio_type, prio_tc);
  268. break;
  269. default:
  270. break;
  271. }
  272. return 0;
  273. }