]>
Commit | Line | Data |
---|---|---|
28c61a66 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
b7ffbd7e JB |
2 | /* |
3 | * mac80211 ethtool hooks for cfg80211 | |
4 | * | |
5 | * Copied from cfg.c - originally | |
6 | * Copyright 2006-2010 Johannes Berg <[email protected]> | |
7 | * Copyright 2014 Intel Corporation (Author: Johannes Berg) | |
01ca280d | 8 | * Copyright (C) 2018, 2022-2023 Intel Corporation |
b7ffbd7e JB |
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 | ||
16 | static int ieee80211_set_ringparam(struct net_device *dev, | |
74624944 HC |
17 | struct ethtool_ringparam *rp, |
18 | struct kernel_ethtool_ringparam *kernel_rp, | |
19 | struct netlink_ext_ack *extack) | |
b7ffbd7e JB |
20 | { |
21 | struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy); | |
22 | ||
23 | if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0) | |
24 | return -EINVAL; | |
25 | ||
8e66f6c6 | 26 | guard(wiphy)(local->hw.wiphy); |
6b348f6e | 27 | |
8e66f6c6 | 28 | return drv_set_ringparam(local, rp->tx_pending, rp->rx_pending); |
b7ffbd7e JB |
29 | } |
30 | ||
31 | static void ieee80211_get_ringparam(struct net_device *dev, | |
74624944 HC |
32 | struct ethtool_ringparam *rp, |
33 | struct kernel_ethtool_ringparam *kernel_rp, | |
34 | struct netlink_ext_ack *extack) | |
b7ffbd7e JB |
35 | { |
36 | struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy); | |
37 | ||
38 | memset(rp, 0, sizeof(*rp)); | |
39 | ||
8e66f6c6 JB |
40 | guard(wiphy)(local->hw.wiphy); |
41 | ||
b7ffbd7e JB |
42 | drv_get_ringparam(local, &rp->tx_pending, &rp->tx_max_pending, |
43 | &rp->rx_pending, &rp->rx_max_pending); | |
44 | } | |
45 | ||
46 | static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = { | |
47 | "rx_packets", "rx_bytes", | |
48 | "rx_duplicates", "rx_fragments", "rx_dropped", | |
f83f1c12 | 49 | "tx_packets", "tx_bytes", |
b7ffbd7e | 50 | "tx_filtered", "tx_retry_failed", "tx_retries", |
976bd9ef | 51 | "sta_state", "txrate", "rxrate", "signal", |
b7ffbd7e JB |
52 | "channel", "noise", "ch_time", "ch_time_busy", |
53 | "ch_time_ext_busy", "ch_time_rx", "ch_time_tx" | |
54 | }; | |
55 | #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats) | |
56 | ||
57 | static int ieee80211_get_sset_count(struct net_device *dev, int sset) | |
58 | { | |
59 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
60 | int rv = 0; | |
61 | ||
62 | if (sset == ETH_SS_STATS) | |
63 | rv += STA_STATS_LEN; | |
64 | ||
65 | rv += drv_get_et_sset_count(sdata, sset); | |
66 | ||
67 | if (rv == 0) | |
68 | return -EOPNOTSUPP; | |
69 | return rv; | |
70 | } | |
71 | ||
72 | static void ieee80211_get_stats(struct net_device *dev, | |
73 | struct ethtool_stats *stats, | |
74 | u64 *data) | |
75 | { | |
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; | |
79 | struct sta_info *sta; | |
80 | struct ieee80211_local *local = sdata->local; | |
73887fd9 | 81 | struct station_info sinfo; |
b7ffbd7e JB |
82 | struct survey_info survey; |
83 | int i, q; | |
84 | #define STA_STATS_SURVEY_LEN 7 | |
85 | ||
86 | memset(data, 0, sizeof(u64) * STA_STATS_LEN); | |
87 | ||
e5a9f8d0 JB |
88 | #define ADD_STA_STATS(sta) \ |
89 | do { \ | |
83888346 RL |
90 | data[i++] += sinfo.rx_packets; \ |
91 | data[i++] += sinfo.rx_bytes; \ | |
ce6893e9 JB |
92 | data[i++] += (sta)->rx_stats.num_duplicates; \ |
93 | data[i++] += (sta)->rx_stats.fragments; \ | |
83888346 | 94 | data[i++] += sinfo.rx_dropped_misc; \ |
e5a9f8d0 | 95 | \ |
73887fd9 JB |
96 | data[i++] += sinfo.tx_packets; \ |
97 | data[i++] += sinfo.tx_bytes; \ | |
ce6893e9 | 98 | data[i++] += (sta)->status_stats.filtered; \ |
83888346 RL |
99 | data[i++] += sinfo.tx_failed; \ |
100 | data[i++] += sinfo.tx_retries; \ | |
b7ffbd7e JB |
101 | } while (0) |
102 | ||
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 | |
106 | * network device. | |
107 | */ | |
108 | ||
8e66f6c6 | 109 | guard(wiphy)(local->hw.wiphy); |
b7ffbd7e JB |
110 | |
111 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { | |
bfd8403a | 112 | sta = sta_info_get_bss(sdata, sdata->deflink.u.mgd.bssid); |
b7ffbd7e JB |
113 | |
114 | if (!(sta && !WARN_ON(sta->sdata->dev != dev))) | |
115 | goto do_survey; | |
116 | ||
73887fd9 | 117 | memset(&sinfo, 0, sizeof(sinfo)); |
0fdf1493 | 118 | sta_set_sinfo(sta, &sinfo, false); |
b7ffbd7e JB |
119 | |
120 | i = 0; | |
ce6893e9 | 121 | ADD_STA_STATS(&sta->deflink); |
b7ffbd7e JB |
122 | |
123 | data[i++] = sta->sta_state; | |
124 | ||
125 | ||
a4217750 | 126 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) |
57c6cb81 | 127 | data[i] = 100000ULL * |
73887fd9 | 128 | cfg80211_calculate_bitrate(&sinfo.txrate); |
b7ffbd7e | 129 | i++; |
a4217750 | 130 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) |
57c6cb81 | 131 | data[i] = 100000ULL * |
73887fd9 | 132 | cfg80211_calculate_bitrate(&sinfo.rxrate); |
b7ffbd7e JB |
133 | i++; |
134 | ||
a4217750 | 135 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG)) |
73887fd9 | 136 | data[i] = (u8)sinfo.signal_avg; |
b7ffbd7e JB |
137 | i++; |
138 | } else { | |
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) | |
142 | continue; | |
143 | ||
73887fd9 | 144 | memset(&sinfo, 0, sizeof(sinfo)); |
0fdf1493 | 145 | sta_set_sinfo(sta, &sinfo, false); |
b7ffbd7e | 146 | i = 0; |
ce6893e9 | 147 | ADD_STA_STATS(&sta->deflink); |
b7ffbd7e JB |
148 | } |
149 | } | |
150 | ||
151 | do_survey: | |
152 | i = STA_STATS_LEN - STA_STATS_SURVEY_LEN; | |
153 | /* Get survey stats for current channel */ | |
154 | survey.filled = 0; | |
155 | ||
156 | rcu_read_lock(); | |
d0a9123e | 157 | chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); |
b7ffbd7e JB |
158 | if (chanctx_conf) |
159 | channel = chanctx_conf->def.chan; | |
4f85a3b3 DE |
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; | |
b7ffbd7e JB |
164 | else |
165 | channel = NULL; | |
166 | rcu_read_unlock(); | |
167 | ||
168 | if (channel) { | |
169 | q = 0; | |
170 | do { | |
171 | survey.filled = 0; | |
172 | if (drv_get_survey(local, q, &survey) != 0) { | |
173 | survey.filled = 0; | |
174 | break; | |
175 | } | |
176 | q++; | |
177 | } while (channel != survey.channel); | |
178 | } | |
179 | ||
180 | if (survey.filled) | |
181 | data[i++] = survey.channel->center_freq; | |
182 | else | |
183 | data[i++] = 0; | |
184 | if (survey.filled & SURVEY_INFO_NOISE_DBM) | |
185 | data[i++] = (u8)survey.noise; | |
186 | else | |
187 | data[i++] = -1LL; | |
4ed20beb JB |
188 | if (survey.filled & SURVEY_INFO_TIME) |
189 | data[i++] = survey.time; | |
b7ffbd7e JB |
190 | else |
191 | data[i++] = -1LL; | |
4ed20beb JB |
192 | if (survey.filled & SURVEY_INFO_TIME_BUSY) |
193 | data[i++] = survey.time_busy; | |
b7ffbd7e JB |
194 | else |
195 | data[i++] = -1LL; | |
4ed20beb JB |
196 | if (survey.filled & SURVEY_INFO_TIME_EXT_BUSY) |
197 | data[i++] = survey.time_ext_busy; | |
b7ffbd7e JB |
198 | else |
199 | data[i++] = -1LL; | |
4ed20beb JB |
200 | if (survey.filled & SURVEY_INFO_TIME_RX) |
201 | data[i++] = survey.time_rx; | |
b7ffbd7e JB |
202 | else |
203 | data[i++] = -1LL; | |
4ed20beb JB |
204 | if (survey.filled & SURVEY_INFO_TIME_TX) |
205 | data[i++] = survey.time_tx; | |
b7ffbd7e JB |
206 | else |
207 | data[i++] = -1LL; | |
208 | ||
8e66f6c6 | 209 | if (WARN_ON(i != STA_STATS_LEN)) |
b7ffbd7e JB |
210 | return; |
211 | ||
212 | drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN])); | |
213 | } | |
214 | ||
215 | static void ieee80211_get_strings(struct net_device *dev, u32 sset, u8 *data) | |
216 | { | |
217 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
218 | int sz_sta_stats = 0; | |
219 | ||
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); | |
223 | } | |
224 | drv_get_et_strings(sdata, sset, &(data[sz_sta_stats])); | |
225 | } | |
226 | ||
227 | static int ieee80211_get_regs_len(struct net_device *dev) | |
228 | { | |
229 | return 0; | |
230 | } | |
231 | ||
232 | static void ieee80211_get_regs(struct net_device *dev, | |
233 | struct ethtool_regs *regs, | |
234 | void *data) | |
235 | { | |
236 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
237 | ||
238 | regs->version = wdev->wiphy->hw_version; | |
239 | regs->len = 0; | |
240 | } | |
241 | ||
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, | |
252 | }; |