fm10k_dcbnl.c 4.9 KB

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