en_dcb_nl.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (c) 2011 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #include <linux/dcbnl.h>
  34. #include "mlx4_en.h"
  35. static int mlx4_en_dcbnl_ieee_getets(struct net_device *dev,
  36. struct ieee_ets *ets)
  37. {
  38. struct mlx4_en_priv *priv = netdev_priv(dev);
  39. struct ieee_ets *my_ets = &priv->ets;
  40. /* No IEEE PFC settings available */
  41. if (!my_ets)
  42. return -EINVAL;
  43. ets->ets_cap = IEEE_8021QAZ_MAX_TCS;
  44. ets->cbs = my_ets->cbs;
  45. memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
  46. memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
  47. memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
  48. return 0;
  49. }
  50. static int mlx4_en_ets_validate(struct mlx4_en_priv *priv, struct ieee_ets *ets)
  51. {
  52. int i;
  53. int total_ets_bw = 0;
  54. int has_ets_tc = 0;
  55. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  56. if (ets->prio_tc[i] > MLX4_EN_NUM_UP) {
  57. en_err(priv, "Bad priority in UP <=> TC mapping. TC: %d, UP: %d\n",
  58. i, ets->prio_tc[i]);
  59. return -EINVAL;
  60. }
  61. switch (ets->tc_tsa[i]) {
  62. case IEEE_8021QAZ_TSA_STRICT:
  63. break;
  64. case IEEE_8021QAZ_TSA_ETS:
  65. has_ets_tc = 1;
  66. total_ets_bw += ets->tc_tx_bw[i];
  67. break;
  68. default:
  69. en_err(priv, "TC[%d]: Not supported TSA: %d\n",
  70. i, ets->tc_tsa[i]);
  71. return -ENOTSUPP;
  72. }
  73. }
  74. if (has_ets_tc && total_ets_bw != MLX4_EN_BW_MAX) {
  75. en_err(priv, "Bad ETS BW sum: %d. Should be exactly 100%%\n",
  76. total_ets_bw);
  77. return -EINVAL;
  78. }
  79. return 0;
  80. }
  81. static int mlx4_en_config_port_scheduler(struct mlx4_en_priv *priv,
  82. struct ieee_ets *ets, u16 *ratelimit)
  83. {
  84. struct mlx4_en_dev *mdev = priv->mdev;
  85. int num_strict = 0;
  86. int i;
  87. __u8 tc_tx_bw[IEEE_8021QAZ_MAX_TCS] = { 0 };
  88. __u8 pg[IEEE_8021QAZ_MAX_TCS] = { 0 };
  89. ets = ets ?: &priv->ets;
  90. /* higher TC means higher priority => lower pg */
  91. for (i = IEEE_8021QAZ_MAX_TCS - 1; i >= 0; i--) {
  92. switch (ets->tc_tsa[i]) {
  93. case IEEE_8021QAZ_TSA_STRICT:
  94. pg[i] = num_strict++;
  95. tc_tx_bw[i] = MLX4_EN_BW_MAX;
  96. break;
  97. case IEEE_8021QAZ_TSA_ETS:
  98. pg[i] = MLX4_EN_TC_ETS;
  99. tc_tx_bw[i] = ets->tc_tx_bw[i] ?: MLX4_EN_BW_MIN;
  100. break;
  101. }
  102. }
  103. return mlx4_SET_PORT_SCHEDULER(mdev->dev, priv->port, tc_tx_bw, pg,
  104. ratelimit);
  105. }
  106. static int
  107. mlx4_en_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
  108. {
  109. struct mlx4_en_priv *priv = netdev_priv(dev);
  110. struct mlx4_en_dev *mdev = priv->mdev;
  111. int err;
  112. err = mlx4_en_ets_validate(priv, ets);
  113. if (err)
  114. return err;
  115. err = mlx4_SET_PORT_PRIO2TC(mdev->dev, priv->port, ets->prio_tc);
  116. if (err)
  117. return err;
  118. err = mlx4_en_config_port_scheduler(priv, ets, NULL);
  119. if (err)
  120. return err;
  121. memcpy(&priv->ets, ets, sizeof(priv->ets));
  122. return 0;
  123. }
  124. static int mlx4_en_dcbnl_ieee_getpfc(struct net_device *dev,
  125. struct ieee_pfc *pfc)
  126. {
  127. struct mlx4_en_priv *priv = netdev_priv(dev);
  128. pfc->pfc_cap = IEEE_8021QAZ_MAX_TCS;
  129. pfc->pfc_en = priv->prof->tx_ppp;
  130. return 0;
  131. }
  132. static int mlx4_en_dcbnl_ieee_setpfc(struct net_device *dev,
  133. struct ieee_pfc *pfc)
  134. {
  135. struct mlx4_en_priv *priv = netdev_priv(dev);
  136. struct mlx4_en_dev *mdev = priv->mdev;
  137. int err;
  138. en_dbg(DRV, priv, "cap: 0x%x en: 0x%x mbc: 0x%x delay: %d\n",
  139. pfc->pfc_cap,
  140. pfc->pfc_en,
  141. pfc->mbc,
  142. pfc->delay);
  143. priv->prof->rx_pause = priv->prof->tx_pause = !!pfc->pfc_en;
  144. priv->prof->rx_ppp = priv->prof->tx_ppp = pfc->pfc_en;
  145. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  146. priv->rx_skb_size + ETH_FCS_LEN,
  147. priv->prof->tx_pause,
  148. priv->prof->tx_ppp,
  149. priv->prof->rx_pause,
  150. priv->prof->rx_ppp);
  151. if (err)
  152. en_err(priv, "Failed setting pause params\n");
  153. return err;
  154. }
  155. static u8 mlx4_en_dcbnl_getdcbx(struct net_device *dev)
  156. {
  157. return DCB_CAP_DCBX_VER_IEEE;
  158. }
  159. static u8 mlx4_en_dcbnl_setdcbx(struct net_device *dev, u8 mode)
  160. {
  161. if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
  162. (mode & DCB_CAP_DCBX_VER_CEE) ||
  163. !(mode & DCB_CAP_DCBX_VER_IEEE) ||
  164. !(mode & DCB_CAP_DCBX_HOST))
  165. return 1;
  166. return 0;
  167. }
  168. const struct dcbnl_rtnl_ops mlx4_en_dcbnl_ops = {
  169. .ieee_getets = mlx4_en_dcbnl_ieee_getets,
  170. .ieee_setets = mlx4_en_dcbnl_ieee_setets,
  171. .ieee_getpfc = mlx4_en_dcbnl_ieee_getpfc,
  172. .ieee_setpfc = mlx4_en_dcbnl_ieee_setpfc,
  173. .getdcbx = mlx4_en_dcbnl_getdcbx,
  174. .setdcbx = mlx4_en_dcbnl_setdcbx,
  175. };