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"
20 #include "rsi_common.h"
22 static const struct ieee80211_channel rsi_2ghz_channels[] = {
23 { .band = NL80211_BAND_2GHZ, .center_freq = 2412,
24 .hw_value = 1 }, /* Channel 1 */
25 { .band = NL80211_BAND_2GHZ, .center_freq = 2417,
26 .hw_value = 2 }, /* Channel 2 */
27 { .band = NL80211_BAND_2GHZ, .center_freq = 2422,
28 .hw_value = 3 }, /* Channel 3 */
29 { .band = NL80211_BAND_2GHZ, .center_freq = 2427,
30 .hw_value = 4 }, /* Channel 4 */
31 { .band = NL80211_BAND_2GHZ, .center_freq = 2432,
32 .hw_value = 5 }, /* Channel 5 */
33 { .band = NL80211_BAND_2GHZ, .center_freq = 2437,
34 .hw_value = 6 }, /* Channel 6 */
35 { .band = NL80211_BAND_2GHZ, .center_freq = 2442,
36 .hw_value = 7 }, /* Channel 7 */
37 { .band = NL80211_BAND_2GHZ, .center_freq = 2447,
38 .hw_value = 8 }, /* Channel 8 */
39 { .band = NL80211_BAND_2GHZ, .center_freq = 2452,
40 .hw_value = 9 }, /* Channel 9 */
41 { .band = NL80211_BAND_2GHZ, .center_freq = 2457,
42 .hw_value = 10 }, /* Channel 10 */
43 { .band = NL80211_BAND_2GHZ, .center_freq = 2462,
44 .hw_value = 11 }, /* Channel 11 */
45 { .band = NL80211_BAND_2GHZ, .center_freq = 2467,
46 .hw_value = 12 }, /* Channel 12 */
47 { .band = NL80211_BAND_2GHZ, .center_freq = 2472,
48 .hw_value = 13 }, /* Channel 13 */
49 { .band = NL80211_BAND_2GHZ, .center_freq = 2484,
50 .hw_value = 14 }, /* Channel 14 */
53 static const struct ieee80211_channel rsi_5ghz_channels[] = {
54 { .band = NL80211_BAND_5GHZ, .center_freq = 5180,
55 .hw_value = 36, }, /* Channel 36 */
56 { .band = NL80211_BAND_5GHZ, .center_freq = 5200,
57 .hw_value = 40, }, /* Channel 40 */
58 { .band = NL80211_BAND_5GHZ, .center_freq = 5220,
59 .hw_value = 44, }, /* Channel 44 */
60 { .band = NL80211_BAND_5GHZ, .center_freq = 5240,
61 .hw_value = 48, }, /* Channel 48 */
62 { .band = NL80211_BAND_5GHZ, .center_freq = 5260,
63 .hw_value = 52, }, /* Channel 52 */
64 { .band = NL80211_BAND_5GHZ, .center_freq = 5280,
65 .hw_value = 56, }, /* Channel 56 */
66 { .band = NL80211_BAND_5GHZ, .center_freq = 5300,
67 .hw_value = 60, }, /* Channel 60 */
68 { .band = NL80211_BAND_5GHZ, .center_freq = 5320,
69 .hw_value = 64, }, /* Channel 64 */
70 { .band = NL80211_BAND_5GHZ, .center_freq = 5500,
71 .hw_value = 100, }, /* Channel 100 */
72 { .band = NL80211_BAND_5GHZ, .center_freq = 5520,
73 .hw_value = 104, }, /* Channel 104 */
74 { .band = NL80211_BAND_5GHZ, .center_freq = 5540,
75 .hw_value = 108, }, /* Channel 108 */
76 { .band = NL80211_BAND_5GHZ, .center_freq = 5560,
77 .hw_value = 112, }, /* Channel 112 */
78 { .band = NL80211_BAND_5GHZ, .center_freq = 5580,
79 .hw_value = 116, }, /* Channel 116 */
80 { .band = NL80211_BAND_5GHZ, .center_freq = 5600,
81 .hw_value = 120, }, /* Channel 120 */
82 { .band = NL80211_BAND_5GHZ, .center_freq = 5620,
83 .hw_value = 124, }, /* Channel 124 */
84 { .band = NL80211_BAND_5GHZ, .center_freq = 5640,
85 .hw_value = 128, }, /* Channel 128 */
86 { .band = NL80211_BAND_5GHZ, .center_freq = 5660,
87 .hw_value = 132, }, /* Channel 132 */
88 { .band = NL80211_BAND_5GHZ, .center_freq = 5680,
89 .hw_value = 136, }, /* Channel 136 */
90 { .band = NL80211_BAND_5GHZ, .center_freq = 5700,
91 .hw_value = 140, }, /* Channel 140 */
92 { .band = NL80211_BAND_5GHZ, .center_freq = 5745,
93 .hw_value = 149, }, /* Channel 149 */
94 { .band = NL80211_BAND_5GHZ, .center_freq = 5765,
95 .hw_value = 153, }, /* Channel 153 */
96 { .band = NL80211_BAND_5GHZ, .center_freq = 5785,
97 .hw_value = 157, }, /* Channel 157 */
98 { .band = NL80211_BAND_5GHZ, .center_freq = 5805,
99 .hw_value = 161, }, /* Channel 161 */
100 { .band = NL80211_BAND_5GHZ, .center_freq = 5825,
101 .hw_value = 165, }, /* Channel 165 */
104 struct ieee80211_rate rsi_rates[12] = {
105 { .bitrate = STD_RATE_01 * 5, .hw_value = RSI_RATE_1 },
106 { .bitrate = STD_RATE_02 * 5, .hw_value = RSI_RATE_2 },
107 { .bitrate = STD_RATE_5_5 * 5, .hw_value = RSI_RATE_5_5 },
108 { .bitrate = STD_RATE_11 * 5, .hw_value = RSI_RATE_11 },
109 { .bitrate = STD_RATE_06 * 5, .hw_value = RSI_RATE_6 },
110 { .bitrate = STD_RATE_09 * 5, .hw_value = RSI_RATE_9 },
111 { .bitrate = STD_RATE_12 * 5, .hw_value = RSI_RATE_12 },
112 { .bitrate = STD_RATE_18 * 5, .hw_value = RSI_RATE_18 },
113 { .bitrate = STD_RATE_24 * 5, .hw_value = RSI_RATE_24 },
114 { .bitrate = STD_RATE_36 * 5, .hw_value = RSI_RATE_36 },
115 { .bitrate = STD_RATE_48 * 5, .hw_value = RSI_RATE_48 },
116 { .bitrate = STD_RATE_54 * 5, .hw_value = RSI_RATE_54 },
119 const u16 rsi_mcsrates[8] = {
120 RSI_RATE_MCS0, RSI_RATE_MCS1, RSI_RATE_MCS2, RSI_RATE_MCS3,
121 RSI_RATE_MCS4, RSI_RATE_MCS5, RSI_RATE_MCS6, RSI_RATE_MCS7
125 * rsi_is_cipher_wep() - This function determines if the cipher is WEP or not.
126 * @common: Pointer to the driver private structure.
128 * Return: If cipher type is WEP, a value of 1 is returned, else 0.
131 bool rsi_is_cipher_wep(struct rsi_common *common)
133 if (((common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP104) ||
134 (common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP40)) &&
135 (!common->secinfo.ptk_cipher))
142 * rsi_register_rates_channels() - This function registers channels and rates.
143 * @adapter: Pointer to the adapter structure.
144 * @band: Operating band to be set.
148 static void rsi_register_rates_channels(struct rsi_hw *adapter, int band)
150 struct ieee80211_supported_band *sbands = &adapter->sbands[band];
151 void *channels = NULL;
153 if (band == NL80211_BAND_2GHZ) {
154 channels = kmalloc(sizeof(rsi_2ghz_channels), GFP_KERNEL);
157 sizeof(rsi_2ghz_channels));
158 sbands->band = NL80211_BAND_2GHZ;
159 sbands->n_channels = ARRAY_SIZE(rsi_2ghz_channels);
160 sbands->bitrates = rsi_rates;
161 sbands->n_bitrates = ARRAY_SIZE(rsi_rates);
163 channels = kmalloc(sizeof(rsi_5ghz_channels), GFP_KERNEL);
166 sizeof(rsi_5ghz_channels));
167 sbands->band = NL80211_BAND_5GHZ;
168 sbands->n_channels = ARRAY_SIZE(rsi_5ghz_channels);
169 sbands->bitrates = &rsi_rates[4];
170 sbands->n_bitrates = ARRAY_SIZE(rsi_rates) - 4;
173 sbands->channels = channels;
175 memset(&sbands->ht_cap, 0, sizeof(struct ieee80211_sta_ht_cap));
176 sbands->ht_cap.ht_supported = true;
177 sbands->ht_cap.cap = (IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
178 IEEE80211_HT_CAP_SGI_20 |
179 IEEE80211_HT_CAP_SGI_40);
180 sbands->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
181 sbands->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
182 sbands->ht_cap.mcs.rx_mask[0] = 0xff;
183 sbands->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
184 /* sbands->ht_cap.mcs.rx_highest = 0x82; */
188 * rsi_mac80211_detach() - This function is used to de-initialize the
190 * @adapter: Pointer to the adapter structure.
194 void rsi_mac80211_detach(struct rsi_hw *adapter)
196 struct ieee80211_hw *hw = adapter->hw;
197 enum nl80211_band band;
200 ieee80211_stop_queues(hw);
201 ieee80211_unregister_hw(hw);
202 ieee80211_free_hw(hw);
205 for (band = 0; band < NUM_NL80211_BANDS; band++) {
206 struct ieee80211_supported_band *sband =
207 &adapter->sbands[band];
209 kfree(sband->channels);
212 #ifdef CONFIG_RSI_DEBUGFS
213 rsi_remove_dbgfs(adapter);
214 kfree(adapter->dfsentry);
217 EXPORT_SYMBOL_GPL(rsi_mac80211_detach);
220 * rsi_indicate_tx_status() - This function indicates the transmit status.
221 * @adapter: Pointer to the adapter structure.
222 * @skb: Pointer to the socket buffer structure.
227 void rsi_indicate_tx_status(struct rsi_hw *adapter,
231 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
233 memset(info->driver_data, 0, IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
236 info->flags |= IEEE80211_TX_STAT_ACK;
238 ieee80211_tx_status_irqsafe(adapter->hw, skb);
242 * rsi_mac80211_tx() - This is the handler that 802.11 module calls for each
243 * transmitted frame.SKB contains the buffer starting
244 * from the IEEE 802.11 header.
245 * @hw: Pointer to the ieee80211_hw structure.
246 * @control: Pointer to the ieee80211_tx_control structure
247 * @skb: Pointer to the socket buffer structure.
251 static void rsi_mac80211_tx(struct ieee80211_hw *hw,
252 struct ieee80211_tx_control *control,
255 struct rsi_hw *adapter = hw->priv;
256 struct rsi_common *common = adapter->priv;
258 rsi_core_xmit(common, skb);
262 * rsi_mac80211_start() - This is first handler that 802.11 module calls, since
263 * the driver init is complete by then, just
265 * @hw: Pointer to the ieee80211_hw structure.
267 * Return: 0 as success.
269 static int rsi_mac80211_start(struct ieee80211_hw *hw)
271 struct rsi_hw *adapter = hw->priv;
272 struct rsi_common *common = adapter->priv;
274 mutex_lock(&common->mutex);
275 common->iface_down = false;
276 mutex_unlock(&common->mutex);
278 rsi_send_rx_filter_frame(common, 0);
284 * rsi_mac80211_stop() - This is the last handler that 802.11 module calls.
285 * @hw: Pointer to the ieee80211_hw structure.
289 static void rsi_mac80211_stop(struct ieee80211_hw *hw)
291 struct rsi_hw *adapter = hw->priv;
292 struct rsi_common *common = adapter->priv;
294 mutex_lock(&common->mutex);
295 common->iface_down = true;
296 mutex_unlock(&common->mutex);
300 * rsi_mac80211_add_interface() - This function is called when a netdevice
301 * attached to the hardware is enabled.
302 * @hw: Pointer to the ieee80211_hw structure.
303 * @vif: Pointer to the ieee80211_vif structure.
305 * Return: ret: 0 on success, negative error code on failure.
307 static int rsi_mac80211_add_interface(struct ieee80211_hw *hw,
308 struct ieee80211_vif *vif)
310 struct rsi_hw *adapter = hw->priv;
311 struct rsi_common *common = adapter->priv;
312 int ret = -EOPNOTSUPP;
314 mutex_lock(&common->mutex);
316 case NL80211_IFTYPE_STATION:
317 if (!adapter->sc_nvifs) {
319 adapter->vifs[0] = vif;
320 ret = rsi_set_vap_capabilities(common,
327 "%s: Interface type %d not supported\n", __func__,
330 mutex_unlock(&common->mutex);
336 * rsi_mac80211_remove_interface() - This function notifies driver that an
337 * interface is going down.
338 * @hw: Pointer to the ieee80211_hw structure.
339 * @vif: Pointer to the ieee80211_vif structure.
343 static void rsi_mac80211_remove_interface(struct ieee80211_hw *hw,
344 struct ieee80211_vif *vif)
346 struct rsi_hw *adapter = hw->priv;
347 struct rsi_common *common = adapter->priv;
349 mutex_lock(&common->mutex);
350 if (vif->type == NL80211_IFTYPE_STATION) {
352 rsi_set_vap_capabilities(common, STA_OPMODE, VAP_DELETE);
355 if (!memcmp(adapter->vifs[0], vif, sizeof(struct ieee80211_vif)))
356 adapter->vifs[0] = NULL;
357 mutex_unlock(&common->mutex);
361 * rsi_channel_change() - This function is a performs the checks
362 * required for changing a channel and sets
363 * the channel accordingly.
364 * @hw: Pointer to the ieee80211_hw structure.
366 * Return: 0 on success, negative error code on failure.
368 static int rsi_channel_change(struct ieee80211_hw *hw)
370 struct rsi_hw *adapter = hw->priv;
371 struct rsi_common *common = adapter->priv;
372 int status = -EOPNOTSUPP;
373 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
374 u16 channel = curchan->hw_value;
375 struct ieee80211_bss_conf *bss = &adapter->vifs[0]->bss_conf;
378 "%s: Set channel: %d MHz type: %d channel_no %d\n",
379 __func__, curchan->center_freq,
380 curchan->flags, channel);
383 if (!common->hw_data_qs_blocked &&
384 (rsi_get_connected_channel(adapter) != channel)) {
385 rsi_dbg(INFO_ZONE, "blk data q %d\n", channel);
386 if (!rsi_send_block_unblock_frame(common, true))
387 common->hw_data_qs_blocked = true;
391 status = rsi_band_check(common);
393 status = rsi_set_channel(adapter->priv, curchan);
396 if (common->hw_data_qs_blocked &&
397 (rsi_get_connected_channel(adapter) == channel)) {
398 rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel);
399 if (!rsi_send_block_unblock_frame(common, false))
400 common->hw_data_qs_blocked = false;
403 if (common->hw_data_qs_blocked) {
404 rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel);
405 if (!rsi_send_block_unblock_frame(common, false))
406 common->hw_data_qs_blocked = false;
414 * rsi_config_power() - This function configures tx power to device
415 * @hw: Pointer to the ieee80211_hw structure.
417 * Return: 0 on success, negative error code on failure.
419 static int rsi_config_power(struct ieee80211_hw *hw)
421 struct rsi_hw *adapter = hw->priv;
422 struct rsi_common *common = adapter->priv;
423 struct ieee80211_conf *conf = &hw->conf;
425 if (adapter->sc_nvifs <= 0) {
426 rsi_dbg(ERR_ZONE, "%s: No virtual interface found\n", __func__);
431 "%s: Set tx power: %d dBM\n", __func__, conf->power_level);
433 if (conf->power_level == common->tx_power)
436 common->tx_power = conf->power_level;
438 return rsi_send_radio_params_update(common);
442 * rsi_mac80211_config() - This function is a handler for configuration
443 * requests. The stack calls this function to
444 * change hardware configuration, e.g., channel.
445 * @hw: Pointer to the ieee80211_hw structure.
446 * @changed: Changed flags set.
448 * Return: 0 on success, negative error code on failure.
450 static int rsi_mac80211_config(struct ieee80211_hw *hw,
453 struct rsi_hw *adapter = hw->priv;
454 struct rsi_common *common = adapter->priv;
455 int status = -EOPNOTSUPP;
457 mutex_lock(&common->mutex);
459 if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
460 status = rsi_channel_change(hw);
463 if (changed & IEEE80211_CONF_CHANGE_POWER) {
464 rsi_dbg(INFO_ZONE, "%s: Configuring Power\n", __func__);
465 status = rsi_config_power(hw);
468 mutex_unlock(&common->mutex);
474 * rsi_get_connected_channel() - This function is used to get the current
475 * connected channel number.
476 * @adapter: Pointer to the adapter structure.
478 * Return: Current connected AP's channel number is returned.
480 u16 rsi_get_connected_channel(struct rsi_hw *adapter)
482 struct ieee80211_vif *vif = adapter->vifs[0];
484 struct ieee80211_bss_conf *bss = &vif->bss_conf;
485 struct ieee80211_channel *channel = bss->chandef.chan;
486 return channel->hw_value;
493 * rsi_mac80211_bss_info_changed() - This function is a handler for config
494 * requests related to BSS parameters that
495 * may vary during BSS's lifespan.
496 * @hw: Pointer to the ieee80211_hw structure.
497 * @vif: Pointer to the ieee80211_vif structure.
498 * @bss_conf: Pointer to the ieee80211_bss_conf structure.
499 * @changed: Changed flags set.
503 static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw,
504 struct ieee80211_vif *vif,
505 struct ieee80211_bss_conf *bss_conf,
508 struct rsi_hw *adapter = hw->priv;
509 struct rsi_common *common = adapter->priv;
510 u16 rx_filter_word = 0;
512 mutex_lock(&common->mutex);
513 if (changed & BSS_CHANGED_ASSOC) {
514 rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n",
515 __func__, bss_conf->assoc);
516 if (bss_conf->assoc) {
517 /* Send the RX filter frame */
518 rx_filter_word = (ALLOW_DATA_ASSOC_PEER |
519 ALLOW_CTRL_ASSOC_PEER |
520 ALLOW_MGMT_ASSOC_PEER);
521 rsi_send_rx_filter_frame(common, rx_filter_word);
523 rsi_inform_bss_status(common,
530 if (changed & BSS_CHANGED_CQM) {
531 common->cqm_info.last_cqm_event_rssi = 0;
532 common->cqm_info.rssi_thold = bss_conf->cqm_rssi_thold;
533 common->cqm_info.rssi_hyst = bss_conf->cqm_rssi_hyst;
534 rsi_dbg(INFO_ZONE, "RSSI throld & hysteresis are: %d %d\n",
535 common->cqm_info.rssi_thold,
536 common->cqm_info.rssi_hyst);
538 mutex_unlock(&common->mutex);
542 * rsi_mac80211_conf_filter() - This function configure the device's RX filter.
543 * @hw: Pointer to the ieee80211_hw structure.
544 * @changed: Changed flags set.
545 * @total_flags: Total initial flags set.
546 * @multicast: Multicast.
550 static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw,
555 /* Not doing much here as of now */
556 *total_flags &= RSI_SUPP_FILTERS;
560 * rsi_mac80211_conf_tx() - This function configures TX queue parameters
561 * (EDCF (aifs, cw_min, cw_max), bursting)
562 * for a hardware TX queue.
563 * @hw: Pointer to the ieee80211_hw structure
564 * @vif: Pointer to the ieee80211_vif structure.
565 * @queue: Queue number.
566 * @params: Pointer to ieee80211_tx_queue_params structure.
568 * Return: 0 on success, negative error code on failure.
570 static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw,
571 struct ieee80211_vif *vif, u16 queue,
572 const struct ieee80211_tx_queue_params *params)
574 struct rsi_hw *adapter = hw->priv;
575 struct rsi_common *common = adapter->priv;
578 if (queue >= IEEE80211_NUM_ACS)
582 "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n",
583 __func__, queue, params->aifs,
584 params->cw_min, params->cw_max, params->txop);
586 mutex_lock(&common->mutex);
587 /* Map into the way the f/w expects */
589 case IEEE80211_AC_VO:
592 case IEEE80211_AC_VI:
595 case IEEE80211_AC_BE:
598 case IEEE80211_AC_BK:
606 memcpy(&common->edca_params[idx],
608 sizeof(struct ieee80211_tx_queue_params));
609 mutex_unlock(&common->mutex);
615 * rsi_hal_key_config() - This function loads the keys into the firmware.
616 * @hw: Pointer to the ieee80211_hw structure.
617 * @vif: Pointer to the ieee80211_vif structure.
618 * @key: Pointer to the ieee80211_key_conf structure.
620 * Return: status: 0 on success, -1 on failure.
622 static int rsi_hal_key_config(struct ieee80211_hw *hw,
623 struct ieee80211_vif *vif,
624 struct ieee80211_key_conf *key)
626 struct rsi_hw *adapter = hw->priv;
630 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
631 key_type = RSI_PAIRWISE_KEY;
633 key_type = RSI_GROUP_KEY;
635 rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n",
636 __func__, key->cipher, key_type, key->keylen);
638 if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
639 (key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
640 status = rsi_hal_load_key(adapter->priv,
649 return rsi_hal_load_key(adapter->priv,
658 * rsi_mac80211_set_key() - This function sets type of key to be loaded.
659 * @hw: Pointer to the ieee80211_hw structure.
660 * @cmd: enum set_key_cmd.
661 * @vif: Pointer to the ieee80211_vif structure.
662 * @sta: Pointer to the ieee80211_sta structure.
663 * @key: Pointer to the ieee80211_key_conf structure.
665 * Return: status: 0 on success, negative error code on failure.
667 static int rsi_mac80211_set_key(struct ieee80211_hw *hw,
668 enum set_key_cmd cmd,
669 struct ieee80211_vif *vif,
670 struct ieee80211_sta *sta,
671 struct ieee80211_key_conf *key)
673 struct rsi_hw *adapter = hw->priv;
674 struct rsi_common *common = adapter->priv;
675 struct security_info *secinfo = &common->secinfo;
678 mutex_lock(&common->mutex);
681 secinfo->security_enable = true;
682 status = rsi_hal_key_config(hw, vif, key);
684 mutex_unlock(&common->mutex);
688 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
689 secinfo->ptk_cipher = key->cipher;
691 secinfo->gtk_cipher = key->cipher;
693 key->hw_key_idx = key->keyidx;
694 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
696 rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__);
700 secinfo->security_enable = false;
701 rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__);
702 memset(key, 0, sizeof(struct ieee80211_key_conf));
703 status = rsi_hal_key_config(hw, vif, key);
707 status = -EOPNOTSUPP;
711 mutex_unlock(&common->mutex);
716 * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for
717 * the corresponding mlme_action flag and
718 * informs the f/w regarding this.
719 * @hw: Pointer to the ieee80211_hw structure.
720 * @vif: Pointer to the ieee80211_vif structure.
721 * @params: Pointer to A-MPDU action parameters
723 * Return: status: 0 on success, negative error code on failure.
725 static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw,
726 struct ieee80211_vif *vif,
727 struct ieee80211_ampdu_params *params)
729 int status = -EOPNOTSUPP;
730 struct rsi_hw *adapter = hw->priv;
731 struct rsi_common *common = adapter->priv;
734 struct ieee80211_sta *sta = params->sta;
735 enum ieee80211_ampdu_mlme_action action = params->action;
736 u16 tid = params->tid;
737 u16 *ssn = ¶ms->ssn;
738 u8 buf_size = params->buf_size;
740 for (ii = 0; ii < RSI_MAX_VIFS; ii++) {
741 if (vif == adapter->vifs[ii])
745 mutex_lock(&common->mutex);
746 rsi_dbg(INFO_ZONE, "%s: AMPDU action %d called\n", __func__, action);
751 case IEEE80211_AMPDU_RX_START:
752 status = rsi_send_aggregation_params_frame(common,
759 case IEEE80211_AMPDU_RX_STOP:
760 status = rsi_send_aggregation_params_frame(common,
767 case IEEE80211_AMPDU_TX_START:
768 common->vif_info[ii].seq_start = seq_no;
769 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
773 case IEEE80211_AMPDU_TX_STOP_CONT:
774 case IEEE80211_AMPDU_TX_STOP_FLUSH:
775 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
776 status = rsi_send_aggregation_params_frame(common,
782 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
785 case IEEE80211_AMPDU_TX_OPERATIONAL:
786 status = rsi_send_aggregation_params_frame(common,
795 rsi_dbg(ERR_ZONE, "%s: Uknown AMPDU action\n", __func__);
799 mutex_unlock(&common->mutex);
804 * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value.
805 * @hw: Pointer to the ieee80211_hw structure.
806 * @value: Rts threshold value.
808 * Return: 0 on success.
810 static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw,
813 struct rsi_hw *adapter = hw->priv;
814 struct rsi_common *common = adapter->priv;
816 mutex_lock(&common->mutex);
817 common->rts_threshold = value;
818 mutex_unlock(&common->mutex);
824 * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used.
825 * @hw: Pointer to the ieee80211_hw structure
826 * @vif: Pointer to the ieee80211_vif structure.
827 * @mask: Pointer to the cfg80211_bitrate_mask structure.
829 * Return: 0 on success.
831 static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw,
832 struct ieee80211_vif *vif,
833 const struct cfg80211_bitrate_mask *mask)
835 struct rsi_hw *adapter = hw->priv;
836 struct rsi_common *common = adapter->priv;
837 enum nl80211_band band = hw->conf.chandef.chan->band;
839 mutex_lock(&common->mutex);
840 common->fixedrate_mask[band] = 0;
842 if (mask->control[band].legacy == 0xfff) {
843 common->fixedrate_mask[band] =
844 (mask->control[band].ht_mcs[0] << 12);
846 common->fixedrate_mask[band] =
847 mask->control[band].legacy;
849 mutex_unlock(&common->mutex);
855 * rsi_perform_cqm() - This function performs cqm.
856 * @common: Pointer to the driver private structure.
857 * @bssid: pointer to the bssid.
860 static void rsi_perform_cqm(struct rsi_common *common,
864 struct rsi_hw *adapter = common->priv;
865 s8 last_event = common->cqm_info.last_cqm_event_rssi;
866 int thold = common->cqm_info.rssi_thold;
867 u32 hyst = common->cqm_info.rssi_hyst;
868 enum nl80211_cqm_rssi_threshold_event event;
870 if (rssi < thold && (last_event == 0 || rssi < (last_event - hyst)))
871 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
872 else if (rssi > thold &&
873 (last_event == 0 || rssi > (last_event + hyst)))
874 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
878 common->cqm_info.last_cqm_event_rssi = rssi;
879 rsi_dbg(INFO_ZONE, "CQM: Notifying event: %d\n", event);
880 ieee80211_cqm_rssi_notify(adapter->vifs[0], event, GFP_KERNEL);
886 * rsi_fill_rx_status() - This function fills rx status in
887 * ieee80211_rx_status structure.
888 * @hw: Pointer to the ieee80211_hw structure.
889 * @skb: Pointer to the socket buffer structure.
890 * @common: Pointer to the driver private structure.
891 * @rxs: Pointer to the ieee80211_rx_status structure.
895 static void rsi_fill_rx_status(struct ieee80211_hw *hw,
897 struct rsi_common *common,
898 struct ieee80211_rx_status *rxs)
900 struct ieee80211_bss_conf *bss = &common->priv->vifs[0]->bss_conf;
901 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
902 struct skb_info *rx_params = (struct skb_info *)info->driver_data;
903 struct ieee80211_hdr *hdr;
904 char rssi = rx_params->rssi;
906 u8 channel = rx_params->channel;
909 hdr = ((struct ieee80211_hdr *)(skb->data));
910 hdrlen = ieee80211_hdrlen(hdr->frame_control);
912 memset(info, 0, sizeof(struct ieee80211_tx_info));
914 rxs->signal = -(rssi);
916 rxs->band = common->band;
918 freq = ieee80211_channel_to_frequency(channel, rxs->band);
923 if (ieee80211_has_protected(hdr->frame_control)) {
924 if (rsi_is_cipher_wep(common)) {
925 memmove(skb->data + 4, skb->data, hdrlen);
928 memmove(skb->data + 8, skb->data, hdrlen);
930 rxs->flag |= RX_FLAG_MMIC_STRIPPED;
932 rxs->flag |= RX_FLAG_DECRYPTED;
933 rxs->flag |= RX_FLAG_IV_STRIPPED;
936 /* CQM only for connected AP beacons, the RSSI is a weighted avg */
937 if (bss->assoc && !(memcmp(bss->bssid, hdr->addr2, ETH_ALEN))) {
938 if (ieee80211_is_beacon(hdr->frame_control))
939 rsi_perform_cqm(common, hdr->addr2, rxs->signal);
946 * rsi_indicate_pkt_to_os() - This function sends recieved packet to mac80211.
947 * @common: Pointer to the driver private structure.
948 * @skb: Pointer to the socket buffer structure.
952 void rsi_indicate_pkt_to_os(struct rsi_common *common,
955 struct rsi_hw *adapter = common->priv;
956 struct ieee80211_hw *hw = adapter->hw;
957 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
959 if ((common->iface_down) || (!adapter->sc_nvifs)) {
964 /* filling in the ieee80211_rx_status flags */
965 rsi_fill_rx_status(hw, skb, common, rx_status);
967 ieee80211_rx_irqsafe(hw, skb);
970 static void rsi_set_min_rate(struct ieee80211_hw *hw,
971 struct ieee80211_sta *sta,
972 struct rsi_common *common)
974 u8 band = hw->conf.chandef.chan->band;
977 bool matched = false;
979 common->bitrate_mask[band] = sta->supp_rates[band];
981 rate_bitmap = (common->fixedrate_mask[band] & sta->supp_rates[band]);
983 if (rate_bitmap & 0xfff) {
984 /* Find out the min rate */
985 for (ii = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
986 if (rate_bitmap & BIT(ii)) {
987 common->min_rate = rsi_rates[ii].hw_value;
994 common->vif_info[0].is_ht = sta->ht_cap.ht_supported;
996 if ((common->vif_info[0].is_ht) && (rate_bitmap >> 12)) {
997 for (ii = 0; ii < ARRAY_SIZE(rsi_mcsrates); ii++) {
998 if ((rate_bitmap >> 12) & BIT(ii)) {
999 common->min_rate = rsi_mcsrates[ii];
1007 common->min_rate = 0xffff;
1011 * rsi_mac80211_sta_add() - This function notifies driver about a peer getting
1013 * @hw: pointer to the ieee80211_hw structure.
1014 * @vif: Pointer to the ieee80211_vif structure.
1015 * @sta: Pointer to the ieee80211_sta structure.
1017 * Return: 0 on success, -1 on failure.
1019 static int rsi_mac80211_sta_add(struct ieee80211_hw *hw,
1020 struct ieee80211_vif *vif,
1021 struct ieee80211_sta *sta)
1023 struct rsi_hw *adapter = hw->priv;
1024 struct rsi_common *common = adapter->priv;
1026 mutex_lock(&common->mutex);
1028 rsi_set_min_rate(hw, sta, common);
1030 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
1031 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) {
1032 common->vif_info[0].sgi = true;
1035 if (sta->ht_cap.ht_supported)
1036 ieee80211_start_tx_ba_session(sta, 0, 0);
1038 mutex_unlock(&common->mutex);
1044 * rsi_mac80211_sta_remove() - This function notifies driver about a peer
1045 * getting disconnected.
1046 * @hw: Pointer to the ieee80211_hw structure.
1047 * @vif: Pointer to the ieee80211_vif structure.
1048 * @sta: Pointer to the ieee80211_sta structure.
1050 * Return: 0 on success, -1 on failure.
1052 static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw,
1053 struct ieee80211_vif *vif,
1054 struct ieee80211_sta *sta)
1056 struct rsi_hw *adapter = hw->priv;
1057 struct rsi_common *common = adapter->priv;
1059 mutex_lock(&common->mutex);
1061 /* Resetting all the fields to default values */
1062 common->bitrate_mask[NL80211_BAND_2GHZ] = 0;
1063 common->bitrate_mask[NL80211_BAND_5GHZ] = 0;
1064 common->min_rate = 0xffff;
1065 common->vif_info[0].is_ht = false;
1066 common->vif_info[0].sgi = false;
1067 common->vif_info[0].seq_start = 0;
1068 common->secinfo.ptk_cipher = 0;
1069 common->secinfo.gtk_cipher = 0;
1071 rsi_send_rx_filter_frame(common, 0);
1073 mutex_unlock(&common->mutex);
1079 * rsi_mac80211_set_antenna() - This function is used to configure
1080 * tx and rx antennas.
1081 * @hw: Pointer to the ieee80211_hw structure.
1082 * @tx_ant: Bitmap for tx antenna
1083 * @rx_ant: Bitmap for rx antenna
1085 * Return: 0 on success, Negative error code on failure.
1087 static int rsi_mac80211_set_antenna(struct ieee80211_hw *hw,
1088 u32 tx_ant, u32 rx_ant)
1090 struct rsi_hw *adapter = hw->priv;
1091 struct rsi_common *common = adapter->priv;
1094 if (tx_ant > 1 || rx_ant > 1) {
1096 "Invalid antenna selection (tx: %d, rx:%d)\n",
1099 "Use 0 for int_ant, 1 for ext_ant\n");
1103 rsi_dbg(INFO_ZONE, "%s: Antenna map Tx %x Rx %d\n",
1104 __func__, tx_ant, rx_ant);
1106 mutex_lock(&common->mutex);
1108 antenna = tx_ant ? ANTENNA_SEL_UFL : ANTENNA_SEL_INT;
1109 if (common->ant_in_use != antenna)
1110 if (rsi_set_antenna(common, antenna))
1111 goto fail_set_antenna;
1113 rsi_dbg(INFO_ZONE, "(%s) Antenna path configured successfully\n",
1114 tx_ant ? "UFL" : "INT");
1116 common->ant_in_use = antenna;
1118 mutex_unlock(&common->mutex);
1123 rsi_dbg(ERR_ZONE, "%s: Failed.\n", __func__);
1124 mutex_unlock(&common->mutex);
1129 * rsi_mac80211_get_antenna() - This function is used to configure
1130 * tx and rx antennas.
1132 * @hw: Pointer to the ieee80211_hw structure.
1133 * @tx_ant: Bitmap for tx antenna
1134 * @rx_ant: Bitmap for rx antenna
1136 * Return: 0 on success, -1 on failure.
1138 static int rsi_mac80211_get_antenna(struct ieee80211_hw *hw,
1139 u32 *tx_ant, u32 *rx_ant)
1141 struct rsi_hw *adapter = hw->priv;
1142 struct rsi_common *common = adapter->priv;
1144 mutex_lock(&common->mutex);
1146 *tx_ant = (common->ant_in_use == ANTENNA_SEL_UFL) ? 1 : 0;
1149 mutex_unlock(&common->mutex);
1154 static void rsi_reg_notify(struct wiphy *wiphy,
1155 struct regulatory_request *request)
1157 struct ieee80211_supported_band *sband;
1158 struct ieee80211_channel *ch;
1159 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1160 struct rsi_hw * adapter = hw->priv;
1163 sband = wiphy->bands[NL80211_BAND_5GHZ];
1165 for (i = 0; i < sband->n_channels; i++) {
1166 ch = &sband->channels[i];
1167 if (ch->flags & IEEE80211_CHAN_DISABLED)
1170 if (ch->flags & IEEE80211_CHAN_RADAR)
1171 ch->flags |= IEEE80211_CHAN_NO_IR;
1175 "country = %s dfs_region = %d\n",
1176 request->alpha2, request->dfs_region);
1177 adapter->dfs_region = request->dfs_region;
1180 static struct ieee80211_ops mac80211_ops = {
1181 .tx = rsi_mac80211_tx,
1182 .start = rsi_mac80211_start,
1183 .stop = rsi_mac80211_stop,
1184 .add_interface = rsi_mac80211_add_interface,
1185 .remove_interface = rsi_mac80211_remove_interface,
1186 .config = rsi_mac80211_config,
1187 .bss_info_changed = rsi_mac80211_bss_info_changed,
1188 .conf_tx = rsi_mac80211_conf_tx,
1189 .configure_filter = rsi_mac80211_conf_filter,
1190 .set_key = rsi_mac80211_set_key,
1191 .set_rts_threshold = rsi_mac80211_set_rts_threshold,
1192 .set_bitrate_mask = rsi_mac80211_set_rate_mask,
1193 .ampdu_action = rsi_mac80211_ampdu_action,
1194 .sta_add = rsi_mac80211_sta_add,
1195 .sta_remove = rsi_mac80211_sta_remove,
1196 .set_antenna = rsi_mac80211_set_antenna,
1197 .get_antenna = rsi_mac80211_get_antenna,
1201 * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack.
1202 * @common: Pointer to the driver private structure.
1204 * Return: 0 on success, -1 on failure.
1206 int rsi_mac80211_attach(struct rsi_common *common)
1209 struct ieee80211_hw *hw = NULL;
1210 struct wiphy *wiphy = NULL;
1211 struct rsi_hw *adapter = common->priv;
1212 u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3};
1214 rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__);
1216 hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops);
1218 rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__);
1224 SET_IEEE80211_DEV(hw, adapter->device);
1229 ieee80211_hw_set(hw, SIGNAL_DBM);
1230 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
1231 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
1233 hw->queues = MAX_HW_QUEUES;
1234 hw->extra_tx_headroom = RSI_NEEDED_HEADROOM;
1237 hw->max_rate_tries = MAX_RETRIES;
1239 hw->max_tx_aggregation_subframes = 6;
1240 rsi_register_rates_channels(adapter, NL80211_BAND_2GHZ);
1241 rsi_register_rates_channels(adapter, NL80211_BAND_5GHZ);
1242 hw->rate_control_algorithm = "AARF";
1244 SET_IEEE80211_PERM_ADDR(hw, common->mac_addr);
1245 ether_addr_copy(hw->wiphy->addr_mask, addr_mask);
1247 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1248 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1249 wiphy->retry_short = RETRY_SHORT;
1250 wiphy->retry_long = RETRY_LONG;
1251 wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1252 wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1255 wiphy->available_antennas_rx = 1;
1256 wiphy->available_antennas_tx = 1;
1257 wiphy->bands[NL80211_BAND_2GHZ] =
1258 &adapter->sbands[NL80211_BAND_2GHZ];
1259 wiphy->bands[NL80211_BAND_5GHZ] =
1260 &adapter->sbands[NL80211_BAND_5GHZ];
1262 wiphy->reg_notifier = rsi_reg_notify;
1264 status = ieee80211_register_hw(hw);
1268 return rsi_init_dbgfs(adapter);