Linux Audio

Check our new training course

Loading...
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * mac80211 ethtool hooks for cfg80211
  4 *
  5 * Copied from cfg.c - originally
  6 * Copyright 2006-2010	Johannes Berg <johannes@sipsolutions.net>
  7 * Copyright 2014	Intel Corporation (Author: Johannes Berg)
  8 * Copyright (C) 2018 Intel Corporation
  9 */
 10#include <linux/types.h>
 11#include <net/cfg80211.h>
 12#include "ieee80211_i.h"
 13#include "sta_info.h"
 14#include "driver-ops.h"
 15
 16static int ieee80211_set_ringparam(struct net_device *dev,
 17				   struct ethtool_ringparam *rp)
 
 
 18{
 19	struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
 
 20
 21	if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
 22		return -EINVAL;
 23
 24	return drv_set_ringparam(local, rp->tx_pending, rp->rx_pending);
 
 
 
 
 25}
 26
 27static void ieee80211_get_ringparam(struct net_device *dev,
 28				    struct ethtool_ringparam *rp)
 
 
 29{
 30	struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
 31
 32	memset(rp, 0, sizeof(*rp));
 33
 
 34	drv_get_ringparam(local, &rp->tx_pending, &rp->tx_max_pending,
 35			  &rp->rx_pending, &rp->rx_max_pending);
 
 36}
 37
 38static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
 39	"rx_packets", "rx_bytes",
 40	"rx_duplicates", "rx_fragments", "rx_dropped",
 41	"tx_packets", "tx_bytes",
 42	"tx_filtered", "tx_retry_failed", "tx_retries",
 43	"sta_state", "txrate", "rxrate", "signal",
 44	"channel", "noise", "ch_time", "ch_time_busy",
 45	"ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
 46};
 47#define STA_STATS_LEN	ARRAY_SIZE(ieee80211_gstrings_sta_stats)
 48
 49static int ieee80211_get_sset_count(struct net_device *dev, int sset)
 50{
 51	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 52	int rv = 0;
 53
 54	if (sset == ETH_SS_STATS)
 55		rv += STA_STATS_LEN;
 56
 57	rv += drv_get_et_sset_count(sdata, sset);
 58
 59	if (rv == 0)
 60		return -EOPNOTSUPP;
 61	return rv;
 62}
 63
 64static void ieee80211_get_stats(struct net_device *dev,
 65				struct ethtool_stats *stats,
 66				u64 *data)
 67{
 68	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 69	struct ieee80211_chanctx_conf *chanctx_conf;
 70	struct ieee80211_channel *channel;
 71	struct sta_info *sta;
 72	struct ieee80211_local *local = sdata->local;
 73	struct station_info sinfo;
 74	struct survey_info survey;
 75	int i, q;
 76#define STA_STATS_SURVEY_LEN 7
 77
 78	memset(data, 0, sizeof(u64) * STA_STATS_LEN);
 79
 80#define ADD_STA_STATS(sta)					\
 81	do {							\
 82		data[i++] += sta->rx_stats.packets;		\
 83		data[i++] += sta->rx_stats.bytes;		\
 84		data[i++] += sta->rx_stats.num_duplicates;	\
 85		data[i++] += sta->rx_stats.fragments;		\
 86		data[i++] += sta->rx_stats.dropped;		\
 87								\
 88		data[i++] += sinfo.tx_packets;			\
 89		data[i++] += sinfo.tx_bytes;			\
 90		data[i++] += sta->status_stats.filtered;	\
 91		data[i++] += sta->status_stats.retry_failed;	\
 92		data[i++] += sta->status_stats.retry_count;	\
 93	} while (0)
 94
 95	/* For Managed stations, find the single station based on BSSID
 96	 * and use that.  For interface types, iterate through all available
 97	 * stations and add stats for any station that is assigned to this
 98	 * network device.
 99	 */
100
101	mutex_lock(&local->sta_mtx);
102
103	if (sdata->vif.type == NL80211_IFTYPE_STATION) {
104		sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
105
106		if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
107			goto do_survey;
108
109		memset(&sinfo, 0, sizeof(sinfo));
110		sta_set_sinfo(sta, &sinfo, false);
111
112		i = 0;
113		ADD_STA_STATS(sta);
114
115		data[i++] = sta->sta_state;
116
117
118		if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE))
119			data[i] = 100000ULL *
120				cfg80211_calculate_bitrate(&sinfo.txrate);
121		i++;
122		if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE))
123			data[i] = 100000ULL *
124				cfg80211_calculate_bitrate(&sinfo.rxrate);
125		i++;
126
127		if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG))
128			data[i] = (u8)sinfo.signal_avg;
129		i++;
130	} else {
131		list_for_each_entry(sta, &local->sta_list, list) {
132			/* Make sure this station belongs to the proper dev */
133			if (sta->sdata->dev != dev)
134				continue;
135
136			memset(&sinfo, 0, sizeof(sinfo));
137			sta_set_sinfo(sta, &sinfo, false);
138			i = 0;
139			ADD_STA_STATS(sta);
140		}
141	}
142
143do_survey:
144	i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
145	/* Get survey stats for current channel */
146	survey.filled = 0;
147
148	rcu_read_lock();
149	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
150	if (chanctx_conf)
151		channel = chanctx_conf->def.chan;
152	else
153		channel = NULL;
154	rcu_read_unlock();
155
156	if (channel) {
157		q = 0;
158		do {
159			survey.filled = 0;
160			if (drv_get_survey(local, q, &survey) != 0) {
161				survey.filled = 0;
162				break;
163			}
164			q++;
165		} while (channel != survey.channel);
166	}
167
168	if (survey.filled)
169		data[i++] = survey.channel->center_freq;
170	else
171		data[i++] = 0;
172	if (survey.filled & SURVEY_INFO_NOISE_DBM)
173		data[i++] = (u8)survey.noise;
174	else
175		data[i++] = -1LL;
176	if (survey.filled & SURVEY_INFO_TIME)
177		data[i++] = survey.time;
178	else
179		data[i++] = -1LL;
180	if (survey.filled & SURVEY_INFO_TIME_BUSY)
181		data[i++] = survey.time_busy;
182	else
183		data[i++] = -1LL;
184	if (survey.filled & SURVEY_INFO_TIME_EXT_BUSY)
185		data[i++] = survey.time_ext_busy;
186	else
187		data[i++] = -1LL;
188	if (survey.filled & SURVEY_INFO_TIME_RX)
189		data[i++] = survey.time_rx;
190	else
191		data[i++] = -1LL;
192	if (survey.filled & SURVEY_INFO_TIME_TX)
193		data[i++] = survey.time_tx;
194	else
195		data[i++] = -1LL;
196
197	mutex_unlock(&local->sta_mtx);
198
199	if (WARN_ON(i != STA_STATS_LEN))
200		return;
 
201
202	drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
 
203}
204
205static void ieee80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
206{
207	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
208	int sz_sta_stats = 0;
209
210	if (sset == ETH_SS_STATS) {
211		sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
212		memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
213	}
214	drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
215}
216
217static int ieee80211_get_regs_len(struct net_device *dev)
218{
219	return 0;
220}
221
222static void ieee80211_get_regs(struct net_device *dev,
223			       struct ethtool_regs *regs,
224			       void *data)
225{
226	struct wireless_dev *wdev = dev->ieee80211_ptr;
227
228	regs->version = wdev->wiphy->hw_version;
229	regs->len = 0;
230}
231
232const struct ethtool_ops ieee80211_ethtool_ops = {
233	.get_drvinfo = cfg80211_get_drvinfo,
234	.get_regs_len = ieee80211_get_regs_len,
235	.get_regs = ieee80211_get_regs,
236	.get_link = ethtool_op_get_link,
237	.get_ringparam = ieee80211_get_ringparam,
238	.set_ringparam = ieee80211_set_ringparam,
239	.get_strings = ieee80211_get_strings,
240	.get_ethtool_stats = ieee80211_get_stats,
241	.get_sset_count = ieee80211_get_sset_count,
242};
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * mac80211 ethtool hooks for cfg80211
  4 *
  5 * Copied from cfg.c - originally
  6 * Copyright 2006-2010	Johannes Berg <johannes@sipsolutions.net>
  7 * Copyright 2014	Intel Corporation (Author: Johannes Berg)
  8 * Copyright (C) 2018, 2022-2023 Intel Corporation
  9 */
 10#include <linux/types.h>
 11#include <net/cfg80211.h>
 12#include "ieee80211_i.h"
 13#include "sta_info.h"
 14#include "driver-ops.h"
 15
 16static int ieee80211_set_ringparam(struct net_device *dev,
 17				   struct ethtool_ringparam *rp,
 18				   struct kernel_ethtool_ringparam *kernel_rp,
 19				   struct netlink_ext_ack *extack)
 20{
 21	struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
 22	int ret;
 23
 24	if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
 25		return -EINVAL;
 26
 27	wiphy_lock(local->hw.wiphy);
 28	ret = drv_set_ringparam(local, rp->tx_pending, rp->rx_pending);
 29	wiphy_unlock(local->hw.wiphy);
 30
 31	return ret;
 32}
 33
 34static void ieee80211_get_ringparam(struct net_device *dev,
 35				    struct ethtool_ringparam *rp,
 36				    struct kernel_ethtool_ringparam *kernel_rp,
 37				    struct netlink_ext_ack *extack)
 38{
 39	struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
 40
 41	memset(rp, 0, sizeof(*rp));
 42
 43	wiphy_lock(local->hw.wiphy);
 44	drv_get_ringparam(local, &rp->tx_pending, &rp->tx_max_pending,
 45			  &rp->rx_pending, &rp->rx_max_pending);
 46	wiphy_unlock(local->hw.wiphy);
 47}
 48
 49static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
 50	"rx_packets", "rx_bytes",
 51	"rx_duplicates", "rx_fragments", "rx_dropped",
 52	"tx_packets", "tx_bytes",
 53	"tx_filtered", "tx_retry_failed", "tx_retries",
 54	"sta_state", "txrate", "rxrate", "signal",
 55	"channel", "noise", "ch_time", "ch_time_busy",
 56	"ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
 57};
 58#define STA_STATS_LEN	ARRAY_SIZE(ieee80211_gstrings_sta_stats)
 59
 60static int ieee80211_get_sset_count(struct net_device *dev, int sset)
 61{
 62	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 63	int rv = 0;
 64
 65	if (sset == ETH_SS_STATS)
 66		rv += STA_STATS_LEN;
 67
 68	rv += drv_get_et_sset_count(sdata, sset);
 69
 70	if (rv == 0)
 71		return -EOPNOTSUPP;
 72	return rv;
 73}
 74
 75static void ieee80211_get_stats(struct net_device *dev,
 76				struct ethtool_stats *stats,
 77				u64 *data)
 78{
 79	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 80	struct ieee80211_chanctx_conf *chanctx_conf;
 81	struct ieee80211_channel *channel;
 82	struct sta_info *sta;
 83	struct ieee80211_local *local = sdata->local;
 84	struct station_info sinfo;
 85	struct survey_info survey;
 86	int i, q;
 87#define STA_STATS_SURVEY_LEN 7
 88
 89	memset(data, 0, sizeof(u64) * STA_STATS_LEN);
 90
 91#define ADD_STA_STATS(sta)					\
 92	do {							\
 93		data[i++] += sinfo.rx_packets;			\
 94		data[i++] += sinfo.rx_bytes;			\
 95		data[i++] += (sta)->rx_stats.num_duplicates;	\
 96		data[i++] += (sta)->rx_stats.fragments;		\
 97		data[i++] += sinfo.rx_dropped_misc;		\
 98								\
 99		data[i++] += sinfo.tx_packets;			\
100		data[i++] += sinfo.tx_bytes;			\
101		data[i++] += (sta)->status_stats.filtered;	\
102		data[i++] += sinfo.tx_failed;			\
103		data[i++] += sinfo.tx_retries;			\
104	} while (0)
105
106	/* For Managed stations, find the single station based on BSSID
107	 * and use that.  For interface types, iterate through all available
108	 * stations and add stats for any station that is assigned to this
109	 * network device.
110	 */
111
112	wiphy_lock(local->hw.wiphy);
113
114	if (sdata->vif.type == NL80211_IFTYPE_STATION) {
115		sta = sta_info_get_bss(sdata, sdata->deflink.u.mgd.bssid);
116
117		if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
118			goto do_survey;
119
120		memset(&sinfo, 0, sizeof(sinfo));
121		sta_set_sinfo(sta, &sinfo, false);
122
123		i = 0;
124		ADD_STA_STATS(&sta->deflink);
125
126		data[i++] = sta->sta_state;
127
128
129		if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE))
130			data[i] = 100000ULL *
131				cfg80211_calculate_bitrate(&sinfo.txrate);
132		i++;
133		if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE))
134			data[i] = 100000ULL *
135				cfg80211_calculate_bitrate(&sinfo.rxrate);
136		i++;
137
138		if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG))
139			data[i] = (u8)sinfo.signal_avg;
140		i++;
141	} else {
142		list_for_each_entry(sta, &local->sta_list, list) {
143			/* Make sure this station belongs to the proper dev */
144			if (sta->sdata->dev != dev)
145				continue;
146
147			memset(&sinfo, 0, sizeof(sinfo));
148			sta_set_sinfo(sta, &sinfo, false);
149			i = 0;
150			ADD_STA_STATS(&sta->deflink);
151		}
152	}
153
154do_survey:
155	i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
156	/* Get survey stats for current channel */
157	survey.filled = 0;
158
159	rcu_read_lock();
160	chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
161	if (chanctx_conf)
162		channel = chanctx_conf->def.chan;
163	else
164		channel = NULL;
165	rcu_read_unlock();
166
167	if (channel) {
168		q = 0;
169		do {
170			survey.filled = 0;
171			if (drv_get_survey(local, q, &survey) != 0) {
172				survey.filled = 0;
173				break;
174			}
175			q++;
176		} while (channel != survey.channel);
177	}
178
179	if (survey.filled)
180		data[i++] = survey.channel->center_freq;
181	else
182		data[i++] = 0;
183	if (survey.filled & SURVEY_INFO_NOISE_DBM)
184		data[i++] = (u8)survey.noise;
185	else
186		data[i++] = -1LL;
187	if (survey.filled & SURVEY_INFO_TIME)
188		data[i++] = survey.time;
189	else
190		data[i++] = -1LL;
191	if (survey.filled & SURVEY_INFO_TIME_BUSY)
192		data[i++] = survey.time_busy;
193	else
194		data[i++] = -1LL;
195	if (survey.filled & SURVEY_INFO_TIME_EXT_BUSY)
196		data[i++] = survey.time_ext_busy;
197	else
198		data[i++] = -1LL;
199	if (survey.filled & SURVEY_INFO_TIME_RX)
200		data[i++] = survey.time_rx;
201	else
202		data[i++] = -1LL;
203	if (survey.filled & SURVEY_INFO_TIME_TX)
204		data[i++] = survey.time_tx;
205	else
206		data[i++] = -1LL;
207
208	if (WARN_ON(i != STA_STATS_LEN)) {
209		wiphy_unlock(local->hw.wiphy);
 
210		return;
211	}
212
213	drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
214	wiphy_unlock(local->hw.wiphy);
215}
216
217static void ieee80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
218{
219	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
220	int sz_sta_stats = 0;
221
222	if (sset == ETH_SS_STATS) {
223		sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
224		memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
225	}
226	drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
227}
228
229static int ieee80211_get_regs_len(struct net_device *dev)
230{
231	return 0;
232}
233
234static void ieee80211_get_regs(struct net_device *dev,
235			       struct ethtool_regs *regs,
236			       void *data)
237{
238	struct wireless_dev *wdev = dev->ieee80211_ptr;
239
240	regs->version = wdev->wiphy->hw_version;
241	regs->len = 0;
242}
243
244const struct ethtool_ops ieee80211_ethtool_ops = {
245	.get_drvinfo = cfg80211_get_drvinfo,
246	.get_regs_len = ieee80211_get_regs_len,
247	.get_regs = ieee80211_get_regs,
248	.get_link = ethtool_op_get_link,
249	.get_ringparam = ieee80211_get_ringparam,
250	.set_ringparam = ieee80211_set_ringparam,
251	.get_strings = ieee80211_get_strings,
252	.get_ethtool_stats = ieee80211_get_stats,
253	.get_sset_count = ieee80211_get_sset_count,
254};