91fe6d83d9f929d16f09f56d6abce0a3fae9baee
[openwrt/staging/wigyori.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Tue, 11 Jun 2024 09:02:55 +0200
3 Subject: [PATCH] wifi: mac80211_hwsim: add support for multi-radio wiphy
4
5 This registers one wiphy radio per supported band. Number of different
6 channels is set per radio.
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10
11 --- a/drivers/net/wireless/virtual/mac80211_hwsim.c
12 +++ b/drivers/net/wireless/virtual/mac80211_hwsim.c
13 @@ -69,6 +69,10 @@ static bool mlo;
14 module_param(mlo, bool, 0444);
15 MODULE_PARM_DESC(mlo, "Support MLO");
16
17 +static bool multi_radio;
18 +module_param(multi_radio, bool, 0444);
19 +MODULE_PARM_DESC(mlo, "Support Multiple Radios per wiphy");
20 +
21 /**
22 * enum hwsim_regtest - the type of regulatory tests we offer
23 *
24 @@ -669,6 +673,10 @@ struct mac80211_hwsim_data {
25 struct ieee80211_iface_limit if_limits[3];
26 int n_if_limits;
27
28 + struct ieee80211_iface_combination if_combination_radio;
29 + struct wiphy_radio_freq_range radio_range[NUM_NL80211_BANDS];
30 + struct wiphy_radio radio[NUM_NL80211_BANDS];
31 +
32 u32 ciphers[ARRAY_SIZE(hwsim_ciphers)];
33
34 struct mac_address addresses[2];
35 @@ -917,6 +925,7 @@ static const struct nla_policy hwsim_gen
36 [HWSIM_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG },
37 [HWSIM_ATTR_PMSR_SUPPORT] = NLA_POLICY_NESTED(hwsim_pmsr_capa_policy),
38 [HWSIM_ATTR_PMSR_RESULT] = NLA_POLICY_NESTED(hwsim_pmsr_peers_result_policy),
39 + [HWSIM_ATTR_MULTI_RADIO] = { .type = NLA_FLAG },
40 };
41
42 #if IS_REACHABLE(CONFIG_VIRTIO)
43 @@ -4007,6 +4016,7 @@ struct hwsim_new_radio_params {
44 bool reg_strict;
45 bool p2p_device;
46 bool use_chanctx;
47 + bool multi_radio;
48 bool destroy_on_close;
49 const char *hwname;
50 bool no_vif;
51 @@ -4083,6 +4093,12 @@ static int append_radio_msg(struct sk_bu
52 return ret;
53 }
54
55 + if (param->multi_radio) {
56 + ret = nla_put_flag(skb, HWSIM_ATTR_MULTI_RADIO);
57 + if (ret < 0)
58 + return ret;
59 + }
60 +
61 if (param->hwname) {
62 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME,
63 strlen(param->hwname), param->hwname);
64 @@ -5099,6 +5115,7 @@ static int mac80211_hwsim_new_radio(stru
65 struct net *net;
66 int idx, i;
67 int n_limits = 0;
68 + int n_bands = 0;
69
70 if (WARN_ON(param->channels > 1 && !param->use_chanctx))
71 return -EINVAL;
72 @@ -5202,22 +5219,22 @@ static int mac80211_hwsim_new_radio(stru
73 n_limits++;
74 }
75
76 + data->if_combination.radar_detect_widths =
77 + BIT(NL80211_CHAN_WIDTH_5) |
78 + BIT(NL80211_CHAN_WIDTH_10) |
79 + BIT(NL80211_CHAN_WIDTH_20_NOHT) |
80 + BIT(NL80211_CHAN_WIDTH_20) |
81 + BIT(NL80211_CHAN_WIDTH_40) |
82 + BIT(NL80211_CHAN_WIDTH_80) |
83 + BIT(NL80211_CHAN_WIDTH_160);
84 +
85 if (data->use_chanctx) {
86 hw->wiphy->max_scan_ssids = 255;
87 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
88 hw->wiphy->max_remain_on_channel_duration = 1000;
89 - data->if_combination.radar_detect_widths = 0;
90 data->if_combination.num_different_channels = data->channels;
91 } else {
92 data->if_combination.num_different_channels = 1;
93 - data->if_combination.radar_detect_widths =
94 - BIT(NL80211_CHAN_WIDTH_5) |
95 - BIT(NL80211_CHAN_WIDTH_10) |
96 - BIT(NL80211_CHAN_WIDTH_20_NOHT) |
97 - BIT(NL80211_CHAN_WIDTH_20) |
98 - BIT(NL80211_CHAN_WIDTH_40) |
99 - BIT(NL80211_CHAN_WIDTH_80) |
100 - BIT(NL80211_CHAN_WIDTH_160);
101 }
102
103 if (!n_limits) {
104 @@ -5333,6 +5350,9 @@ static int mac80211_hwsim_new_radio(stru
105
106 for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
107 struct ieee80211_supported_band *sband = &data->bands[band];
108 + struct wiphy_radio_freq_range *radio_range;
109 + const struct ieee80211_channel *c;
110 + struct wiphy_radio *radio;
111
112 sband->band = band;
113
114 @@ -5406,8 +5426,36 @@ static int mac80211_hwsim_new_radio(stru
115 mac80211_hwsim_sband_capab(sband);
116
117 hw->wiphy->bands[band] = sband;
118 +
119 + if (!param->multi_radio)
120 + continue;
121 +
122 + c = sband->channels;
123 + radio_range = &data->radio_range[n_bands];
124 + radio_range->start_freq = ieee80211_channel_to_khz(c) - 10000;
125 +
126 + c += sband->n_channels - 1;
127 + radio_range->end_freq = ieee80211_channel_to_khz(c) + 10000;
128 +
129 + radio = &data->radio[n_bands++];
130 + radio->freq_range = radio_range;
131 + radio->n_freq_range = 1;
132 + radio->iface_combinations = &data->if_combination_radio;
133 + radio->n_iface_combinations = 1;
134 }
135
136 + if (param->multi_radio) {
137 + hw->wiphy->radio = data->radio;
138 + hw->wiphy->n_radio = n_bands;
139 +
140 + memcpy(&data->if_combination_radio, &data->if_combination,
141 + sizeof(data->if_combination));
142 + data->if_combination.num_different_channels *= n_bands;
143 + }
144 +
145 + if (data->use_chanctx)
146 + data->if_combination.radar_detect_widths = 0;
147 +
148 /* By default all radios belong to the first group */
149 data->group = 1;
150 mutex_init(&data->mutex);
151 @@ -6025,6 +6073,9 @@ static int hwsim_new_radio_nl(struct sk_
152 else
153 param.use_chanctx = (param.channels > 1);
154
155 + if (info->attrs[HWSIM_ATTR_MULTI_RADIO])
156 + param.multi_radio = true;
157 +
158 if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2])
159 param.reg_alpha2 =
160 nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]);
161 @@ -6105,7 +6156,7 @@ static int hwsim_new_radio_nl(struct sk_
162
163 param.mlo = info->attrs[HWSIM_ATTR_MLO_SUPPORT];
164
165 - if (param.mlo)
166 + if (param.mlo || param.multi_radio)
167 param.use_chanctx = true;
168
169 if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
170 @@ -6802,7 +6853,8 @@ static int __init init_mac80211_hwsim(vo
171
172 param.p2p_device = support_p2p_device;
173 param.mlo = mlo;
174 - param.use_chanctx = channels > 1 || mlo;
175 + param.multi_radio = multi_radio;
176 + param.use_chanctx = channels > 1 || mlo || multi_radio;
177 param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK;
178 if (param.p2p_device)
179 param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
180 --- a/drivers/net/wireless/virtual/mac80211_hwsim.h
181 +++ b/drivers/net/wireless/virtual/mac80211_hwsim.h
182 @@ -157,6 +157,9 @@ enum hwsim_commands {
183 * to provide details about peer measurement request (nl80211_peer_measurement_attrs)
184 * @HWSIM_ATTR_PMSR_RESULT: nested attributed used with %HWSIM_CMD_REPORT_PMSR
185 * to provide peer measurement result (nl80211_peer_measurement_attrs)
186 + * @HWSIM_ATTR_MULTI_RADIO: Register multiple wiphy radios (flag).
187 + * Adds one radio for each band. Number of supported channels will be set for
188 + * each radio instead of for the wiphy.
189 * @__HWSIM_ATTR_MAX: enum limit
190 */
191 enum hwsim_attrs {
192 @@ -189,6 +192,7 @@ enum hwsim_attrs {
193 HWSIM_ATTR_PMSR_SUPPORT,
194 HWSIM_ATTR_PMSR_REQUEST,
195 HWSIM_ATTR_PMSR_RESULT,
196 + HWSIM_ATTR_MULTI_RADIO,
197 __HWSIM_ATTR_MAX,
198 };
199 #define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1)