Loading...
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
7#include <linux/etherdevice.h>
8#include <linux/pci.h>
9#include <linux/rtnetlink.h>
10#include <net/cfg80211.h>
11
12#include "wil6210.h"
13
14static int
15wil_ethtoolops_get_coalesce(struct net_device *ndev,
16 struct ethtool_coalesce *cp,
17 struct kernel_ethtool_coalesce *kernel_coal,
18 struct netlink_ext_ack *extack)
19{
20 struct wil6210_priv *wil = ndev_to_wil(ndev);
21 u32 tx_itr_en, tx_itr_val = 0;
22 u32 rx_itr_en, rx_itr_val = 0;
23 int ret;
24
25 mutex_lock(&wil->mutex);
26 wil_dbg_misc(wil, "ethtoolops_get_coalesce\n");
27
28 ret = wil_pm_runtime_get(wil);
29 if (ret < 0)
30 goto out;
31
32 tx_itr_en = wil_r(wil, RGF_DMA_ITR_TX_CNT_CTL);
33 if (tx_itr_en & BIT_DMA_ITR_TX_CNT_CTL_EN)
34 tx_itr_val = wil_r(wil, RGF_DMA_ITR_TX_CNT_TRSH);
35
36 rx_itr_en = wil_r(wil, RGF_DMA_ITR_RX_CNT_CTL);
37 if (rx_itr_en & BIT_DMA_ITR_RX_CNT_CTL_EN)
38 rx_itr_val = wil_r(wil, RGF_DMA_ITR_RX_CNT_TRSH);
39
40 wil_pm_runtime_put(wil);
41
42 cp->tx_coalesce_usecs = tx_itr_val;
43 cp->rx_coalesce_usecs = rx_itr_val;
44 ret = 0;
45
46out:
47 mutex_unlock(&wil->mutex);
48 return ret;
49}
50
51static int
52wil_ethtoolops_set_coalesce(struct net_device *ndev,
53 struct ethtool_coalesce *cp,
54 struct kernel_ethtool_coalesce *kernel_coal,
55 struct netlink_ext_ack *extack)
56{
57 struct wil6210_priv *wil = ndev_to_wil(ndev);
58 struct wireless_dev *wdev = ndev->ieee80211_ptr;
59 int ret;
60
61 mutex_lock(&wil->mutex);
62 wil_dbg_misc(wil, "ethtoolops_set_coalesce: rx %d usec, tx %d usec\n",
63 cp->rx_coalesce_usecs, cp->tx_coalesce_usecs);
64
65 if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
66 wil_dbg_misc(wil, "No IRQ coalescing in monitor mode\n");
67 ret = -EINVAL;
68 goto out;
69 }
70
71 /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported,
72 * ignore other parameters
73 */
74
75 if (cp->rx_coalesce_usecs > WIL6210_ITR_TRSH_MAX ||
76 cp->tx_coalesce_usecs > WIL6210_ITR_TRSH_MAX)
77 goto out_bad;
78
79 wil->tx_max_burst_duration = cp->tx_coalesce_usecs;
80 wil->rx_max_burst_duration = cp->rx_coalesce_usecs;
81
82 ret = wil_pm_runtime_get(wil);
83 if (ret < 0)
84 goto out;
85
86 wil->txrx_ops.configure_interrupt_moderation(wil);
87
88 wil_pm_runtime_put(wil);
89 ret = 0;
90
91out:
92 mutex_unlock(&wil->mutex);
93 return ret;
94
95out_bad:
96 wil_dbg_misc(wil, "Unsupported coalescing params. Raw command:\n");
97 print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET, 16, 4,
98 cp, sizeof(*cp), false);
99 mutex_unlock(&wil->mutex);
100 return -EINVAL;
101}
102
103static const struct ethtool_ops wil_ethtool_ops = {
104 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
105 .get_drvinfo = cfg80211_get_drvinfo,
106 .get_coalesce = wil_ethtoolops_get_coalesce,
107 .set_coalesce = wil_ethtoolops_set_coalesce,
108};
109
110void wil_set_ethtoolops(struct net_device *ndev)
111{
112 ndev->ethtool_ops = &wil_ethtool_ops;
113}
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
17#include <linux/etherdevice.h>
18#include <linux/pci.h>
19#include <linux/rtnetlink.h>
20#include <net/cfg80211.h>
21
22#include "wil6210.h"
23
24static int wil_ethtoolops_begin(struct net_device *ndev)
25{
26 struct wil6210_priv *wil = ndev_to_wil(ndev);
27
28 mutex_lock(&wil->mutex);
29
30 wil_dbg_misc(wil, "%s()\n", __func__);
31
32 return 0;
33}
34
35static void wil_ethtoolops_complete(struct net_device *ndev)
36{
37 struct wil6210_priv *wil = ndev_to_wil(ndev);
38
39 wil_dbg_misc(wil, "%s()\n", __func__);
40
41 mutex_unlock(&wil->mutex);
42}
43
44static int wil_ethtoolops_get_coalesce(struct net_device *ndev,
45 struct ethtool_coalesce *cp)
46{
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;
50
51 wil_dbg_misc(wil, "%s()\n", __func__);
52
53 tx_itr_en = wil_r(wil, RGF_DMA_ITR_TX_CNT_CTL);
54 if (tx_itr_en & BIT_DMA_ITR_TX_CNT_CTL_EN)
55 tx_itr_val = wil_r(wil, RGF_DMA_ITR_TX_CNT_TRSH);
56
57 rx_itr_en = wil_r(wil, RGF_DMA_ITR_RX_CNT_CTL);
58 if (rx_itr_en & BIT_DMA_ITR_RX_CNT_CTL_EN)
59 rx_itr_val = wil_r(wil, RGF_DMA_ITR_RX_CNT_TRSH);
60
61 cp->tx_coalesce_usecs = tx_itr_val;
62 cp->rx_coalesce_usecs = rx_itr_val;
63 return 0;
64}
65
66static int wil_ethtoolops_set_coalesce(struct net_device *ndev,
67 struct ethtool_coalesce *cp)
68{
69 struct wil6210_priv *wil = ndev_to_wil(ndev);
70
71 wil_dbg_misc(wil, "%s(rx %d usec, tx %d usec)\n", __func__,
72 cp->rx_coalesce_usecs, cp->tx_coalesce_usecs);
73
74 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) {
75 wil_dbg_misc(wil, "No IRQ coalescing in monitor mode\n");
76 return -EINVAL;
77 }
78
79 /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported,
80 * ignore other parameters
81 */
82
83 if (cp->rx_coalesce_usecs > WIL6210_ITR_TRSH_MAX ||
84 cp->tx_coalesce_usecs > WIL6210_ITR_TRSH_MAX)
85 goto out_bad;
86
87 wil->tx_max_burst_duration = cp->tx_coalesce_usecs;
88 wil->rx_max_burst_duration = cp->rx_coalesce_usecs;
89 wil_configure_interrupt_moderation(wil);
90
91 return 0;
92
93out_bad:
94 wil_dbg_misc(wil, "Unsupported coalescing params. Raw command:\n");
95 print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET, 16, 4,
96 cp, sizeof(*cp), false);
97 return -EINVAL;
98}
99
100static const struct ethtool_ops wil_ethtool_ops = {
101 .begin = wil_ethtoolops_begin,
102 .complete = wil_ethtoolops_complete,
103 .get_drvinfo = cfg80211_get_drvinfo,
104 .get_coalesce = wil_ethtoolops_get_coalesce,
105 .set_coalesce = wil_ethtoolops_set_coalesce,
106};
107
108void wil_set_ethtoolops(struct net_device *ndev)
109{
110 ndev->ethtool_ops = &wil_ethtool_ops;
111}