2 * Copyright (c) 2014,2017 Qualcomm Atheros, Inc.
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.
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.
17 #include <linux/etherdevice.h>
18 #include <linux/pci.h>
19 #include <linux/rtnetlink.h>
20 #include <net/cfg80211.h>
24 static int wil_ethtoolops_begin(struct net_device
*ndev
)
26 struct wil6210_priv
*wil
= ndev_to_wil(ndev
);
28 mutex_lock(&wil
->mutex
);
30 wil_dbg_misc(wil
, "ethtoolops_begin\n");
35 static void wil_ethtoolops_complete(struct net_device
*ndev
)
37 struct wil6210_priv
*wil
= ndev_to_wil(ndev
);
39 wil_dbg_misc(wil
, "ethtoolops_complete\n");
41 mutex_unlock(&wil
->mutex
);
44 static int wil_ethtoolops_get_coalesce(struct net_device
*ndev
,
45 struct ethtool_coalesce
*cp
)
47 struct wil6210_priv
*wil
= ndev_to_wil(ndev
);
48 u32 tx_itr_en
, tx_itr_val
= 0;
49 u32 rx_itr_en
, rx_itr_val
= 0;
52 wil_dbg_misc(wil
, "ethtoolops_get_coalesce\n");
54 ret
= wil_pm_runtime_get(wil
);
58 tx_itr_en
= wil_r(wil
, RGF_DMA_ITR_TX_CNT_CTL
);
59 if (tx_itr_en
& BIT_DMA_ITR_TX_CNT_CTL_EN
)
60 tx_itr_val
= wil_r(wil
, RGF_DMA_ITR_TX_CNT_TRSH
);
62 rx_itr_en
= wil_r(wil
, RGF_DMA_ITR_RX_CNT_CTL
);
63 if (rx_itr_en
& BIT_DMA_ITR_RX_CNT_CTL_EN
)
64 rx_itr_val
= wil_r(wil
, RGF_DMA_ITR_RX_CNT_TRSH
);
66 wil_pm_runtime_put(wil
);
68 cp
->tx_coalesce_usecs
= tx_itr_val
;
69 cp
->rx_coalesce_usecs
= rx_itr_val
;
73 static int wil_ethtoolops_set_coalesce(struct net_device
*ndev
,
74 struct ethtool_coalesce
*cp
)
76 struct wil6210_priv
*wil
= ndev_to_wil(ndev
);
79 wil_dbg_misc(wil
, "ethtoolops_set_coalesce: rx %d usec, tx %d usec\n",
80 cp
->rx_coalesce_usecs
, cp
->tx_coalesce_usecs
);
82 if (wil
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
) {
83 wil_dbg_misc(wil
, "No IRQ coalescing in monitor mode\n");
87 /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported,
88 * ignore other parameters
91 if (cp
->rx_coalesce_usecs
> WIL6210_ITR_TRSH_MAX
||
92 cp
->tx_coalesce_usecs
> WIL6210_ITR_TRSH_MAX
)
95 wil
->tx_max_burst_duration
= cp
->tx_coalesce_usecs
;
96 wil
->rx_max_burst_duration
= cp
->rx_coalesce_usecs
;
98 ret
= wil_pm_runtime_get(wil
);
102 wil_configure_interrupt_moderation(wil
);
104 wil_pm_runtime_put(wil
);
109 wil_dbg_misc(wil
, "Unsupported coalescing params. Raw command:\n");
110 print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET
, 16, 4,
111 cp
, sizeof(*cp
), false);
115 static const struct ethtool_ops wil_ethtool_ops
= {
116 .begin
= wil_ethtoolops_begin
,
117 .complete
= wil_ethtoolops_complete
,
118 .get_drvinfo
= cfg80211_get_drvinfo
,
119 .get_coalesce
= wil_ethtoolops_get_coalesce
,
120 .set_coalesce
= wil_ethtoolops_set_coalesce
,
123 void wil_set_ethtoolops(struct net_device
*ndev
)
125 ndev
->ethtool_ops
= &wil_ethtool_ops
;