fm10k_dcbnl.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include "fm10k.h"
  4. /**
  5. * fm10k_dcbnl_ieee_getets - get the ETS configuration for the device
  6. * @dev: netdev interface for the device
  7. * @ets: ETS structure to push configuration to
  8. **/
  9. static int fm10k_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets)
  10. {
  11. int i;
  12. /* we support 8 TCs in all modes */
  13. ets->ets_cap = IEEE_8021QAZ_MAX_TCS;
  14. ets->cbs = 0;
  15. /* we only support strict priority and cannot do traffic shaping */
  16. memset(ets->tc_tx_bw, 0, sizeof(ets->tc_tx_bw));
  17. memset(ets->tc_rx_bw, 0, sizeof(ets->tc_rx_bw));
  18. memset(ets->tc_tsa, IEEE_8021QAZ_TSA_STRICT, sizeof(ets->tc_tsa));
  19. /* populate the prio map based on the netdev */
  20. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
  21. ets->prio_tc[i] = netdev_get_prio_tc_map(dev, i);
  22. return 0;
  23. }
  24. /**
  25. * fm10k_dcbnl_ieee_setets - set the ETS configuration for the device
  26. * @dev: netdev interface for the device
  27. * @ets: ETS structure to pull configuration from
  28. **/
  29. static int fm10k_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
  30. {
  31. u8 num_tc = 0;
  32. int i, err;
  33. /* verify type and determine num_tcs needed */
  34. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  35. if (ets->tc_tx_bw[i] || ets->tc_rx_bw[i])
  36. return -EINVAL;
  37. if (ets->tc_tsa[i] != IEEE_8021QAZ_TSA_STRICT)
  38. return -EINVAL;
  39. if (ets->prio_tc[i] > num_tc)
  40. num_tc = ets->prio_tc[i];
  41. }
  42. /* if requested TC is greater than 0 then num_tcs is max + 1 */
  43. if (num_tc)
  44. num_tc++;
  45. if (num_tc > IEEE_8021QAZ_MAX_TCS)
  46. return -EINVAL;
  47. /* update TC hardware mapping if necessary */
  48. if (num_tc != netdev_get_num_tc(dev)) {
  49. err = fm10k_setup_tc(dev, num_tc);
  50. if (err)
  51. return err;
  52. }
  53. /* update priority mapping */
  54. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
  55. netdev_set_prio_tc_map(dev, i, ets->prio_tc[i]);
  56. return 0;
  57. }
  58. /**
  59. * fm10k_dcbnl_ieee_getpfc - get the PFC configuration for the device
  60. * @dev: netdev interface for the device
  61. * @pfc: PFC structure to push configuration to
  62. **/
  63. static int fm10k_dcbnl_ieee_getpfc(struct net_device *dev, struct ieee_pfc *pfc)
  64. {
  65. struct fm10k_intfc *interface = netdev_priv(dev);
  66. /* record flow control max count and state of TCs */
  67. pfc->pfc_cap = IEEE_8021QAZ_MAX_TCS;
  68. pfc->pfc_en = interface->pfc_en;
  69. return 0;
  70. }
  71. /**
  72. * fm10k_dcbnl_ieee_setpfc - set the PFC configuration for the device
  73. * @dev: netdev interface for the device
  74. * @pfc: PFC structure to pull configuration from
  75. **/
  76. static int fm10k_dcbnl_ieee_setpfc(struct net_device *dev, struct ieee_pfc *pfc)
  77. {
  78. struct fm10k_intfc *interface = netdev_priv(dev);
  79. /* record PFC configuration to interface */
  80. interface->pfc_en = pfc->pfc_en;
  81. /* if we are running update the drop_en state for all queues */
  82. if (netif_running(dev))
  83. fm10k_update_rx_drop_en(interface);
  84. return 0;
  85. }
  86. /**
  87. * fm10k_dcbnl_ieee_getdcbx - get the DCBX configuration for the device
  88. * @dev: netdev interface for the device
  89. *
  90. * Returns that we support only IEEE DCB for this interface
  91. **/
  92. static u8 fm10k_dcbnl_getdcbx(struct net_device __always_unused *dev)
  93. {
  94. return DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
  95. }
  96. /**
  97. * fm10k_dcbnl_ieee_setdcbx - get the DCBX configuration for the device
  98. * @dev: netdev interface for the device
  99. * @mode: new mode for this device
  100. *
  101. * Returns error on attempt to enable anything but IEEE DCB for this interface
  102. **/
  103. static u8 fm10k_dcbnl_setdcbx(struct net_device __always_unused *dev, u8 mode)
  104. {
  105. return (mode != (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE)) ? 1 : 0;
  106. }
  107. static const struct dcbnl_rtnl_ops fm10k_dcbnl_ops = {
  108. .ieee_getets = fm10k_dcbnl_ieee_getets,
  109. .ieee_setets = fm10k_dcbnl_ieee_setets,
  110. .ieee_getpfc = fm10k_dcbnl_ieee_getpfc,
  111. .ieee_setpfc = fm10k_dcbnl_ieee_setpfc,
  112. .getdcbx = fm10k_dcbnl_getdcbx,
  113. .setdcbx = fm10k_dcbnl_setdcbx,
  114. };
  115. /**
  116. * fm10k_dcbnl_set_ops - Configures dcbnl ops pointer for netdev
  117. * @dev: netdev interface for the device
  118. *
  119. * Enables PF for DCB by assigning DCBNL ops pointer.
  120. **/
  121. void fm10k_dcbnl_set_ops(struct net_device *dev)
  122. {
  123. struct fm10k_intfc *interface = netdev_priv(dev);
  124. struct fm10k_hw *hw = &interface->hw;
  125. if (hw->mac.type == fm10k_mac_pf)
  126. dev->dcbnl_ops = &fm10k_dcbnl_ops;
  127. }