ixgbe_dcb.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2010 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_dcb_calculate_tc_credits - Calculates traffic class credits
  28. * @ixgbe_dcb_config: Struct containing DCB settings.
  29. * @direction: Configuring either Tx or Rx.
  30. *
  31. * This function calculates the credits allocated to each traffic class.
  32. * It should be called only after the rules are checked by
  33. * ixgbe_dcb_check_config().
  34. */
  35. s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_dcb_config *dcb_config,
  36. int max_frame, u8 direction)
  37. {
  38. struct tc_bw_alloc *p;
  39. int min_credit;
  40. int min_multiplier;
  41. int min_percent = 100;
  42. s32 ret_val = 0;
  43. /* Initialization values default for Tx settings */
  44. u32 credit_refill = 0;
  45. u32 credit_max = 0;
  46. u16 link_percentage = 0;
  47. u8 bw_percent = 0;
  48. u8 i;
  49. if (dcb_config == NULL) {
  50. ret_val = DCB_ERR_CONFIG;
  51. goto out;
  52. }
  53. min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
  54. DCB_CREDIT_QUANTUM;
  55. /* Find smallest link percentage */
  56. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  57. p = &dcb_config->tc_config[i].path[direction];
  58. bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
  59. link_percentage = p->bwg_percent;
  60. link_percentage = (link_percentage * bw_percent) / 100;
  61. if (link_percentage && link_percentage < min_percent)
  62. min_percent = link_percentage;
  63. }
  64. /*
  65. * The ratio between traffic classes will control the bandwidth
  66. * percentages seen on the wire. To calculate this ratio we use
  67. * a multiplier. It is required that the refill credits must be
  68. * larger than the max frame size so here we find the smallest
  69. * multiplier that will allow all bandwidth percentages to be
  70. * greater than the max frame size.
  71. */
  72. min_multiplier = (min_credit / min_percent) + 1;
  73. /* Find out the link percentage for each TC first */
  74. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  75. p = &dcb_config->tc_config[i].path[direction];
  76. bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
  77. link_percentage = p->bwg_percent;
  78. /* Must be careful of integer division for very small nums */
  79. link_percentage = (link_percentage * bw_percent) / 100;
  80. if (p->bwg_percent > 0 && link_percentage == 0)
  81. link_percentage = 1;
  82. /* Save link_percentage for reference */
  83. p->link_percent = (u8)link_percentage;
  84. /* Calculate credit refill ratio using multiplier */
  85. credit_refill = min(link_percentage * min_multiplier,
  86. MAX_CREDIT_REFILL);
  87. p->data_credits_refill = (u16)credit_refill;
  88. /* Calculate maximum credit for the TC */
  89. credit_max = (link_percentage * MAX_CREDIT) / 100;
  90. /*
  91. * Adjustment based on rule checking, if the percentage
  92. * of a TC is too small, the maximum credit may not be
  93. * enough to send out a jumbo frame in data plane arbitration.
  94. */
  95. if (credit_max && (credit_max < min_credit))
  96. credit_max = min_credit;
  97. if (direction == DCB_TX_CONFIG) {
  98. /*
  99. * Adjustment based on rule checking, if the
  100. * percentage of a TC is too small, the maximum
  101. * credit may not be enough to send out a TSO
  102. * packet in descriptor plane arbitration.
  103. */
  104. if (credit_max &&
  105. (credit_max < MINIMUM_CREDIT_FOR_TSO))
  106. credit_max = MINIMUM_CREDIT_FOR_TSO;
  107. dcb_config->tc_config[i].desc_credits_max =
  108. (u16)credit_max;
  109. }
  110. p->data_credits_max = (u16)credit_max;
  111. }
  112. out:
  113. return ret_val;
  114. }
  115. /**
  116. * ixgbe_dcb_hw_config - Config and enable DCB
  117. * @hw: pointer to hardware structure
  118. * @dcb_config: pointer to ixgbe_dcb_config structure
  119. *
  120. * Configure dcb settings and enable dcb mode.
  121. */
  122. s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw,
  123. struct ixgbe_dcb_config *dcb_config)
  124. {
  125. s32 ret = 0;
  126. if (hw->mac.type == ixgbe_mac_82598EB)
  127. ret = ixgbe_dcb_hw_config_82598(hw, dcb_config);
  128. else if (hw->mac.type == ixgbe_mac_82599EB)
  129. ret = ixgbe_dcb_hw_config_82599(hw, dcb_config);
  130. return ret;
  131. }