2 * Copyright (c) 2014 Redpine Signals Inc.
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.
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.
17 #include <linux/etherdevice.h>
18 #include "rsi_debugfs.h"
21 #include "rsi_common.h"
24 static const struct ieee80211_channel rsi_2ghz_channels[] = {
25 { .band = NL80211_BAND_2GHZ, .center_freq = 2412,
26 .hw_value = 1 }, /* Channel 1 */
27 { .band = NL80211_BAND_2GHZ, .center_freq = 2417,
28 .hw_value = 2 }, /* Channel 2 */
29 { .band = NL80211_BAND_2GHZ, .center_freq = 2422,
30 .hw_value = 3 }, /* Channel 3 */
31 { .band = NL80211_BAND_2GHZ, .center_freq = 2427,
32 .hw_value = 4 }, /* Channel 4 */
33 { .band = NL80211_BAND_2GHZ, .center_freq = 2432,
34 .hw_value = 5 }, /* Channel 5 */
35 { .band = NL80211_BAND_2GHZ, .center_freq = 2437,
36 .hw_value = 6 }, /* Channel 6 */
37 { .band = NL80211_BAND_2GHZ, .center_freq = 2442,
38 .hw_value = 7 }, /* Channel 7 */
39 { .band = NL80211_BAND_2GHZ, .center_freq = 2447,
40 .hw_value = 8 }, /* Channel 8 */
41 { .band = NL80211_BAND_2GHZ, .center_freq = 2452,
42 .hw_value = 9 }, /* Channel 9 */
43 { .band = NL80211_BAND_2GHZ, .center_freq = 2457,
44 .hw_value = 10 }, /* Channel 10 */
45 { .band = NL80211_BAND_2GHZ, .center_freq = 2462,
46 .hw_value = 11 }, /* Channel 11 */
47 { .band = NL80211_BAND_2GHZ, .center_freq = 2467,
48 .hw_value = 12 }, /* Channel 12 */
49 { .band = NL80211_BAND_2GHZ, .center_freq = 2472,
50 .hw_value = 13 }, /* Channel 13 */
51 { .band = NL80211_BAND_2GHZ, .center_freq = 2484,
52 .hw_value = 14 }, /* Channel 14 */
55 static const struct ieee80211_channel rsi_5ghz_channels[] = {
56 { .band = NL80211_BAND_5GHZ, .center_freq = 5180,
57 .hw_value = 36, }, /* Channel 36 */
58 { .band = NL80211_BAND_5GHZ, .center_freq = 5200,
59 .hw_value = 40, }, /* Channel 40 */
60 { .band = NL80211_BAND_5GHZ, .center_freq = 5220,
61 .hw_value = 44, }, /* Channel 44 */
62 { .band = NL80211_BAND_5GHZ, .center_freq = 5240,
63 .hw_value = 48, }, /* Channel 48 */
64 { .band = NL80211_BAND_5GHZ, .center_freq = 5260,
65 .hw_value = 52, }, /* Channel 52 */
66 { .band = NL80211_BAND_5GHZ, .center_freq = 5280,
67 .hw_value = 56, }, /* Channel 56 */
68 { .band = NL80211_BAND_5GHZ, .center_freq = 5300,
69 .hw_value = 60, }, /* Channel 60 */
70 { .band = NL80211_BAND_5GHZ, .center_freq = 5320,
71 .hw_value = 64, }, /* Channel 64 */
72 { .band = NL80211_BAND_5GHZ, .center_freq = 5500,
73 .hw_value = 100, }, /* Channel 100 */
74 { .band = NL80211_BAND_5GHZ, .center_freq = 5520,
75 .hw_value = 104, }, /* Channel 104 */
76 { .band = NL80211_BAND_5GHZ, .center_freq = 5540,
77 .hw_value = 108, }, /* Channel 108 */
78 { .band = NL80211_BAND_5GHZ, .center_freq = 5560,
79 .hw_value = 112, }, /* Channel 112 */
80 { .band = NL80211_BAND_5GHZ, .center_freq = 5580,
81 .hw_value = 116, }, /* Channel 116 */
82 { .band = NL80211_BAND_5GHZ, .center_freq = 5600,
83 .hw_value = 120, }, /* Channel 120 */
84 { .band = NL80211_BAND_5GHZ, .center_freq = 5620,
85 .hw_value = 124, }, /* Channel 124 */
86 { .band = NL80211_BAND_5GHZ, .center_freq = 5640,
87 .hw_value = 128, }, /* Channel 128 */
88 { .band = NL80211_BAND_5GHZ, .center_freq = 5660,
89 .hw_value = 132, }, /* Channel 132 */
90 { .band = NL80211_BAND_5GHZ, .center_freq = 5680,
91 .hw_value = 136, }, /* Channel 136 */
92 { .band = NL80211_BAND_5GHZ, .center_freq = 5700,
93 .hw_value = 140, }, /* Channel 140 */
94 { .band = NL80211_BAND_5GHZ, .center_freq = 5745,
95 .hw_value = 149, }, /* Channel 149 */
96 { .band = NL80211_BAND_5GHZ, .center_freq = 5765,
97 .hw_value = 153, }, /* Channel 153 */
98 { .band = NL80211_BAND_5GHZ, .center_freq = 5785,
99 .hw_value = 157, }, /* Channel 157 */
100 { .band = NL80211_BAND_5GHZ, .center_freq = 5805,
101 .hw_value = 161, }, /* Channel 161 */
102 { .band = NL80211_BAND_5GHZ, .center_freq = 5825,
103 .hw_value = 165, }, /* Channel 165 */
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 },
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
126 static const u32 rsi_max_ap_stas[16] = {
127 32, /* 1 - Wi-Fi alone */
130 0, /* 4 - BT EDR alone */
131 4, /* 5 - STA + BT EDR */
132 32, /* 6 - AP + BT EDR */
134 0, /* 8 - BT LE alone */
135 4, /* 9 - STA + BE LE */
139 1, /* 13 - STA + BT Dual */
140 4, /* 14 - AP + BT Dual */
143 static const struct ieee80211_iface_limit rsi_iface_limits[] = {
146 .types = BIT(NL80211_IFTYPE_STATION),
150 .types = BIT(NL80211_IFTYPE_AP) |
151 BIT(NL80211_IFTYPE_P2P_CLIENT) |
152 BIT(NL80211_IFTYPE_P2P_GO),
156 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
160 static const struct ieee80211_iface_combination rsi_iface_combinations[] = {
162 .num_different_channels = 1,
164 .limits = rsi_iface_limits,
165 .n_limits = ARRAY_SIZE(rsi_iface_limits),
170 * rsi_is_cipher_wep() - This function determines if the cipher is WEP or not.
171 * @common: Pointer to the driver private structure.
173 * Return: If cipher type is WEP, a value of 1 is returned, else 0.
176 bool rsi_is_cipher_wep(struct rsi_common *common)
178 if (((common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP104) ||
179 (common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP40)) &&
180 (!common->secinfo.ptk_cipher))
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.
191 * Return: int - 0 on success, negative error on failure.
193 static int rsi_register_rates_channels(struct rsi_hw *adapter, int band)
195 struct ieee80211_supported_band *sbands = &adapter->sbands[band];
196 void *channels = NULL;
198 if (band == NL80211_BAND_2GHZ) {
199 channels = kmemdup(rsi_2ghz_channels, sizeof(rsi_2ghz_channels),
203 sbands->band = NL80211_BAND_2GHZ;
204 sbands->n_channels = ARRAY_SIZE(rsi_2ghz_channels);
205 sbands->bitrates = rsi_rates;
206 sbands->n_bitrates = ARRAY_SIZE(rsi_rates);
208 channels = kmemdup(rsi_5ghz_channels, sizeof(rsi_5ghz_channels),
212 sbands->band = NL80211_BAND_5GHZ;
213 sbands->n_channels = ARRAY_SIZE(rsi_5ghz_channels);
214 sbands->bitrates = &rsi_rates[4];
215 sbands->n_bitrates = ARRAY_SIZE(rsi_rates) - 4;
218 sbands->channels = channels;
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);
225 sbands->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
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; */
234 * rsi_mac80211_detach() - This function is used to de-initialize the
236 * @adapter: Pointer to the adapter structure.
240 void rsi_mac80211_detach(struct rsi_hw *adapter)
242 struct ieee80211_hw *hw = adapter->hw;
243 enum nl80211_band band;
246 ieee80211_stop_queues(hw);
247 ieee80211_unregister_hw(hw);
248 ieee80211_free_hw(hw);
252 for (band = 0; band < NUM_NL80211_BANDS; band++) {
253 struct ieee80211_supported_band *sband =
254 &adapter->sbands[band];
256 kfree(sband->channels);
259 #ifdef CONFIG_RSI_DEBUGFS
260 rsi_remove_dbgfs(adapter);
261 kfree(adapter->dfsentry);
264 EXPORT_SYMBOL_GPL(rsi_mac80211_detach);
267 * rsi_indicate_tx_status() - This function indicates the transmit status.
268 * @adapter: Pointer to the adapter structure.
269 * @skb: Pointer to the socket buffer structure.
274 void rsi_indicate_tx_status(struct rsi_hw *adapter,
278 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
279 struct skb_info *tx_params;
282 rsi_dbg(ERR_ZONE, "##### No MAC #####\n");
287 info->flags |= IEEE80211_TX_STAT_ACK;
289 tx_params = (struct skb_info *)info->driver_data;
290 skb_pull(skb, tx_params->internal_hdr_size);
291 memset(info->driver_data, 0, IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
293 ieee80211_tx_status_irqsafe(adapter->hw, skb);
297 * rsi_mac80211_tx() - This is the handler that 802.11 module calls for each
298 * transmitted frame.SKB contains the buffer starting
299 * from the IEEE 802.11 header.
300 * @hw: Pointer to the ieee80211_hw structure.
301 * @control: Pointer to the ieee80211_tx_control structure
302 * @skb: Pointer to the socket buffer structure.
306 static void rsi_mac80211_tx(struct ieee80211_hw *hw,
307 struct ieee80211_tx_control *control,
310 struct rsi_hw *adapter = hw->priv;
311 struct rsi_common *common = adapter->priv;
313 rsi_core_xmit(common, skb);
317 * rsi_mac80211_start() - This is first handler that 802.11 module calls, since
318 * the driver init is complete by then, just
320 * @hw: Pointer to the ieee80211_hw structure.
322 * Return: 0 as success.
324 static int rsi_mac80211_start(struct ieee80211_hw *hw)
326 struct rsi_hw *adapter = hw->priv;
327 struct rsi_common *common = adapter->priv;
329 rsi_dbg(ERR_ZONE, "===> Interface UP <===\n");
330 mutex_lock(&common->mutex);
331 if (common->hibernate_resume) {
332 common->reinit_hw = true;
333 adapter->host_intf_ops->reinit_device(adapter);
334 wait_for_completion(&adapter->priv->wlan_init_completion);
336 common->iface_down = false;
337 wiphy_rfkill_start_polling(hw->wiphy);
338 rsi_send_rx_filter_frame(common, 0);
339 mutex_unlock(&common->mutex);
345 * rsi_mac80211_stop() - This is the last handler that 802.11 module calls.
346 * @hw: Pointer to the ieee80211_hw structure.
350 static void rsi_mac80211_stop(struct ieee80211_hw *hw)
352 struct rsi_hw *adapter = hw->priv;
353 struct rsi_common *common = adapter->priv;
355 rsi_dbg(ERR_ZONE, "===> Interface DOWN <===\n");
356 mutex_lock(&common->mutex);
357 common->iface_down = true;
358 wiphy_rfkill_stop_polling(hw->wiphy);
360 /* Block all rx frames */
361 rsi_send_rx_filter_frame(common, 0xffff);
363 mutex_unlock(&common->mutex);
366 static int rsi_map_intf_mode(enum nl80211_iftype vif_type)
369 case NL80211_IFTYPE_STATION:
370 return RSI_OPMODE_STA;
371 case NL80211_IFTYPE_AP:
372 return RSI_OPMODE_AP;
373 case NL80211_IFTYPE_P2P_DEVICE:
374 return RSI_OPMODE_P2P_CLIENT;
375 case NL80211_IFTYPE_P2P_CLIENT:
376 return RSI_OPMODE_P2P_CLIENT;
377 case NL80211_IFTYPE_P2P_GO:
378 return RSI_OPMODE_P2P_GO;
380 return RSI_OPMODE_UNSUPPORTED;
385 * rsi_mac80211_add_interface() - This function is called when a netdevice
386 * attached to the hardware is enabled.
387 * @hw: Pointer to the ieee80211_hw structure.
388 * @vif: Pointer to the ieee80211_vif structure.
390 * Return: ret: 0 on success, negative error code on failure.
392 static int rsi_mac80211_add_interface(struct ieee80211_hw *hw,
393 struct ieee80211_vif *vif)
395 struct rsi_hw *adapter = hw->priv;
396 struct rsi_common *common = adapter->priv;
397 struct vif_priv *vif_info = (struct vif_priv *)vif->drv_priv;
398 enum opmode intf_mode;
399 enum vap_status vap_status;
402 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
403 mutex_lock(&common->mutex);
405 intf_mode = rsi_map_intf_mode(vif->type);
406 if (intf_mode == RSI_OPMODE_UNSUPPORTED) {
408 "%s: Interface type %d not supported\n", __func__,
410 mutex_unlock(&common->mutex);
413 if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) ||
414 (vif->type == NL80211_IFTYPE_P2P_CLIENT) ||
415 (vif->type == NL80211_IFTYPE_P2P_GO))
416 common->p2p_enabled = true;
418 /* Get free vap index */
419 for (i = 0; i < RSI_MAX_VIFS; i++) {
420 if (!adapter->vifs[i] ||
421 !memcmp(vif->addr, adapter->vifs[i]->addr, ETH_ALEN)) {
427 rsi_dbg(ERR_ZONE, "Reject: Max VAPs reached\n");
428 mutex_unlock(&common->mutex);
431 vif_info->vap_id = vap_idx;
432 adapter->vifs[vap_idx] = vif;
434 vap_status = VAP_ADD;
436 if (rsi_set_vap_capabilities(common, intf_mode, vif->addr,
437 vif_info->vap_id, vap_status)) {
438 rsi_dbg(ERR_ZONE, "Failed to set VAP capabilities\n");
439 mutex_unlock(&common->mutex);
443 if ((vif->type == NL80211_IFTYPE_AP) ||
444 (vif->type == NL80211_IFTYPE_P2P_GO)) {
445 rsi_send_rx_filter_frame(common, DISALLOW_BEACONS);
446 for (i = 0; i < common->max_stations; i++)
447 common->stations[i].sta = NULL;
450 mutex_unlock(&common->mutex);
456 * rsi_mac80211_remove_interface() - This function notifies driver that an
457 * interface is going down.
458 * @hw: Pointer to the ieee80211_hw structure.
459 * @vif: Pointer to the ieee80211_vif structure.
463 static void rsi_mac80211_remove_interface(struct ieee80211_hw *hw,
464 struct ieee80211_vif *vif)
466 struct rsi_hw *adapter = hw->priv;
467 struct rsi_common *common = adapter->priv;
471 rsi_dbg(INFO_ZONE, "Remove Interface Called\n");
473 mutex_lock(&common->mutex);
475 if (adapter->sc_nvifs <= 0) {
476 mutex_unlock(&common->mutex);
480 opmode = rsi_map_intf_mode(vif->type);
481 if (opmode == RSI_OPMODE_UNSUPPORTED) {
482 rsi_dbg(ERR_ZONE, "Opmode error : %d\n", opmode);
483 mutex_unlock(&common->mutex);
486 for (i = 0; i < RSI_MAX_VIFS; i++) {
487 if (!adapter->vifs[i])
489 if (vif == adapter->vifs[i]) {
490 rsi_set_vap_capabilities(common, opmode, vif->addr,
493 adapter->vifs[i] = NULL;
496 mutex_unlock(&common->mutex);
500 * rsi_channel_change() - This function is a performs the checks
501 * required for changing a channel and sets
502 * the channel accordingly.
503 * @hw: Pointer to the ieee80211_hw structure.
505 * Return: 0 on success, negative error code on failure.
507 static int rsi_channel_change(struct ieee80211_hw *hw)
509 struct rsi_hw *adapter = hw->priv;
510 struct rsi_common *common = adapter->priv;
511 int status = -EOPNOTSUPP;
512 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
513 u16 channel = curchan->hw_value;
514 struct ieee80211_vif *vif;
515 struct ieee80211_bss_conf *bss;
520 "%s: Set channel: %d MHz type: %d channel_no %d\n",
521 __func__, curchan->center_freq,
522 curchan->flags, channel);
524 for (i = 0; i < RSI_MAX_VIFS; i++) {
525 vif = adapter->vifs[i];
528 if (vif->type == NL80211_IFTYPE_STATION) {
529 bss = &vif->bss_conf;
537 if (!common->hw_data_qs_blocked &&
538 (rsi_get_connected_channel(vif) != channel)) {
539 rsi_dbg(INFO_ZONE, "blk data q %d\n", channel);
540 if (!rsi_send_block_unblock_frame(common, true))
541 common->hw_data_qs_blocked = true;
545 status = rsi_band_check(common, curchan);
547 status = rsi_set_channel(adapter->priv, curchan);
550 if (common->hw_data_qs_blocked &&
551 (rsi_get_connected_channel(vif) == channel)) {
552 rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel);
553 if (!rsi_send_block_unblock_frame(common, false))
554 common->hw_data_qs_blocked = false;
562 * rsi_config_power() - This function configures tx power to device
563 * @hw: Pointer to the ieee80211_hw structure.
565 * Return: 0 on success, negative error code on failure.
567 static int rsi_config_power(struct ieee80211_hw *hw)
569 struct rsi_hw *adapter = hw->priv;
570 struct rsi_common *common = adapter->priv;
571 struct ieee80211_conf *conf = &hw->conf;
573 if (adapter->sc_nvifs <= 0) {
574 rsi_dbg(ERR_ZONE, "%s: No virtual interface found\n", __func__);
579 "%s: Set tx power: %d dBM\n", __func__, conf->power_level);
581 if (conf->power_level == common->tx_power)
584 common->tx_power = conf->power_level;
586 return rsi_send_radio_params_update(common);
590 * rsi_mac80211_config() - This function is a handler for configuration
591 * requests. The stack calls this function to
592 * change hardware configuration, e.g., channel.
593 * @hw: Pointer to the ieee80211_hw structure.
594 * @changed: Changed flags set.
596 * Return: 0 on success, negative error code on failure.
598 static int rsi_mac80211_config(struct ieee80211_hw *hw,
601 struct rsi_hw *adapter = hw->priv;
602 struct rsi_common *common = adapter->priv;
603 struct ieee80211_conf *conf = &hw->conf;
604 int status = -EOPNOTSUPP;
606 mutex_lock(&common->mutex);
608 if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
609 status = rsi_channel_change(hw);
612 if (changed & IEEE80211_CONF_CHANGE_POWER) {
613 rsi_dbg(INFO_ZONE, "%s: Configuring Power\n", __func__);
614 status = rsi_config_power(hw);
617 /* Power save parameters */
618 if (changed & IEEE80211_CONF_CHANGE_PS) {
619 struct ieee80211_vif *vif, *sta_vif = NULL;
623 for (i = 0; i < RSI_MAX_VIFS; i++) {
624 vif = adapter->vifs[i];
627 /* Don't go to power save if AP vap exists */
628 if ((vif->type == NL80211_IFTYPE_AP) ||
629 (vif->type == NL80211_IFTYPE_P2P_GO)) {
633 if ((vif->type == NL80211_IFTYPE_STATION ||
634 vif->type == NL80211_IFTYPE_P2P_CLIENT) &&
635 (!sta_vif || vif->bss_conf.assoc))
638 if (set_ps && sta_vif) {
639 spin_lock_irqsave(&adapter->ps_lock, flags);
640 if (conf->flags & IEEE80211_CONF_PS)
641 rsi_enable_ps(adapter, sta_vif);
643 rsi_disable_ps(adapter, sta_vif);
644 spin_unlock_irqrestore(&adapter->ps_lock, flags);
649 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
650 rsi_dbg(INFO_ZONE, "RTS threshold\n");
651 if ((common->rts_threshold) <= IEEE80211_MAX_RTS_THRESHOLD) {
653 "%s: Sending vap updates....\n", __func__);
654 status = rsi_send_vap_dynamic_update(common);
657 mutex_unlock(&common->mutex);
663 * rsi_get_connected_channel() - This function is used to get the current
664 * connected channel number.
665 * @adapter: Pointer to the adapter structure.
667 * Return: Current connected AP's channel number is returned.
669 u16 rsi_get_connected_channel(struct ieee80211_vif *vif)
671 struct ieee80211_bss_conf *bss;
672 struct ieee80211_channel *channel;
677 bss = &vif->bss_conf;
678 channel = bss->chandef.chan;
683 return channel->hw_value;
686 static void rsi_switch_channel(struct rsi_hw *adapter,
687 struct ieee80211_vif *vif)
689 struct rsi_common *common = adapter->priv;
690 struct ieee80211_channel *channel;
692 if (common->iface_down)
697 channel = vif->bss_conf.chandef.chan;
702 rsi_band_check(common, channel);
703 rsi_set_channel(common, channel);
704 rsi_dbg(INFO_ZONE, "Switched to channel - %d\n", channel->hw_value);
708 * rsi_mac80211_bss_info_changed() - This function is a handler for config
709 * requests related to BSS parameters that
710 * may vary during BSS's lifespan.
711 * @hw: Pointer to the ieee80211_hw structure.
712 * @vif: Pointer to the ieee80211_vif structure.
713 * @bss_conf: Pointer to the ieee80211_bss_conf structure.
714 * @changed: Changed flags set.
718 static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw,
719 struct ieee80211_vif *vif,
720 struct ieee80211_bss_conf *bss_conf,
723 struct rsi_hw *adapter = hw->priv;
724 struct rsi_common *common = adapter->priv;
725 struct ieee80211_bss_conf *bss = &vif->bss_conf;
726 struct ieee80211_conf *conf = &hw->conf;
727 u16 rx_filter_word = 0;
729 mutex_lock(&common->mutex);
730 if (changed & BSS_CHANGED_ASSOC) {
731 rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n",
732 __func__, bss_conf->assoc);
733 if (bss_conf->assoc) {
734 /* Send the RX filter frame */
735 rx_filter_word = (ALLOW_DATA_ASSOC_PEER |
736 ALLOW_CTRL_ASSOC_PEER |
737 ALLOW_MGMT_ASSOC_PEER);
738 rsi_send_rx_filter_frame(common, rx_filter_word);
740 rsi_inform_bss_status(common,
747 bss_conf->assoc_capability, vif);
748 adapter->ps_info.dtim_interval_duration = bss->dtim_period;
749 adapter->ps_info.listen_interval = conf->listen_interval;
751 /* If U-APSD is updated, send ps parameters to firmware */
753 if (common->uapsd_bitmap) {
754 rsi_dbg(INFO_ZONE, "Configuring UAPSD\n");
755 rsi_conf_uapsd(adapter, vif);
758 common->uapsd_bitmap = 0;
762 if (changed & BSS_CHANGED_CQM) {
763 common->cqm_info.last_cqm_event_rssi = 0;
764 common->cqm_info.rssi_thold = bss_conf->cqm_rssi_thold;
765 common->cqm_info.rssi_hyst = bss_conf->cqm_rssi_hyst;
766 rsi_dbg(INFO_ZONE, "RSSI throld & hysteresis are: %d %d\n",
767 common->cqm_info.rssi_thold,
768 common->cqm_info.rssi_hyst);
771 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
772 ((vif->type == NL80211_IFTYPE_AP) ||
773 (vif->type == NL80211_IFTYPE_P2P_GO))) {
774 if (bss->enable_beacon) {
775 rsi_dbg(INFO_ZONE, "===> BEACON ENABLED <===\n");
776 common->beacon_enabled = 1;
778 rsi_dbg(INFO_ZONE, "===> BEACON DISABLED <===\n");
779 common->beacon_enabled = 0;
783 mutex_unlock(&common->mutex);
787 * rsi_mac80211_conf_filter() - This function configure the device's RX filter.
788 * @hw: Pointer to the ieee80211_hw structure.
789 * @changed: Changed flags set.
790 * @total_flags: Total initial flags set.
791 * @multicast: Multicast.
795 static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw,
800 /* Not doing much here as of now */
801 *total_flags &= RSI_SUPP_FILTERS;
805 * rsi_mac80211_conf_tx() - This function configures TX queue parameters
806 * (EDCF (aifs, cw_min, cw_max), bursting)
807 * for a hardware TX queue.
808 * @hw: Pointer to the ieee80211_hw structure
809 * @vif: Pointer to the ieee80211_vif structure.
810 * @queue: Queue number.
811 * @params: Pointer to ieee80211_tx_queue_params structure.
813 * Return: 0 on success, negative error code on failure.
815 static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw,
816 struct ieee80211_vif *vif, u16 queue,
817 const struct ieee80211_tx_queue_params *params)
819 struct rsi_hw *adapter = hw->priv;
820 struct rsi_common *common = adapter->priv;
823 if (queue >= IEEE80211_NUM_ACS)
827 "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n",
828 __func__, queue, params->aifs,
829 params->cw_min, params->cw_max, params->txop);
831 mutex_lock(&common->mutex);
832 /* Map into the way the f/w expects */
834 case IEEE80211_AC_VO:
837 case IEEE80211_AC_VI:
840 case IEEE80211_AC_BE:
843 case IEEE80211_AC_BK:
851 memcpy(&common->edca_params[idx],
853 sizeof(struct ieee80211_tx_queue_params));
856 common->uapsd_bitmap |= idx;
858 common->uapsd_bitmap &= (~idx);
860 mutex_unlock(&common->mutex);
866 * rsi_hal_key_config() - This function loads the keys into the firmware.
867 * @hw: Pointer to the ieee80211_hw structure.
868 * @vif: Pointer to the ieee80211_vif structure.
869 * @key: Pointer to the ieee80211_key_conf structure.
871 * Return: status: 0 on success, negative error codes on failure.
873 static int rsi_hal_key_config(struct ieee80211_hw *hw,
874 struct ieee80211_vif *vif,
875 struct ieee80211_key_conf *key,
876 struct ieee80211_sta *sta)
878 struct rsi_hw *adapter = hw->priv;
879 struct rsi_sta *rsta = NULL;
884 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
885 key_type = RSI_PAIRWISE_KEY;
887 key_type = RSI_GROUP_KEY;
889 rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n",
890 __func__, key->cipher, key_type, key->keylen);
892 if ((vif->type == NL80211_IFTYPE_AP) ||
893 (vif->type == NL80211_IFTYPE_P2P_GO)) {
895 rsta = rsi_find_sta(adapter->priv, sta->addr);
897 sta_id = rsta->sta_id;
899 adapter->priv->key = key;
901 if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
902 (key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
903 status = rsi_hal_load_key(adapter->priv,
916 status = rsi_hal_load_key(adapter->priv,
927 if (vif->type == NL80211_IFTYPE_STATION &&
928 (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
929 key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
930 if (!rsi_send_block_unblock_frame(adapter->priv, false))
931 adapter->priv->hw_data_qs_blocked = false;
938 * rsi_mac80211_set_key() - This function sets type of key to be loaded.
939 * @hw: Pointer to the ieee80211_hw structure.
940 * @cmd: enum set_key_cmd.
941 * @vif: Pointer to the ieee80211_vif structure.
942 * @sta: Pointer to the ieee80211_sta structure.
943 * @key: Pointer to the ieee80211_key_conf structure.
945 * Return: status: 0 on success, negative error code on failure.
947 static int rsi_mac80211_set_key(struct ieee80211_hw *hw,
948 enum set_key_cmd cmd,
949 struct ieee80211_vif *vif,
950 struct ieee80211_sta *sta,
951 struct ieee80211_key_conf *key)
953 struct rsi_hw *adapter = hw->priv;
954 struct rsi_common *common = adapter->priv;
955 struct security_info *secinfo = &common->secinfo;
958 mutex_lock(&common->mutex);
961 status = rsi_hal_key_config(hw, vif, key, sta);
963 mutex_unlock(&common->mutex);
967 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
968 secinfo->ptk_cipher = key->cipher;
970 secinfo->gtk_cipher = key->cipher;
972 key->hw_key_idx = key->keyidx;
973 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
975 rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__);
979 rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__);
980 memset(key, 0, sizeof(struct ieee80211_key_conf));
981 status = rsi_hal_key_config(hw, vif, key, sta);
985 status = -EOPNOTSUPP;
989 mutex_unlock(&common->mutex);
994 * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for
995 * the corresponding mlme_action flag and
996 * informs the f/w regarding this.
997 * @hw: Pointer to the ieee80211_hw structure.
998 * @vif: Pointer to the ieee80211_vif structure.
999 * @params: Pointer to A-MPDU action parameters
1001 * Return: status: 0 on success, negative error code on failure.
1003 static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw,
1004 struct ieee80211_vif *vif,
1005 struct ieee80211_ampdu_params *params)
1007 int status = -EOPNOTSUPP;
1008 struct rsi_hw *adapter = hw->priv;
1009 struct rsi_common *common = adapter->priv;
1010 struct rsi_sta *rsta = NULL;
1011 u16 seq_no = 0, seq_start = 0;
1013 struct ieee80211_sta *sta = params->sta;
1015 enum ieee80211_ampdu_mlme_action action = params->action;
1016 u16 tid = params->tid;
1017 u16 *ssn = ¶ms->ssn;
1018 u8 buf_size = params->buf_size;
1020 for (ii = 0; ii < RSI_MAX_VIFS; ii++) {
1021 if (vif == adapter->vifs[ii])
1025 mutex_lock(&common->mutex);
1030 if ((vif->type == NL80211_IFTYPE_AP) ||
1031 (vif->type == NL80211_IFTYPE_P2P_GO)) {
1032 rsta = rsi_find_sta(common, sta->addr);
1034 rsi_dbg(ERR_ZONE, "No station mapped\n");
1038 sta_id = rsta->sta_id;
1042 "%s: AMPDU action tid=%d ssn=0x%x, buf_size=%d sta_id=%d\n",
1043 __func__, tid, seq_no, buf_size, sta_id);
1046 case IEEE80211_AMPDU_RX_START:
1047 status = rsi_send_aggregation_params_frame(common,
1055 case IEEE80211_AMPDU_RX_STOP:
1056 status = rsi_send_aggregation_params_frame(common,
1064 case IEEE80211_AMPDU_TX_START:
1065 if ((vif->type == NL80211_IFTYPE_STATION) ||
1066 (vif->type == NL80211_IFTYPE_P2P_CLIENT))
1067 common->vif_info[ii].seq_start = seq_no;
1068 else if ((vif->type == NL80211_IFTYPE_AP) ||
1069 (vif->type == NL80211_IFTYPE_P2P_GO))
1070 rsta->seq_start[tid] = seq_no;
1071 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1075 case IEEE80211_AMPDU_TX_STOP_CONT:
1076 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1077 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1078 status = rsi_send_aggregation_params_frame(common,
1085 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1088 case IEEE80211_AMPDU_TX_OPERATIONAL:
1089 if ((vif->type == NL80211_IFTYPE_STATION) ||
1090 (vif->type == NL80211_IFTYPE_P2P_CLIENT))
1091 seq_start = common->vif_info[ii].seq_start;
1092 else if ((vif->type == NL80211_IFTYPE_AP) ||
1093 (vif->type == NL80211_IFTYPE_P2P_GO))
1094 seq_start = rsta->seq_start[tid];
1095 status = rsi_send_aggregation_params_frame(common,
1104 rsi_dbg(ERR_ZONE, "%s: Unknown AMPDU action\n", __func__);
1109 mutex_unlock(&common->mutex);
1114 * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value.
1115 * @hw: Pointer to the ieee80211_hw structure.
1116 * @value: Rts threshold value.
1118 * Return: 0 on success.
1120 static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw,
1123 struct rsi_hw *adapter = hw->priv;
1124 struct rsi_common *common = adapter->priv;
1126 mutex_lock(&common->mutex);
1127 common->rts_threshold = value;
1128 mutex_unlock(&common->mutex);
1134 * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used.
1135 * @hw: Pointer to the ieee80211_hw structure
1136 * @vif: Pointer to the ieee80211_vif structure.
1137 * @mask: Pointer to the cfg80211_bitrate_mask structure.
1139 * Return: 0 on success.
1141 static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw,
1142 struct ieee80211_vif *vif,
1143 const struct cfg80211_bitrate_mask *mask)
1145 const unsigned int mcs_offset = ARRAY_SIZE(rsi_rates);
1146 struct rsi_hw *adapter = hw->priv;
1147 struct rsi_common *common = adapter->priv;
1150 mutex_lock(&common->mutex);
1152 for (i = 0; i < ARRAY_SIZE(common->rate_config); i++) {
1153 struct rsi_rate_config *cfg = &common->rate_config[i];
1156 bm = mask->control[i].legacy | (mask->control[i].ht_mcs[0] << mcs_offset);
1157 if (hweight32(bm) == 1) { /* single rate */
1158 int rate_index = ffs(bm) - 1;
1160 if (rate_index < mcs_offset)
1161 cfg->fixed_hw_rate = rsi_rates[rate_index].hw_value;
1163 cfg->fixed_hw_rate = rsi_mcsrates[rate_index - mcs_offset];
1164 cfg->fixed_enabled = true;
1166 cfg->configured_mask = bm;
1167 cfg->fixed_enabled = false;
1171 mutex_unlock(&common->mutex);
1177 * rsi_perform_cqm() - This function performs cqm.
1178 * @common: Pointer to the driver private structure.
1179 * @bssid: pointer to the bssid.
1180 * @rssi: RSSI value.
1182 static void rsi_perform_cqm(struct rsi_common *common,
1185 struct ieee80211_vif *vif)
1187 s8 last_event = common->cqm_info.last_cqm_event_rssi;
1188 int thold = common->cqm_info.rssi_thold;
1189 u32 hyst = common->cqm_info.rssi_hyst;
1190 enum nl80211_cqm_rssi_threshold_event event;
1192 if (rssi < thold && (last_event == 0 || rssi < (last_event - hyst)))
1193 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
1194 else if (rssi > thold &&
1195 (last_event == 0 || rssi > (last_event + hyst)))
1196 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
1200 common->cqm_info.last_cqm_event_rssi = rssi;
1201 rsi_dbg(INFO_ZONE, "CQM: Notifying event: %d\n", event);
1202 ieee80211_cqm_rssi_notify(vif, event, rssi, GFP_KERNEL);
1208 * rsi_fill_rx_status() - This function fills rx status in
1209 * ieee80211_rx_status structure.
1210 * @hw: Pointer to the ieee80211_hw structure.
1211 * @skb: Pointer to the socket buffer structure.
1212 * @common: Pointer to the driver private structure.
1213 * @rxs: Pointer to the ieee80211_rx_status structure.
1217 static void rsi_fill_rx_status(struct ieee80211_hw *hw,
1218 struct sk_buff *skb,
1219 struct rsi_common *common,
1220 struct ieee80211_rx_status *rxs)
1222 struct rsi_hw *adapter = common->priv;
1223 struct ieee80211_vif *vif;
1224 struct ieee80211_bss_conf *bss = NULL;
1225 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1226 struct skb_info *rx_params = (struct skb_info *)info->driver_data;
1227 struct ieee80211_hdr *hdr;
1228 char rssi = rx_params->rssi;
1230 u8 channel = rx_params->channel;
1234 hdr = ((struct ieee80211_hdr *)(skb->data));
1235 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1237 memset(info, 0, sizeof(struct ieee80211_tx_info));
1239 rxs->signal = -(rssi);
1241 rxs->band = common->band;
1243 freq = ieee80211_channel_to_frequency(channel, rxs->band);
1248 if (ieee80211_has_protected(hdr->frame_control)) {
1249 if (rsi_is_cipher_wep(common)) {
1250 memmove(skb->data + 4, skb->data, hdrlen);
1253 memmove(skb->data + 8, skb->data, hdrlen);
1255 rxs->flag |= RX_FLAG_MMIC_STRIPPED;
1257 rxs->flag |= RX_FLAG_DECRYPTED;
1258 rxs->flag |= RX_FLAG_IV_STRIPPED;
1261 for (i = 0; i < RSI_MAX_VIFS; i++) {
1262 vif = adapter->vifs[i];
1265 if (vif->type == NL80211_IFTYPE_STATION) {
1266 bss = &vif->bss_conf;
1272 /* CQM only for connected AP beacons, the RSSI is a weighted avg */
1273 if (bss->assoc && !(memcmp(bss->bssid, hdr->addr2, ETH_ALEN))) {
1274 if (ieee80211_is_beacon(hdr->frame_control))
1275 rsi_perform_cqm(common, hdr->addr2, rxs->signal, vif);
1282 * rsi_indicate_pkt_to_os() - This function sends recieved packet to mac80211.
1283 * @common: Pointer to the driver private structure.
1284 * @skb: Pointer to the socket buffer structure.
1288 void rsi_indicate_pkt_to_os(struct rsi_common *common,
1289 struct sk_buff *skb)
1291 struct rsi_hw *adapter = common->priv;
1292 struct ieee80211_hw *hw = adapter->hw;
1293 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
1295 if ((common->iface_down) || (!adapter->sc_nvifs)) {
1300 /* filling in the ieee80211_rx_status flags */
1301 rsi_fill_rx_status(hw, skb, common, rx_status);
1303 ieee80211_rx_irqsafe(hw, skb);
1307 * rsi_mac80211_sta_add() - This function notifies driver about a peer getting
1309 * @hw: pointer to the ieee80211_hw structure.
1310 * @vif: Pointer to the ieee80211_vif structure.
1311 * @sta: Pointer to the ieee80211_sta structure.
1313 * Return: 0 on success, negative error codes on failure.
1315 static int rsi_mac80211_sta_add(struct ieee80211_hw *hw,
1316 struct ieee80211_vif *vif,
1317 struct ieee80211_sta *sta)
1319 struct rsi_hw *adapter = hw->priv;
1320 struct rsi_common *common = adapter->priv;
1321 bool sta_exist = false;
1322 struct rsi_sta *rsta;
1325 rsi_dbg(INFO_ZONE, "Station Add: %pM\n", sta->addr);
1327 mutex_lock(&common->mutex);
1329 if ((vif->type == NL80211_IFTYPE_AP) ||
1330 (vif->type == NL80211_IFTYPE_P2P_GO)) {
1333 int free_index = -1;
1335 /* Check if max stations reached */
1336 if (common->num_stations >= common->max_stations) {
1337 rsi_dbg(ERR_ZONE, "Reject: Max Stations exists\n");
1338 status = -EOPNOTSUPP;
1341 for (cnt = 0; cnt < common->max_stations; cnt++) {
1342 rsta = &common->stations[cnt];
1349 if (!memcmp(rsta->sta->addr, sta->addr, ETH_ALEN)) {
1350 rsi_dbg(INFO_ZONE, "Station exists\n");
1357 if (free_index >= 0)
1358 sta_idx = free_index;
1362 "%s: Some problem reaching here...\n",
1367 rsta = &common->stations[sta_idx];
1369 rsta->sta_id = sta_idx;
1370 for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++)
1371 rsta->start_tx_aggr[cnt] = false;
1372 for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++)
1373 rsta->seq_start[cnt] = 0;
1375 rsi_dbg(INFO_ZONE, "New Station\n");
1377 /* Send peer notify to device */
1378 rsi_dbg(INFO_ZONE, "Indicate bss status to device\n");
1379 rsi_inform_bss_status(common, RSI_OPMODE_AP, 1,
1380 sta->addr, sta->wme, sta->aid,
1381 sta, sta_idx, 0, vif);
1384 struct ieee80211_key_conf *key = common->key;
1386 if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
1387 (key->cipher == WLAN_CIPHER_SUITE_WEP40))
1388 rsi_hal_load_key(adapter->priv,
1398 common->num_stations++;
1402 if ((vif->type == NL80211_IFTYPE_STATION) ||
1403 (vif->type == NL80211_IFTYPE_P2P_CLIENT)) {
1404 common->bitrate_mask[common->band] = sta->supp_rates[common->band];
1405 common->vif_info[0].is_ht = sta->ht_cap.ht_supported;
1406 if (sta->ht_cap.ht_supported) {
1407 common->bitrate_mask[NL80211_BAND_2GHZ] =
1408 sta->supp_rates[NL80211_BAND_2GHZ];
1409 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
1410 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
1411 common->vif_info[0].sgi = true;
1412 ieee80211_start_tx_ba_session(sta, 0, 0);
1417 mutex_unlock(&common->mutex);
1423 * rsi_mac80211_sta_remove() - This function notifies driver about a peer
1424 * getting disconnected.
1425 * @hw: Pointer to the ieee80211_hw structure.
1426 * @vif: Pointer to the ieee80211_vif structure.
1427 * @sta: Pointer to the ieee80211_sta structure.
1429 * Return: 0 on success, negative error codes on failure.
1431 static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw,
1432 struct ieee80211_vif *vif,
1433 struct ieee80211_sta *sta)
1435 struct rsi_hw *adapter = hw->priv;
1436 struct rsi_common *common = adapter->priv;
1437 struct ieee80211_bss_conf *bss = &vif->bss_conf;
1438 struct rsi_sta *rsta;
1440 rsi_dbg(INFO_ZONE, "Station Remove: %pM\n", sta->addr);
1442 mutex_lock(&common->mutex);
1444 if ((vif->type == NL80211_IFTYPE_AP) ||
1445 (vif->type == NL80211_IFTYPE_P2P_GO)) {
1448 /* Send peer notify to device */
1449 rsi_dbg(INFO_ZONE, "Indicate bss status to device\n");
1450 for (sta_idx = 0; sta_idx < common->max_stations; sta_idx++) {
1451 rsta = &common->stations[sta_idx];
1455 if (!memcmp(rsta->sta->addr, sta->addr, ETH_ALEN)) {
1456 rsi_inform_bss_status(common, RSI_OPMODE_AP, 0,
1457 sta->addr, sta->wme,
1458 sta->aid, sta, sta_idx,
1462 for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++)
1463 rsta->start_tx_aggr[cnt] = false;
1464 if (common->num_stations > 0)
1465 common->num_stations--;
1469 if (sta_idx >= common->max_stations)
1470 rsi_dbg(ERR_ZONE, "%s: No station found\n", __func__);
1473 if ((vif->type == NL80211_IFTYPE_STATION) ||
1474 (vif->type == NL80211_IFTYPE_P2P_CLIENT)) {
1475 /* Resetting all the fields to default values */
1476 memcpy((u8 *)bss->bssid, (u8 *)sta->addr, ETH_ALEN);
1477 bss->qos = sta->wme;
1478 common->bitrate_mask[NL80211_BAND_2GHZ] = 0;
1479 common->bitrate_mask[NL80211_BAND_5GHZ] = 0;
1480 common->vif_info[0].is_ht = false;
1481 common->vif_info[0].sgi = false;
1482 common->vif_info[0].seq_start = 0;
1483 common->secinfo.ptk_cipher = 0;
1484 common->secinfo.gtk_cipher = 0;
1485 if (!common->iface_down)
1486 rsi_send_rx_filter_frame(common, 0);
1488 mutex_unlock(&common->mutex);
1494 * rsi_mac80211_set_antenna() - This function is used to configure
1495 * tx and rx antennas.
1496 * @hw: Pointer to the ieee80211_hw structure.
1497 * @tx_ant: Bitmap for tx antenna
1498 * @rx_ant: Bitmap for rx antenna
1500 * Return: 0 on success, Negative error code on failure.
1502 static int rsi_mac80211_set_antenna(struct ieee80211_hw *hw,
1503 u32 tx_ant, u32 rx_ant)
1505 struct rsi_hw *adapter = hw->priv;
1506 struct rsi_common *common = adapter->priv;
1509 if (tx_ant > 1 || rx_ant > 1) {
1511 "Invalid antenna selection (tx: %d, rx:%d)\n",
1514 "Use 0 for int_ant, 1 for ext_ant\n");
1518 rsi_dbg(INFO_ZONE, "%s: Antenna map Tx %x Rx %d\n",
1519 __func__, tx_ant, rx_ant);
1521 mutex_lock(&common->mutex);
1523 antenna = tx_ant ? ANTENNA_SEL_UFL : ANTENNA_SEL_INT;
1524 if (common->ant_in_use != antenna)
1525 if (rsi_set_antenna(common, antenna))
1526 goto fail_set_antenna;
1528 rsi_dbg(INFO_ZONE, "(%s) Antenna path configured successfully\n",
1529 tx_ant ? "UFL" : "INT");
1531 common->ant_in_use = antenna;
1533 mutex_unlock(&common->mutex);
1538 rsi_dbg(ERR_ZONE, "%s: Failed.\n", __func__);
1539 mutex_unlock(&common->mutex);
1544 * rsi_mac80211_get_antenna() - This function is used to configure
1545 * tx and rx antennas.
1547 * @hw: Pointer to the ieee80211_hw structure.
1548 * @tx_ant: Bitmap for tx antenna
1549 * @rx_ant: Bitmap for rx antenna
1551 * Return: 0 on success, negative error codes on failure.
1553 static int rsi_mac80211_get_antenna(struct ieee80211_hw *hw,
1554 u32 *tx_ant, u32 *rx_ant)
1556 struct rsi_hw *adapter = hw->priv;
1557 struct rsi_common *common = adapter->priv;
1559 mutex_lock(&common->mutex);
1561 *tx_ant = (common->ant_in_use == ANTENNA_SEL_UFL) ? 1 : 0;
1564 mutex_unlock(&common->mutex);
1569 static int rsi_map_region_code(enum nl80211_dfs_regions region_code)
1571 switch (region_code) {
1572 case NL80211_DFS_FCC:
1573 return RSI_REGION_FCC;
1574 case NL80211_DFS_ETSI:
1575 return RSI_REGION_ETSI;
1576 case NL80211_DFS_JP:
1577 return RSI_REGION_TELEC;
1578 case NL80211_DFS_UNSET:
1579 return RSI_REGION_WORLD;
1581 return RSI_REGION_WORLD;
1584 static void rsi_reg_notify(struct wiphy *wiphy,
1585 struct regulatory_request *request)
1587 struct ieee80211_supported_band *sband;
1588 struct ieee80211_channel *ch;
1589 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1590 struct rsi_hw * adapter = hw->priv;
1591 struct rsi_common *common = adapter->priv;
1594 mutex_lock(&common->mutex);
1596 rsi_dbg(INFO_ZONE, "country = %s dfs_region = %d\n",
1597 request->alpha2, request->dfs_region);
1599 if (common->num_supp_bands > 1) {
1600 sband = wiphy->bands[NL80211_BAND_5GHZ];
1602 for (i = 0; i < sband->n_channels; i++) {
1603 ch = &sband->channels[i];
1604 if (ch->flags & IEEE80211_CHAN_DISABLED)
1607 if (ch->flags & IEEE80211_CHAN_RADAR)
1608 ch->flags |= IEEE80211_CHAN_NO_IR;
1611 adapter->dfs_region = rsi_map_region_code(request->dfs_region);
1612 rsi_dbg(INFO_ZONE, "RSI region code = %d\n", adapter->dfs_region);
1614 adapter->country[0] = request->alpha2[0];
1615 adapter->country[1] = request->alpha2[1];
1617 mutex_unlock(&common->mutex);
1620 static void rsi_mac80211_rfkill_poll(struct ieee80211_hw *hw)
1622 struct rsi_hw *adapter = hw->priv;
1623 struct rsi_common *common = adapter->priv;
1625 mutex_lock(&common->mutex);
1626 if (common->fsm_state != FSM_MAC_INIT_DONE)
1627 wiphy_rfkill_set_hw_state(hw->wiphy, true);
1629 wiphy_rfkill_set_hw_state(hw->wiphy, false);
1630 mutex_unlock(&common->mutex);
1633 static void rsi_resume_conn_channel(struct rsi_common *common)
1635 struct rsi_hw *adapter = common->priv;
1636 struct ieee80211_vif *vif;
1639 for (cnt = 0; cnt < RSI_MAX_VIFS; cnt++) {
1640 vif = adapter->vifs[cnt];
1644 if ((vif->type == NL80211_IFTYPE_AP) ||
1645 (vif->type == NL80211_IFTYPE_P2P_GO)) {
1646 rsi_switch_channel(adapter, vif);
1649 if (((vif->type == NL80211_IFTYPE_STATION) ||
1650 (vif->type == NL80211_IFTYPE_P2P_CLIENT)) &&
1651 vif->bss_conf.assoc) {
1652 rsi_switch_channel(adapter, vif);
1658 void rsi_roc_timeout(struct timer_list *t)
1660 struct rsi_common *common = from_timer(common, t, roc_timer);
1662 rsi_dbg(INFO_ZONE, "Remain on channel expired\n");
1664 mutex_lock(&common->mutex);
1665 ieee80211_remain_on_channel_expired(common->priv->hw);
1667 if (timer_pending(&common->roc_timer))
1668 del_timer(&common->roc_timer);
1670 rsi_resume_conn_channel(common);
1671 mutex_unlock(&common->mutex);
1674 static int rsi_mac80211_roc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1675 struct ieee80211_channel *chan, int duration,
1676 enum ieee80211_roc_type type)
1678 struct rsi_hw *adapter = (struct rsi_hw *)hw->priv;
1679 struct rsi_common *common = (struct rsi_common *)adapter->priv;
1682 rsi_dbg(INFO_ZONE, "***** Remain on channel *****\n");
1684 mutex_lock(&common->mutex);
1685 rsi_dbg(INFO_ZONE, "%s: channel: %d duration: %dms\n",
1686 __func__, chan->hw_value, duration);
1688 if (timer_pending(&common->roc_timer)) {
1689 rsi_dbg(INFO_ZONE, "Stop on-going ROC\n");
1690 del_timer(&common->roc_timer);
1692 common->roc_timer.expires = msecs_to_jiffies(duration) + jiffies;
1693 add_timer(&common->roc_timer);
1695 /* Configure band */
1696 if (rsi_band_check(common, chan)) {
1697 rsi_dbg(ERR_ZONE, "Failed to set band\n");
1702 /* Configure channel */
1703 if (rsi_set_channel(common, chan)) {
1704 rsi_dbg(ERR_ZONE, "Failed to set the channel\n");
1709 common->roc_vif = vif;
1710 ieee80211_ready_on_channel(hw);
1711 rsi_dbg(INFO_ZONE, "%s: Ready on channel :%d\n",
1712 __func__, chan->hw_value);
1715 mutex_unlock(&common->mutex);
1720 static int rsi_mac80211_cancel_roc(struct ieee80211_hw *hw)
1722 struct rsi_hw *adapter = hw->priv;
1723 struct rsi_common *common = adapter->priv;
1725 rsi_dbg(INFO_ZONE, "Cancel remain on channel\n");
1727 mutex_lock(&common->mutex);
1728 if (!timer_pending(&common->roc_timer)) {
1729 mutex_unlock(&common->mutex);
1733 del_timer(&common->roc_timer);
1735 rsi_resume_conn_channel(common);
1736 mutex_unlock(&common->mutex);
1742 static const struct wiphy_wowlan_support rsi_wowlan_support = {
1743 .flags = WIPHY_WOWLAN_ANY |
1744 WIPHY_WOWLAN_MAGIC_PKT |
1745 WIPHY_WOWLAN_DISCONNECT |
1746 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
1747 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
1748 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
1749 WIPHY_WOWLAN_4WAY_HANDSHAKE,
1752 static u16 rsi_wow_map_triggers(struct rsi_common *common,
1753 struct cfg80211_wowlan *wowlan)
1755 u16 wow_triggers = 0;
1757 rsi_dbg(INFO_ZONE, "Mapping wowlan triggers\n");
1760 wow_triggers |= RSI_WOW_ANY;
1761 if (wowlan->magic_pkt)
1762 wow_triggers |= RSI_WOW_MAGIC_PKT;
1763 if (wowlan->disconnect)
1764 wow_triggers |= RSI_WOW_DISCONNECT;
1765 if (wowlan->gtk_rekey_failure || wowlan->eap_identity_req ||
1766 wowlan->four_way_handshake)
1767 wow_triggers |= RSI_WOW_GTK_REKEY;
1769 return wow_triggers;
1772 int rsi_config_wowlan(struct rsi_hw *adapter, struct cfg80211_wowlan *wowlan)
1774 struct rsi_common *common = adapter->priv;
1776 u16 rx_filter_word = 0;
1777 struct ieee80211_bss_conf *bss = NULL;
1779 rsi_dbg(INFO_ZONE, "Config WoWLAN to device\n");
1781 if (!adapter->vifs[0])
1784 bss = &adapter->vifs[0]->bss_conf;
1786 if (WARN_ON(!wowlan)) {
1787 rsi_dbg(ERR_ZONE, "WoW triggers not enabled\n");
1791 common->wow_flags |= RSI_WOW_ENABLED;
1792 triggers = rsi_wow_map_triggers(common, wowlan);
1794 rsi_dbg(ERR_ZONE, "%s:No valid WoW triggers\n", __func__);
1799 "Cannot configure WoWLAN (Station not connected)\n");
1800 common->wow_flags |= RSI_WOW_NO_CONNECTION;
1803 rsi_dbg(INFO_ZONE, "TRIGGERS %x\n", triggers);
1804 rsi_send_wowlan_request(common, triggers, 1);
1807 * Increase the beacon_miss threshold & keep-alive timers in
1810 rsi_send_vap_dynamic_update(common);
1812 rx_filter_word = (ALLOW_DATA_ASSOC_PEER | DISALLOW_BEACONS);
1813 rsi_send_rx_filter_frame(common, rx_filter_word);
1817 EXPORT_SYMBOL(rsi_config_wowlan);
1819 static int rsi_mac80211_suspend(struct ieee80211_hw *hw,
1820 struct cfg80211_wowlan *wowlan)
1822 struct rsi_hw *adapter = hw->priv;
1823 struct rsi_common *common = adapter->priv;
1825 rsi_dbg(INFO_ZONE, "%s: mac80211 suspend\n", __func__);
1826 mutex_lock(&common->mutex);
1827 if (rsi_config_wowlan(adapter, wowlan)) {
1828 rsi_dbg(ERR_ZONE, "Failed to configure WoWLAN\n");
1829 mutex_unlock(&common->mutex);
1832 mutex_unlock(&common->mutex);
1837 static int rsi_mac80211_resume(struct ieee80211_hw *hw)
1839 u16 rx_filter_word = 0;
1840 struct rsi_hw *adapter = hw->priv;
1841 struct rsi_common *common = adapter->priv;
1843 common->wow_flags = 0;
1845 rsi_dbg(INFO_ZONE, "%s: mac80211 resume\n", __func__);
1847 if (common->hibernate_resume)
1850 mutex_lock(&common->mutex);
1851 rsi_send_wowlan_request(common, 0, 0);
1853 rx_filter_word = (ALLOW_DATA_ASSOC_PEER | ALLOW_CTRL_ASSOC_PEER |
1854 ALLOW_MGMT_ASSOC_PEER);
1855 rsi_send_rx_filter_frame(common, rx_filter_word);
1856 mutex_unlock(&common->mutex);
1863 static const struct ieee80211_ops mac80211_ops = {
1864 .tx = rsi_mac80211_tx,
1865 .start = rsi_mac80211_start,
1866 .stop = rsi_mac80211_stop,
1867 .add_interface = rsi_mac80211_add_interface,
1868 .remove_interface = rsi_mac80211_remove_interface,
1869 .config = rsi_mac80211_config,
1870 .bss_info_changed = rsi_mac80211_bss_info_changed,
1871 .conf_tx = rsi_mac80211_conf_tx,
1872 .configure_filter = rsi_mac80211_conf_filter,
1873 .set_key = rsi_mac80211_set_key,
1874 .set_rts_threshold = rsi_mac80211_set_rts_threshold,
1875 .set_bitrate_mask = rsi_mac80211_set_rate_mask,
1876 .ampdu_action = rsi_mac80211_ampdu_action,
1877 .sta_add = rsi_mac80211_sta_add,
1878 .sta_remove = rsi_mac80211_sta_remove,
1879 .set_antenna = rsi_mac80211_set_antenna,
1880 .get_antenna = rsi_mac80211_get_antenna,
1881 .rfkill_poll = rsi_mac80211_rfkill_poll,
1882 .remain_on_channel = rsi_mac80211_roc,
1883 .cancel_remain_on_channel = rsi_mac80211_cancel_roc,
1885 .suspend = rsi_mac80211_suspend,
1886 .resume = rsi_mac80211_resume,
1891 * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack.
1892 * @common: Pointer to the driver private structure.
1894 * Return: 0 on success, negative error codes on failure.
1896 int rsi_mac80211_attach(struct rsi_common *common)
1899 struct ieee80211_hw *hw = NULL;
1900 struct wiphy *wiphy = NULL;
1901 struct rsi_hw *adapter = common->priv;
1902 u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3};
1904 rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__);
1906 hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops);
1908 rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__);
1914 SET_IEEE80211_DEV(hw, adapter->device);
1919 ieee80211_hw_set(hw, SIGNAL_DBM);
1920 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
1921 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
1922 ieee80211_hw_set(hw, SUPPORTS_PS);
1923 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
1925 hw->queues = MAX_HW_QUEUES;
1926 hw->extra_tx_headroom = RSI_NEEDED_HEADROOM;
1929 hw->max_rate_tries = MAX_RETRIES;
1930 hw->uapsd_queues = RSI_IEEE80211_UAPSD_QUEUES;
1931 hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL;
1933 hw->max_tx_aggregation_subframes = RSI_MAX_TX_AGGR_FRMS;
1934 hw->max_rx_aggregation_subframes = RSI_MAX_RX_AGGR_FRMS;
1935 hw->rate_control_algorithm = "AARF";
1937 SET_IEEE80211_PERM_ADDR(hw, common->mac_addr);
1938 ether_addr_copy(hw->wiphy->addr_mask, addr_mask);
1940 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1941 BIT(NL80211_IFTYPE_AP) |
1942 BIT(NL80211_IFTYPE_P2P_DEVICE) |
1943 BIT(NL80211_IFTYPE_P2P_CLIENT) |
1944 BIT(NL80211_IFTYPE_P2P_GO);
1946 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1947 wiphy->retry_short = RETRY_SHORT;
1948 wiphy->retry_long = RETRY_LONG;
1949 wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1950 wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1953 wiphy->available_antennas_rx = 1;
1954 wiphy->available_antennas_tx = 1;
1956 status = rsi_register_rates_channels(adapter, NL80211_BAND_2GHZ);
1959 wiphy->bands[NL80211_BAND_2GHZ] =
1960 &adapter->sbands[NL80211_BAND_2GHZ];
1961 if (common->num_supp_bands > 1) {
1962 status = rsi_register_rates_channels(adapter,
1966 wiphy->bands[NL80211_BAND_5GHZ] =
1967 &adapter->sbands[NL80211_BAND_5GHZ];
1971 wiphy->max_ap_assoc_sta = rsi_max_ap_stas[common->oper_mode - 1];
1972 common->max_stations = wiphy->max_ap_assoc_sta;
1973 rsi_dbg(ERR_ZONE, "Max Stations Allowed = %d\n", common->max_stations);
1974 hw->sta_data_size = sizeof(struct rsi_sta);
1975 wiphy->flags = WIPHY_FLAG_REPORTS_OBSS;
1976 wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
1977 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
1978 wiphy->reg_notifier = rsi_reg_notify;
1981 wiphy->wowlan = &rsi_wowlan_support;
1984 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
1986 /* Wi-Fi direct parameters */
1987 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
1988 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX;
1989 wiphy->max_remain_on_channel_duration = 10000;
1990 hw->max_listen_interval = 10;
1991 wiphy->iface_combinations = rsi_iface_combinations;
1992 wiphy->n_iface_combinations = ARRAY_SIZE(rsi_iface_combinations);
1994 if (common->coex_mode > 1)
1995 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
1997 status = ieee80211_register_hw(hw);
2001 return rsi_init_dbgfs(adapter);