]>
Commit | Line | Data |
---|---|---|
dad0d04f FF |
1 | /** |
2 | * Copyright (c) 2014 Redpine Signals Inc. | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include <linux/etherdevice.h> | |
18 | #include "rsi_debugfs.h" | |
19 | #include "rsi_mgmt.h" | |
b6c8d06c | 20 | #include "rsi_sdio.h" |
dad0d04f | 21 | #include "rsi_common.h" |
ce86893f | 22 | #include "rsi_ps.h" |
dad0d04f FF |
23 | |
24 | static const struct ieee80211_channel rsi_2ghz_channels[] = { | |
57fbcce3 | 25 | { .band = NL80211_BAND_2GHZ, .center_freq = 2412, |
dad0d04f | 26 | .hw_value = 1 }, /* Channel 1 */ |
57fbcce3 | 27 | { .band = NL80211_BAND_2GHZ, .center_freq = 2417, |
dad0d04f | 28 | .hw_value = 2 }, /* Channel 2 */ |
57fbcce3 | 29 | { .band = NL80211_BAND_2GHZ, .center_freq = 2422, |
dad0d04f | 30 | .hw_value = 3 }, /* Channel 3 */ |
57fbcce3 | 31 | { .band = NL80211_BAND_2GHZ, .center_freq = 2427, |
dad0d04f | 32 | .hw_value = 4 }, /* Channel 4 */ |
57fbcce3 | 33 | { .band = NL80211_BAND_2GHZ, .center_freq = 2432, |
dad0d04f | 34 | .hw_value = 5 }, /* Channel 5 */ |
57fbcce3 | 35 | { .band = NL80211_BAND_2GHZ, .center_freq = 2437, |
dad0d04f | 36 | .hw_value = 6 }, /* Channel 6 */ |
57fbcce3 | 37 | { .band = NL80211_BAND_2GHZ, .center_freq = 2442, |
dad0d04f | 38 | .hw_value = 7 }, /* Channel 7 */ |
57fbcce3 | 39 | { .band = NL80211_BAND_2GHZ, .center_freq = 2447, |
dad0d04f | 40 | .hw_value = 8 }, /* Channel 8 */ |
57fbcce3 | 41 | { .band = NL80211_BAND_2GHZ, .center_freq = 2452, |
dad0d04f | 42 | .hw_value = 9 }, /* Channel 9 */ |
57fbcce3 | 43 | { .band = NL80211_BAND_2GHZ, .center_freq = 2457, |
dad0d04f | 44 | .hw_value = 10 }, /* Channel 10 */ |
57fbcce3 | 45 | { .band = NL80211_BAND_2GHZ, .center_freq = 2462, |
dad0d04f | 46 | .hw_value = 11 }, /* Channel 11 */ |
57fbcce3 | 47 | { .band = NL80211_BAND_2GHZ, .center_freq = 2467, |
dad0d04f | 48 | .hw_value = 12 }, /* Channel 12 */ |
57fbcce3 | 49 | { .band = NL80211_BAND_2GHZ, .center_freq = 2472, |
dad0d04f | 50 | .hw_value = 13 }, /* Channel 13 */ |
57fbcce3 | 51 | { .band = NL80211_BAND_2GHZ, .center_freq = 2484, |
dad0d04f FF |
52 | .hw_value = 14 }, /* Channel 14 */ |
53 | }; | |
54 | ||
55 | static const struct ieee80211_channel rsi_5ghz_channels[] = { | |
57fbcce3 | 56 | { .band = NL80211_BAND_5GHZ, .center_freq = 5180, |
dad0d04f | 57 | .hw_value = 36, }, /* Channel 36 */ |
57fbcce3 | 58 | { .band = NL80211_BAND_5GHZ, .center_freq = 5200, |
dad0d04f | 59 | .hw_value = 40, }, /* Channel 40 */ |
57fbcce3 | 60 | { .band = NL80211_BAND_5GHZ, .center_freq = 5220, |
dad0d04f | 61 | .hw_value = 44, }, /* Channel 44 */ |
57fbcce3 | 62 | { .band = NL80211_BAND_5GHZ, .center_freq = 5240, |
dad0d04f | 63 | .hw_value = 48, }, /* Channel 48 */ |
57fbcce3 | 64 | { .band = NL80211_BAND_5GHZ, .center_freq = 5260, |
dad0d04f | 65 | .hw_value = 52, }, /* Channel 52 */ |
57fbcce3 | 66 | { .band = NL80211_BAND_5GHZ, .center_freq = 5280, |
dad0d04f | 67 | .hw_value = 56, }, /* Channel 56 */ |
57fbcce3 | 68 | { .band = NL80211_BAND_5GHZ, .center_freq = 5300, |
dad0d04f | 69 | .hw_value = 60, }, /* Channel 60 */ |
57fbcce3 | 70 | { .band = NL80211_BAND_5GHZ, .center_freq = 5320, |
dad0d04f | 71 | .hw_value = 64, }, /* Channel 64 */ |
57fbcce3 | 72 | { .band = NL80211_BAND_5GHZ, .center_freq = 5500, |
dad0d04f | 73 | .hw_value = 100, }, /* Channel 100 */ |
57fbcce3 | 74 | { .band = NL80211_BAND_5GHZ, .center_freq = 5520, |
dad0d04f | 75 | .hw_value = 104, }, /* Channel 104 */ |
57fbcce3 | 76 | { .band = NL80211_BAND_5GHZ, .center_freq = 5540, |
dad0d04f | 77 | .hw_value = 108, }, /* Channel 108 */ |
57fbcce3 | 78 | { .band = NL80211_BAND_5GHZ, .center_freq = 5560, |
dad0d04f | 79 | .hw_value = 112, }, /* Channel 112 */ |
57fbcce3 | 80 | { .band = NL80211_BAND_5GHZ, .center_freq = 5580, |
dad0d04f | 81 | .hw_value = 116, }, /* Channel 116 */ |
57fbcce3 | 82 | { .band = NL80211_BAND_5GHZ, .center_freq = 5600, |
dad0d04f | 83 | .hw_value = 120, }, /* Channel 120 */ |
57fbcce3 | 84 | { .band = NL80211_BAND_5GHZ, .center_freq = 5620, |
dad0d04f | 85 | .hw_value = 124, }, /* Channel 124 */ |
57fbcce3 | 86 | { .band = NL80211_BAND_5GHZ, .center_freq = 5640, |
dad0d04f | 87 | .hw_value = 128, }, /* Channel 128 */ |
57fbcce3 | 88 | { .band = NL80211_BAND_5GHZ, .center_freq = 5660, |
dad0d04f | 89 | .hw_value = 132, }, /* Channel 132 */ |
57fbcce3 | 90 | { .band = NL80211_BAND_5GHZ, .center_freq = 5680, |
dad0d04f | 91 | .hw_value = 136, }, /* Channel 136 */ |
57fbcce3 | 92 | { .band = NL80211_BAND_5GHZ, .center_freq = 5700, |
dad0d04f | 93 | .hw_value = 140, }, /* Channel 140 */ |
57fbcce3 | 94 | { .band = NL80211_BAND_5GHZ, .center_freq = 5745, |
dad0d04f | 95 | .hw_value = 149, }, /* Channel 149 */ |
57fbcce3 | 96 | { .band = NL80211_BAND_5GHZ, .center_freq = 5765, |
dad0d04f | 97 | .hw_value = 153, }, /* Channel 153 */ |
57fbcce3 | 98 | { .band = NL80211_BAND_5GHZ, .center_freq = 5785, |
dad0d04f | 99 | .hw_value = 157, }, /* Channel 157 */ |
57fbcce3 | 100 | { .band = NL80211_BAND_5GHZ, .center_freq = 5805, |
dad0d04f | 101 | .hw_value = 161, }, /* Channel 161 */ |
57fbcce3 | 102 | { .band = NL80211_BAND_5GHZ, .center_freq = 5825, |
dad0d04f FF |
103 | .hw_value = 165, }, /* Channel 165 */ |
104 | }; | |
105 | ||
106 | struct ieee80211_rate rsi_rates[12] = { | |
107 | { .bitrate = STD_RATE_01 * 5, .hw_value = RSI_RATE_1 }, | |
108 | { .bitrate = STD_RATE_02 * 5, .hw_value = RSI_RATE_2 }, | |
109 | { .bitrate = STD_RATE_5_5 * 5, .hw_value = RSI_RATE_5_5 }, | |
110 | { .bitrate = STD_RATE_11 * 5, .hw_value = RSI_RATE_11 }, | |
111 | { .bitrate = STD_RATE_06 * 5, .hw_value = RSI_RATE_6 }, | |
112 | { .bitrate = STD_RATE_09 * 5, .hw_value = RSI_RATE_9 }, | |
113 | { .bitrate = STD_RATE_12 * 5, .hw_value = RSI_RATE_12 }, | |
114 | { .bitrate = STD_RATE_18 * 5, .hw_value = RSI_RATE_18 }, | |
115 | { .bitrate = STD_RATE_24 * 5, .hw_value = RSI_RATE_24 }, | |
116 | { .bitrate = STD_RATE_36 * 5, .hw_value = RSI_RATE_36 }, | |
117 | { .bitrate = STD_RATE_48 * 5, .hw_value = RSI_RATE_48 }, | |
118 | { .bitrate = STD_RATE_54 * 5, .hw_value = RSI_RATE_54 }, | |
119 | }; | |
120 | ||
121 | const u16 rsi_mcsrates[8] = { | |
122 | RSI_RATE_MCS0, RSI_RATE_MCS1, RSI_RATE_MCS2, RSI_RATE_MCS3, | |
123 | RSI_RATE_MCS4, RSI_RATE_MCS5, RSI_RATE_MCS6, RSI_RATE_MCS7 | |
124 | }; | |
125 | ||
6da1e00a PRG |
126 | static const u32 rsi_max_ap_stas[16] = { |
127 | 32, /* 1 - Wi-Fi alone */ | |
128 | 0, /* 2 */ | |
129 | 0, /* 3 */ | |
130 | 0, /* 4 - BT EDR alone */ | |
131 | 4, /* 5 - STA + BT EDR */ | |
132 | 32, /* 6 - AP + BT EDR */ | |
133 | 0, /* 7 */ | |
134 | 0, /* 8 - BT LE alone */ | |
135 | 4, /* 9 - STA + BE LE */ | |
136 | 0, /* 10 */ | |
137 | 0, /* 11 */ | |
138 | 0, /* 12 */ | |
139 | 1, /* 13 - STA + BT Dual */ | |
140 | 4, /* 14 - AP + BT Dual */ | |
141 | }; | |
142 | ||
421eedff PRG |
143 | static const struct ieee80211_iface_limit rsi_iface_limits[] = { |
144 | { | |
145 | .max = 1, | |
146 | .types = BIT(NL80211_IFTYPE_STATION), | |
147 | }, | |
148 | { | |
149 | .max = 1, | |
150 | .types = BIT(NL80211_IFTYPE_AP) | | |
151 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
152 | BIT(NL80211_IFTYPE_P2P_GO), | |
153 | }, | |
154 | { | |
155 | .max = 1, | |
156 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), | |
157 | }, | |
158 | }; | |
159 | ||
160 | static const struct ieee80211_iface_combination rsi_iface_combinations[] = { | |
161 | { | |
162 | .num_different_channels = 1, | |
163 | .max_interfaces = 3, | |
164 | .limits = rsi_iface_limits, | |
165 | .n_limits = ARRAY_SIZE(rsi_iface_limits), | |
166 | }, | |
167 | }; | |
168 | ||
dad0d04f FF |
169 | /** |
170 | * rsi_is_cipher_wep() - This function determines if the cipher is WEP or not. | |
171 | * @common: Pointer to the driver private structure. | |
172 | * | |
173 | * Return: If cipher type is WEP, a value of 1 is returned, else 0. | |
174 | */ | |
175 | ||
176 | bool rsi_is_cipher_wep(struct rsi_common *common) | |
177 | { | |
178 | if (((common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP104) || | |
179 | (common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP40)) && | |
180 | (!common->secinfo.ptk_cipher)) | |
181 | return true; | |
182 | else | |
183 | return false; | |
184 | } | |
185 | ||
186 | /** | |
187 | * rsi_register_rates_channels() - This function registers channels and rates. | |
188 | * @adapter: Pointer to the adapter structure. | |
189 | * @band: Operating band to be set. | |
190 | * | |
191 | * Return: None. | |
192 | */ | |
193 | static void rsi_register_rates_channels(struct rsi_hw *adapter, int band) | |
194 | { | |
195 | struct ieee80211_supported_band *sbands = &adapter->sbands[band]; | |
196 | void *channels = NULL; | |
197 | ||
57fbcce3 | 198 | if (band == NL80211_BAND_2GHZ) { |
dad0d04f FF |
199 | channels = kmalloc(sizeof(rsi_2ghz_channels), GFP_KERNEL); |
200 | memcpy(channels, | |
201 | rsi_2ghz_channels, | |
202 | sizeof(rsi_2ghz_channels)); | |
57fbcce3 | 203 | sbands->band = NL80211_BAND_2GHZ; |
dad0d04f FF |
204 | sbands->n_channels = ARRAY_SIZE(rsi_2ghz_channels); |
205 | sbands->bitrates = rsi_rates; | |
206 | sbands->n_bitrates = ARRAY_SIZE(rsi_rates); | |
207 | } else { | |
208 | channels = kmalloc(sizeof(rsi_5ghz_channels), GFP_KERNEL); | |
209 | memcpy(channels, | |
210 | rsi_5ghz_channels, | |
211 | sizeof(rsi_5ghz_channels)); | |
57fbcce3 | 212 | sbands->band = NL80211_BAND_5GHZ; |
dad0d04f FF |
213 | sbands->n_channels = ARRAY_SIZE(rsi_5ghz_channels); |
214 | sbands->bitrates = &rsi_rates[4]; | |
215 | sbands->n_bitrates = ARRAY_SIZE(rsi_rates) - 4; | |
216 | } | |
217 | ||
218 | sbands->channels = channels; | |
219 | ||
220 | memset(&sbands->ht_cap, 0, sizeof(struct ieee80211_sta_ht_cap)); | |
221 | sbands->ht_cap.ht_supported = true; | |
222 | sbands->ht_cap.cap = (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | | |
223 | IEEE80211_HT_CAP_SGI_20 | | |
224 | IEEE80211_HT_CAP_SGI_40); | |
e8c58e7a | 225 | sbands->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K; |
dad0d04f FF |
226 | sbands->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; |
227 | sbands->ht_cap.mcs.rx_mask[0] = 0xff; | |
228 | sbands->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | |
229 | /* sbands->ht_cap.mcs.rx_highest = 0x82; */ | |
230 | } | |
231 | ||
232 | /** | |
19d2e619 | 233 | * rsi_mac80211_detach() - This function is used to de-initialize the |
dad0d04f FF |
234 | * Mac80211 stack. |
235 | * @adapter: Pointer to the adapter structure. | |
236 | * | |
237 | * Return: None. | |
238 | */ | |
239 | void rsi_mac80211_detach(struct rsi_hw *adapter) | |
240 | { | |
241 | struct ieee80211_hw *hw = adapter->hw; | |
b022539d | 242 | enum nl80211_band band; |
dad0d04f FF |
243 | |
244 | if (hw) { | |
245 | ieee80211_stop_queues(hw); | |
246 | ieee80211_unregister_hw(hw); | |
247 | ieee80211_free_hw(hw); | |
248 | } | |
249 | ||
b022539d PRG |
250 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
251 | struct ieee80211_supported_band *sband = | |
252 | &adapter->sbands[band]; | |
253 | ||
254 | kfree(sband->channels); | |
255 | } | |
256 | ||
257 | #ifdef CONFIG_RSI_DEBUGFS | |
dad0d04f | 258 | rsi_remove_dbgfs(adapter); |
b022539d PRG |
259 | kfree(adapter->dfsentry); |
260 | #endif | |
dad0d04f FF |
261 | } |
262 | EXPORT_SYMBOL_GPL(rsi_mac80211_detach); | |
263 | ||
264 | /** | |
265 | * rsi_indicate_tx_status() - This function indicates the transmit status. | |
266 | * @adapter: Pointer to the adapter structure. | |
267 | * @skb: Pointer to the socket buffer structure. | |
268 | * @status: Status | |
269 | * | |
270 | * Return: None. | |
271 | */ | |
272 | void rsi_indicate_tx_status(struct rsi_hw *adapter, | |
273 | struct sk_buff *skb, | |
274 | int status) | |
275 | { | |
276 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
5059afac | 277 | struct skb_info *tx_params; |
dad0d04f | 278 | |
5059afac PRG |
279 | if (!adapter->hw) { |
280 | rsi_dbg(ERR_ZONE, "##### No MAC #####\n"); | |
281 | return; | |
282 | } | |
dad0d04f FF |
283 | |
284 | if (!status) | |
285 | info->flags |= IEEE80211_TX_STAT_ACK; | |
286 | ||
5059afac PRG |
287 | tx_params = (struct skb_info *)info->driver_data; |
288 | skb_pull(skb, tx_params->internal_hdr_size); | |
289 | memset(info->driver_data, 0, IEEE80211_TX_INFO_DRIVER_DATA_SIZE); | |
290 | ||
dad0d04f FF |
291 | ieee80211_tx_status_irqsafe(adapter->hw, skb); |
292 | } | |
293 | ||
294 | /** | |
295 | * rsi_mac80211_tx() - This is the handler that 802.11 module calls for each | |
296 | * transmitted frame.SKB contains the buffer starting | |
297 | * from the IEEE 802.11 header. | |
298 | * @hw: Pointer to the ieee80211_hw structure. | |
299 | * @control: Pointer to the ieee80211_tx_control structure | |
300 | * @skb: Pointer to the socket buffer structure. | |
301 | * | |
302 | * Return: None | |
303 | */ | |
304 | static void rsi_mac80211_tx(struct ieee80211_hw *hw, | |
305 | struct ieee80211_tx_control *control, | |
306 | struct sk_buff *skb) | |
307 | { | |
308 | struct rsi_hw *adapter = hw->priv; | |
309 | struct rsi_common *common = adapter->priv; | |
310 | ||
311 | rsi_core_xmit(common, skb); | |
312 | } | |
313 | ||
314 | /** | |
315 | * rsi_mac80211_start() - This is first handler that 802.11 module calls, since | |
316 | * the driver init is complete by then, just | |
317 | * returns success. | |
318 | * @hw: Pointer to the ieee80211_hw structure. | |
319 | * | |
320 | * Return: 0 as success. | |
321 | */ | |
322 | static int rsi_mac80211_start(struct ieee80211_hw *hw) | |
323 | { | |
324 | struct rsi_hw *adapter = hw->priv; | |
325 | struct rsi_common *common = adapter->priv; | |
326 | ||
edba3532 | 327 | rsi_dbg(ERR_ZONE, "===> Interface UP <===\n"); |
dad0d04f | 328 | mutex_lock(&common->mutex); |
b6c8d06c KE |
329 | if (common->hibernate_resume) { |
330 | common->reinit_hw = true; | |
331 | adapter->host_intf_ops->reinit_device(adapter); | |
332 | wait_for_completion(&adapter->priv->wlan_init_completion); | |
333 | } | |
dad0d04f | 334 | common->iface_down = false; |
edba3532 | 335 | wiphy_rfkill_start_polling(hw->wiphy); |
e6d64284 | 336 | rsi_send_rx_filter_frame(common, 0); |
edba3532 | 337 | mutex_unlock(&common->mutex); |
e6d64284 | 338 | |
dad0d04f FF |
339 | return 0; |
340 | } | |
341 | ||
342 | /** | |
343 | * rsi_mac80211_stop() - This is the last handler that 802.11 module calls. | |
344 | * @hw: Pointer to the ieee80211_hw structure. | |
345 | * | |
346 | * Return: None. | |
347 | */ | |
348 | static void rsi_mac80211_stop(struct ieee80211_hw *hw) | |
349 | { | |
350 | struct rsi_hw *adapter = hw->priv; | |
351 | struct rsi_common *common = adapter->priv; | |
352 | ||
edba3532 | 353 | rsi_dbg(ERR_ZONE, "===> Interface DOWN <===\n"); |
dad0d04f FF |
354 | mutex_lock(&common->mutex); |
355 | common->iface_down = true; | |
edba3532 | 356 | wiphy_rfkill_stop_polling(hw->wiphy); |
86583258 PRG |
357 | |
358 | /* Block all rx frames */ | |
359 | rsi_send_rx_filter_frame(common, 0xffff); | |
360 | ||
dad0d04f FF |
361 | mutex_unlock(&common->mutex); |
362 | } | |
363 | ||
b8bd3a43 PRG |
364 | static int rsi_map_intf_mode(enum nl80211_iftype vif_type) |
365 | { | |
366 | switch (vif_type) { | |
367 | case NL80211_IFTYPE_STATION: | |
368 | return RSI_OPMODE_STA; | |
369 | case NL80211_IFTYPE_AP: | |
370 | return RSI_OPMODE_AP; | |
371 | case NL80211_IFTYPE_P2P_DEVICE: | |
372 | return RSI_OPMODE_P2P_CLIENT; | |
373 | case NL80211_IFTYPE_P2P_CLIENT: | |
374 | return RSI_OPMODE_P2P_CLIENT; | |
375 | case NL80211_IFTYPE_P2P_GO: | |
376 | return RSI_OPMODE_P2P_GO; | |
377 | default: | |
378 | return RSI_OPMODE_UNSUPPORTED; | |
379 | } | |
380 | } | |
381 | ||
dad0d04f FF |
382 | /** |
383 | * rsi_mac80211_add_interface() - This function is called when a netdevice | |
384 | * attached to the hardware is enabled. | |
385 | * @hw: Pointer to the ieee80211_hw structure. | |
386 | * @vif: Pointer to the ieee80211_vif structure. | |
387 | * | |
388 | * Return: ret: 0 on success, negative error code on failure. | |
389 | */ | |
390 | static int rsi_mac80211_add_interface(struct ieee80211_hw *hw, | |
391 | struct ieee80211_vif *vif) | |
392 | { | |
393 | struct rsi_hw *adapter = hw->priv; | |
394 | struct rsi_common *common = adapter->priv; | |
b8bd3a43 | 395 | struct vif_priv *vif_info = (struct vif_priv *)vif->drv_priv; |
03c34c0d | 396 | enum opmode intf_mode; |
b8bd3a43 PRG |
397 | enum vap_status vap_status; |
398 | int vap_idx = -1, i; | |
dad0d04f | 399 | |
db07971d | 400 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
dad0d04f | 401 | mutex_lock(&common->mutex); |
03c34c0d | 402 | |
b8bd3a43 PRG |
403 | intf_mode = rsi_map_intf_mode(vif->type); |
404 | if (intf_mode == RSI_OPMODE_UNSUPPORTED) { | |
dad0d04f FF |
405 | rsi_dbg(ERR_ZONE, |
406 | "%s: Interface type %d not supported\n", __func__, | |
407 | vif->type); | |
b8bd3a43 PRG |
408 | mutex_unlock(&common->mutex); |
409 | return -EOPNOTSUPP; | |
03c34c0d | 410 | } |
b8bd3a43 PRG |
411 | if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) || |
412 | (vif->type == NL80211_IFTYPE_P2P_CLIENT) || | |
413 | (vif->type == NL80211_IFTYPE_P2P_GO)) | |
414 | common->p2p_enabled = true; | |
415 | ||
416 | /* Get free vap index */ | |
417 | for (i = 0; i < RSI_MAX_VIFS; i++) { | |
418 | if (!adapter->vifs[i]) { | |
419 | vap_idx = i; | |
420 | break; | |
421 | } | |
422 | } | |
423 | if (vap_idx < 0) { | |
424 | rsi_dbg(ERR_ZONE, "Reject: Max VAPs reached\n"); | |
425 | mutex_unlock(&common->mutex); | |
426 | return -EOPNOTSUPP; | |
427 | } | |
428 | vif_info->vap_id = vap_idx; | |
429 | adapter->vifs[vap_idx] = vif; | |
430 | adapter->sc_nvifs++; | |
431 | vap_status = VAP_ADD; | |
03c34c0d | 432 | |
b8bd3a43 PRG |
433 | if (rsi_set_vap_capabilities(common, intf_mode, vif->addr, |
434 | vif_info->vap_id, vap_status)) { | |
03c34c0d | 435 | rsi_dbg(ERR_ZONE, "Failed to set VAP capabilities\n"); |
b8bd3a43 PRG |
436 | mutex_unlock(&common->mutex); |
437 | return -EINVAL; | |
dad0d04f | 438 | } |
03c34c0d | 439 | |
b8bd3a43 PRG |
440 | if ((vif->type == NL80211_IFTYPE_AP) || |
441 | (vif->type == NL80211_IFTYPE_P2P_GO)) { | |
03c34c0d PRG |
442 | rsi_send_rx_filter_frame(common, DISALLOW_BEACONS); |
443 | common->min_rate = RSI_RATE_AUTO; | |
444 | for (i = 0; i < common->max_stations; i++) | |
445 | common->stations[i].sta = NULL; | |
446 | } | |
447 | ||
dad0d04f FF |
448 | mutex_unlock(&common->mutex); |
449 | ||
b8bd3a43 | 450 | return 0; |
dad0d04f FF |
451 | } |
452 | ||
453 | /** | |
454 | * rsi_mac80211_remove_interface() - This function notifies driver that an | |
455 | * interface is going down. | |
456 | * @hw: Pointer to the ieee80211_hw structure. | |
457 | * @vif: Pointer to the ieee80211_vif structure. | |
458 | * | |
459 | * Return: None. | |
460 | */ | |
461 | static void rsi_mac80211_remove_interface(struct ieee80211_hw *hw, | |
462 | struct ieee80211_vif *vif) | |
463 | { | |
464 | struct rsi_hw *adapter = hw->priv; | |
465 | struct rsi_common *common = adapter->priv; | |
75ca0049 | 466 | enum opmode opmode; |
b8bd3a43 | 467 | int i; |
75ca0049 PRG |
468 | |
469 | rsi_dbg(INFO_ZONE, "Remove Interface Called\n"); | |
dad0d04f FF |
470 | |
471 | mutex_lock(&common->mutex); | |
75ca0049 PRG |
472 | |
473 | if (adapter->sc_nvifs <= 0) { | |
474 | mutex_unlock(&common->mutex); | |
475 | return; | |
476 | } | |
477 | ||
b8bd3a43 PRG |
478 | opmode = rsi_map_intf_mode(vif->type); |
479 | if (opmode == RSI_OPMODE_UNSUPPORTED) { | |
480 | rsi_dbg(ERR_ZONE, "Opmode error : %d\n", opmode); | |
75ca0049 PRG |
481 | mutex_unlock(&common->mutex); |
482 | return; | |
77364aae | 483 | } |
b8bd3a43 PRG |
484 | for (i = 0; i < RSI_MAX_VIFS; i++) { |
485 | if (!adapter->vifs[i]) | |
486 | continue; | |
487 | if (vif == adapter->vifs[i]) { | |
488 | rsi_set_vap_capabilities(common, opmode, vif->addr, | |
489 | i, VAP_DELETE); | |
490 | adapter->sc_nvifs--; | |
491 | adapter->vifs[i] = NULL; | |
492 | } | |
493 | } | |
dad0d04f FF |
494 | mutex_unlock(&common->mutex); |
495 | } | |
496 | ||
686a2541 JM |
497 | /** |
498 | * rsi_channel_change() - This function is a performs the checks | |
499 | * required for changing a channel and sets | |
500 | * the channel accordingly. | |
501 | * @hw: Pointer to the ieee80211_hw structure. | |
502 | * | |
503 | * Return: 0 on success, negative error code on failure. | |
504 | */ | |
505 | static int rsi_channel_change(struct ieee80211_hw *hw) | |
506 | { | |
507 | struct rsi_hw *adapter = hw->priv; | |
508 | struct rsi_common *common = adapter->priv; | |
509 | int status = -EOPNOTSUPP; | |
510 | struct ieee80211_channel *curchan = hw->conf.chandef.chan; | |
511 | u16 channel = curchan->hw_value; | |
df771911 PRG |
512 | struct ieee80211_vif *vif; |
513 | struct ieee80211_bss_conf *bss; | |
514 | bool assoc = false; | |
515 | int i; | |
686a2541 JM |
516 | |
517 | rsi_dbg(INFO_ZONE, | |
518 | "%s: Set channel: %d MHz type: %d channel_no %d\n", | |
519 | __func__, curchan->center_freq, | |
520 | curchan->flags, channel); | |
521 | ||
df771911 PRG |
522 | for (i = 0; i < RSI_MAX_VIFS; i++) { |
523 | vif = adapter->vifs[i]; | |
524 | if (!vif) | |
525 | continue; | |
526 | if (vif->type == NL80211_IFTYPE_STATION) { | |
527 | bss = &vif->bss_conf; | |
528 | if (bss->assoc) { | |
529 | assoc = true; | |
530 | break; | |
531 | } | |
532 | } | |
533 | } | |
534 | if (assoc) { | |
686a2541 | 535 | if (!common->hw_data_qs_blocked && |
df771911 | 536 | (rsi_get_connected_channel(vif) != channel)) { |
686a2541 JM |
537 | rsi_dbg(INFO_ZONE, "blk data q %d\n", channel); |
538 | if (!rsi_send_block_unblock_frame(common, true)) | |
539 | common->hw_data_qs_blocked = true; | |
540 | } | |
541 | } | |
542 | ||
df771911 | 543 | status = rsi_band_check(common, curchan); |
686a2541 | 544 | if (!status) |
61d10842 | 545 | status = rsi_set_channel(adapter->priv, curchan); |
686a2541 | 546 | |
df771911 | 547 | if (assoc) { |
686a2541 | 548 | if (common->hw_data_qs_blocked && |
df771911 | 549 | (rsi_get_connected_channel(vif) == channel)) { |
686a2541 JM |
550 | rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel); |
551 | if (!rsi_send_block_unblock_frame(common, false)) | |
552 | common->hw_data_qs_blocked = false; | |
553 | } | |
554 | } | |
555 | ||
556 | return status; | |
557 | } | |
558 | ||
8b36de8c PRG |
559 | /** |
560 | * rsi_config_power() - This function configures tx power to device | |
561 | * @hw: Pointer to the ieee80211_hw structure. | |
562 | * | |
563 | * Return: 0 on success, negative error code on failure. | |
564 | */ | |
565 | static int rsi_config_power(struct ieee80211_hw *hw) | |
566 | { | |
567 | struct rsi_hw *adapter = hw->priv; | |
568 | struct rsi_common *common = adapter->priv; | |
569 | struct ieee80211_conf *conf = &hw->conf; | |
570 | ||
571 | if (adapter->sc_nvifs <= 0) { | |
572 | rsi_dbg(ERR_ZONE, "%s: No virtual interface found\n", __func__); | |
573 | return -EINVAL; | |
574 | } | |
575 | ||
576 | rsi_dbg(INFO_ZONE, | |
577 | "%s: Set tx power: %d dBM\n", __func__, conf->power_level); | |
578 | ||
579 | if (conf->power_level == common->tx_power) | |
580 | return 0; | |
581 | ||
582 | common->tx_power = conf->power_level; | |
583 | ||
584 | return rsi_send_radio_params_update(common); | |
585 | } | |
586 | ||
dad0d04f FF |
587 | /** |
588 | * rsi_mac80211_config() - This function is a handler for configuration | |
589 | * requests. The stack calls this function to | |
590 | * change hardware configuration, e.g., channel. | |
591 | * @hw: Pointer to the ieee80211_hw structure. | |
592 | * @changed: Changed flags set. | |
593 | * | |
594 | * Return: 0 on success, negative error code on failure. | |
595 | */ | |
596 | static int rsi_mac80211_config(struct ieee80211_hw *hw, | |
597 | u32 changed) | |
598 | { | |
599 | struct rsi_hw *adapter = hw->priv; | |
600 | struct rsi_common *common = adapter->priv; | |
ce86893f | 601 | struct ieee80211_conf *conf = &hw->conf; |
dad0d04f FF |
602 | int status = -EOPNOTSUPP; |
603 | ||
604 | mutex_lock(&common->mutex); | |
686a2541 JM |
605 | |
606 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) | |
607 | status = rsi_channel_change(hw); | |
608 | ||
8b36de8c PRG |
609 | /* tx power */ |
610 | if (changed & IEEE80211_CONF_CHANGE_POWER) { | |
611 | rsi_dbg(INFO_ZONE, "%s: Configuring Power\n", __func__); | |
612 | status = rsi_config_power(hw); | |
613 | } | |
614 | ||
ce86893f | 615 | /* Power save parameters */ |
efe877aa PRG |
616 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
617 | struct ieee80211_vif *vif; | |
ce86893f | 618 | unsigned long flags; |
efe877aa PRG |
619 | int i, set_ps = 1; |
620 | ||
621 | for (i = 0; i < RSI_MAX_VIFS; i++) { | |
622 | vif = adapter->vifs[i]; | |
623 | if (!vif) | |
624 | continue; | |
625 | /* Don't go to power save if AP vap exists */ | |
626 | if ((vif->type == NL80211_IFTYPE_AP) || | |
627 | (vif->type == NL80211_IFTYPE_P2P_GO)) { | |
628 | set_ps = 0; | |
629 | break; | |
630 | } | |
631 | } | |
632 | if (set_ps) { | |
633 | spin_lock_irqsave(&adapter->ps_lock, flags); | |
634 | if (conf->flags & IEEE80211_CONF_PS) | |
635 | rsi_enable_ps(adapter, vif); | |
636 | else | |
637 | rsi_disable_ps(adapter, vif); | |
638 | spin_unlock_irqrestore(&adapter->ps_lock, flags); | |
639 | } | |
ce86893f KE |
640 | } |
641 | ||
80a88ecf KE |
642 | /* RTS threshold */ |
643 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { | |
644 | rsi_dbg(INFO_ZONE, "RTS threshold\n"); | |
645 | if ((common->rts_threshold) <= IEEE80211_MAX_RTS_THRESHOLD) { | |
646 | rsi_dbg(INFO_ZONE, | |
647 | "%s: Sending vap updates....\n", __func__); | |
648 | status = rsi_send_vap_dynamic_update(common); | |
649 | } | |
650 | } | |
dad0d04f FF |
651 | mutex_unlock(&common->mutex); |
652 | ||
653 | return status; | |
654 | } | |
655 | ||
656 | /** | |
657 | * rsi_get_connected_channel() - This function is used to get the current | |
658 | * connected channel number. | |
659 | * @adapter: Pointer to the adapter structure. | |
660 | * | |
661 | * Return: Current connected AP's channel number is returned. | |
662 | */ | |
df771911 | 663 | u16 rsi_get_connected_channel(struct ieee80211_vif *vif) |
dad0d04f | 664 | { |
df771911 PRG |
665 | struct ieee80211_bss_conf *bss; |
666 | struct ieee80211_channel *channel; | |
dad0d04f | 667 | |
df771911 PRG |
668 | if (!vif) |
669 | return 0; | |
670 | ||
671 | bss = &vif->bss_conf; | |
672 | channel = bss->chandef.chan; | |
673 | ||
674 | if (!channel) | |
675 | return 0; | |
676 | ||
677 | return channel->hw_value; | |
678 | } | |
679 | ||
680 | static void rsi_switch_channel(struct rsi_hw *adapter, | |
681 | struct ieee80211_vif *vif) | |
682 | { | |
683 | struct rsi_common *common = adapter->priv; | |
684 | struct ieee80211_channel *channel; | |
685 | ||
686 | if (common->iface_down) | |
687 | return; | |
688 | if (!vif) | |
689 | return; | |
690 | ||
691 | channel = vif->bss_conf.chandef.chan; | |
692 | ||
693 | if (!channel) | |
694 | return; | |
695 | ||
696 | rsi_band_check(common, channel); | |
697 | rsi_set_channel(common, channel); | |
698 | rsi_dbg(INFO_ZONE, "Switched to channel - %d\n", channel->hw_value); | |
dad0d04f FF |
699 | } |
700 | ||
701 | /** | |
702 | * rsi_mac80211_bss_info_changed() - This function is a handler for config | |
703 | * requests related to BSS parameters that | |
704 | * may vary during BSS's lifespan. | |
705 | * @hw: Pointer to the ieee80211_hw structure. | |
706 | * @vif: Pointer to the ieee80211_vif structure. | |
707 | * @bss_conf: Pointer to the ieee80211_bss_conf structure. | |
708 | * @changed: Changed flags set. | |
709 | * | |
710 | * Return: None. | |
711 | */ | |
712 | static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw, | |
713 | struct ieee80211_vif *vif, | |
714 | struct ieee80211_bss_conf *bss_conf, | |
715 | u32 changed) | |
716 | { | |
717 | struct rsi_hw *adapter = hw->priv; | |
718 | struct rsi_common *common = adapter->priv; | |
ce86893f KE |
719 | struct ieee80211_bss_conf *bss = &vif->bss_conf; |
720 | struct ieee80211_conf *conf = &hw->conf; | |
e6d64284 | 721 | u16 rx_filter_word = 0; |
dad0d04f FF |
722 | |
723 | mutex_lock(&common->mutex); | |
724 | if (changed & BSS_CHANGED_ASSOC) { | |
725 | rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n", | |
726 | __func__, bss_conf->assoc); | |
e6d64284 PRG |
727 | if (bss_conf->assoc) { |
728 | /* Send the RX filter frame */ | |
729 | rx_filter_word = (ALLOW_DATA_ASSOC_PEER | | |
730 | ALLOW_CTRL_ASSOC_PEER | | |
731 | ALLOW_MGMT_ASSOC_PEER); | |
732 | rsi_send_rx_filter_frame(common, rx_filter_word); | |
733 | } | |
dad0d04f | 734 | rsi_inform_bss_status(common, |
b8bd3a43 | 735 | RSI_OPMODE_STA, |
dad0d04f FF |
736 | bss_conf->assoc, |
737 | bss_conf->bssid, | |
738 | bss_conf->qos, | |
3528608f | 739 | bss_conf->aid, |
4671c209 | 740 | NULL, 0, vif); |
ce86893f KE |
741 | adapter->ps_info.dtim_interval_duration = bss->dtim_period; |
742 | adapter->ps_info.listen_interval = conf->listen_interval; | |
db07971d KE |
743 | |
744 | /* If U-APSD is updated, send ps parameters to firmware */ | |
745 | if (bss->assoc) { | |
746 | if (common->uapsd_bitmap) { | |
747 | rsi_dbg(INFO_ZONE, "Configuring UAPSD\n"); | |
efe877aa | 748 | rsi_conf_uapsd(adapter, vif); |
db07971d KE |
749 | } |
750 | } else { | |
751 | common->uapsd_bitmap = 0; | |
752 | } | |
dad0d04f | 753 | } |
686a2541 JM |
754 | |
755 | if (changed & BSS_CHANGED_CQM) { | |
756 | common->cqm_info.last_cqm_event_rssi = 0; | |
757 | common->cqm_info.rssi_thold = bss_conf->cqm_rssi_thold; | |
758 | common->cqm_info.rssi_hyst = bss_conf->cqm_rssi_hyst; | |
759 | rsi_dbg(INFO_ZONE, "RSSI throld & hysteresis are: %d %d\n", | |
760 | common->cqm_info.rssi_thold, | |
761 | common->cqm_info.rssi_hyst); | |
762 | } | |
d26a9559 PRG |
763 | |
764 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && | |
af756872 PRG |
765 | ((vif->type == NL80211_IFTYPE_AP) || |
766 | (vif->type == NL80211_IFTYPE_P2P_GO))) { | |
d26a9559 PRG |
767 | if (bss->enable_beacon) { |
768 | rsi_dbg(INFO_ZONE, "===> BEACON ENABLED <===\n"); | |
769 | common->beacon_enabled = 1; | |
770 | } else { | |
771 | rsi_dbg(INFO_ZONE, "===> BEACON DISABLED <===\n"); | |
772 | common->beacon_enabled = 0; | |
773 | } | |
774 | } | |
775 | ||
dad0d04f FF |
776 | mutex_unlock(&common->mutex); |
777 | } | |
778 | ||
779 | /** | |
780 | * rsi_mac80211_conf_filter() - This function configure the device's RX filter. | |
781 | * @hw: Pointer to the ieee80211_hw structure. | |
782 | * @changed: Changed flags set. | |
783 | * @total_flags: Total initial flags set. | |
784 | * @multicast: Multicast. | |
785 | * | |
786 | * Return: None. | |
787 | */ | |
788 | static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw, | |
789 | u32 changed_flags, | |
790 | u32 *total_flags, | |
791 | u64 multicast) | |
792 | { | |
793 | /* Not doing much here as of now */ | |
794 | *total_flags &= RSI_SUPP_FILTERS; | |
795 | } | |
796 | ||
797 | /** | |
798 | * rsi_mac80211_conf_tx() - This function configures TX queue parameters | |
799 | * (EDCF (aifs, cw_min, cw_max), bursting) | |
800 | * for a hardware TX queue. | |
801 | * @hw: Pointer to the ieee80211_hw structure | |
802 | * @vif: Pointer to the ieee80211_vif structure. | |
803 | * @queue: Queue number. | |
804 | * @params: Pointer to ieee80211_tx_queue_params structure. | |
805 | * | |
806 | * Return: 0 on success, negative error code on failure. | |
807 | */ | |
808 | static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw, | |
809 | struct ieee80211_vif *vif, u16 queue, | |
810 | const struct ieee80211_tx_queue_params *params) | |
811 | { | |
812 | struct rsi_hw *adapter = hw->priv; | |
813 | struct rsi_common *common = adapter->priv; | |
814 | u8 idx = 0; | |
815 | ||
816 | if (queue >= IEEE80211_NUM_ACS) | |
817 | return 0; | |
818 | ||
819 | rsi_dbg(INFO_ZONE, | |
820 | "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n", | |
821 | __func__, queue, params->aifs, | |
822 | params->cw_min, params->cw_max, params->txop); | |
823 | ||
824 | mutex_lock(&common->mutex); | |
825 | /* Map into the way the f/w expects */ | |
826 | switch (queue) { | |
827 | case IEEE80211_AC_VO: | |
828 | idx = VO_Q; | |
829 | break; | |
830 | case IEEE80211_AC_VI: | |
831 | idx = VI_Q; | |
832 | break; | |
833 | case IEEE80211_AC_BE: | |
834 | idx = BE_Q; | |
835 | break; | |
836 | case IEEE80211_AC_BK: | |
837 | idx = BK_Q; | |
838 | break; | |
839 | default: | |
840 | idx = BE_Q; | |
841 | break; | |
842 | } | |
843 | ||
844 | memcpy(&common->edca_params[idx], | |
845 | params, | |
846 | sizeof(struct ieee80211_tx_queue_params)); | |
db07971d KE |
847 | |
848 | if (params->uapsd) | |
849 | common->uapsd_bitmap |= idx; | |
850 | else | |
851 | common->uapsd_bitmap &= (~idx); | |
852 | ||
dad0d04f FF |
853 | mutex_unlock(&common->mutex); |
854 | ||
855 | return 0; | |
856 | } | |
857 | ||
858 | /** | |
859 | * rsi_hal_key_config() - This function loads the keys into the firmware. | |
860 | * @hw: Pointer to the ieee80211_hw structure. | |
861 | * @vif: Pointer to the ieee80211_vif structure. | |
862 | * @key: Pointer to the ieee80211_key_conf structure. | |
863 | * | |
fc438672 | 864 | * Return: status: 0 on success, negative error codes on failure. |
dad0d04f FF |
865 | */ |
866 | static int rsi_hal_key_config(struct ieee80211_hw *hw, | |
867 | struct ieee80211_vif *vif, | |
38ef6235 PRG |
868 | struct ieee80211_key_conf *key, |
869 | struct ieee80211_sta *sta) | |
dad0d04f FF |
870 | { |
871 | struct rsi_hw *adapter = hw->priv; | |
38ef6235 | 872 | struct rsi_sta *rsta = NULL; |
dad0d04f FF |
873 | int status; |
874 | u8 key_type; | |
38ef6235 | 875 | s16 sta_id = 0; |
dad0d04f FF |
876 | |
877 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
878 | key_type = RSI_PAIRWISE_KEY; | |
879 | else | |
880 | key_type = RSI_GROUP_KEY; | |
881 | ||
882 | rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n", | |
883 | __func__, key->cipher, key_type, key->keylen); | |
884 | ||
4671c209 PRG |
885 | if ((vif->type == NL80211_IFTYPE_AP) || |
886 | (vif->type == NL80211_IFTYPE_P2P_GO)) { | |
38ef6235 PRG |
887 | if (sta) { |
888 | rsta = rsi_find_sta(adapter->priv, sta->addr); | |
889 | if (rsta) | |
890 | sta_id = rsta->sta_id; | |
891 | } | |
892 | adapter->priv->key = key; | |
893 | } else { | |
894 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) || | |
895 | (key->cipher == WLAN_CIPHER_SUITE_WEP40)) { | |
896 | status = rsi_hal_load_key(adapter->priv, | |
897 | key->key, | |
898 | key->keylen, | |
899 | RSI_PAIRWISE_KEY, | |
900 | key->keyidx, | |
901 | key->cipher, | |
eac4eed3 PRG |
902 | sta_id, |
903 | vif); | |
38ef6235 PRG |
904 | if (status) |
905 | return status; | |
906 | } | |
dad0d04f | 907 | } |
38ef6235 | 908 | |
dad0d04f FF |
909 | return rsi_hal_load_key(adapter->priv, |
910 | key->key, | |
911 | key->keylen, | |
912 | key_type, | |
913 | key->keyidx, | |
38ef6235 | 914 | key->cipher, |
eac4eed3 PRG |
915 | sta_id, |
916 | vif); | |
dad0d04f FF |
917 | } |
918 | ||
919 | /** | |
920 | * rsi_mac80211_set_key() - This function sets type of key to be loaded. | |
921 | * @hw: Pointer to the ieee80211_hw structure. | |
922 | * @cmd: enum set_key_cmd. | |
923 | * @vif: Pointer to the ieee80211_vif structure. | |
924 | * @sta: Pointer to the ieee80211_sta structure. | |
925 | * @key: Pointer to the ieee80211_key_conf structure. | |
926 | * | |
927 | * Return: status: 0 on success, negative error code on failure. | |
928 | */ | |
929 | static int rsi_mac80211_set_key(struct ieee80211_hw *hw, | |
930 | enum set_key_cmd cmd, | |
931 | struct ieee80211_vif *vif, | |
932 | struct ieee80211_sta *sta, | |
933 | struct ieee80211_key_conf *key) | |
934 | { | |
935 | struct rsi_hw *adapter = hw->priv; | |
936 | struct rsi_common *common = adapter->priv; | |
937 | struct security_info *secinfo = &common->secinfo; | |
938 | int status; | |
939 | ||
940 | mutex_lock(&common->mutex); | |
941 | switch (cmd) { | |
942 | case SET_KEY: | |
943 | secinfo->security_enable = true; | |
38ef6235 | 944 | status = rsi_hal_key_config(hw, vif, key, sta); |
dad0d04f FF |
945 | if (status) { |
946 | mutex_unlock(&common->mutex); | |
947 | return status; | |
948 | } | |
949 | ||
950 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
951 | secinfo->ptk_cipher = key->cipher; | |
952 | else | |
953 | secinfo->gtk_cipher = key->cipher; | |
954 | ||
955 | key->hw_key_idx = key->keyidx; | |
956 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
957 | ||
958 | rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__); | |
959 | break; | |
960 | ||
961 | case DISABLE_KEY: | |
38ef6235 PRG |
962 | if (vif->type == NL80211_IFTYPE_STATION) |
963 | secinfo->security_enable = false; | |
dad0d04f FF |
964 | rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__); |
965 | memset(key, 0, sizeof(struct ieee80211_key_conf)); | |
38ef6235 | 966 | status = rsi_hal_key_config(hw, vif, key, sta); |
dad0d04f FF |
967 | break; |
968 | ||
969 | default: | |
970 | status = -EOPNOTSUPP; | |
971 | break; | |
972 | } | |
973 | ||
974 | mutex_unlock(&common->mutex); | |
975 | return status; | |
976 | } | |
977 | ||
978 | /** | |
979 | * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for | |
980 | * the corresponding mlme_action flag and | |
981 | * informs the f/w regarding this. | |
982 | * @hw: Pointer to the ieee80211_hw structure. | |
983 | * @vif: Pointer to the ieee80211_vif structure. | |
50ea05ef | 984 | * @params: Pointer to A-MPDU action parameters |
dad0d04f FF |
985 | * |
986 | * Return: status: 0 on success, negative error code on failure. | |
987 | */ | |
988 | static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw, | |
989 | struct ieee80211_vif *vif, | |
50ea05ef | 990 | struct ieee80211_ampdu_params *params) |
dad0d04f FF |
991 | { |
992 | int status = -EOPNOTSUPP; | |
993 | struct rsi_hw *adapter = hw->priv; | |
994 | struct rsi_common *common = adapter->priv; | |
32be57a6 PRG |
995 | struct rsi_sta *rsta = NULL; |
996 | u16 seq_no = 0, seq_start = 0; | |
dad0d04f | 997 | u8 ii = 0; |
50ea05ef | 998 | struct ieee80211_sta *sta = params->sta; |
32be57a6 | 999 | u8 sta_id = 0; |
50ea05ef SS |
1000 | enum ieee80211_ampdu_mlme_action action = params->action; |
1001 | u16 tid = params->tid; | |
1002 | u16 *ssn = ¶ms->ssn; | |
1003 | u8 buf_size = params->buf_size; | |
dad0d04f FF |
1004 | |
1005 | for (ii = 0; ii < RSI_MAX_VIFS; ii++) { | |
1006 | if (vif == adapter->vifs[ii]) | |
1007 | break; | |
1008 | } | |
1009 | ||
1010 | mutex_lock(&common->mutex); | |
32be57a6 | 1011 | |
dad0d04f FF |
1012 | if (ssn != NULL) |
1013 | seq_no = *ssn; | |
1014 | ||
c7245c09 PRG |
1015 | if ((vif->type == NL80211_IFTYPE_AP) || |
1016 | (vif->type == NL80211_IFTYPE_P2P_GO)) { | |
32be57a6 PRG |
1017 | rsta = rsi_find_sta(common, sta->addr); |
1018 | if (!rsta) { | |
1019 | rsi_dbg(ERR_ZONE, "No station mapped\n"); | |
0270639e DC |
1020 | status = 0; |
1021 | goto unlock; | |
32be57a6 PRG |
1022 | } |
1023 | sta_id = rsta->sta_id; | |
1024 | } | |
1025 | ||
1026 | rsi_dbg(INFO_ZONE, | |
1027 | "%s: AMPDU action tid=%d ssn=0x%x, buf_size=%d sta_id=%d\n", | |
1028 | __func__, tid, seq_no, buf_size, sta_id); | |
1029 | ||
dad0d04f FF |
1030 | switch (action) { |
1031 | case IEEE80211_AMPDU_RX_START: | |
1032 | status = rsi_send_aggregation_params_frame(common, | |
1033 | tid, | |
1034 | seq_no, | |
1035 | buf_size, | |
32be57a6 PRG |
1036 | STA_RX_ADDBA_DONE, |
1037 | sta_id); | |
dad0d04f FF |
1038 | break; |
1039 | ||
1040 | case IEEE80211_AMPDU_RX_STOP: | |
1041 | status = rsi_send_aggregation_params_frame(common, | |
1042 | tid, | |
1043 | 0, | |
1044 | buf_size, | |
32be57a6 PRG |
1045 | STA_RX_DELBA, |
1046 | sta_id); | |
dad0d04f FF |
1047 | break; |
1048 | ||
1049 | case IEEE80211_AMPDU_TX_START: | |
c7245c09 PRG |
1050 | if ((vif->type == NL80211_IFTYPE_STATION) || |
1051 | (vif->type == NL80211_IFTYPE_P2P_CLIENT)) | |
32be57a6 | 1052 | common->vif_info[ii].seq_start = seq_no; |
c7245c09 PRG |
1053 | else if ((vif->type == NL80211_IFTYPE_AP) || |
1054 | (vif->type == NL80211_IFTYPE_P2P_GO)) | |
32be57a6 | 1055 | rsta->seq_start[tid] = seq_no; |
dad0d04f | 1056 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
5f407acb | 1057 | status = 0; |
dad0d04f FF |
1058 | break; |
1059 | ||
1060 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
1061 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
1062 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
1063 | status = rsi_send_aggregation_params_frame(common, | |
1064 | tid, | |
1065 | seq_no, | |
1066 | buf_size, | |
32be57a6 PRG |
1067 | STA_TX_DELBA, |
1068 | sta_id); | |
dad0d04f FF |
1069 | if (!status) |
1070 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
1071 | break; | |
1072 | ||
1073 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
c7245c09 PRG |
1074 | if ((vif->type == NL80211_IFTYPE_STATION) || |
1075 | (vif->type == NL80211_IFTYPE_P2P_CLIENT)) | |
32be57a6 | 1076 | seq_start = common->vif_info[ii].seq_start; |
c7245c09 PRG |
1077 | else if ((vif->type == NL80211_IFTYPE_AP) || |
1078 | (vif->type == NL80211_IFTYPE_P2P_GO)) | |
32be57a6 | 1079 | seq_start = rsta->seq_start[tid]; |
dad0d04f FF |
1080 | status = rsi_send_aggregation_params_frame(common, |
1081 | tid, | |
32be57a6 | 1082 | seq_start, |
dad0d04f | 1083 | buf_size, |
32be57a6 PRG |
1084 | STA_TX_ADDBA_DONE, |
1085 | sta_id); | |
dad0d04f FF |
1086 | break; |
1087 | ||
1088 | default: | |
1089 | rsi_dbg(ERR_ZONE, "%s: Uknown AMPDU action\n", __func__); | |
1090 | break; | |
1091 | } | |
1092 | ||
0270639e | 1093 | unlock: |
dad0d04f FF |
1094 | mutex_unlock(&common->mutex); |
1095 | return status; | |
1096 | } | |
1097 | ||
1098 | /** | |
1099 | * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value. | |
1100 | * @hw: Pointer to the ieee80211_hw structure. | |
1101 | * @value: Rts threshold value. | |
1102 | * | |
1103 | * Return: 0 on success. | |
1104 | */ | |
1105 | static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw, | |
1106 | u32 value) | |
1107 | { | |
1108 | struct rsi_hw *adapter = hw->priv; | |
1109 | struct rsi_common *common = adapter->priv; | |
1110 | ||
1111 | mutex_lock(&common->mutex); | |
1112 | common->rts_threshold = value; | |
1113 | mutex_unlock(&common->mutex); | |
1114 | ||
1115 | return 0; | |
1116 | } | |
1117 | ||
1118 | /** | |
1119 | * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used. | |
1120 | * @hw: Pointer to the ieee80211_hw structure | |
1121 | * @vif: Pointer to the ieee80211_vif structure. | |
1122 | * @mask: Pointer to the cfg80211_bitrate_mask structure. | |
1123 | * | |
1124 | * Return: 0 on success. | |
1125 | */ | |
1126 | static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw, | |
1127 | struct ieee80211_vif *vif, | |
1128 | const struct cfg80211_bitrate_mask *mask) | |
1129 | { | |
1130 | struct rsi_hw *adapter = hw->priv; | |
1131 | struct rsi_common *common = adapter->priv; | |
57fbcce3 | 1132 | enum nl80211_band band = hw->conf.chandef.chan->band; |
dad0d04f FF |
1133 | |
1134 | mutex_lock(&common->mutex); | |
85af5bf8 | 1135 | common->fixedrate_mask[band] = 0; |
dad0d04f | 1136 | |
85af5bf8 JM |
1137 | if (mask->control[band].legacy == 0xfff) { |
1138 | common->fixedrate_mask[band] = | |
1139 | (mask->control[band].ht_mcs[0] << 12); | |
dad0d04f | 1140 | } else { |
85af5bf8 JM |
1141 | common->fixedrate_mask[band] = |
1142 | mask->control[band].legacy; | |
dad0d04f FF |
1143 | } |
1144 | mutex_unlock(&common->mutex); | |
1145 | ||
1146 | return 0; | |
1147 | } | |
1148 | ||
686a2541 JM |
1149 | /** |
1150 | * rsi_perform_cqm() - This function performs cqm. | |
1151 | * @common: Pointer to the driver private structure. | |
1152 | * @bssid: pointer to the bssid. | |
1153 | * @rssi: RSSI value. | |
1154 | */ | |
1155 | static void rsi_perform_cqm(struct rsi_common *common, | |
1156 | u8 *bssid, | |
af756872 PRG |
1157 | s8 rssi, |
1158 | struct ieee80211_vif *vif) | |
686a2541 | 1159 | { |
686a2541 JM |
1160 | s8 last_event = common->cqm_info.last_cqm_event_rssi; |
1161 | int thold = common->cqm_info.rssi_thold; | |
1162 | u32 hyst = common->cqm_info.rssi_hyst; | |
1163 | enum nl80211_cqm_rssi_threshold_event event; | |
1164 | ||
1165 | if (rssi < thold && (last_event == 0 || rssi < (last_event - hyst))) | |
1166 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; | |
1167 | else if (rssi > thold && | |
1168 | (last_event == 0 || rssi > (last_event + hyst))) | |
1169 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; | |
1170 | else | |
1171 | return; | |
1172 | ||
1173 | common->cqm_info.last_cqm_event_rssi = rssi; | |
1174 | rsi_dbg(INFO_ZONE, "CQM: Notifying event: %d\n", event); | |
af756872 | 1175 | ieee80211_cqm_rssi_notify(vif, event, rssi, GFP_KERNEL); |
686a2541 JM |
1176 | |
1177 | return; | |
1178 | } | |
1179 | ||
dad0d04f FF |
1180 | /** |
1181 | * rsi_fill_rx_status() - This function fills rx status in | |
1182 | * ieee80211_rx_status structure. | |
1183 | * @hw: Pointer to the ieee80211_hw structure. | |
1184 | * @skb: Pointer to the socket buffer structure. | |
1185 | * @common: Pointer to the driver private structure. | |
1186 | * @rxs: Pointer to the ieee80211_rx_status structure. | |
1187 | * | |
1188 | * Return: None. | |
1189 | */ | |
1190 | static void rsi_fill_rx_status(struct ieee80211_hw *hw, | |
1191 | struct sk_buff *skb, | |
1192 | struct rsi_common *common, | |
1193 | struct ieee80211_rx_status *rxs) | |
1194 | { | |
eac4eed3 PRG |
1195 | struct rsi_hw *adapter = common->priv; |
1196 | struct ieee80211_vif *vif; | |
1197 | struct ieee80211_bss_conf *bss = NULL; | |
dad0d04f FF |
1198 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
1199 | struct skb_info *rx_params = (struct skb_info *)info->driver_data; | |
1200 | struct ieee80211_hdr *hdr; | |
1201 | char rssi = rx_params->rssi; | |
1202 | u8 hdrlen = 0; | |
1203 | u8 channel = rx_params->channel; | |
1204 | s32 freq; | |
eac4eed3 | 1205 | int i; |
dad0d04f FF |
1206 | |
1207 | hdr = ((struct ieee80211_hdr *)(skb->data)); | |
1208 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | |
1209 | ||
1210 | memset(info, 0, sizeof(struct ieee80211_tx_info)); | |
1211 | ||
1212 | rxs->signal = -(rssi); | |
1213 | ||
aabd3ad4 | 1214 | rxs->band = common->band; |
dad0d04f FF |
1215 | |
1216 | freq = ieee80211_channel_to_frequency(channel, rxs->band); | |
1217 | ||
1218 | if (freq) | |
1219 | rxs->freq = freq; | |
1220 | ||
1221 | if (ieee80211_has_protected(hdr->frame_control)) { | |
1222 | if (rsi_is_cipher_wep(common)) { | |
1223 | memmove(skb->data + 4, skb->data, hdrlen); | |
1224 | skb_pull(skb, 4); | |
1225 | } else { | |
1226 | memmove(skb->data + 8, skb->data, hdrlen); | |
1227 | skb_pull(skb, 8); | |
1228 | rxs->flag |= RX_FLAG_MMIC_STRIPPED; | |
1229 | } | |
1230 | rxs->flag |= RX_FLAG_DECRYPTED; | |
1231 | rxs->flag |= RX_FLAG_IV_STRIPPED; | |
1232 | } | |
686a2541 | 1233 | |
eac4eed3 PRG |
1234 | for (i = 0; i < RSI_MAX_VIFS; i++) { |
1235 | vif = adapter->vifs[i]; | |
1236 | if (!vif) | |
1237 | continue; | |
af756872 | 1238 | if (vif->type == NL80211_IFTYPE_STATION) { |
eac4eed3 | 1239 | bss = &vif->bss_conf; |
af756872 PRG |
1240 | break; |
1241 | } | |
eac4eed3 PRG |
1242 | } |
1243 | if (!bss) | |
1244 | return; | |
686a2541 JM |
1245 | /* CQM only for connected AP beacons, the RSSI is a weighted avg */ |
1246 | if (bss->assoc && !(memcmp(bss->bssid, hdr->addr2, ETH_ALEN))) { | |
1247 | if (ieee80211_is_beacon(hdr->frame_control)) | |
af756872 | 1248 | rsi_perform_cqm(common, hdr->addr2, rxs->signal, vif); |
686a2541 JM |
1249 | } |
1250 | ||
1251 | return; | |
dad0d04f FF |
1252 | } |
1253 | ||
1254 | /** | |
1255 | * rsi_indicate_pkt_to_os() - This function sends recieved packet to mac80211. | |
1256 | * @common: Pointer to the driver private structure. | |
1257 | * @skb: Pointer to the socket buffer structure. | |
1258 | * | |
1259 | * Return: None. | |
1260 | */ | |
1261 | void rsi_indicate_pkt_to_os(struct rsi_common *common, | |
1262 | struct sk_buff *skb) | |
1263 | { | |
1264 | struct rsi_hw *adapter = common->priv; | |
1265 | struct ieee80211_hw *hw = adapter->hw; | |
1266 | struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); | |
1267 | ||
1268 | if ((common->iface_down) || (!adapter->sc_nvifs)) { | |
1269 | dev_kfree_skb(skb); | |
1270 | return; | |
1271 | } | |
1272 | ||
1273 | /* filling in the ieee80211_rx_status flags */ | |
1274 | rsi_fill_rx_status(hw, skb, common, rx_status); | |
1275 | ||
1276 | ieee80211_rx_irqsafe(hw, skb); | |
1277 | } | |
1278 | ||
1279 | static void rsi_set_min_rate(struct ieee80211_hw *hw, | |
1280 | struct ieee80211_sta *sta, | |
1281 | struct rsi_common *common) | |
1282 | { | |
1283 | u8 band = hw->conf.chandef.chan->band; | |
1284 | u8 ii; | |
1285 | u32 rate_bitmap; | |
1286 | bool matched = false; | |
1287 | ||
1288 | common->bitrate_mask[band] = sta->supp_rates[band]; | |
1289 | ||
1290 | rate_bitmap = (common->fixedrate_mask[band] & sta->supp_rates[band]); | |
1291 | ||
1292 | if (rate_bitmap & 0xfff) { | |
1293 | /* Find out the min rate */ | |
1294 | for (ii = 0; ii < ARRAY_SIZE(rsi_rates); ii++) { | |
1295 | if (rate_bitmap & BIT(ii)) { | |
1296 | common->min_rate = rsi_rates[ii].hw_value; | |
1297 | matched = true; | |
1298 | break; | |
1299 | } | |
1300 | } | |
1301 | } | |
1302 | ||
1303 | common->vif_info[0].is_ht = sta->ht_cap.ht_supported; | |
1304 | ||
1305 | if ((common->vif_info[0].is_ht) && (rate_bitmap >> 12)) { | |
1306 | for (ii = 0; ii < ARRAY_SIZE(rsi_mcsrates); ii++) { | |
1307 | if ((rate_bitmap >> 12) & BIT(ii)) { | |
1308 | common->min_rate = rsi_mcsrates[ii]; | |
1309 | matched = true; | |
1310 | break; | |
1311 | } | |
1312 | } | |
1313 | } | |
1314 | ||
1315 | if (!matched) | |
1316 | common->min_rate = 0xffff; | |
1317 | } | |
1318 | ||
1319 | /** | |
1320 | * rsi_mac80211_sta_add() - This function notifies driver about a peer getting | |
1321 | * connected. | |
1322 | * @hw: pointer to the ieee80211_hw structure. | |
1323 | * @vif: Pointer to the ieee80211_vif structure. | |
1324 | * @sta: Pointer to the ieee80211_sta structure. | |
1325 | * | |
fc438672 | 1326 | * Return: 0 on success, negative error codes on failure. |
dad0d04f FF |
1327 | */ |
1328 | static int rsi_mac80211_sta_add(struct ieee80211_hw *hw, | |
1329 | struct ieee80211_vif *vif, | |
1330 | struct ieee80211_sta *sta) | |
1331 | { | |
1332 | struct rsi_hw *adapter = hw->priv; | |
1333 | struct rsi_common *common = adapter->priv; | |
3528608f PRG |
1334 | bool sta_exist = false; |
1335 | struct rsi_sta *rsta; | |
0270639e | 1336 | int status = 0; |
3528608f PRG |
1337 | |
1338 | rsi_dbg(INFO_ZONE, "Station Add: %pM\n", sta->addr); | |
dad0d04f FF |
1339 | |
1340 | mutex_lock(&common->mutex); | |
1341 | ||
4671c209 PRG |
1342 | if ((vif->type == NL80211_IFTYPE_AP) || |
1343 | (vif->type == NL80211_IFTYPE_P2P_GO)) { | |
3528608f PRG |
1344 | u8 cnt; |
1345 | int sta_idx = -1; | |
1346 | int free_index = -1; | |
dad0d04f | 1347 | |
3528608f PRG |
1348 | /* Check if max stations reached */ |
1349 | if (common->num_stations >= common->max_stations) { | |
1350 | rsi_dbg(ERR_ZONE, "Reject: Max Stations exists\n"); | |
0270639e DC |
1351 | status = -EOPNOTSUPP; |
1352 | goto unlock; | |
3528608f PRG |
1353 | } |
1354 | for (cnt = 0; cnt < common->max_stations; cnt++) { | |
1355 | rsta = &common->stations[cnt]; | |
1356 | ||
1357 | if (!rsta->sta) { | |
1358 | if (free_index < 0) | |
1359 | free_index = cnt; | |
1360 | continue; | |
1361 | } | |
1362 | if (!memcmp(rsta->sta->addr, sta->addr, ETH_ALEN)) { | |
1363 | rsi_dbg(INFO_ZONE, "Station exists\n"); | |
1364 | sta_idx = cnt; | |
1365 | sta_exist = true; | |
1366 | break; | |
1367 | } | |
1368 | } | |
1369 | if (!sta_exist) { | |
1370 | if (free_index >= 0) | |
1371 | sta_idx = free_index; | |
1372 | } | |
1373 | if (sta_idx < 0) { | |
1374 | rsi_dbg(ERR_ZONE, | |
1375 | "%s: Some problem reaching here...\n", | |
1376 | __func__); | |
0270639e DC |
1377 | status = -EINVAL; |
1378 | goto unlock; | |
3528608f PRG |
1379 | } |
1380 | rsta = &common->stations[sta_idx]; | |
1381 | rsta->sta = sta; | |
1382 | rsta->sta_id = sta_idx; | |
1383 | for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++) | |
1384 | rsta->start_tx_aggr[cnt] = false; | |
1385 | for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++) | |
1386 | rsta->seq_start[cnt] = 0; | |
1387 | if (!sta_exist) { | |
1388 | rsi_dbg(INFO_ZONE, "New Station\n"); | |
1389 | ||
1390 | /* Send peer notify to device */ | |
1391 | rsi_dbg(INFO_ZONE, "Indicate bss status to device\n"); | |
b8bd3a43 PRG |
1392 | rsi_inform_bss_status(common, RSI_OPMODE_AP, 1, |
1393 | sta->addr, sta->wme, sta->aid, | |
4671c209 | 1394 | sta, sta_idx, vif); |
3528608f | 1395 | |
38ef6235 PRG |
1396 | if (common->key) { |
1397 | struct ieee80211_key_conf *key = common->key; | |
1398 | ||
1399 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) || | |
1400 | (key->cipher == WLAN_CIPHER_SUITE_WEP40)) | |
1401 | rsi_hal_load_key(adapter->priv, | |
1402 | key->key, | |
1403 | key->keylen, | |
1404 | RSI_PAIRWISE_KEY, | |
1405 | key->keyidx, | |
1406 | key->cipher, | |
eac4eed3 PRG |
1407 | sta_idx, |
1408 | vif); | |
38ef6235 PRG |
1409 | } |
1410 | ||
3528608f PRG |
1411 | common->num_stations++; |
1412 | } | |
dad0d04f FF |
1413 | } |
1414 | ||
4671c209 PRG |
1415 | if ((vif->type == NL80211_IFTYPE_STATION) || |
1416 | (vif->type == NL80211_IFTYPE_P2P_CLIENT)) { | |
3528608f PRG |
1417 | rsi_set_min_rate(hw, sta, common); |
1418 | if (sta->ht_cap.ht_supported) { | |
1419 | common->vif_info[0].is_ht = true; | |
1420 | common->bitrate_mask[NL80211_BAND_2GHZ] = | |
1421 | sta->supp_rates[NL80211_BAND_2GHZ]; | |
1422 | if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) || | |
1423 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) | |
1424 | common->vif_info[0].sgi = true; | |
1425 | ieee80211_start_tx_ba_session(sta, 0, 0); | |
1426 | } | |
1427 | } | |
dad0d04f | 1428 | |
0270639e | 1429 | unlock: |
dad0d04f FF |
1430 | mutex_unlock(&common->mutex); |
1431 | ||
0270639e | 1432 | return status; |
dad0d04f FF |
1433 | } |
1434 | ||
1435 | /** | |
1436 | * rsi_mac80211_sta_remove() - This function notifies driver about a peer | |
1437 | * getting disconnected. | |
1438 | * @hw: Pointer to the ieee80211_hw structure. | |
1439 | * @vif: Pointer to the ieee80211_vif structure. | |
1440 | * @sta: Pointer to the ieee80211_sta structure. | |
1441 | * | |
fc438672 | 1442 | * Return: 0 on success, negative error codes on failure. |
dad0d04f FF |
1443 | */ |
1444 | static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw, | |
1445 | struct ieee80211_vif *vif, | |
1446 | struct ieee80211_sta *sta) | |
1447 | { | |
1448 | struct rsi_hw *adapter = hw->priv; | |
1449 | struct rsi_common *common = adapter->priv; | |
571b050b PRG |
1450 | struct ieee80211_bss_conf *bss = &vif->bss_conf; |
1451 | struct rsi_sta *rsta; | |
1452 | ||
1453 | rsi_dbg(INFO_ZONE, "Station Remove: %pM\n", sta->addr); | |
dad0d04f FF |
1454 | |
1455 | mutex_lock(&common->mutex); | |
e6d64284 | 1456 | |
4671c209 PRG |
1457 | if ((vif->type == NL80211_IFTYPE_AP) || |
1458 | (vif->type == NL80211_IFTYPE_P2P_GO)) { | |
571b050b | 1459 | u8 sta_idx, cnt; |
dad0d04f | 1460 | |
571b050b PRG |
1461 | /* Send peer notify to device */ |
1462 | rsi_dbg(INFO_ZONE, "Indicate bss status to device\n"); | |
1463 | for (sta_idx = 0; sta_idx < common->max_stations; sta_idx++) { | |
1464 | rsta = &common->stations[sta_idx]; | |
1465 | ||
1466 | if (!rsta->sta) | |
1467 | continue; | |
1468 | if (!memcmp(rsta->sta->addr, sta->addr, ETH_ALEN)) { | |
b8bd3a43 | 1469 | rsi_inform_bss_status(common, RSI_OPMODE_AP, 0, |
571b050b | 1470 | sta->addr, sta->wme, |
4671c209 PRG |
1471 | sta->aid, sta, sta_idx, |
1472 | vif); | |
571b050b PRG |
1473 | rsta->sta = NULL; |
1474 | rsta->sta_id = -1; | |
1475 | for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++) | |
1476 | rsta->start_tx_aggr[cnt] = false; | |
1477 | if (common->num_stations > 0) | |
1478 | common->num_stations--; | |
1479 | break; | |
1480 | } | |
1481 | } | |
1482 | if (sta_idx >= common->max_stations) | |
1483 | rsi_dbg(ERR_ZONE, "%s: No station found\n", __func__); | |
1484 | } | |
1485 | ||
4671c209 PRG |
1486 | if ((vif->type == NL80211_IFTYPE_STATION) || |
1487 | (vif->type == NL80211_IFTYPE_P2P_CLIENT)) { | |
571b050b PRG |
1488 | /* Resetting all the fields to default values */ |
1489 | memcpy((u8 *)bss->bssid, (u8 *)sta->addr, ETH_ALEN); | |
1490 | bss->qos = sta->wme; | |
1491 | common->bitrate_mask[NL80211_BAND_2GHZ] = 0; | |
1492 | common->bitrate_mask[NL80211_BAND_5GHZ] = 0; | |
1493 | common->min_rate = 0xffff; | |
1494 | common->vif_info[0].is_ht = false; | |
1495 | common->vif_info[0].sgi = false; | |
1496 | common->vif_info[0].seq_start = 0; | |
1497 | common->secinfo.ptk_cipher = 0; | |
1498 | common->secinfo.gtk_cipher = 0; | |
1499 | if (!common->iface_down) | |
1500 | rsi_send_rx_filter_frame(common, 0); | |
1501 | } | |
e6d64284 PRG |
1502 | mutex_unlock(&common->mutex); |
1503 | ||
dad0d04f FF |
1504 | return 0; |
1505 | } | |
1506 | ||
4edbcd1a PRG |
1507 | /** |
1508 | * rsi_mac80211_set_antenna() - This function is used to configure | |
1509 | * tx and rx antennas. | |
1510 | * @hw: Pointer to the ieee80211_hw structure. | |
1511 | * @tx_ant: Bitmap for tx antenna | |
1512 | * @rx_ant: Bitmap for rx antenna | |
1513 | * | |
1514 | * Return: 0 on success, Negative error code on failure. | |
1515 | */ | |
1516 | static int rsi_mac80211_set_antenna(struct ieee80211_hw *hw, | |
1517 | u32 tx_ant, u32 rx_ant) | |
1518 | { | |
1519 | struct rsi_hw *adapter = hw->priv; | |
1520 | struct rsi_common *common = adapter->priv; | |
1521 | u8 antenna = 0; | |
1522 | ||
1523 | if (tx_ant > 1 || rx_ant > 1) { | |
1524 | rsi_dbg(ERR_ZONE, | |
1525 | "Invalid antenna selection (tx: %d, rx:%d)\n", | |
1526 | tx_ant, rx_ant); | |
1527 | rsi_dbg(ERR_ZONE, | |
1528 | "Use 0 for int_ant, 1 for ext_ant\n"); | |
1529 | return -EINVAL; | |
1530 | } | |
1531 | ||
1532 | rsi_dbg(INFO_ZONE, "%s: Antenna map Tx %x Rx %d\n", | |
1533 | __func__, tx_ant, rx_ant); | |
1534 | ||
1535 | mutex_lock(&common->mutex); | |
1536 | ||
1537 | antenna = tx_ant ? ANTENNA_SEL_UFL : ANTENNA_SEL_INT; | |
1538 | if (common->ant_in_use != antenna) | |
1539 | if (rsi_set_antenna(common, antenna)) | |
1540 | goto fail_set_antenna; | |
1541 | ||
1542 | rsi_dbg(INFO_ZONE, "(%s) Antenna path configured successfully\n", | |
1543 | tx_ant ? "UFL" : "INT"); | |
1544 | ||
1545 | common->ant_in_use = antenna; | |
1546 | ||
1547 | mutex_unlock(&common->mutex); | |
1548 | ||
1549 | return 0; | |
1550 | ||
1551 | fail_set_antenna: | |
1552 | rsi_dbg(ERR_ZONE, "%s: Failed.\n", __func__); | |
1553 | mutex_unlock(&common->mutex); | |
1554 | return -EINVAL; | |
1555 | } | |
1556 | ||
1557 | /** | |
1558 | * rsi_mac80211_get_antenna() - This function is used to configure | |
1559 | * tx and rx antennas. | |
1560 | * | |
1561 | * @hw: Pointer to the ieee80211_hw structure. | |
1562 | * @tx_ant: Bitmap for tx antenna | |
1563 | * @rx_ant: Bitmap for rx antenna | |
1564 | * | |
fc438672 | 1565 | * Return: 0 on success, negative error codes on failure. |
4edbcd1a PRG |
1566 | */ |
1567 | static int rsi_mac80211_get_antenna(struct ieee80211_hw *hw, | |
1568 | u32 *tx_ant, u32 *rx_ant) | |
1569 | { | |
1570 | struct rsi_hw *adapter = hw->priv; | |
1571 | struct rsi_common *common = adapter->priv; | |
1572 | ||
1573 | mutex_lock(&common->mutex); | |
1574 | ||
1575 | *tx_ant = (common->ant_in_use == ANTENNA_SEL_UFL) ? 1 : 0; | |
1576 | *rx_ant = 0; | |
1577 | ||
1578 | mutex_unlock(&common->mutex); | |
1579 | ||
1580 | return 0; | |
1581 | } | |
1582 | ||
d7203a83 PRG |
1583 | static int rsi_map_region_code(enum nl80211_dfs_regions region_code) |
1584 | { | |
1585 | switch (region_code) { | |
1586 | case NL80211_DFS_FCC: | |
1587 | return RSI_REGION_FCC; | |
1588 | case NL80211_DFS_ETSI: | |
1589 | return RSI_REGION_ETSI; | |
1590 | case NL80211_DFS_JP: | |
1591 | return RSI_REGION_TELEC; | |
1592 | case NL80211_DFS_UNSET: | |
1593 | return RSI_REGION_WORLD; | |
1594 | } | |
1595 | return RSI_REGION_WORLD; | |
1596 | } | |
1597 | ||
61d10842 PRG |
1598 | static void rsi_reg_notify(struct wiphy *wiphy, |
1599 | struct regulatory_request *request) | |
1600 | { | |
1601 | struct ieee80211_supported_band *sband; | |
1602 | struct ieee80211_channel *ch; | |
1603 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); | |
1604 | struct rsi_hw * adapter = hw->priv; | |
d7203a83 | 1605 | struct rsi_common *common = adapter->priv; |
61d10842 | 1606 | int i; |
61d10842 | 1607 | |
d7203a83 PRG |
1608 | mutex_lock(&common->mutex); |
1609 | ||
1610 | rsi_dbg(INFO_ZONE, "country = %s dfs_region = %d\n", | |
1611 | request->alpha2, request->dfs_region); | |
1612 | ||
1613 | if (common->num_supp_bands > 1) { | |
1614 | sband = wiphy->bands[NL80211_BAND_5GHZ]; | |
61d10842 | 1615 | |
d7203a83 PRG |
1616 | for (i = 0; i < sband->n_channels; i++) { |
1617 | ch = &sband->channels[i]; | |
1618 | if (ch->flags & IEEE80211_CHAN_DISABLED) | |
1619 | continue; | |
1620 | ||
1621 | if (ch->flags & IEEE80211_CHAN_RADAR) | |
1622 | ch->flags |= IEEE80211_CHAN_NO_IR; | |
1623 | } | |
61d10842 | 1624 | } |
d7203a83 PRG |
1625 | adapter->dfs_region = rsi_map_region_code(request->dfs_region); |
1626 | rsi_dbg(INFO_ZONE, "RSI region code = %d\n", adapter->dfs_region); | |
61d10842 | 1627 | |
d7203a83 PRG |
1628 | adapter->country[0] = request->alpha2[0]; |
1629 | adapter->country[1] = request->alpha2[1]; | |
1630 | ||
1631 | mutex_unlock(&common->mutex); | |
61d10842 PRG |
1632 | } |
1633 | ||
edba3532 PM |
1634 | static void rsi_mac80211_rfkill_poll(struct ieee80211_hw *hw) |
1635 | { | |
1636 | struct rsi_hw *adapter = hw->priv; | |
1637 | struct rsi_common *common = adapter->priv; | |
1638 | ||
1639 | mutex_lock(&common->mutex); | |
1640 | if (common->fsm_state != FSM_MAC_INIT_DONE) | |
1641 | wiphy_rfkill_set_hw_state(hw->wiphy, true); | |
1642 | else | |
1643 | wiphy_rfkill_set_hw_state(hw->wiphy, false); | |
1644 | mutex_unlock(&common->mutex); | |
1645 | } | |
1646 | ||
df771911 PRG |
1647 | static void rsi_resume_conn_channel(struct rsi_common *common) |
1648 | { | |
1649 | struct rsi_hw *adapter = common->priv; | |
1650 | struct ieee80211_vif *vif; | |
1651 | int cnt; | |
1652 | ||
1653 | for (cnt = 0; cnt < RSI_MAX_VIFS; cnt++) { | |
1654 | vif = adapter->vifs[cnt]; | |
1655 | if (!vif) | |
1656 | continue; | |
1657 | ||
1658 | if ((vif->type == NL80211_IFTYPE_AP) || | |
1659 | (vif->type == NL80211_IFTYPE_P2P_GO)) { | |
1660 | rsi_switch_channel(adapter, vif); | |
1661 | break; | |
1662 | } | |
1663 | if (((vif->type == NL80211_IFTYPE_STATION) || | |
1664 | (vif->type == NL80211_IFTYPE_P2P_CLIENT)) && | |
1665 | vif->bss_conf.assoc) { | |
1666 | rsi_switch_channel(adapter, vif); | |
1667 | break; | |
1668 | } | |
1669 | } | |
1670 | } | |
1671 | ||
dfefb9f8 | 1672 | void rsi_roc_timeout(struct timer_list *t) |
df771911 | 1673 | { |
dfefb9f8 | 1674 | struct rsi_common *common = from_timer(common, t, roc_timer); |
df771911 PRG |
1675 | |
1676 | rsi_dbg(INFO_ZONE, "Remain on channel expired\n"); | |
1677 | ||
1678 | mutex_lock(&common->mutex); | |
1679 | ieee80211_remain_on_channel_expired(common->priv->hw); | |
1680 | ||
1681 | if (timer_pending(&common->roc_timer)) | |
1682 | del_timer(&common->roc_timer); | |
1683 | ||
1684 | rsi_resume_conn_channel(common); | |
1685 | mutex_unlock(&common->mutex); | |
1686 | } | |
1687 | ||
1688 | static int rsi_mac80211_roc(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | |
1689 | struct ieee80211_channel *chan, int duration, | |
1690 | enum ieee80211_roc_type type) | |
1691 | { | |
1692 | struct rsi_hw *adapter = (struct rsi_hw *)hw->priv; | |
1693 | struct rsi_common *common = (struct rsi_common *)adapter->priv; | |
1694 | int status = 0; | |
1695 | ||
1696 | rsi_dbg(INFO_ZONE, "***** Remain on channel *****\n"); | |
1697 | ||
1698 | mutex_lock(&common->mutex); | |
1699 | rsi_dbg(INFO_ZONE, "%s: channel: %d duration: %dms\n", | |
1700 | __func__, chan->hw_value, duration); | |
1701 | ||
1702 | if (timer_pending(&common->roc_timer)) { | |
1703 | rsi_dbg(INFO_ZONE, "Stop on-going ROC\n"); | |
1704 | del_timer(&common->roc_timer); | |
1705 | } | |
1706 | common->roc_timer.expires = msecs_to_jiffies(duration) + jiffies; | |
1707 | add_timer(&common->roc_timer); | |
1708 | ||
1709 | /* Configure band */ | |
1710 | if (rsi_band_check(common, chan)) { | |
1711 | rsi_dbg(ERR_ZONE, "Failed to set band\n"); | |
1712 | status = -EINVAL; | |
1713 | goto out; | |
1714 | } | |
1715 | ||
1716 | /* Configure channel */ | |
1717 | if (rsi_set_channel(common, chan)) { | |
1718 | rsi_dbg(ERR_ZONE, "Failed to set the channel\n"); | |
1719 | status = -EINVAL; | |
1720 | goto out; | |
1721 | } | |
1722 | ||
1723 | common->roc_vif = vif; | |
1724 | ieee80211_ready_on_channel(hw); | |
1725 | rsi_dbg(INFO_ZONE, "%s: Ready on channel :%d\n", | |
1726 | __func__, chan->hw_value); | |
1727 | ||
1728 | out: | |
1729 | mutex_unlock(&common->mutex); | |
1730 | ||
1731 | return status; | |
1732 | } | |
1733 | ||
1734 | static int rsi_mac80211_cancel_roc(struct ieee80211_hw *hw) | |
1735 | { | |
1736 | struct rsi_hw *adapter = hw->priv; | |
1737 | struct rsi_common *common = adapter->priv; | |
1738 | ||
1739 | rsi_dbg(INFO_ZONE, "Cancel remain on channel\n"); | |
1740 | ||
1741 | mutex_lock(&common->mutex); | |
1742 | if (!timer_pending(&common->roc_timer)) { | |
1743 | mutex_unlock(&common->mutex); | |
1744 | return 0; | |
1745 | } | |
1746 | ||
1747 | del_timer(&common->roc_timer); | |
1748 | ||
1749 | rsi_resume_conn_channel(common); | |
1750 | mutex_unlock(&common->mutex); | |
1751 | ||
1752 | return 0; | |
1753 | } | |
1754 | ||
e6b3b2ed | 1755 | #ifdef CONFIG_PM |
f3ac4e73 KE |
1756 | static const struct wiphy_wowlan_support rsi_wowlan_support = { |
1757 | .flags = WIPHY_WOWLAN_ANY | | |
1758 | WIPHY_WOWLAN_MAGIC_PKT | | |
1759 | WIPHY_WOWLAN_DISCONNECT | | |
1760 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | | |
1761 | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | | |
1762 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | | |
1763 | WIPHY_WOWLAN_4WAY_HANDSHAKE, | |
1764 | }; | |
1765 | ||
1766 | static u16 rsi_wow_map_triggers(struct rsi_common *common, | |
1767 | struct cfg80211_wowlan *wowlan) | |
1768 | { | |
1769 | u16 wow_triggers = 0; | |
1770 | ||
1771 | rsi_dbg(INFO_ZONE, "Mapping wowlan triggers\n"); | |
1772 | ||
1773 | if (wowlan->any) | |
1774 | wow_triggers |= RSI_WOW_ANY; | |
1775 | if (wowlan->magic_pkt) | |
1776 | wow_triggers |= RSI_WOW_MAGIC_PKT; | |
1777 | if (wowlan->disconnect) | |
1778 | wow_triggers |= RSI_WOW_DISCONNECT; | |
1779 | if (wowlan->gtk_rekey_failure || wowlan->eap_identity_req || | |
1780 | wowlan->four_way_handshake) | |
1781 | wow_triggers |= RSI_WOW_GTK_REKEY; | |
1782 | ||
1783 | return wow_triggers; | |
1784 | } | |
1785 | ||
1786 | int rsi_config_wowlan(struct rsi_hw *adapter, struct cfg80211_wowlan *wowlan) | |
1787 | { | |
1788 | struct rsi_common *common = adapter->priv; | |
1789 | u16 triggers = 0; | |
1790 | u16 rx_filter_word = 0; | |
87834af2 | 1791 | struct ieee80211_bss_conf *bss = NULL; |
f3ac4e73 KE |
1792 | |
1793 | rsi_dbg(INFO_ZONE, "Config WoWLAN to device\n"); | |
1794 | ||
87834af2 SKK |
1795 | if (!adapter->vifs[0]) |
1796 | return -EINVAL; | |
1797 | ||
1798 | bss = &adapter->vifs[0]->bss_conf; | |
1799 | ||
f3ac4e73 KE |
1800 | if (WARN_ON(!wowlan)) { |
1801 | rsi_dbg(ERR_ZONE, "WoW triggers not enabled\n"); | |
1802 | return -EINVAL; | |
1803 | } | |
1804 | ||
1805 | triggers = rsi_wow_map_triggers(common, wowlan); | |
1806 | if (!triggers) { | |
1807 | rsi_dbg(ERR_ZONE, "%s:No valid WoW triggers\n", __func__); | |
1808 | return -EINVAL; | |
1809 | } | |
1810 | if (!bss->assoc) { | |
1811 | rsi_dbg(ERR_ZONE, | |
1812 | "Cannot configure WoWLAN (Station not connected)\n"); | |
1813 | common->wow_flags |= RSI_WOW_NO_CONNECTION; | |
1814 | return 0; | |
1815 | } | |
1816 | rsi_dbg(INFO_ZONE, "TRIGGERS %x\n", triggers); | |
1817 | rsi_send_wowlan_request(common, triggers, 1); | |
1818 | ||
1819 | /** | |
1820 | * Increase the beacon_miss threshold & keep-alive timers in | |
1821 | * vap_update frame | |
1822 | */ | |
1823 | rsi_send_vap_dynamic_update(common); | |
1824 | ||
1825 | rx_filter_word = (ALLOW_DATA_ASSOC_PEER | DISALLOW_BEACONS); | |
1826 | rsi_send_rx_filter_frame(common, rx_filter_word); | |
1827 | common->wow_flags |= RSI_WOW_ENABLED; | |
1828 | ||
1829 | return 0; | |
1830 | } | |
063848c3 | 1831 | EXPORT_SYMBOL(rsi_config_wowlan); |
f3ac4e73 | 1832 | |
f3ac4e73 KE |
1833 | static int rsi_mac80211_suspend(struct ieee80211_hw *hw, |
1834 | struct cfg80211_wowlan *wowlan) | |
1835 | { | |
1836 | struct rsi_hw *adapter = hw->priv; | |
1837 | struct rsi_common *common = adapter->priv; | |
1838 | ||
1839 | rsi_dbg(INFO_ZONE, "%s: mac80211 suspend\n", __func__); | |
1840 | mutex_lock(&common->mutex); | |
1841 | if (rsi_config_wowlan(adapter, wowlan)) { | |
1842 | rsi_dbg(ERR_ZONE, "Failed to configure WoWLAN\n"); | |
1843 | mutex_unlock(&common->mutex); | |
1844 | return 1; | |
1845 | } | |
1846 | mutex_unlock(&common->mutex); | |
1847 | ||
1848 | return 0; | |
1849 | } | |
1850 | ||
1851 | static int rsi_mac80211_resume(struct ieee80211_hw *hw) | |
1852 | { | |
1853 | u16 rx_filter_word = 0; | |
1854 | struct rsi_hw *adapter = hw->priv; | |
1855 | struct rsi_common *common = adapter->priv; | |
1856 | ||
1857 | common->wow_flags = 0; | |
1858 | ||
1859 | rsi_dbg(INFO_ZONE, "%s: mac80211 resume\n", __func__); | |
1860 | ||
b6c8d06c KE |
1861 | if (common->hibernate_resume) |
1862 | return 0; | |
1863 | ||
f3ac4e73 KE |
1864 | mutex_lock(&common->mutex); |
1865 | rsi_send_wowlan_request(common, 0, 0); | |
1866 | ||
1867 | rx_filter_word = (ALLOW_DATA_ASSOC_PEER | ALLOW_CTRL_ASSOC_PEER | | |
1868 | ALLOW_MGMT_ASSOC_PEER); | |
1869 | rsi_send_rx_filter_frame(common, rx_filter_word); | |
1870 | mutex_unlock(&common->mutex); | |
1871 | ||
1872 | return 0; | |
1873 | } | |
1874 | ||
1875 | #endif | |
1876 | ||
9ea792a4 | 1877 | static const struct ieee80211_ops mac80211_ops = { |
dad0d04f FF |
1878 | .tx = rsi_mac80211_tx, |
1879 | .start = rsi_mac80211_start, | |
1880 | .stop = rsi_mac80211_stop, | |
1881 | .add_interface = rsi_mac80211_add_interface, | |
1882 | .remove_interface = rsi_mac80211_remove_interface, | |
1883 | .config = rsi_mac80211_config, | |
1884 | .bss_info_changed = rsi_mac80211_bss_info_changed, | |
1885 | .conf_tx = rsi_mac80211_conf_tx, | |
1886 | .configure_filter = rsi_mac80211_conf_filter, | |
1887 | .set_key = rsi_mac80211_set_key, | |
1888 | .set_rts_threshold = rsi_mac80211_set_rts_threshold, | |
1889 | .set_bitrate_mask = rsi_mac80211_set_rate_mask, | |
1890 | .ampdu_action = rsi_mac80211_ampdu_action, | |
1891 | .sta_add = rsi_mac80211_sta_add, | |
1892 | .sta_remove = rsi_mac80211_sta_remove, | |
4edbcd1a PRG |
1893 | .set_antenna = rsi_mac80211_set_antenna, |
1894 | .get_antenna = rsi_mac80211_get_antenna, | |
edba3532 | 1895 | .rfkill_poll = rsi_mac80211_rfkill_poll, |
df771911 PRG |
1896 | .remain_on_channel = rsi_mac80211_roc, |
1897 | .cancel_remain_on_channel = rsi_mac80211_cancel_roc, | |
f3ac4e73 KE |
1898 | #ifdef CONFIG_PM |
1899 | .suspend = rsi_mac80211_suspend, | |
1900 | .resume = rsi_mac80211_resume, | |
1901 | #endif | |
dad0d04f FF |
1902 | }; |
1903 | ||
1904 | /** | |
1905 | * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack. | |
1906 | * @common: Pointer to the driver private structure. | |
1907 | * | |
fc438672 | 1908 | * Return: 0 on success, negative error codes on failure. |
dad0d04f FF |
1909 | */ |
1910 | int rsi_mac80211_attach(struct rsi_common *common) | |
1911 | { | |
1912 | int status = 0; | |
1913 | struct ieee80211_hw *hw = NULL; | |
1914 | struct wiphy *wiphy = NULL; | |
1915 | struct rsi_hw *adapter = common->priv; | |
1916 | u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3}; | |
1917 | ||
1918 | rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__); | |
1919 | ||
1920 | hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops); | |
1921 | if (!hw) { | |
1922 | rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__); | |
1923 | return -ENOMEM; | |
1924 | } | |
1925 | ||
1926 | wiphy = hw->wiphy; | |
1927 | ||
1928 | SET_IEEE80211_DEV(hw, adapter->device); | |
1929 | ||
1930 | hw->priv = adapter; | |
1931 | adapter->hw = hw; | |
1932 | ||
30686bf7 JB |
1933 | ieee80211_hw_set(hw, SIGNAL_DBM); |
1934 | ieee80211_hw_set(hw, HAS_RATE_CONTROL); | |
1935 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); | |
ce86893f KE |
1936 | ieee80211_hw_set(hw, SUPPORTS_PS); |
1937 | ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); | |
dad0d04f FF |
1938 | |
1939 | hw->queues = MAX_HW_QUEUES; | |
1940 | hw->extra_tx_headroom = RSI_NEEDED_HEADROOM; | |
1941 | ||
1942 | hw->max_rates = 1; | |
1943 | hw->max_rate_tries = MAX_RETRIES; | |
db07971d KE |
1944 | hw->uapsd_queues = RSI_IEEE80211_UAPSD_QUEUES; |
1945 | hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL; | |
dad0d04f FF |
1946 | |
1947 | hw->max_tx_aggregation_subframes = 6; | |
57fbcce3 JB |
1948 | rsi_register_rates_channels(adapter, NL80211_BAND_2GHZ); |
1949 | rsi_register_rates_channels(adapter, NL80211_BAND_5GHZ); | |
dad0d04f FF |
1950 | hw->rate_control_algorithm = "AARF"; |
1951 | ||
1952 | SET_IEEE80211_PERM_ADDR(hw, common->mac_addr); | |
1953 | ether_addr_copy(hw->wiphy->addr_mask, addr_mask); | |
1954 | ||
6da1e00a | 1955 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
421eedff PRG |
1956 | BIT(NL80211_IFTYPE_AP) | |
1957 | BIT(NL80211_IFTYPE_P2P_DEVICE) | | |
1958 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
1959 | BIT(NL80211_IFTYPE_P2P_GO); | |
1960 | ||
dad0d04f FF |
1961 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
1962 | wiphy->retry_short = RETRY_SHORT; | |
1963 | wiphy->retry_long = RETRY_LONG; | |
1964 | wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD; | |
1965 | wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
1966 | wiphy->flags = 0; | |
1967 | ||
1968 | wiphy->available_antennas_rx = 1; | |
1969 | wiphy->available_antennas_tx = 1; | |
57fbcce3 JB |
1970 | wiphy->bands[NL80211_BAND_2GHZ] = |
1971 | &adapter->sbands[NL80211_BAND_2GHZ]; | |
1972 | wiphy->bands[NL80211_BAND_5GHZ] = | |
1973 | &adapter->sbands[NL80211_BAND_5GHZ]; | |
dad0d04f | 1974 | |
6da1e00a PRG |
1975 | /* AP Parameters */ |
1976 | wiphy->max_ap_assoc_sta = rsi_max_ap_stas[common->oper_mode - 1]; | |
1977 | common->max_stations = wiphy->max_ap_assoc_sta; | |
1978 | rsi_dbg(ERR_ZONE, "Max Stations Allowed = %d\n", common->max_stations); | |
1979 | hw->sta_data_size = sizeof(struct rsi_sta); | |
1980 | wiphy->flags = WIPHY_FLAG_REPORTS_OBSS; | |
1981 | wiphy->flags |= WIPHY_FLAG_AP_UAPSD; | |
1982 | wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER; | |
61d10842 PRG |
1983 | wiphy->reg_notifier = rsi_reg_notify; |
1984 | ||
e6b3b2ed | 1985 | #ifdef CONFIG_PM |
f3ac4e73 | 1986 | wiphy->wowlan = &rsi_wowlan_support; |
e6b3b2ed AK |
1987 | #endif |
1988 | ||
ae44b502 AZ |
1989 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); |
1990 | ||
421eedff | 1991 | /* Wi-Fi direct parameters */ |
df771911 PRG |
1992 | wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
1993 | wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX; | |
1994 | wiphy->max_remain_on_channel_duration = 10000; | |
421eedff PRG |
1995 | hw->max_listen_interval = 10; |
1996 | wiphy->iface_combinations = rsi_iface_combinations; | |
1997 | wiphy->n_iface_combinations = ARRAY_SIZE(rsi_iface_combinations); | |
1998 | ||
dad0d04f FF |
1999 | status = ieee80211_register_hw(hw); |
2000 | if (status) | |
2001 | return status; | |
2002 | ||
2003 | return rsi_init_dbgfs(adapter); | |
2004 | } |