ethtool.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. tx_itr_en = wil_r(wil, RGF_DMA_ITR_TX_CNT_CTL);
  42. if (tx_itr_en & BIT_DMA_ITR_TX_CNT_CTL_EN)
  43. tx_itr_val = wil_r(wil, RGF_DMA_ITR_TX_CNT_TRSH);
  44. rx_itr_en = wil_r(wil, RGF_DMA_ITR_RX_CNT_CTL);
  45. if (rx_itr_en & BIT_DMA_ITR_RX_CNT_CTL_EN)
  46. rx_itr_val = wil_r(wil, RGF_DMA_ITR_RX_CNT_TRSH);
  47. cp->tx_coalesce_usecs = tx_itr_val;
  48. cp->rx_coalesce_usecs = rx_itr_val;
  49. return 0;
  50. }
  51. static int wil_ethtoolops_set_coalesce(struct net_device *ndev,
  52. struct ethtool_coalesce *cp)
  53. {
  54. struct wil6210_priv *wil = ndev_to_wil(ndev);
  55. wil_dbg_misc(wil, "%s(rx %d usec, tx %d usec)\n", __func__,
  56. cp->rx_coalesce_usecs, cp->tx_coalesce_usecs);
  57. if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) {
  58. wil_dbg_misc(wil, "No IRQ coalescing in monitor mode\n");
  59. return -EINVAL;
  60. }
  61. /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported,
  62. * ignore other parameters
  63. */
  64. if (cp->rx_coalesce_usecs > WIL6210_ITR_TRSH_MAX ||
  65. cp->tx_coalesce_usecs > WIL6210_ITR_TRSH_MAX)
  66. goto out_bad;
  67. wil->tx_max_burst_duration = cp->tx_coalesce_usecs;
  68. wil->rx_max_burst_duration = cp->rx_coalesce_usecs;
  69. wil_configure_interrupt_moderation(wil);
  70. return 0;
  71. out_bad:
  72. wil_dbg_misc(wil, "Unsupported coalescing params. Raw command:\n");
  73. print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET, 16, 4,
  74. cp, sizeof(*cp), false);
  75. return -EINVAL;
  76. }
  77. static const struct ethtool_ops wil_ethtool_ops = {
  78. .begin = wil_ethtoolops_begin,
  79. .complete = wil_ethtoolops_complete,
  80. .get_drvinfo = cfg80211_get_drvinfo,
  81. .get_coalesce = wil_ethtoolops_get_coalesce,
  82. .set_coalesce = wil_ethtoolops_set_coalesce,
  83. };
  84. void wil_set_ethtoolops(struct net_device *ndev)
  85. {
  86. ndev->ethtool_ops = &wil_ethtool_ops;
  87. }