ethtool.c 3.5 KB

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