ethtool.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2014 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/etherdevice.h>
  17. #include <linux/pci.h>
  18. #include <linux/rtnetlink.h>
  19. #include <net/cfg80211.h>
  20. #include "wil6210.h"
  21. static int wil_ethtoolops_begin(struct net_device *ndev)
  22. {
  23. struct wil6210_priv *wil = ndev_to_wil(ndev);
  24. mutex_lock(&wil->mutex);
  25. wil_dbg_misc(wil, "%s()\n", __func__);
  26. return 0;
  27. }
  28. static void wil_ethtoolops_complete(struct net_device *ndev)
  29. {
  30. struct wil6210_priv *wil = ndev_to_wil(ndev);
  31. wil_dbg_misc(wil, "%s()\n", __func__);
  32. mutex_unlock(&wil->mutex);
  33. }
  34. static int wil_ethtoolops_get_coalesce(struct net_device *ndev,
  35. struct ethtool_coalesce *cp)
  36. {
  37. struct wil6210_priv *wil = ndev_to_wil(ndev);
  38. u32 tx_itr_en, tx_itr_val = 0;
  39. u32 rx_itr_en, rx_itr_val = 0;
  40. wil_dbg_misc(wil, "%s()\n", __func__);
  41. if (test_bit(hw_capability_advanced_itr_moderation,
  42. wil->hw_capabilities)) {
  43. tx_itr_en = ioread32(wil->csr +
  44. HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL));
  45. if (tx_itr_en & BIT_DMA_ITR_TX_CNT_CTL_EN)
  46. tx_itr_val =
  47. ioread32(wil->csr +
  48. HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH));
  49. rx_itr_en = ioread32(wil->csr +
  50. HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL));
  51. if (rx_itr_en & BIT_DMA_ITR_RX_CNT_CTL_EN)
  52. rx_itr_val =
  53. ioread32(wil->csr +
  54. HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH));
  55. } else {
  56. rx_itr_en = ioread32(wil->csr + HOSTADDR(RGF_DMA_ITR_CNT_CRL));
  57. if (rx_itr_en & BIT_DMA_ITR_CNT_CRL_EN)
  58. rx_itr_val = ioread32(wil->csr +
  59. HOSTADDR(RGF_DMA_ITR_CNT_TRSH));
  60. }
  61. cp->tx_coalesce_usecs = tx_itr_val;
  62. cp->rx_coalesce_usecs = rx_itr_val;
  63. return 0;
  64. }
  65. static int wil_ethtoolops_set_coalesce(struct net_device *ndev,
  66. struct ethtool_coalesce *cp)
  67. {
  68. struct wil6210_priv *wil = ndev_to_wil(ndev);
  69. wil_dbg_misc(wil, "%s(rx %d usec, tx %d usec)\n", __func__,
  70. cp->rx_coalesce_usecs, cp->tx_coalesce_usecs);
  71. if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) {
  72. wil_dbg_misc(wil, "No IRQ coalescing in monitor mode\n");
  73. return -EINVAL;
  74. }
  75. /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported,
  76. * ignore other parameters
  77. */
  78. if (cp->rx_coalesce_usecs > WIL6210_ITR_TRSH_MAX ||
  79. cp->tx_coalesce_usecs > WIL6210_ITR_TRSH_MAX)
  80. goto out_bad;
  81. wil->tx_max_burst_duration = cp->tx_coalesce_usecs;
  82. wil->rx_max_burst_duration = cp->rx_coalesce_usecs;
  83. wil_configure_interrupt_moderation(wil);
  84. return 0;
  85. out_bad:
  86. wil_dbg_misc(wil, "Unsupported coalescing params. Raw command:\n");
  87. print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET, 16, 4,
  88. cp, sizeof(*cp), false);
  89. return -EINVAL;
  90. }
  91. static const struct ethtool_ops wil_ethtool_ops = {
  92. .begin = wil_ethtoolops_begin,
  93. .complete = wil_ethtoolops_complete,
  94. .get_drvinfo = cfg80211_get_drvinfo,
  95. .get_coalesce = wil_ethtoolops_get_coalesce,
  96. .set_coalesce = wil_ethtoolops_set_coalesce,
  97. };
  98. void wil_set_ethtoolops(struct net_device *ndev)
  99. {
  100. ndev->ethtool_ops = &wil_ethtool_ops;
  101. }