Skip to content

Commit 291040c

Browse files
committed
Merge tag 'mac80211-next-for-davem-2018-01-22' of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next
Johannes Berg says: ==================== Less than a handful of changes: * possible memory leak fix in hwsim * speed up hwsim * add hwsim userspace rate control API * code cleanups ==================== A conflict was resolved in mac80211_hwsim.c, mostly of the simple overlapping changes category. One adding a rhashtable and another adding a workqueue. Signed-off-by: David S. Miller <[email protected]>
2 parents b75703d + 0ddcff4 commit 291040c

File tree

3 files changed

+145
-21
lines changed

3 files changed

+145
-21
lines changed

drivers/net/wireless/mac80211_hwsim.c

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <net/genetlink.h>
3333
#include <net/net_namespace.h>
3434
#include <net/netns/generic.h>
35+
#include <linux/rhashtable.h>
3536
#include "mac80211_hwsim.h"
3637

3738
#define WARN_QUEUE 100
@@ -490,6 +491,7 @@ static const struct ieee80211_iface_combination hwsim_if_comb_p2p_dev[] = {
490491
static spinlock_t hwsim_radio_lock;
491492
static LIST_HEAD(hwsim_radios);
492493
static struct workqueue_struct *hwsim_wq;
494+
static struct rhashtable hwsim_radios_rht;
493495
static int hwsim_radio_idx;
494496

495497
static struct platform_driver mac80211_hwsim_driver = {
@@ -500,6 +502,7 @@ static struct platform_driver mac80211_hwsim_driver = {
500502

501503
struct mac80211_hwsim_data {
502504
struct list_head list;
505+
struct rhash_head rht;
503506
struct ieee80211_hw *hw;
504507
struct device *dev;
505508
struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
@@ -574,6 +577,13 @@ struct mac80211_hwsim_data {
574577
u64 tx_failed;
575578
};
576579

580+
static const struct rhashtable_params hwsim_rht_params = {
581+
.nelem_hint = 2,
582+
.automatic_shrinking = true,
583+
.key_len = ETH_ALEN,
584+
.key_offset = offsetof(struct mac80211_hwsim_data, addresses[1]),
585+
.head_offset = offsetof(struct mac80211_hwsim_data, rht),
586+
};
577587

578588
struct hwsim_radiotap_hdr {
579589
struct ieee80211_radiotap_header hdr;
@@ -1009,6 +1019,36 @@ static int hwsim_unicast_netgroup(struct mac80211_hwsim_data *data,
10091019
return res;
10101020
}
10111021

1022+
static inline u16 trans_tx_rate_flags_ieee2hwsim(struct ieee80211_tx_rate *rate)
1023+
{
1024+
u16 result = 0;
1025+
1026+
if (rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
1027+
result |= MAC80211_HWSIM_TX_RC_USE_RTS_CTS;
1028+
if (rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
1029+
result |= MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT;
1030+
if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1031+
result |= MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE;
1032+
if (rate->flags & IEEE80211_TX_RC_MCS)
1033+
result |= MAC80211_HWSIM_TX_RC_MCS;
1034+
if (rate->flags & IEEE80211_TX_RC_GREEN_FIELD)
1035+
result |= MAC80211_HWSIM_TX_RC_GREEN_FIELD;
1036+
if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1037+
result |= MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH;
1038+
if (rate->flags & IEEE80211_TX_RC_DUP_DATA)
1039+
result |= MAC80211_HWSIM_TX_RC_DUP_DATA;
1040+
if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
1041+
result |= MAC80211_HWSIM_TX_RC_SHORT_GI;
1042+
if (rate->flags & IEEE80211_TX_RC_VHT_MCS)
1043+
result |= MAC80211_HWSIM_TX_RC_VHT_MCS;
1044+
if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
1045+
result |= MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH;
1046+
if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
1047+
result |= MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH;
1048+
1049+
return result;
1050+
}
1051+
10121052
static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
10131053
struct sk_buff *my_skb,
10141054
int dst_portid)
@@ -1021,6 +1061,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
10211061
unsigned int hwsim_flags = 0;
10221062
int i;
10231063
struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES];
1064+
struct hwsim_tx_rate_flag tx_attempts_flags[IEEE80211_TX_MAX_RATES];
10241065
uintptr_t cookie;
10251066

10261067
if (data->ps != PS_DISABLED)
@@ -1072,14 +1113,23 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
10721113

10731114
for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
10741115
tx_attempts[i].idx = info->status.rates[i].idx;
1116+
tx_attempts_flags[i].idx = info->status.rates[i].idx;
10751117
tx_attempts[i].count = info->status.rates[i].count;
1118+
tx_attempts_flags[i].flags =
1119+
trans_tx_rate_flags_ieee2hwsim(
1120+
&info->status.rates[i]);
10761121
}
10771122

10781123
if (nla_put(skb, HWSIM_ATTR_TX_INFO,
10791124
sizeof(struct hwsim_tx_rate)*IEEE80211_TX_MAX_RATES,
10801125
tx_attempts))
10811126
goto nla_put_failure;
10821127

1128+
if (nla_put(skb, HWSIM_ATTR_TX_INFO_FLAGS,
1129+
sizeof(struct hwsim_tx_rate_flag) * IEEE80211_TX_MAX_RATES,
1130+
tx_attempts_flags))
1131+
goto nla_put_failure;
1132+
10831133
/* We create a cookie to identify this skb */
10841134
data->pending_cookie++;
10851135
cookie = data->pending_cookie;
@@ -2732,6 +2782,15 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
27322782
CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
27332783

27342784
spin_lock_bh(&hwsim_radio_lock);
2785+
err = rhashtable_insert_fast(&hwsim_radios_rht, &data->rht,
2786+
hwsim_rht_params);
2787+
if (err < 0) {
2788+
pr_debug("mac80211_hwsim: radio index %d already present\n",
2789+
idx);
2790+
spin_unlock_bh(&hwsim_radio_lock);
2791+
goto failed_final_insert;
2792+
}
2793+
27352794
list_add_tail(&data->list, &hwsim_radios);
27362795
spin_unlock_bh(&hwsim_radio_lock);
27372796

@@ -2740,6 +2799,9 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
27402799

27412800
return idx;
27422801

2802+
failed_final_insert:
2803+
debugfs_remove_recursive(data->debugfs);
2804+
ieee80211_unregister_hw(data->hw);
27432805
failed_hw:
27442806
device_release_driver(data->dev);
27452807
failed_bind:
@@ -2875,22 +2937,9 @@ static void hwsim_mon_setup(struct net_device *dev)
28752937

28762938
static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr)
28772939
{
2878-
struct mac80211_hwsim_data *data;
2879-
bool _found = false;
2880-
2881-
spin_lock_bh(&hwsim_radio_lock);
2882-
list_for_each_entry(data, &hwsim_radios, list) {
2883-
if (memcmp(data->addresses[1].addr, addr, ETH_ALEN) == 0) {
2884-
_found = true;
2885-
break;
2886-
}
2887-
}
2888-
spin_unlock_bh(&hwsim_radio_lock);
2889-
2890-
if (!_found)
2891-
return NULL;
2892-
2893-
return data;
2940+
return rhashtable_lookup_fast(&hwsim_radios_rht,
2941+
addr,
2942+
hwsim_rht_params);
28942943
}
28952944

28962945
static void hwsim_register_wmediumd(struct net *net, u32 portid)
@@ -2975,7 +3024,6 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
29753024
for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
29763025
txi->status.rates[i].idx = tx_attempts[i].idx;
29773026
txi->status.rates[i].count = tx_attempts[i].count;
2978-
/*txi->status.rates[i].flags = 0;*/
29793027
}
29803028

29813029
txi->status.ack_signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);
@@ -3155,8 +3203,10 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
31553203
if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) {
31563204
u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]);
31573205

3158-
if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom))
3206+
if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom)) {
3207+
kfree(hwname);
31593208
return -EINVAL;
3209+
}
31603210
param.regd = hwsim_world_regdom_custom[idx];
31613211
}
31623212

@@ -3197,6 +3247,8 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
31973247
continue;
31983248

31993249
list_del(&data->list);
3250+
rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
3251+
hwsim_rht_params);
32003252
spin_unlock_bh(&hwsim_radio_lock);
32013253
mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
32023254
info);
@@ -3352,6 +3404,8 @@ static void remove_user_radios(u32 portid)
33523404
list_for_each_entry_safe(entry, tmp, &hwsim_radios, list) {
33533405
if (entry->destroy_on_close && entry->portid == portid) {
33543406
list_del(&entry->list);
3407+
rhashtable_remove_fast(&hwsim_radios_rht, &entry->rht,
3408+
hwsim_rht_params);
33553409
INIT_WORK(&entry->destroy_work, destroy_radio);
33563410
queue_work(hwsim_wq, &entry->destroy_work);
33573411
}
@@ -3427,6 +3481,8 @@ static void __net_exit hwsim_exit_net(struct net *net)
34273481
continue;
34283482

34293483
list_del(&data->list);
3484+
rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
3485+
hwsim_rht_params);
34303486
INIT_WORK(&data->destroy_work, destroy_radio);
34313487
queue_work(hwsim_wq, &data->destroy_work);
34323488
}
@@ -3463,6 +3519,7 @@ static int __init init_mac80211_hwsim(void)
34633519
hwsim_wq = alloc_workqueue("hwsim_wq",WQ_MEM_RECLAIM,0);
34643520
if (!hwsim_wq)
34653521
return -ENOMEM;
3522+
rhashtable_init(&hwsim_radios_rht, &hwsim_rht_params);
34663523

34673524
err = register_pernet_device(&hwsim_net_ops);
34683525
if (err)
@@ -3604,6 +3661,7 @@ static void __exit exit_mac80211_hwsim(void)
36043661
mac80211_hwsim_free();
36053662
flush_workqueue(hwsim_wq);
36063663

3664+
rhashtable_destroy(&hwsim_radios_rht);
36073665
unregister_netdev(hwsim_mon);
36083666
platform_driver_unregister(&mac80211_hwsim_driver);
36093667
unregister_pernet_device(&hwsim_net_ops);

drivers/net/wireless/mac80211_hwsim.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ enum hwsim_tx_control_flags {
6464
* @HWSIM_CMD_TX_INFO_FRAME: Transmission info report from user space to
6565
* kernel, uses:
6666
* %HWSIM_ATTR_ADDR_TRANSMITTER, %HWSIM_ATTR_FLAGS,
67-
* %HWSIM_ATTR_TX_INFO, %HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE
67+
* %HWSIM_ATTR_TX_INFO, %WSIM_ATTR_TX_INFO_FLAGS,
68+
* %HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE
6869
* @HWSIM_CMD_NEW_RADIO: create a new radio with the given parameters,
6970
* returns the radio ID (>= 0) or negative on errors, if successful
7071
* then multicast the result
@@ -123,6 +124,8 @@ enum {
123124
* @HWSIM_ATTR_RADIO_NAME: Name of radio, e.g. phy666
124125
* @HWSIM_ATTR_NO_VIF: Do not create vif (wlanX) when creating radio.
125126
* @HWSIM_ATTR_FREQ: Frequency at which packet is transmitted or received.
127+
* @HWSIM_ATTR_TX_INFO_FLAGS: additional flags for corresponding
128+
* rates of %HWSIM_ATTR_TX_INFO
126129
* @__HWSIM_ATTR_MAX: enum limit
127130
*/
128131

@@ -149,6 +152,7 @@ enum {
149152
HWSIM_ATTR_NO_VIF,
150153
HWSIM_ATTR_FREQ,
151154
HWSIM_ATTR_PAD,
155+
HWSIM_ATTR_TX_INFO_FLAGS,
152156
__HWSIM_ATTR_MAX,
153157
};
154158
#define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1)
@@ -171,4 +175,66 @@ struct hwsim_tx_rate {
171175
u8 count;
172176
} __packed;
173177

178+
/**
179+
* enum hwsim_tx_rate_flags - per-rate flags set by the rate control algorithm.
180+
* Inspired by structure mac80211_rate_control_flags. New flags may be
181+
* appended, but old flags not deleted, to keep compatibility for
182+
* userspace.
183+
*
184+
* These flags are set by the Rate control algorithm for each rate during tx,
185+
* in the @flags member of struct ieee80211_tx_rate.
186+
*
187+
* @MAC80211_HWSIM_TX_RC_USE_RTS_CTS: Use RTS/CTS exchange for this rate.
188+
* @MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT: CTS-to-self protection is required.
189+
* This is set if the current BSS requires ERP protection.
190+
* @MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE: Use short preamble.
191+
* @MAC80211_HWSIM_TX_RC_MCS: HT rate.
192+
* @MAC80211_HWSIM_TX_RC_VHT_MCS: VHT MCS rate, in this case the idx field is
193+
* split into a higher 4 bits (Nss) and lower 4 bits (MCS number)
194+
* @MAC80211_HWSIM_TX_RC_GREEN_FIELD: Indicates whether this rate should be used
195+
* in Greenfield mode.
196+
* @MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH: Indicates if the Channel Width should be
197+
* 40 MHz.
198+
* @MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH: Indicates 80 MHz transmission
199+
* @MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH: Indicates 160 MHz transmission
200+
* (80+80 isn't supported yet)
201+
* @MAC80211_HWSIM_TX_RC_DUP_DATA: The frame should be transmitted on both of
202+
* the adjacent 20 MHz channels, if the current channel type is
203+
* NL80211_CHAN_HT40MINUS or NL80211_CHAN_HT40PLUS.
204+
* @MAC80211_HWSIM_TX_RC_SHORT_GI: Short Guard interval should be used for this
205+
* rate.
206+
*/
207+
enum hwsim_tx_rate_flags {
208+
MAC80211_HWSIM_TX_RC_USE_RTS_CTS = BIT(0),
209+
MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT = BIT(1),
210+
MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE = BIT(2),
211+
212+
/* rate index is an HT/VHT MCS instead of an index */
213+
MAC80211_HWSIM_TX_RC_MCS = BIT(3),
214+
MAC80211_HWSIM_TX_RC_GREEN_FIELD = BIT(4),
215+
MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH = BIT(5),
216+
MAC80211_HWSIM_TX_RC_DUP_DATA = BIT(6),
217+
MAC80211_HWSIM_TX_RC_SHORT_GI = BIT(7),
218+
MAC80211_HWSIM_TX_RC_VHT_MCS = BIT(8),
219+
MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH = BIT(9),
220+
MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH = BIT(10),
221+
};
222+
223+
/**
224+
* struct hwsim_tx_rate - rate selection/status
225+
*
226+
* @idx: rate index to attempt to send with
227+
* @count: number of tries in this rate before going to the next rate
228+
*
229+
* A value of -1 for @idx indicates an invalid rate and, if used
230+
* in an array of retry rates, that no more rates should be tried.
231+
*
232+
* When used for transmit status reporting, the driver should
233+
* always report the rate and number of retries used.
234+
*
235+
*/
236+
struct hwsim_tx_rate_flag {
237+
s8 idx;
238+
u16 flags;
239+
} __packed;
174240
#endif /* __MAC80211_HWSIM_H */

net/mac80211/debugfs_sta.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
420420
default:
421421
p += scnprintf(p, sizeof(buf) + buf - p,
422422
"\t\tMAX-MPDU-UNKNOWN\n");
423-
};
423+
}
424424
switch (vhtc->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
425425
case 0:
426426
p += scnprintf(p, sizeof(buf) + buf - p,
@@ -438,7 +438,7 @@ static ssize_t sta_vht_capa_read(struct file *file, char __user *userbuf,
438438
p += scnprintf(p, sizeof(buf) + buf - p,
439439
"\t\tUNKNOWN-MHZ: 0x%x\n",
440440
(vhtc->cap >> 2) & 0x3);
441-
};
441+
}
442442
PFLAG(RXLDPC, "RXLDPC");
443443
PFLAG(SHORT_GI_80, "SHORT-GI-80");
444444
PFLAG(SHORT_GI_160, "SHORT-GI-160");

0 commit comments

Comments
 (0)