fm10k_dcbnl.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Intel(R) Ethernet Switch Host Interface Driver
  2. * Copyright(c) 2013 - 2016 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. * Contact Information:
  17. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. */
  20. #include "fm10k.h"
  21. /**
  22. * fm10k_dcbnl_ieee_getets - get the ETS configuration for the device
  23. * @dev: netdev interface for the device
  24. * @ets: ETS structure to push configuration to
  25. **/
  26. static int fm10k_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets)
  27. {
  28. int i;
  29. /* we support 8 TCs in all modes */
  30. ets->ets_cap = IEEE_8021QAZ_MAX_TCS;
  31. ets->cbs = 0;
  32. /* we only support strict priority and cannot do traffic shaping */
  33. memset(ets->tc_tx_bw, 0, sizeof(ets->tc_tx_bw));
  34. memset(ets->tc_rx_bw, 0, sizeof(ets->tc_rx_bw));
  35. memset(ets->tc_tsa, IEEE_8021QAZ_TSA_STRICT, sizeof(ets->tc_tsa));
  36. /* populate the prio map based on the netdev */
  37. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
  38. ets->prio_tc[i] = netdev_get_prio_tc_map(dev, i);
  39. return 0;
  40. }
  41. /**
  42. * fm10k_dcbnl_ieee_setets - set the ETS configuration for the device
  43. * @dev: netdev interface for the device
  44. * @ets: ETS structure to pull configuration from
  45. **/
  46. static int fm10k_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
  47. {
  48. u8 num_tc = 0;
  49. int i, err;
  50. /* verify type and determine num_tcs needed */
  51. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  52. if (ets->tc_tx_bw[i] || ets->tc_rx_bw[i])
  53. return -EINVAL;
  54. if (ets->tc_tsa[i] != IEEE_8021QAZ_TSA_STRICT)
  55. return -EINVAL;
  56. if (ets->prio_tc[i] > num_tc)
  57. num_tc = ets->prio_tc[i];
  58. }
  59. /* if requested TC is greater than 0 then num_tcs is max + 1 */
  60. if (num_tc)
  61. num_tc++;
  62. if (num_tc > IEEE_8021QAZ_MAX_TCS)
  63. return -EINVAL;
  64. /* update TC hardware mapping if necessary */
  65. if (num_tc != netdev_get_num_tc(dev)) {
  66. err = fm10k_setup_tc(dev, num_tc);
  67. if (err)
  68. return err;
  69. }
  70. /* update priority mapping */
  71. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
  72. netdev_set_prio_tc_map(dev, i, ets->prio_tc[i]);
  73. return 0;
  74. }
  75. /**
  76. * fm10k_dcbnl_ieee_getpfc - get the PFC configuration for the device
  77. * @dev: netdev interface for the device
  78. * @pfc: PFC structure to push configuration to
  79. **/
  80. static int fm10k_dcbnl_ieee_getpfc(struct net_device *dev, struct ieee_pfc *pfc)
  81. {
  82. struct fm10k_intfc *interface = netdev_priv(dev);
  83. /* record flow control max count and state of TCs */
  84. pfc->pfc_cap = IEEE_8021QAZ_MAX_TCS;
  85. pfc->pfc_en = interface->pfc_en;
  86. return 0;
  87. }
  88. /**
  89. * fm10k_dcbnl_ieee_setpfc - set the PFC configuration for the device
  90. * @dev: netdev interface for the device
  91. * @pfc: PFC structure to pull configuration from
  92. **/
  93. static int fm10k_dcbnl_ieee_setpfc(struct net_device *dev, struct ieee_pfc *pfc)
  94. {
  95. struct fm10k_intfc *interface = netdev_priv(dev);
  96. /* record PFC configuration to interface */
  97. interface->pfc_en = pfc->pfc_en;
  98. /* if we are running update the drop_en state for all queues */
  99. if (netif_running(dev))
  100. fm10k_update_rx_drop_en(interface);
  101. return 0;
  102. }
  103. /**
  104. * fm10k_dcbnl_ieee_getdcbx - get the DCBX configuration for the device
  105. * @dev: netdev interface for the device
  106. *
  107. * Returns that we support only IEEE DCB for this interface
  108. **/
  109. static u8 fm10k_dcbnl_getdcbx(struct net_device __always_unused *dev)
  110. {
  111. return DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
  112. }
  113. /**
  114. * fm10k_dcbnl_ieee_setdcbx - get the DCBX configuration for the device
  115. * @dev: netdev interface for the device
  116. * @mode: new mode for this device
  117. *
  118. * Returns error on attempt to enable anything but IEEE DCB for this interface
  119. **/
  120. static u8 fm10k_dcbnl_setdcbx(struct net_device __always_unused *dev, u8 mode)
  121. {
  122. return (mode != (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE)) ? 1 : 0;
  123. }
  124. static const struct dcbnl_rtnl_ops fm10k_dcbnl_ops = {
  125. .ieee_getets = fm10k_dcbnl_ieee_getets,
  126. .ieee_setets = fm10k_dcbnl_ieee_setets,
  127. .ieee_getpfc = fm10k_dcbnl_ieee_getpfc,
  128. .ieee_setpfc = fm10k_dcbnl_ieee_setpfc,
  129. .getdcbx = fm10k_dcbnl_getdcbx,
  130. .setdcbx = fm10k_dcbnl_setdcbx,
  131. };
  132. /**
  133. * fm10k_dcbnl_set_ops - Configures dcbnl ops pointer for netdev
  134. * @dev: netdev interface for the device
  135. *
  136. * Enables PF for DCB by assigning DCBNL ops pointer.
  137. **/
  138. void fm10k_dcbnl_set_ops(struct net_device *dev)
  139. {
  140. struct fm10k_intfc *interface = netdev_priv(dev);
  141. struct fm10k_hw *hw = &interface->hw;
  142. if (hw->mac.type == fm10k_mac_pf)
  143. dev->dcbnl_ops = &fm10k_dcbnl_ops;
  144. }