ixgbe_dcb.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. u8 direction)
  37. {
  38. struct tc_bw_alloc *p;
  39. s32 ret_val = 0;
  40. /* Initialization values default for Tx settings */
  41. u32 credit_refill = 0;
  42. u32 credit_max = 0;
  43. u16 link_percentage = 0;
  44. u8 bw_percent = 0;
  45. u8 i;
  46. if (dcb_config == NULL) {
  47. ret_val = DCB_ERR_CONFIG;
  48. goto out;
  49. }
  50. /* Find out the link percentage for each TC first */
  51. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  52. p = &dcb_config->tc_config[i].path[direction];
  53. bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
  54. link_percentage = p->bwg_percent;
  55. /* Must be careful of integer division for very small nums */
  56. link_percentage = (link_percentage * bw_percent) / 100;
  57. if (p->bwg_percent > 0 && link_percentage == 0)
  58. link_percentage = 1;
  59. /* Save link_percentage for reference */
  60. p->link_percent = (u8)link_percentage;
  61. /* Calculate credit refill and save it */
  62. credit_refill = link_percentage * MINIMUM_CREDIT_REFILL;
  63. p->data_credits_refill = (u16)credit_refill;
  64. /* Calculate maximum credit for the TC */
  65. credit_max = (link_percentage * MAX_CREDIT) / 100;
  66. /*
  67. * Adjustment based on rule checking, if the percentage
  68. * of a TC is too small, the maximum credit may not be
  69. * enough to send out a jumbo frame in data plane arbitration.
  70. */
  71. if (credit_max && (credit_max < MINIMUM_CREDIT_FOR_JUMBO))
  72. credit_max = MINIMUM_CREDIT_FOR_JUMBO;
  73. if (direction == DCB_TX_CONFIG) {
  74. /*
  75. * Adjustment based on rule checking, if the
  76. * percentage of a TC is too small, the maximum
  77. * credit may not be enough to send out a TSO
  78. * packet in descriptor plane arbitration.
  79. */
  80. if (credit_max &&
  81. (credit_max < MINIMUM_CREDIT_FOR_TSO))
  82. credit_max = MINIMUM_CREDIT_FOR_TSO;
  83. dcb_config->tc_config[i].desc_credits_max =
  84. (u16)credit_max;
  85. }
  86. p->data_credits_max = (u16)credit_max;
  87. }
  88. out:
  89. return ret_val;
  90. }
  91. /**
  92. * ixgbe_dcb_hw_config - Config and enable DCB
  93. * @hw: pointer to hardware structure
  94. * @dcb_config: pointer to ixgbe_dcb_config structure
  95. *
  96. * Configure dcb settings and enable dcb mode.
  97. */
  98. s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw,
  99. struct ixgbe_dcb_config *dcb_config)
  100. {
  101. s32 ret = 0;
  102. if (hw->mac.type == ixgbe_mac_82598EB)
  103. ret = ixgbe_dcb_hw_config_82598(hw, dcb_config);
  104. else if (hw->mac.type == ixgbe_mac_82599EB)
  105. ret = ixgbe_dcb_hw_config_82599(hw, dcb_config);
  106. return ret;
  107. }