blob: 0ea695ff98adeda1185382bfda7b58958b579275 [file] [log] [blame]
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +03001/*
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);
Vladimir Kondratiev78366f62014-12-23 09:47:19 +020048 u32 tx_itr_en, tx_itr_val = 0;
49 u32 rx_itr_en, rx_itr_val = 0;
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030050
51 wil_dbg_misc(wil, "%s()\n", __func__);
52
Vladimir Kondratiev9a5511b2015-02-15 14:02:31 +020053 tx_itr_en = ioread32(wil->csr +
54 HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL));
55 if (tx_itr_en & BIT_DMA_ITR_TX_CNT_CTL_EN)
56 tx_itr_val =
57 ioread32(wil->csr +
58 HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH));
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030059
Vladimir Kondratiev9a5511b2015-02-15 14:02:31 +020060 rx_itr_en = ioread32(wil->csr +
61 HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL));
62 if (rx_itr_en & BIT_DMA_ITR_RX_CNT_CTL_EN)
63 rx_itr_val =
64 ioread32(wil->csr +
65 HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH));
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030066
Vladimir Kondratiev78366f62014-12-23 09:47:19 +020067 cp->tx_coalesce_usecs = tx_itr_val;
68 cp->rx_coalesce_usecs = rx_itr_val;
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030069 return 0;
70}
71
72static int wil_ethtoolops_set_coalesce(struct net_device *ndev,
73 struct ethtool_coalesce *cp)
74{
75 struct wil6210_priv *wil = ndev_to_wil(ndev);
76
Vladimir Kondratiev78366f62014-12-23 09:47:19 +020077 wil_dbg_misc(wil, "%s(rx %d usec, tx %d usec)\n", __func__,
78 cp->rx_coalesce_usecs, cp->tx_coalesce_usecs);
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030079
80 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) {
81 wil_dbg_misc(wil, "No IRQ coalescing in monitor mode\n");
82 return -EINVAL;
83 }
84
Vladimir Kondratiev78366f62014-12-23 09:47:19 +020085 /* only @rx_coalesce_usecs and @tx_coalesce_usecs supported,
86 * ignore other parameters
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030087 */
88
Vladimir Kondratiev78366f62014-12-23 09:47:19 +020089 if (cp->rx_coalesce_usecs > WIL6210_ITR_TRSH_MAX ||
90 cp->tx_coalesce_usecs > WIL6210_ITR_TRSH_MAX)
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030091 goto out_bad;
92
Vladimir Kondratiev78366f62014-12-23 09:47:19 +020093 wil->tx_max_burst_duration = cp->tx_coalesce_usecs;
94 wil->rx_max_burst_duration = cp->rx_coalesce_usecs;
95 wil_configure_interrupt_moderation(wil);
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030096
97 return 0;
98
99out_bad:
100 wil_dbg_misc(wil, "Unsupported coalescing params. Raw command:\n");
101 print_hex_dump_debug("DBG[MISC] coal ", DUMP_PREFIX_OFFSET, 16, 4,
102 cp, sizeof(*cp), false);
103 return -EINVAL;
104}
105
106static const struct ethtool_ops wil_ethtool_ops = {
107 .begin = wil_ethtoolops_begin,
108 .complete = wil_ethtoolops_complete,
109 .get_drvinfo = cfg80211_get_drvinfo,
110 .get_coalesce = wil_ethtoolops_get_coalesce,
111 .set_coalesce = wil_ethtoolops_set_coalesce,
112};
113
114void wil_set_ethtoolops(struct net_device *ndev)
115{
116 ndev->ethtool_ops = &wil_ethtool_ops;
117}