ixgbe_dcb.c 5.1 KB

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