ethtool.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (c) 2014,2017 Qualcomm Atheros, Inc.
  4. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  5. */
  6. #include <linux/etherdevice.h>
  7. #include <linux/pci.h>
  8. #include <linux/rtnetlink.h>
  9. #include <net/cfg80211.h>
  10. #include "wil6210.h"
  11. static int
  12. wil_ethtoolops_get_coalesce(struct net_device *ndev,
  13. struct ethtool_coalesce *cp,
  14. struct kernel_ethtool_coalesce *kernel_coal,
  15. struct netlink_ext_ack *extack)
  16. {
  17. struct wil6210_priv *wil = ndev_to_wil(ndev);
  18. u32 tx_itr_en, tx_itr_val = 0;
  19. u32 rx_itr_en, rx_itr_val = 0;
  20. int ret;
  21. mutex_lock(&wil->mutex);
  22. wil_dbg_misc(wil, "ethtoolops_get_coalesce\n");
  23. ret = wil_pm_runtime_get(wil);
  24. if (ret < 0)
  25. goto out;
  26. tx_itr_en = wil_r(wil, RGF_DMA_ITR_TX_CNT_CTL);
  27. if (tx_itr_en & BIT_DMA_ITR_TX_CNT_CTL_EN)
  28. tx_itr_val = wil_r(wil, RGF_DMA_ITR_TX_CNT_TRSH);
  29. rx_itr_en = wil_r(wil, RGF_DMA_ITR_RX_CNT_CTL);
  30. if (rx_itr_en & BIT_DMA_ITR_RX_CNT_CTL_EN)
  31. rx_itr_val = wil_r(wil, RGF_DMA_ITR_RX_CNT_TRSH);
  32. wil_pm_runtime_put(wil);
  33. cp->tx_coalesce_usecs = tx_itr_val;
  34. cp->rx_coalesce_usecs = rx_itr_val;
  35. ret = 0;
  36. out:
  37. mutex_unlock(&wil->mutex);
  38. return ret;
  39. }
  40. static int
  41. wil_ethtoolops_set_coalesce(struct net_device *ndev,
  42. struct ethtool_coalesce *cp,
  43. struct kernel_ethtool_coalesce *kernel_coal,
  44. struct netlink_ext_ack *extack)
  45. {
  46. struct wil6210_priv *wil = ndev_to_wil(ndev);
  47. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  48. int ret;
  49. mutex_lock(&wil->mutex);
  50. wil_dbg_misc(wil, "ethtoolops_set_coalesce: rx %d usec, tx %d usec\n",
  51. cp->rx_coalesce_usecs, cp->tx_coalesce_usecs);
  52. if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
  53. wil_dbg_misc(wil, "No IRQ coalescing in monitor mode\n");
  54. ret = -EINVAL;
  55. goto out;
  56. }
  57. /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported,
  58. * ignore other parameters
  59. */
  60. if (cp->rx_coalesce_usecs > WIL6210_ITR_TRSH_MAX ||
  61. cp->tx_coalesce_usecs > WIL6210_ITR_TRSH_MAX)
  62. goto out_bad;
  63. wil->tx_max_burst_duration = cp->tx_coalesce_usecs;
  64. wil->rx_max_burst_duration = cp->rx_coalesce_usecs;
  65. ret = wil_pm_runtime_get(wil);
  66. if (ret < 0)
  67. goto out;
  68. wil->txrx_ops.configure_interrupt_moderation(wil);
  69. wil_pm_runtime_put(wil);
  70. ret = 0;
  71. out:
  72. mutex_unlock(&wil->mutex);
  73. return ret;
  74. out_bad:
  75. wil_dbg_misc(wil, "Unsupported coalescing params. Raw command:\n");
  76. print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET, 16, 4,
  77. cp, sizeof(*cp), false);
  78. mutex_unlock(&wil->mutex);
  79. return -EINVAL;
  80. }
  81. static const struct ethtool_ops wil_ethtool_ops = {
  82. .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
  83. .get_drvinfo = cfg80211_get_drvinfo,
  84. .get_coalesce = wil_ethtoolops_get_coalesce,
  85. .set_coalesce = wil_ethtoolops_set_coalesce,
  86. };
  87. void wil_set_ethtoolops(struct net_device *ndev)
  88. {
  89. ndev->ethtool_ops = &wil_ethtool_ops;
  90. }