ipoib_ethtool.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 2007 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. #include <linux/kernel.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/netdevice.h>
  35. #include "ipoib.h"
  36. static void ipoib_get_drvinfo(struct net_device *netdev,
  37. struct ethtool_drvinfo *drvinfo)
  38. {
  39. strncpy(drvinfo->driver, "ipoib", sizeof(drvinfo->driver) - 1);
  40. }
  41. static u32 ipoib_get_rx_csum(struct net_device *dev)
  42. {
  43. struct ipoib_dev_priv *priv = netdev_priv(dev);
  44. return test_bit(IPOIB_FLAG_CSUM, &priv->flags) &&
  45. !test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
  46. }
  47. static int ipoib_get_coalesce(struct net_device *dev,
  48. struct ethtool_coalesce *coal)
  49. {
  50. struct ipoib_dev_priv *priv = netdev_priv(dev);
  51. coal->rx_coalesce_usecs = priv->ethtool.coalesce_usecs;
  52. coal->tx_coalesce_usecs = priv->ethtool.coalesce_usecs;
  53. coal->rx_max_coalesced_frames = priv->ethtool.max_coalesced_frames;
  54. coal->tx_max_coalesced_frames = priv->ethtool.max_coalesced_frames;
  55. return 0;
  56. }
  57. static int ipoib_set_coalesce(struct net_device *dev,
  58. struct ethtool_coalesce *coal)
  59. {
  60. struct ipoib_dev_priv *priv = netdev_priv(dev);
  61. int ret;
  62. /*
  63. * Since IPoIB uses a single CQ for both rx and tx, we assume
  64. * that rx params dictate the configuration. These values are
  65. * saved in the private data and returned when ipoib_get_coalesce()
  66. * is called.
  67. */
  68. if (coal->rx_coalesce_usecs > 0xffff ||
  69. coal->rx_max_coalesced_frames > 0xffff)
  70. return -EINVAL;
  71. ret = ib_modify_cq(priv->recv_cq, coal->rx_max_coalesced_frames,
  72. coal->rx_coalesce_usecs);
  73. if (ret && ret != -ENOSYS) {
  74. ipoib_warn(priv, "failed modifying CQ (%d)\n", ret);
  75. return ret;
  76. }
  77. coal->tx_coalesce_usecs = coal->rx_coalesce_usecs;
  78. coal->tx_max_coalesced_frames = coal->rx_max_coalesced_frames;
  79. priv->ethtool.coalesce_usecs = coal->rx_coalesce_usecs;
  80. priv->ethtool.max_coalesced_frames = coal->rx_max_coalesced_frames;
  81. return 0;
  82. }
  83. static const char ipoib_stats_keys[][ETH_GSTRING_LEN] = {
  84. "LRO aggregated", "LRO flushed",
  85. "LRO avg aggr", "LRO no desc"
  86. };
  87. static void ipoib_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  88. {
  89. switch (stringset) {
  90. case ETH_SS_STATS:
  91. memcpy(data, *ipoib_stats_keys, sizeof(ipoib_stats_keys));
  92. break;
  93. }
  94. }
  95. static int ipoib_get_sset_count(struct net_device *dev, int sset)
  96. {
  97. switch (sset) {
  98. case ETH_SS_STATS:
  99. return ARRAY_SIZE(ipoib_stats_keys);
  100. default:
  101. return -EOPNOTSUPP;
  102. }
  103. }
  104. static void ipoib_get_ethtool_stats(struct net_device *dev,
  105. struct ethtool_stats *stats, uint64_t *data)
  106. {
  107. struct ipoib_dev_priv *priv = netdev_priv(dev);
  108. int index = 0;
  109. /* Get LRO statistics */
  110. data[index++] = priv->lro.lro_mgr.stats.aggregated;
  111. data[index++] = priv->lro.lro_mgr.stats.flushed;
  112. if (priv->lro.lro_mgr.stats.flushed)
  113. data[index++] = priv->lro.lro_mgr.stats.aggregated /
  114. priv->lro.lro_mgr.stats.flushed;
  115. else
  116. data[index++] = 0;
  117. data[index++] = priv->lro.lro_mgr.stats.no_desc;
  118. }
  119. static const struct ethtool_ops ipoib_ethtool_ops = {
  120. .get_drvinfo = ipoib_get_drvinfo,
  121. .get_rx_csum = ipoib_get_rx_csum,
  122. .get_coalesce = ipoib_get_coalesce,
  123. .set_coalesce = ipoib_set_coalesce,
  124. .get_flags = ethtool_op_get_flags,
  125. .set_flags = ethtool_op_set_flags,
  126. .get_strings = ipoib_get_strings,
  127. .get_sset_count = ipoib_get_sset_count,
  128. .get_ethtool_stats = ipoib_get_ethtool_stats,
  129. };
  130. void ipoib_set_ethtool_ops(struct net_device *dev)
  131. {
  132. SET_ETHTOOL_OPS(dev, &ipoib_ethtool_ops);
  133. }