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