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