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 = IEEE80211_BAND_2GHZ, .center_freq = 2412,
24 .hw_value = 1 }, /* Channel 1 */
25 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2417,
26 .hw_value = 2 }, /* Channel 2 */
27 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2422,
28 .hw_value = 3 }, /* Channel 3 */
29 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2427,
30 .hw_value = 4 }, /* Channel 4 */
31 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2432,
32 .hw_value = 5 }, /* Channel 5 */
33 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2437,
34 .hw_value = 6 }, /* Channel 6 */
35 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2442,
36 .hw_value = 7 }, /* Channel 7 */
37 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2447,
38 .hw_value = 8 }, /* Channel 8 */
39 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2452,
40 .hw_value = 9 }, /* Channel 9 */
41 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2457,
42 .hw_value = 10 }, /* Channel 10 */
43 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2462,
44 .hw_value = 11 }, /* Channel 11 */
45 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2467,
46 .hw_value = 12 }, /* Channel 12 */
47 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2472,
48 .hw_value = 13 }, /* Channel 13 */
49 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2484,
50 .hw_value = 14 }, /* Channel 14 */
53 static const struct ieee80211_channel rsi_5ghz_channels[] = {
54 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5180,
55 .hw_value = 36, }, /* Channel 36 */
56 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5200,
57 .hw_value = 40, }, /* Channel 40 */
58 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5220,
59 .hw_value = 44, }, /* Channel 44 */
60 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5240,
61 .hw_value = 48, }, /* Channel 48 */
62 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5260,
63 .hw_value = 52, }, /* Channel 52 */
64 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5280,
65 .hw_value = 56, }, /* Channel 56 */
66 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5300,
67 .hw_value = 60, }, /* Channel 60 */
68 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5320,
69 .hw_value = 64, }, /* Channel 64 */
70 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5500,
71 .hw_value = 100, }, /* Channel 100 */
72 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5520,
73 .hw_value = 104, }, /* Channel 104 */
74 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5540,
75 .hw_value = 108, }, /* Channel 108 */
76 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5560,
77 .hw_value = 112, }, /* Channel 112 */
78 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5580,
79 .hw_value = 116, }, /* Channel 116 */
80 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5600,
81 .hw_value = 120, }, /* Channel 120 */
82 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5620,
83 .hw_value = 124, }, /* Channel 124 */
84 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5640,
85 .hw_value = 128, }, /* Channel 128 */
86 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5660,
87 .hw_value = 132, }, /* Channel 132 */
88 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5680,
89 .hw_value = 136, }, /* Channel 136 */
90 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5700,
91 .hw_value = 140, }, /* Channel 140 */
92 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5745,
93 .hw_value = 149, }, /* Channel 149 */
94 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5765,
95 .hw_value = 153, }, /* Channel 153 */
96 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5785,
97 .hw_value = 157, }, /* Channel 157 */
98 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5805,
99 .hw_value = 161, }, /* Channel 161 */
100 { .band = IEEE80211_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 == IEEE80211_BAND_2GHZ) {
154 channels = kmalloc(sizeof(rsi_2ghz_channels), GFP_KERNEL);
157 sizeof(rsi_2ghz_channels));
158 sbands->band = IEEE80211_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 = IEEE80211_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;
199 ieee80211_stop_queues(hw);
200 ieee80211_unregister_hw(hw);
201 ieee80211_free_hw(hw);
205 rsi_remove_dbgfs(adapter);
207 EXPORT_SYMBOL_GPL(rsi_mac80211_detach);
210 * rsi_indicate_tx_status() - This function indicates the transmit status.
211 * @adapter: Pointer to the adapter structure.
212 * @skb: Pointer to the socket buffer structure.
217 void rsi_indicate_tx_status(struct rsi_hw *adapter,
221 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
223 memset(info->driver_data, 0, IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
226 info->flags |= IEEE80211_TX_STAT_ACK;
228 ieee80211_tx_status_irqsafe(adapter->hw, skb);
232 * rsi_mac80211_tx() - This is the handler that 802.11 module calls for each
233 * transmitted frame.SKB contains the buffer starting
234 * from the IEEE 802.11 header.
235 * @hw: Pointer to the ieee80211_hw structure.
236 * @control: Pointer to the ieee80211_tx_control structure
237 * @skb: Pointer to the socket buffer structure.
241 static void rsi_mac80211_tx(struct ieee80211_hw *hw,
242 struct ieee80211_tx_control *control,
245 struct rsi_hw *adapter = hw->priv;
246 struct rsi_common *common = adapter->priv;
248 rsi_core_xmit(common, skb);
252 * rsi_mac80211_start() - This is first handler that 802.11 module calls, since
253 * the driver init is complete by then, just
255 * @hw: Pointer to the ieee80211_hw structure.
257 * Return: 0 as success.
259 static int rsi_mac80211_start(struct ieee80211_hw *hw)
261 struct rsi_hw *adapter = hw->priv;
262 struct rsi_common *common = adapter->priv;
264 mutex_lock(&common->mutex);
265 common->iface_down = false;
266 mutex_unlock(&common->mutex);
272 * rsi_mac80211_stop() - This is the last handler that 802.11 module calls.
273 * @hw: Pointer to the ieee80211_hw structure.
277 static void rsi_mac80211_stop(struct ieee80211_hw *hw)
279 struct rsi_hw *adapter = hw->priv;
280 struct rsi_common *common = adapter->priv;
282 mutex_lock(&common->mutex);
283 common->iface_down = true;
284 mutex_unlock(&common->mutex);
288 * rsi_mac80211_add_interface() - This function is called when a netdevice
289 * attached to the hardware is enabled.
290 * @hw: Pointer to the ieee80211_hw structure.
291 * @vif: Pointer to the ieee80211_vif structure.
293 * Return: ret: 0 on success, negative error code on failure.
295 static int rsi_mac80211_add_interface(struct ieee80211_hw *hw,
296 struct ieee80211_vif *vif)
298 struct rsi_hw *adapter = hw->priv;
299 struct rsi_common *common = adapter->priv;
300 int ret = -EOPNOTSUPP;
302 mutex_lock(&common->mutex);
304 case NL80211_IFTYPE_STATION:
305 if (!adapter->sc_nvifs) {
307 adapter->vifs[0] = vif;
308 ret = rsi_set_vap_capabilities(common, STA_OPMODE);
313 "%s: Interface type %d not supported\n", __func__,
316 mutex_unlock(&common->mutex);
322 * rsi_mac80211_remove_interface() - This function notifies driver that an
323 * interface is going down.
324 * @hw: Pointer to the ieee80211_hw structure.
325 * @vif: Pointer to the ieee80211_vif structure.
329 static void rsi_mac80211_remove_interface(struct ieee80211_hw *hw,
330 struct ieee80211_vif *vif)
332 struct rsi_hw *adapter = hw->priv;
333 struct rsi_common *common = adapter->priv;
335 mutex_lock(&common->mutex);
336 if (vif->type == NL80211_IFTYPE_STATION)
339 if (!memcmp(adapter->vifs[0], vif, sizeof(struct ieee80211_vif)))
340 adapter->vifs[0] = NULL;
341 mutex_unlock(&common->mutex);
345 * rsi_channel_change() - This function is a performs the checks
346 * required for changing a channel and sets
347 * the channel accordingly.
348 * @hw: Pointer to the ieee80211_hw structure.
350 * Return: 0 on success, negative error code on failure.
352 static int rsi_channel_change(struct ieee80211_hw *hw)
354 struct rsi_hw *adapter = hw->priv;
355 struct rsi_common *common = adapter->priv;
356 int status = -EOPNOTSUPP;
357 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
358 u16 channel = curchan->hw_value;
359 struct ieee80211_bss_conf *bss = &adapter->vifs[0]->bss_conf;
362 "%s: Set channel: %d MHz type: %d channel_no %d\n",
363 __func__, curchan->center_freq,
364 curchan->flags, channel);
367 if (!common->hw_data_qs_blocked &&
368 (rsi_get_connected_channel(adapter) != channel)) {
369 rsi_dbg(INFO_ZONE, "blk data q %d\n", channel);
370 if (!rsi_send_block_unblock_frame(common, true))
371 common->hw_data_qs_blocked = true;
375 status = rsi_band_check(common);
377 status = rsi_set_channel(adapter->priv, channel);
380 if (common->hw_data_qs_blocked &&
381 (rsi_get_connected_channel(adapter) == channel)) {
382 rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel);
383 if (!rsi_send_block_unblock_frame(common, false))
384 common->hw_data_qs_blocked = false;
387 if (common->hw_data_qs_blocked) {
388 rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel);
389 if (!rsi_send_block_unblock_frame(common, false))
390 common->hw_data_qs_blocked = false;
398 * rsi_mac80211_config() - This function is a handler for configuration
399 * requests. The stack calls this function to
400 * change hardware configuration, e.g., channel.
401 * @hw: Pointer to the ieee80211_hw structure.
402 * @changed: Changed flags set.
404 * Return: 0 on success, negative error code on failure.
406 static int rsi_mac80211_config(struct ieee80211_hw *hw,
409 struct rsi_hw *adapter = hw->priv;
410 struct rsi_common *common = adapter->priv;
411 int status = -EOPNOTSUPP;
413 mutex_lock(&common->mutex);
415 if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
416 status = rsi_channel_change(hw);
418 mutex_unlock(&common->mutex);
424 * rsi_get_connected_channel() - This function is used to get the current
425 * connected channel number.
426 * @adapter: Pointer to the adapter structure.
428 * Return: Current connected AP's channel number is returned.
430 u16 rsi_get_connected_channel(struct rsi_hw *adapter)
432 struct ieee80211_vif *vif = adapter->vifs[0];
434 struct ieee80211_bss_conf *bss = &vif->bss_conf;
435 struct ieee80211_channel *channel = bss->chandef.chan;
436 return channel->hw_value;
443 * rsi_mac80211_bss_info_changed() - This function is a handler for config
444 * requests related to BSS parameters that
445 * may vary during BSS's lifespan.
446 * @hw: Pointer to the ieee80211_hw structure.
447 * @vif: Pointer to the ieee80211_vif structure.
448 * @bss_conf: Pointer to the ieee80211_bss_conf structure.
449 * @changed: Changed flags set.
453 static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw,
454 struct ieee80211_vif *vif,
455 struct ieee80211_bss_conf *bss_conf,
458 struct rsi_hw *adapter = hw->priv;
459 struct rsi_common *common = adapter->priv;
461 mutex_lock(&common->mutex);
462 if (changed & BSS_CHANGED_ASSOC) {
463 rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n",
464 __func__, bss_conf->assoc);
465 rsi_inform_bss_status(common,
472 if (changed & BSS_CHANGED_CQM) {
473 common->cqm_info.last_cqm_event_rssi = 0;
474 common->cqm_info.rssi_thold = bss_conf->cqm_rssi_thold;
475 common->cqm_info.rssi_hyst = bss_conf->cqm_rssi_hyst;
476 rsi_dbg(INFO_ZONE, "RSSI throld & hysteresis are: %d %d\n",
477 common->cqm_info.rssi_thold,
478 common->cqm_info.rssi_hyst);
480 mutex_unlock(&common->mutex);
484 * rsi_mac80211_conf_filter() - This function configure the device's RX filter.
485 * @hw: Pointer to the ieee80211_hw structure.
486 * @changed: Changed flags set.
487 * @total_flags: Total initial flags set.
488 * @multicast: Multicast.
492 static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw,
497 /* Not doing much here as of now */
498 *total_flags &= RSI_SUPP_FILTERS;
502 * rsi_mac80211_conf_tx() - This function configures TX queue parameters
503 * (EDCF (aifs, cw_min, cw_max), bursting)
504 * for a hardware TX queue.
505 * @hw: Pointer to the ieee80211_hw structure
506 * @vif: Pointer to the ieee80211_vif structure.
507 * @queue: Queue number.
508 * @params: Pointer to ieee80211_tx_queue_params structure.
510 * Return: 0 on success, negative error code on failure.
512 static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw,
513 struct ieee80211_vif *vif, u16 queue,
514 const struct ieee80211_tx_queue_params *params)
516 struct rsi_hw *adapter = hw->priv;
517 struct rsi_common *common = adapter->priv;
520 if (queue >= IEEE80211_NUM_ACS)
524 "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n",
525 __func__, queue, params->aifs,
526 params->cw_min, params->cw_max, params->txop);
528 mutex_lock(&common->mutex);
529 /* Map into the way the f/w expects */
531 case IEEE80211_AC_VO:
534 case IEEE80211_AC_VI:
537 case IEEE80211_AC_BE:
540 case IEEE80211_AC_BK:
548 memcpy(&common->edca_params[idx],
550 sizeof(struct ieee80211_tx_queue_params));
551 mutex_unlock(&common->mutex);
557 * rsi_hal_key_config() - This function loads the keys into the firmware.
558 * @hw: Pointer to the ieee80211_hw structure.
559 * @vif: Pointer to the ieee80211_vif structure.
560 * @key: Pointer to the ieee80211_key_conf structure.
562 * Return: status: 0 on success, -1 on failure.
564 static int rsi_hal_key_config(struct ieee80211_hw *hw,
565 struct ieee80211_vif *vif,
566 struct ieee80211_key_conf *key)
568 struct rsi_hw *adapter = hw->priv;
572 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
573 key_type = RSI_PAIRWISE_KEY;
575 key_type = RSI_GROUP_KEY;
577 rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n",
578 __func__, key->cipher, key_type, key->keylen);
580 if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
581 (key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
582 status = rsi_hal_load_key(adapter->priv,
591 return rsi_hal_load_key(adapter->priv,
600 * rsi_mac80211_set_key() - This function sets type of key to be loaded.
601 * @hw: Pointer to the ieee80211_hw structure.
602 * @cmd: enum set_key_cmd.
603 * @vif: Pointer to the ieee80211_vif structure.
604 * @sta: Pointer to the ieee80211_sta structure.
605 * @key: Pointer to the ieee80211_key_conf structure.
607 * Return: status: 0 on success, negative error code on failure.
609 static int rsi_mac80211_set_key(struct ieee80211_hw *hw,
610 enum set_key_cmd cmd,
611 struct ieee80211_vif *vif,
612 struct ieee80211_sta *sta,
613 struct ieee80211_key_conf *key)
615 struct rsi_hw *adapter = hw->priv;
616 struct rsi_common *common = adapter->priv;
617 struct security_info *secinfo = &common->secinfo;
620 mutex_lock(&common->mutex);
623 secinfo->security_enable = true;
624 status = rsi_hal_key_config(hw, vif, key);
626 mutex_unlock(&common->mutex);
630 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
631 secinfo->ptk_cipher = key->cipher;
633 secinfo->gtk_cipher = key->cipher;
635 key->hw_key_idx = key->keyidx;
636 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
638 rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__);
642 secinfo->security_enable = false;
643 rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__);
644 memset(key, 0, sizeof(struct ieee80211_key_conf));
645 status = rsi_hal_key_config(hw, vif, key);
649 status = -EOPNOTSUPP;
653 mutex_unlock(&common->mutex);
658 * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for
659 * the corresponding mlme_action flag and
660 * informs the f/w regarding this.
661 * @hw: Pointer to the ieee80211_hw structure.
662 * @vif: Pointer to the ieee80211_vif structure.
663 * @params: Pointer to A-MPDU action parameters
665 * Return: status: 0 on success, negative error code on failure.
667 static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw,
668 struct ieee80211_vif *vif,
669 struct ieee80211_ampdu_params *params)
671 int status = -EOPNOTSUPP;
672 struct rsi_hw *adapter = hw->priv;
673 struct rsi_common *common = adapter->priv;
676 struct ieee80211_sta *sta = params->sta;
677 enum ieee80211_ampdu_mlme_action action = params->action;
678 u16 tid = params->tid;
679 u16 *ssn = ¶ms->ssn;
680 u8 buf_size = params->buf_size;
682 for (ii = 0; ii < RSI_MAX_VIFS; ii++) {
683 if (vif == adapter->vifs[ii])
687 mutex_lock(&common->mutex);
688 rsi_dbg(INFO_ZONE, "%s: AMPDU action %d called\n", __func__, action);
693 case IEEE80211_AMPDU_RX_START:
694 status = rsi_send_aggregation_params_frame(common,
701 case IEEE80211_AMPDU_RX_STOP:
702 status = rsi_send_aggregation_params_frame(common,
709 case IEEE80211_AMPDU_TX_START:
710 common->vif_info[ii].seq_start = seq_no;
711 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
715 case IEEE80211_AMPDU_TX_STOP_CONT:
716 case IEEE80211_AMPDU_TX_STOP_FLUSH:
717 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
718 status = rsi_send_aggregation_params_frame(common,
724 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
727 case IEEE80211_AMPDU_TX_OPERATIONAL:
728 status = rsi_send_aggregation_params_frame(common,
737 rsi_dbg(ERR_ZONE, "%s: Uknown AMPDU action\n", __func__);
741 mutex_unlock(&common->mutex);
746 * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value.
747 * @hw: Pointer to the ieee80211_hw structure.
748 * @value: Rts threshold value.
750 * Return: 0 on success.
752 static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw,
755 struct rsi_hw *adapter = hw->priv;
756 struct rsi_common *common = adapter->priv;
758 mutex_lock(&common->mutex);
759 common->rts_threshold = value;
760 mutex_unlock(&common->mutex);
766 * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used.
767 * @hw: Pointer to the ieee80211_hw structure
768 * @vif: Pointer to the ieee80211_vif structure.
769 * @mask: Pointer to the cfg80211_bitrate_mask structure.
771 * Return: 0 on success.
773 static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw,
774 struct ieee80211_vif *vif,
775 const struct cfg80211_bitrate_mask *mask)
777 struct rsi_hw *adapter = hw->priv;
778 struct rsi_common *common = adapter->priv;
779 enum ieee80211_band band = hw->conf.chandef.chan->band;
781 mutex_lock(&common->mutex);
782 common->fixedrate_mask[band] = 0;
784 if (mask->control[band].legacy == 0xfff) {
785 common->fixedrate_mask[band] =
786 (mask->control[band].ht_mcs[0] << 12);
788 common->fixedrate_mask[band] =
789 mask->control[band].legacy;
791 mutex_unlock(&common->mutex);
797 * rsi_perform_cqm() - This function performs cqm.
798 * @common: Pointer to the driver private structure.
799 * @bssid: pointer to the bssid.
802 static void rsi_perform_cqm(struct rsi_common *common,
806 struct rsi_hw *adapter = common->priv;
807 s8 last_event = common->cqm_info.last_cqm_event_rssi;
808 int thold = common->cqm_info.rssi_thold;
809 u32 hyst = common->cqm_info.rssi_hyst;
810 enum nl80211_cqm_rssi_threshold_event event;
812 if (rssi < thold && (last_event == 0 || rssi < (last_event - hyst)))
813 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
814 else if (rssi > thold &&
815 (last_event == 0 || rssi > (last_event + hyst)))
816 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
820 common->cqm_info.last_cqm_event_rssi = rssi;
821 rsi_dbg(INFO_ZONE, "CQM: Notifying event: %d\n", event);
822 ieee80211_cqm_rssi_notify(adapter->vifs[0], event, GFP_KERNEL);
828 * rsi_fill_rx_status() - This function fills rx status in
829 * ieee80211_rx_status structure.
830 * @hw: Pointer to the ieee80211_hw structure.
831 * @skb: Pointer to the socket buffer structure.
832 * @common: Pointer to the driver private structure.
833 * @rxs: Pointer to the ieee80211_rx_status structure.
837 static void rsi_fill_rx_status(struct ieee80211_hw *hw,
839 struct rsi_common *common,
840 struct ieee80211_rx_status *rxs)
842 struct ieee80211_bss_conf *bss = &common->priv->vifs[0]->bss_conf;
843 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
844 struct skb_info *rx_params = (struct skb_info *)info->driver_data;
845 struct ieee80211_hdr *hdr;
846 char rssi = rx_params->rssi;
848 u8 channel = rx_params->channel;
851 hdr = ((struct ieee80211_hdr *)(skb->data));
852 hdrlen = ieee80211_hdrlen(hdr->frame_control);
854 memset(info, 0, sizeof(struct ieee80211_tx_info));
856 rxs->signal = -(rssi);
858 rxs->band = common->band;
860 freq = ieee80211_channel_to_frequency(channel, rxs->band);
865 if (ieee80211_has_protected(hdr->frame_control)) {
866 if (rsi_is_cipher_wep(common)) {
867 memmove(skb->data + 4, skb->data, hdrlen);
870 memmove(skb->data + 8, skb->data, hdrlen);
872 rxs->flag |= RX_FLAG_MMIC_STRIPPED;
874 rxs->flag |= RX_FLAG_DECRYPTED;
875 rxs->flag |= RX_FLAG_IV_STRIPPED;
878 /* CQM only for connected AP beacons, the RSSI is a weighted avg */
879 if (bss->assoc && !(memcmp(bss->bssid, hdr->addr2, ETH_ALEN))) {
880 if (ieee80211_is_beacon(hdr->frame_control))
881 rsi_perform_cqm(common, hdr->addr2, rxs->signal);
888 * rsi_indicate_pkt_to_os() - This function sends recieved packet to mac80211.
889 * @common: Pointer to the driver private structure.
890 * @skb: Pointer to the socket buffer structure.
894 void rsi_indicate_pkt_to_os(struct rsi_common *common,
897 struct rsi_hw *adapter = common->priv;
898 struct ieee80211_hw *hw = adapter->hw;
899 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
901 if ((common->iface_down) || (!adapter->sc_nvifs)) {
906 /* filling in the ieee80211_rx_status flags */
907 rsi_fill_rx_status(hw, skb, common, rx_status);
909 ieee80211_rx_irqsafe(hw, skb);
912 static void rsi_set_min_rate(struct ieee80211_hw *hw,
913 struct ieee80211_sta *sta,
914 struct rsi_common *common)
916 u8 band = hw->conf.chandef.chan->band;
919 bool matched = false;
921 common->bitrate_mask[band] = sta->supp_rates[band];
923 rate_bitmap = (common->fixedrate_mask[band] & sta->supp_rates[band]);
925 if (rate_bitmap & 0xfff) {
926 /* Find out the min rate */
927 for (ii = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
928 if (rate_bitmap & BIT(ii)) {
929 common->min_rate = rsi_rates[ii].hw_value;
936 common->vif_info[0].is_ht = sta->ht_cap.ht_supported;
938 if ((common->vif_info[0].is_ht) && (rate_bitmap >> 12)) {
939 for (ii = 0; ii < ARRAY_SIZE(rsi_mcsrates); ii++) {
940 if ((rate_bitmap >> 12) & BIT(ii)) {
941 common->min_rate = rsi_mcsrates[ii];
949 common->min_rate = 0xffff;
953 * rsi_mac80211_sta_add() - This function notifies driver about a peer getting
955 * @hw: pointer to the ieee80211_hw structure.
956 * @vif: Pointer to the ieee80211_vif structure.
957 * @sta: Pointer to the ieee80211_sta structure.
959 * Return: 0 on success, -1 on failure.
961 static int rsi_mac80211_sta_add(struct ieee80211_hw *hw,
962 struct ieee80211_vif *vif,
963 struct ieee80211_sta *sta)
965 struct rsi_hw *adapter = hw->priv;
966 struct rsi_common *common = adapter->priv;
968 mutex_lock(&common->mutex);
970 rsi_set_min_rate(hw, sta, common);
972 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
973 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) {
974 common->vif_info[0].sgi = true;
977 if (sta->ht_cap.ht_supported)
978 ieee80211_start_tx_ba_session(sta, 0, 0);
980 mutex_unlock(&common->mutex);
986 * rsi_mac80211_sta_remove() - This function notifies driver about a peer
987 * getting disconnected.
988 * @hw: Pointer to the ieee80211_hw structure.
989 * @vif: Pointer to the ieee80211_vif structure.
990 * @sta: Pointer to the ieee80211_sta structure.
992 * Return: 0 on success, -1 on failure.
994 static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw,
995 struct ieee80211_vif *vif,
996 struct ieee80211_sta *sta)
998 struct rsi_hw *adapter = hw->priv;
999 struct rsi_common *common = adapter->priv;
1001 mutex_lock(&common->mutex);
1002 /* Resetting all the fields to default values */
1003 common->bitrate_mask[IEEE80211_BAND_2GHZ] = 0;
1004 common->bitrate_mask[IEEE80211_BAND_5GHZ] = 0;
1005 common->min_rate = 0xffff;
1006 common->vif_info[0].is_ht = false;
1007 common->vif_info[0].sgi = false;
1008 common->vif_info[0].seq_start = 0;
1009 common->secinfo.ptk_cipher = 0;
1010 common->secinfo.gtk_cipher = 0;
1011 mutex_unlock(&common->mutex);
1016 static struct ieee80211_ops mac80211_ops = {
1017 .tx = rsi_mac80211_tx,
1018 .start = rsi_mac80211_start,
1019 .stop = rsi_mac80211_stop,
1020 .add_interface = rsi_mac80211_add_interface,
1021 .remove_interface = rsi_mac80211_remove_interface,
1022 .config = rsi_mac80211_config,
1023 .bss_info_changed = rsi_mac80211_bss_info_changed,
1024 .conf_tx = rsi_mac80211_conf_tx,
1025 .configure_filter = rsi_mac80211_conf_filter,
1026 .set_key = rsi_mac80211_set_key,
1027 .set_rts_threshold = rsi_mac80211_set_rts_threshold,
1028 .set_bitrate_mask = rsi_mac80211_set_rate_mask,
1029 .ampdu_action = rsi_mac80211_ampdu_action,
1030 .sta_add = rsi_mac80211_sta_add,
1031 .sta_remove = rsi_mac80211_sta_remove,
1035 * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack.
1036 * @common: Pointer to the driver private structure.
1038 * Return: 0 on success, -1 on failure.
1040 int rsi_mac80211_attach(struct rsi_common *common)
1043 struct ieee80211_hw *hw = NULL;
1044 struct wiphy *wiphy = NULL;
1045 struct rsi_hw *adapter = common->priv;
1046 u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3};
1048 rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__);
1050 hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops);
1052 rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__);
1058 SET_IEEE80211_DEV(hw, adapter->device);
1063 ieee80211_hw_set(hw, SIGNAL_DBM);
1064 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
1065 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
1067 hw->queues = MAX_HW_QUEUES;
1068 hw->extra_tx_headroom = RSI_NEEDED_HEADROOM;
1071 hw->max_rate_tries = MAX_RETRIES;
1073 hw->max_tx_aggregation_subframes = 6;
1074 rsi_register_rates_channels(adapter, IEEE80211_BAND_2GHZ);
1075 rsi_register_rates_channels(adapter, IEEE80211_BAND_5GHZ);
1076 hw->rate_control_algorithm = "AARF";
1078 SET_IEEE80211_PERM_ADDR(hw, common->mac_addr);
1079 ether_addr_copy(hw->wiphy->addr_mask, addr_mask);
1081 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1082 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1083 wiphy->retry_short = RETRY_SHORT;
1084 wiphy->retry_long = RETRY_LONG;
1085 wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1086 wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1089 wiphy->available_antennas_rx = 1;
1090 wiphy->available_antennas_tx = 1;
1091 wiphy->bands[IEEE80211_BAND_2GHZ] =
1092 &adapter->sbands[IEEE80211_BAND_2GHZ];
1093 wiphy->bands[IEEE80211_BAND_5GHZ] =
1094 &adapter->sbands[IEEE80211_BAND_5GHZ];
1096 status = ieee80211_register_hw(hw);
1100 return rsi_init_dbgfs(adapter);