1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2014,2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
7 #include <linux/etherdevice.h>
9 #include <linux/rtnetlink.h>
10 #include <net/cfg80211.h>
14 static int wil_ethtoolops_get_coalesce(struct net_device
*ndev
,
15 struct ethtool_coalesce
*cp
)
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;
22 mutex_lock(&wil
->mutex
);
23 wil_dbg_misc(wil
, "ethtoolops_get_coalesce\n");
25 ret
= wil_pm_runtime_get(wil
);
29 tx_itr_en
= wil_r(wil
, RGF_DMA_ITR_TX_CNT_CTL
);
30 if (tx_itr_en
& BIT_DMA_ITR_TX_CNT_CTL_EN
)
31 tx_itr_val
= wil_r(wil
, RGF_DMA_ITR_TX_CNT_TRSH
);
33 rx_itr_en
= wil_r(wil
, RGF_DMA_ITR_RX_CNT_CTL
);
34 if (rx_itr_en
& BIT_DMA_ITR_RX_CNT_CTL_EN
)
35 rx_itr_val
= wil_r(wil
, RGF_DMA_ITR_RX_CNT_TRSH
);
37 wil_pm_runtime_put(wil
);
39 cp
->tx_coalesce_usecs
= tx_itr_val
;
40 cp
->rx_coalesce_usecs
= rx_itr_val
;
44 mutex_unlock(&wil
->mutex
);
48 static int wil_ethtoolops_set_coalesce(struct net_device
*ndev
,
49 struct ethtool_coalesce
*cp
)
51 struct wil6210_priv
*wil
= ndev_to_wil(ndev
);
52 struct wireless_dev
*wdev
= ndev
->ieee80211_ptr
;
55 mutex_lock(&wil
->mutex
);
56 wil_dbg_misc(wil
, "ethtoolops_set_coalesce: rx %d usec, tx %d usec\n",
57 cp
->rx_coalesce_usecs
, cp
->tx_coalesce_usecs
);
59 if (wdev
->iftype
== NL80211_IFTYPE_MONITOR
) {
60 wil_dbg_misc(wil
, "No IRQ coalescing in monitor mode\n");
65 /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported,
66 * ignore other parameters
69 if (cp
->rx_coalesce_usecs
> WIL6210_ITR_TRSH_MAX
||
70 cp
->tx_coalesce_usecs
> WIL6210_ITR_TRSH_MAX
)
73 wil
->tx_max_burst_duration
= cp
->tx_coalesce_usecs
;
74 wil
->rx_max_burst_duration
= cp
->rx_coalesce_usecs
;
76 ret
= wil_pm_runtime_get(wil
);
80 wil
->txrx_ops
.configure_interrupt_moderation(wil
);
82 wil_pm_runtime_put(wil
);
86 mutex_unlock(&wil
->mutex
);
90 wil_dbg_misc(wil
, "Unsupported coalescing params. Raw command:\n");
91 print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET
, 16, 4,
92 cp
, sizeof(*cp
), false);
93 mutex_unlock(&wil
->mutex
);
97 static const struct ethtool_ops wil_ethtool_ops
= {
98 .get_drvinfo
= cfg80211_get_drvinfo
,
99 .get_coalesce
= wil_ethtoolops_get_coalesce
,
100 .set_coalesce
= wil_ethtoolops_set_coalesce
,
103 void wil_set_ethtoolops(struct net_device
*ndev
)
105 ndev
->ethtool_ops
= &wil_ethtool_ops
;