blob: 5ac743816b59eb416f2153887e3608c72ca89b68 [file] [log] [blame]
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001/*
2 * mac80211 ethtool hooks for cfg80211
3 *
4 * Copied from cfg.c - originally
5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2014 Intel Corporation (Author: Johannes Berg)
Johannes Bergbfb27812018-04-20 13:49:22 +03007 * Copyright (C) 2018 Intel Corporation
Johannes Bergb7ffbd72014-06-04 17:31:56 +02008 *
9 * This file is GPLv2 as found in COPYING.
10 */
11#include <linux/types.h>
12#include <net/cfg80211.h>
13#include "ieee80211_i.h"
14#include "sta_info.h"
15#include "driver-ops.h"
16
17static int ieee80211_set_ringparam(struct net_device *dev,
18 struct ethtool_ringparam *rp)
19{
20 struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
21
22 if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
23 return -EINVAL;
24
25 return drv_set_ringparam(local, rp->tx_pending, rp->rx_pending);
26}
27
28static void ieee80211_get_ringparam(struct net_device *dev,
29 struct ethtool_ringparam *rp)
30{
31 struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
32
33 memset(rp, 0, sizeof(*rp));
34
35 drv_get_ringparam(local, &rp->tx_pending, &rp->tx_max_pending,
36 &rp->rx_pending, &rp->rx_max_pending);
37}
38
39static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
40 "rx_packets", "rx_bytes",
41 "rx_duplicates", "rx_fragments", "rx_dropped",
Johannes Bergf83f1c12015-04-22 20:55:55 +020042 "tx_packets", "tx_bytes",
Johannes Bergb7ffbd72014-06-04 17:31:56 +020043 "tx_filtered", "tx_retry_failed", "tx_retries",
Johannes Berg976bd9e2015-10-16 17:18:11 +020044 "sta_state", "txrate", "rxrate", "signal",
Johannes Bergb7ffbd72014-06-04 17:31:56 +020045 "channel", "noise", "ch_time", "ch_time_busy",
46 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
47};
48#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
49
50static int ieee80211_get_sset_count(struct net_device *dev, int sset)
51{
52 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
53 int rv = 0;
54
55 if (sset == ETH_SS_STATS)
56 rv += STA_STATS_LEN;
57
58 rv += drv_get_et_sset_count(sdata, sset);
59
60 if (rv == 0)
61 return -EOPNOTSUPP;
62 return rv;
63}
64
65static void ieee80211_get_stats(struct net_device *dev,
66 struct ethtool_stats *stats,
67 u64 *data)
68{
69 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
70 struct ieee80211_chanctx_conf *chanctx_conf;
71 struct ieee80211_channel *channel;
72 struct sta_info *sta;
73 struct ieee80211_local *local = sdata->local;
Johannes Berg73887fd2018-05-18 09:57:55 +020074 struct station_info sinfo;
Johannes Bergb7ffbd72014-06-04 17:31:56 +020075 struct survey_info survey;
76 int i, q;
77#define STA_STATS_SURVEY_LEN 7
78
79 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
80
Johannes Berge5a9f8d2015-10-16 17:54:47 +020081#define ADD_STA_STATS(sta) \
82 do { \
83 data[i++] += sta->rx_stats.packets; \
84 data[i++] += sta->rx_stats.bytes; \
85 data[i++] += sta->rx_stats.num_duplicates; \
86 data[i++] += sta->rx_stats.fragments; \
87 data[i++] += sta->rx_stats.dropped; \
88 \
Johannes Berg73887fd2018-05-18 09:57:55 +020089 data[i++] += sinfo.tx_packets; \
90 data[i++] += sinfo.tx_bytes; \
Johannes Berge5a9f8d2015-10-16 17:54:47 +020091 data[i++] += sta->status_stats.filtered; \
92 data[i++] += sta->status_stats.retry_failed; \
93 data[i++] += sta->status_stats.retry_count; \
Johannes Bergb7ffbd72014-06-04 17:31:56 +020094 } while (0)
95
96 /* For Managed stations, find the single station based on BSSID
97 * and use that. For interface types, iterate through all available
98 * stations and add stats for any station that is assigned to this
99 * network device.
100 */
101
102 mutex_lock(&local->sta_mtx);
103
104 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
105 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
106
107 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
108 goto do_survey;
109
Johannes Berg73887fd2018-05-18 09:57:55 +0200110 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg0fdf1492018-05-18 11:40:44 +0200111 sta_set_sinfo(sta, &sinfo, false);
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200112
113 i = 0;
114 ADD_STA_STATS(sta);
115
116 data[i++] = sta->sta_state;
117
118
Omer Efrata4217752018-06-17 13:06:25 +0300119 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE))
Colin Ian King57c6cb82018-05-08 13:57:32 +0100120 data[i] = 100000ULL *
Johannes Berg73887fd2018-05-18 09:57:55 +0200121 cfg80211_calculate_bitrate(&sinfo.txrate);
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200122 i++;
Omer Efrata4217752018-06-17 13:06:25 +0300123 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE))
Colin Ian King57c6cb82018-05-08 13:57:32 +0100124 data[i] = 100000ULL *
Johannes Berg73887fd2018-05-18 09:57:55 +0200125 cfg80211_calculate_bitrate(&sinfo.rxrate);
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200126 i++;
127
Omer Efrata4217752018-06-17 13:06:25 +0300128 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG))
Johannes Berg73887fd2018-05-18 09:57:55 +0200129 data[i] = (u8)sinfo.signal_avg;
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200130 i++;
131 } else {
132 list_for_each_entry(sta, &local->sta_list, list) {
133 /* Make sure this station belongs to the proper dev */
134 if (sta->sdata->dev != dev)
135 continue;
136
Johannes Berg73887fd2018-05-18 09:57:55 +0200137 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg0fdf1492018-05-18 11:40:44 +0200138 sta_set_sinfo(sta, &sinfo, false);
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200139 i = 0;
140 ADD_STA_STATS(sta);
141 }
142 }
143
144do_survey:
145 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
146 /* Get survey stats for current channel */
147 survey.filled = 0;
148
149 rcu_read_lock();
150 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
151 if (chanctx_conf)
152 channel = chanctx_conf->def.chan;
153 else
154 channel = NULL;
155 rcu_read_unlock();
156
157 if (channel) {
158 q = 0;
159 do {
160 survey.filled = 0;
161 if (drv_get_survey(local, q, &survey) != 0) {
162 survey.filled = 0;
163 break;
164 }
165 q++;
166 } while (channel != survey.channel);
167 }
168
169 if (survey.filled)
170 data[i++] = survey.channel->center_freq;
171 else
172 data[i++] = 0;
173 if (survey.filled & SURVEY_INFO_NOISE_DBM)
174 data[i++] = (u8)survey.noise;
175 else
176 data[i++] = -1LL;
Johannes Berg4ed20be2014-11-14 16:35:34 +0100177 if (survey.filled & SURVEY_INFO_TIME)
178 data[i++] = survey.time;
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200179 else
180 data[i++] = -1LL;
Johannes Berg4ed20be2014-11-14 16:35:34 +0100181 if (survey.filled & SURVEY_INFO_TIME_BUSY)
182 data[i++] = survey.time_busy;
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200183 else
184 data[i++] = -1LL;
Johannes Berg4ed20be2014-11-14 16:35:34 +0100185 if (survey.filled & SURVEY_INFO_TIME_EXT_BUSY)
186 data[i++] = survey.time_ext_busy;
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200187 else
188 data[i++] = -1LL;
Johannes Berg4ed20be2014-11-14 16:35:34 +0100189 if (survey.filled & SURVEY_INFO_TIME_RX)
190 data[i++] = survey.time_rx;
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200191 else
192 data[i++] = -1LL;
Johannes Berg4ed20be2014-11-14 16:35:34 +0100193 if (survey.filled & SURVEY_INFO_TIME_TX)
194 data[i++] = survey.time_tx;
Johannes Bergb7ffbd72014-06-04 17:31:56 +0200195 else
196 data[i++] = -1LL;
197
198 mutex_unlock(&local->sta_mtx);
199
200 if (WARN_ON(i != STA_STATS_LEN))
201 return;
202
203 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
204}
205
206static void ieee80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
207{
208 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
209 int sz_sta_stats = 0;
210
211 if (sset == ETH_SS_STATS) {
212 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
213 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
214 }
215 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
216}
217
218static int ieee80211_get_regs_len(struct net_device *dev)
219{
220 return 0;
221}
222
223static void ieee80211_get_regs(struct net_device *dev,
224 struct ethtool_regs *regs,
225 void *data)
226{
227 struct wireless_dev *wdev = dev->ieee80211_ptr;
228
229 regs->version = wdev->wiphy->hw_version;
230 regs->len = 0;
231}
232
233const struct ethtool_ops ieee80211_ethtool_ops = {
234 .get_drvinfo = cfg80211_get_drvinfo,
235 .get_regs_len = ieee80211_get_regs_len,
236 .get_regs = ieee80211_get_regs,
237 .get_link = ethtool_op_get_link,
238 .get_ringparam = ieee80211_get_ringparam,
239 .set_ringparam = ieee80211_set_ringparam,
240 .get_strings = ieee80211_get_strings,
241 .get_ethtool_stats = ieee80211_get_stats,
242 .get_sset_count = ieee80211_get_sset_count,
243};