0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/types.h>
0011 #include <net/cfg80211.h>
0012 #include "ieee80211_i.h"
0013 #include "sta_info.h"
0014 #include "driver-ops.h"
0015
0016 static int ieee80211_set_ringparam(struct net_device *dev,
0017 struct ethtool_ringparam *rp,
0018 struct kernel_ethtool_ringparam *kernel_rp,
0019 struct netlink_ext_ack *extack)
0020 {
0021 struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
0022
0023 if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
0024 return -EINVAL;
0025
0026 return drv_set_ringparam(local, rp->tx_pending, rp->rx_pending);
0027 }
0028
0029 static void ieee80211_get_ringparam(struct net_device *dev,
0030 struct ethtool_ringparam *rp,
0031 struct kernel_ethtool_ringparam *kernel_rp,
0032 struct netlink_ext_ack *extack)
0033 {
0034 struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
0035
0036 memset(rp, 0, sizeof(*rp));
0037
0038 drv_get_ringparam(local, &rp->tx_pending, &rp->tx_max_pending,
0039 &rp->rx_pending, &rp->rx_max_pending);
0040 }
0041
0042 static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
0043 "rx_packets", "rx_bytes",
0044 "rx_duplicates", "rx_fragments", "rx_dropped",
0045 "tx_packets", "tx_bytes",
0046 "tx_filtered", "tx_retry_failed", "tx_retries",
0047 "sta_state", "txrate", "rxrate", "signal",
0048 "channel", "noise", "ch_time", "ch_time_busy",
0049 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
0050 };
0051 #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
0052
0053 static int ieee80211_get_sset_count(struct net_device *dev, int sset)
0054 {
0055 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
0056 int rv = 0;
0057
0058 if (sset == ETH_SS_STATS)
0059 rv += STA_STATS_LEN;
0060
0061 rv += drv_get_et_sset_count(sdata, sset);
0062
0063 if (rv == 0)
0064 return -EOPNOTSUPP;
0065 return rv;
0066 }
0067
0068 static void ieee80211_get_stats(struct net_device *dev,
0069 struct ethtool_stats *stats,
0070 u64 *data)
0071 {
0072 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
0073 struct ieee80211_chanctx_conf *chanctx_conf;
0074 struct ieee80211_channel *channel;
0075 struct sta_info *sta;
0076 struct ieee80211_local *local = sdata->local;
0077 struct station_info sinfo;
0078 struct survey_info survey;
0079 int i, q;
0080 #define STA_STATS_SURVEY_LEN 7
0081
0082 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
0083
0084 #define ADD_STA_STATS(sta) \
0085 do { \
0086 data[i++] += (sta)->rx_stats.packets; \
0087 data[i++] += (sta)->rx_stats.bytes; \
0088 data[i++] += (sta)->rx_stats.num_duplicates; \
0089 data[i++] += (sta)->rx_stats.fragments; \
0090 data[i++] += (sta)->rx_stats.dropped; \
0091 \
0092 data[i++] += sinfo.tx_packets; \
0093 data[i++] += sinfo.tx_bytes; \
0094 data[i++] += (sta)->status_stats.filtered; \
0095 data[i++] += (sta)->status_stats.retry_failed; \
0096 data[i++] += (sta)->status_stats.retry_count; \
0097 } while (0)
0098
0099
0100
0101
0102
0103
0104
0105 mutex_lock(&local->sta_mtx);
0106
0107 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
0108 sta = sta_info_get_bss(sdata, sdata->deflink.u.mgd.bssid);
0109
0110 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
0111 goto do_survey;
0112
0113 memset(&sinfo, 0, sizeof(sinfo));
0114 sta_set_sinfo(sta, &sinfo, false);
0115
0116 i = 0;
0117 ADD_STA_STATS(&sta->deflink);
0118
0119 data[i++] = sta->sta_state;
0120
0121
0122 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE))
0123 data[i] = 100000ULL *
0124 cfg80211_calculate_bitrate(&sinfo.txrate);
0125 i++;
0126 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE))
0127 data[i] = 100000ULL *
0128 cfg80211_calculate_bitrate(&sinfo.rxrate);
0129 i++;
0130
0131 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG))
0132 data[i] = (u8)sinfo.signal_avg;
0133 i++;
0134 } else {
0135 list_for_each_entry(sta, &local->sta_list, list) {
0136
0137 if (sta->sdata->dev != dev)
0138 continue;
0139
0140 memset(&sinfo, 0, sizeof(sinfo));
0141 sta_set_sinfo(sta, &sinfo, false);
0142 i = 0;
0143 ADD_STA_STATS(&sta->deflink);
0144 }
0145 }
0146
0147 do_survey:
0148 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
0149
0150 survey.filled = 0;
0151
0152 rcu_read_lock();
0153 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
0154 if (chanctx_conf)
0155 channel = chanctx_conf->def.chan;
0156 else
0157 channel = NULL;
0158 rcu_read_unlock();
0159
0160 if (channel) {
0161 q = 0;
0162 do {
0163 survey.filled = 0;
0164 if (drv_get_survey(local, q, &survey) != 0) {
0165 survey.filled = 0;
0166 break;
0167 }
0168 q++;
0169 } while (channel != survey.channel);
0170 }
0171
0172 if (survey.filled)
0173 data[i++] = survey.channel->center_freq;
0174 else
0175 data[i++] = 0;
0176 if (survey.filled & SURVEY_INFO_NOISE_DBM)
0177 data[i++] = (u8)survey.noise;
0178 else
0179 data[i++] = -1LL;
0180 if (survey.filled & SURVEY_INFO_TIME)
0181 data[i++] = survey.time;
0182 else
0183 data[i++] = -1LL;
0184 if (survey.filled & SURVEY_INFO_TIME_BUSY)
0185 data[i++] = survey.time_busy;
0186 else
0187 data[i++] = -1LL;
0188 if (survey.filled & SURVEY_INFO_TIME_EXT_BUSY)
0189 data[i++] = survey.time_ext_busy;
0190 else
0191 data[i++] = -1LL;
0192 if (survey.filled & SURVEY_INFO_TIME_RX)
0193 data[i++] = survey.time_rx;
0194 else
0195 data[i++] = -1LL;
0196 if (survey.filled & SURVEY_INFO_TIME_TX)
0197 data[i++] = survey.time_tx;
0198 else
0199 data[i++] = -1LL;
0200
0201 mutex_unlock(&local->sta_mtx);
0202
0203 if (WARN_ON(i != STA_STATS_LEN))
0204 return;
0205
0206 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
0207 }
0208
0209 static void ieee80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
0210 {
0211 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
0212 int sz_sta_stats = 0;
0213
0214 if (sset == ETH_SS_STATS) {
0215 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
0216 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
0217 }
0218 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
0219 }
0220
0221 static int ieee80211_get_regs_len(struct net_device *dev)
0222 {
0223 return 0;
0224 }
0225
0226 static void ieee80211_get_regs(struct net_device *dev,
0227 struct ethtool_regs *regs,
0228 void *data)
0229 {
0230 struct wireless_dev *wdev = dev->ieee80211_ptr;
0231
0232 regs->version = wdev->wiphy->hw_version;
0233 regs->len = 0;
0234 }
0235
0236 const struct ethtool_ops ieee80211_ethtool_ops = {
0237 .get_drvinfo = cfg80211_get_drvinfo,
0238 .get_regs_len = ieee80211_get_regs_len,
0239 .get_regs = ieee80211_get_regs,
0240 .get_link = ethtool_op_get_link,
0241 .get_ringparam = ieee80211_get_ringparam,
0242 .set_ringparam = ieee80211_set_ringparam,
0243 .get_strings = ieee80211_get_strings,
0244 .get_ethtool_stats = ieee80211_get_stats,
0245 .get_sset_count = ieee80211_get_sset_count,
0246 };