1 // SPDX-License-Identifier: GPL-2.0-only
3 * mac80211 ethtool hooks for cfg80211
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
10 #include <linux/types.h>
11 #include <net/cfg80211.h>
12 #include "ieee80211_i.h"
14 #include "driver-ops.h"
16 static 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
)
21 struct ieee80211_local
*local
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
23 if (rp
->rx_mini_pending
!= 0 || rp
->rx_jumbo_pending
!= 0)
26 guard(wiphy
)(local
->hw
.wiphy
);
28 return drv_set_ringparam(local
, rp
->tx_pending
, rp
->rx_pending
);
31 static void ieee80211_get_ringparam(struct net_device
*dev
,
32 struct ethtool_ringparam
*rp
,
33 struct kernel_ethtool_ringparam
*kernel_rp
,
34 struct netlink_ext_ack
*extack
)
36 struct ieee80211_local
*local
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
38 memset(rp
, 0, sizeof(*rp
));
40 guard(wiphy
)(local
->hw
.wiphy
);
42 drv_get_ringparam(local
, &rp
->tx_pending
, &rp
->tx_max_pending
,
43 &rp
->rx_pending
, &rp
->rx_max_pending
);
46 static const char ieee80211_gstrings_sta_stats
[][ETH_GSTRING_LEN
] = {
47 "rx_packets", "rx_bytes",
48 "rx_duplicates", "rx_fragments", "rx_dropped",
49 "tx_packets", "tx_bytes",
50 "tx_filtered", "tx_retry_failed", "tx_retries",
51 "sta_state", "txrate", "rxrate", "signal",
52 "channel", "noise", "ch_time", "ch_time_busy",
53 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
55 #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
57 static int ieee80211_get_sset_count(struct net_device
*dev
, int sset
)
59 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
62 if (sset
== ETH_SS_STATS
)
65 rv
+= drv_get_et_sset_count(sdata
, sset
);
72 static void ieee80211_get_stats(struct net_device
*dev
,
73 struct ethtool_stats
*stats
,
76 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
77 struct ieee80211_chanctx_conf
*chanctx_conf
;
78 struct ieee80211_channel
*channel
;
80 struct ieee80211_local
*local
= sdata
->local
;
81 struct station_info sinfo
;
82 struct survey_info survey
;
84 #define STA_STATS_SURVEY_LEN 7
86 memset(data
, 0, sizeof(u64
) * STA_STATS_LEN
);
88 #define ADD_STA_STATS(sta) \
90 data[i++] += sinfo.rx_packets; \
91 data[i++] += sinfo.rx_bytes; \
92 data[i++] += (sta)->rx_stats.num_duplicates; \
93 data[i++] += (sta)->rx_stats.fragments; \
94 data[i++] += sinfo.rx_dropped_misc; \
96 data[i++] += sinfo.tx_packets; \
97 data[i++] += sinfo.tx_bytes; \
98 data[i++] += (sta)->status_stats.filtered; \
99 data[i++] += sinfo.tx_failed; \
100 data[i++] += sinfo.tx_retries; \
103 /* For Managed stations, find the single station based on BSSID
104 * and use that. For interface types, iterate through all available
105 * stations and add stats for any station that is assigned to this
109 guard(wiphy
)(local
->hw
.wiphy
);
111 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
112 sta
= sta_info_get_bss(sdata
, sdata
->deflink
.u
.mgd
.bssid
);
114 if (!(sta
&& !WARN_ON(sta
->sdata
->dev
!= dev
)))
117 memset(&sinfo
, 0, sizeof(sinfo
));
118 sta_set_sinfo(sta
, &sinfo
, false);
121 ADD_STA_STATS(&sta
->deflink
);
123 data
[i
++] = sta
->sta_state
;
126 if (sinfo
.filled
& BIT_ULL(NL80211_STA_INFO_TX_BITRATE
))
127 data
[i
] = 100000ULL *
128 cfg80211_calculate_bitrate(&sinfo
.txrate
);
130 if (sinfo
.filled
& BIT_ULL(NL80211_STA_INFO_RX_BITRATE
))
131 data
[i
] = 100000ULL *
132 cfg80211_calculate_bitrate(&sinfo
.rxrate
);
135 if (sinfo
.filled
& BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG
))
136 data
[i
] = (u8
)sinfo
.signal_avg
;
139 list_for_each_entry(sta
, &local
->sta_list
, list
) {
140 /* Make sure this station belongs to the proper dev */
141 if (sta
->sdata
->dev
!= dev
)
144 memset(&sinfo
, 0, sizeof(sinfo
));
145 sta_set_sinfo(sta
, &sinfo
, false);
147 ADD_STA_STATS(&sta
->deflink
);
152 i
= STA_STATS_LEN
- STA_STATS_SURVEY_LEN
;
153 /* Get survey stats for current channel */
157 chanctx_conf
= rcu_dereference(sdata
->vif
.bss_conf
.chanctx_conf
);
159 channel
= chanctx_conf
->def
.chan
;
160 else if (local
->open_count
> 0 &&
161 local
->open_count
== local
->monitors
&&
162 sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
)
163 channel
= local
->monitor_chanreq
.oper
.chan
;
172 if (drv_get_survey(local
, q
, &survey
) != 0) {
177 } while (channel
!= survey
.channel
);
181 data
[i
++] = survey
.channel
->center_freq
;
184 if (survey
.filled
& SURVEY_INFO_NOISE_DBM
)
185 data
[i
++] = (u8
)survey
.noise
;
188 if (survey
.filled
& SURVEY_INFO_TIME
)
189 data
[i
++] = survey
.time
;
192 if (survey
.filled
& SURVEY_INFO_TIME_BUSY
)
193 data
[i
++] = survey
.time_busy
;
196 if (survey
.filled
& SURVEY_INFO_TIME_EXT_BUSY
)
197 data
[i
++] = survey
.time_ext_busy
;
200 if (survey
.filled
& SURVEY_INFO_TIME_RX
)
201 data
[i
++] = survey
.time_rx
;
204 if (survey
.filled
& SURVEY_INFO_TIME_TX
)
205 data
[i
++] = survey
.time_tx
;
209 if (WARN_ON(i
!= STA_STATS_LEN
))
212 drv_get_et_stats(sdata
, stats
, &(data
[STA_STATS_LEN
]));
215 static void ieee80211_get_strings(struct net_device
*dev
, u32 sset
, u8
*data
)
217 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
218 int sz_sta_stats
= 0;
220 if (sset
== ETH_SS_STATS
) {
221 sz_sta_stats
= sizeof(ieee80211_gstrings_sta_stats
);
222 memcpy(data
, ieee80211_gstrings_sta_stats
, sz_sta_stats
);
224 drv_get_et_strings(sdata
, sset
, &(data
[sz_sta_stats
]));
227 static int ieee80211_get_regs_len(struct net_device
*dev
)
232 static void ieee80211_get_regs(struct net_device
*dev
,
233 struct ethtool_regs
*regs
,
236 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
238 regs
->version
= wdev
->wiphy
->hw_version
;
242 const struct ethtool_ops ieee80211_ethtool_ops
= {
243 .get_drvinfo
= cfg80211_get_drvinfo
,
244 .get_regs_len
= ieee80211_get_regs_len
,
245 .get_regs
= ieee80211_get_regs
,
246 .get_link
= ethtool_op_get_link
,
247 .get_ringparam
= ieee80211_get_ringparam
,
248 .set_ringparam
= ieee80211_set_ringparam
,
249 .get_strings
= ieee80211_get_strings
,
250 .get_ethtool_stats
= ieee80211_get_stats
,
251 .get_sset_count
= ieee80211_get_sset_count
,