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