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_8K;
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_attach() - 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);
204 rsi_remove_dbgfs(adapter);
206 EXPORT_SYMBOL_GPL(rsi_mac80211_detach);
209 * rsi_indicate_tx_status() - This function indicates the transmit status.
210 * @adapter: Pointer to the adapter structure.
211 * @skb: Pointer to the socket buffer structure.
216 void rsi_indicate_tx_status(struct rsi_hw *adapter,
220 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
222 memset(info->driver_data, 0, IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
225 info->flags |= IEEE80211_TX_STAT_ACK;
227 ieee80211_tx_status_irqsafe(adapter->hw, skb);
231 * rsi_mac80211_tx() - This is the handler that 802.11 module calls for each
232 * transmitted frame.SKB contains the buffer starting
233 * from the IEEE 802.11 header.
234 * @hw: Pointer to the ieee80211_hw structure.
235 * @control: Pointer to the ieee80211_tx_control structure
236 * @skb: Pointer to the socket buffer structure.
240 static void rsi_mac80211_tx(struct ieee80211_hw *hw,
241 struct ieee80211_tx_control *control,
244 struct rsi_hw *adapter = hw->priv;
245 struct rsi_common *common = adapter->priv;
247 rsi_core_xmit(common, skb);
251 * rsi_mac80211_start() - This is first handler that 802.11 module calls, since
252 * the driver init is complete by then, just
254 * @hw: Pointer to the ieee80211_hw structure.
256 * Return: 0 as success.
258 static int rsi_mac80211_start(struct ieee80211_hw *hw)
260 struct rsi_hw *adapter = hw->priv;
261 struct rsi_common *common = adapter->priv;
263 mutex_lock(&common->mutex);
264 common->iface_down = false;
265 mutex_unlock(&common->mutex);
271 * rsi_mac80211_stop() - This is the last handler that 802.11 module calls.
272 * @hw: Pointer to the ieee80211_hw structure.
276 static void rsi_mac80211_stop(struct ieee80211_hw *hw)
278 struct rsi_hw *adapter = hw->priv;
279 struct rsi_common *common = adapter->priv;
281 mutex_lock(&common->mutex);
282 common->iface_down = true;
283 mutex_unlock(&common->mutex);
287 * rsi_mac80211_add_interface() - This function is called when a netdevice
288 * attached to the hardware is enabled.
289 * @hw: Pointer to the ieee80211_hw structure.
290 * @vif: Pointer to the ieee80211_vif structure.
292 * Return: ret: 0 on success, negative error code on failure.
294 static int rsi_mac80211_add_interface(struct ieee80211_hw *hw,
295 struct ieee80211_vif *vif)
297 struct rsi_hw *adapter = hw->priv;
298 struct rsi_common *common = adapter->priv;
299 int ret = -EOPNOTSUPP;
301 mutex_lock(&common->mutex);
303 case NL80211_IFTYPE_STATION:
304 if (!adapter->sc_nvifs) {
306 adapter->vifs[0] = vif;
307 ret = rsi_set_vap_capabilities(common, STA_OPMODE);
312 "%s: Interface type %d not supported\n", __func__,
315 mutex_unlock(&common->mutex);
321 * rsi_mac80211_remove_interface() - This function notifies driver that an
322 * interface is going down.
323 * @hw: Pointer to the ieee80211_hw structure.
324 * @vif: Pointer to the ieee80211_vif structure.
328 static void rsi_mac80211_remove_interface(struct ieee80211_hw *hw,
329 struct ieee80211_vif *vif)
331 struct rsi_hw *adapter = hw->priv;
332 struct rsi_common *common = adapter->priv;
334 mutex_lock(&common->mutex);
335 if (vif->type == NL80211_IFTYPE_STATION)
338 if (!memcmp(adapter->vifs[0], vif, sizeof(struct ieee80211_vif)))
339 adapter->vifs[0] = NULL;
340 mutex_unlock(&common->mutex);
344 * rsi_mac80211_config() - This function is a handler for configuration
345 * requests. The stack calls this function to
346 * change hardware configuration, e.g., channel.
347 * @hw: Pointer to the ieee80211_hw structure.
348 * @changed: Changed flags set.
350 * Return: 0 on success, negative error code on failure.
352 static int rsi_mac80211_config(struct ieee80211_hw *hw,
355 struct rsi_hw *adapter = hw->priv;
356 struct rsi_common *common = adapter->priv;
357 int status = -EOPNOTSUPP;
359 mutex_lock(&common->mutex);
360 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
361 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
362 u16 channel = curchan->hw_value;
365 "%s: Set channel: %d MHz type: %d channel_no %d\n",
366 __func__, curchan->center_freq,
367 curchan->flags, channel);
368 common->band = curchan->band;
369 status = rsi_set_channel(adapter->priv, channel);
371 mutex_unlock(&common->mutex);
377 * rsi_get_connected_channel() - This function is used to get the current
378 * connected channel number.
379 * @adapter: Pointer to the adapter structure.
381 * Return: Current connected AP's channel number is returned.
383 u16 rsi_get_connected_channel(struct rsi_hw *adapter)
385 struct ieee80211_vif *vif = adapter->vifs[0];
387 struct ieee80211_bss_conf *bss = &vif->bss_conf;
388 struct ieee80211_channel *channel = bss->chandef.chan;
389 return channel->hw_value;
396 * rsi_mac80211_bss_info_changed() - This function is a handler for config
397 * requests related to BSS parameters that
398 * may vary during BSS's lifespan.
399 * @hw: Pointer to the ieee80211_hw structure.
400 * @vif: Pointer to the ieee80211_vif structure.
401 * @bss_conf: Pointer to the ieee80211_bss_conf structure.
402 * @changed: Changed flags set.
406 static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw,
407 struct ieee80211_vif *vif,
408 struct ieee80211_bss_conf *bss_conf,
411 struct rsi_hw *adapter = hw->priv;
412 struct rsi_common *common = adapter->priv;
414 mutex_lock(&common->mutex);
415 if (changed & BSS_CHANGED_ASSOC) {
416 rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n",
417 __func__, bss_conf->assoc);
418 rsi_inform_bss_status(common,
424 mutex_unlock(&common->mutex);
428 * rsi_mac80211_conf_filter() - This function configure the device's RX filter.
429 * @hw: Pointer to the ieee80211_hw structure.
430 * @changed: Changed flags set.
431 * @total_flags: Total initial flags set.
432 * @multicast: Multicast.
436 static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw,
441 /* Not doing much here as of now */
442 *total_flags &= RSI_SUPP_FILTERS;
446 * rsi_mac80211_conf_tx() - This function configures TX queue parameters
447 * (EDCF (aifs, cw_min, cw_max), bursting)
448 * for a hardware TX queue.
449 * @hw: Pointer to the ieee80211_hw structure
450 * @vif: Pointer to the ieee80211_vif structure.
451 * @queue: Queue number.
452 * @params: Pointer to ieee80211_tx_queue_params structure.
454 * Return: 0 on success, negative error code on failure.
456 static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw,
457 struct ieee80211_vif *vif, u16 queue,
458 const struct ieee80211_tx_queue_params *params)
460 struct rsi_hw *adapter = hw->priv;
461 struct rsi_common *common = adapter->priv;
464 if (queue >= IEEE80211_NUM_ACS)
468 "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n",
469 __func__, queue, params->aifs,
470 params->cw_min, params->cw_max, params->txop);
472 mutex_lock(&common->mutex);
473 /* Map into the way the f/w expects */
475 case IEEE80211_AC_VO:
478 case IEEE80211_AC_VI:
481 case IEEE80211_AC_BE:
484 case IEEE80211_AC_BK:
492 memcpy(&common->edca_params[idx],
494 sizeof(struct ieee80211_tx_queue_params));
495 mutex_unlock(&common->mutex);
501 * rsi_hal_key_config() - This function loads the keys into the firmware.
502 * @hw: Pointer to the ieee80211_hw structure.
503 * @vif: Pointer to the ieee80211_vif structure.
504 * @key: Pointer to the ieee80211_key_conf structure.
506 * Return: status: 0 on success, -1 on failure.
508 static int rsi_hal_key_config(struct ieee80211_hw *hw,
509 struct ieee80211_vif *vif,
510 struct ieee80211_key_conf *key)
512 struct rsi_hw *adapter = hw->priv;
516 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
517 key_type = RSI_PAIRWISE_KEY;
519 key_type = RSI_GROUP_KEY;
521 rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n",
522 __func__, key->cipher, key_type, key->keylen);
524 if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
525 (key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
526 status = rsi_hal_load_key(adapter->priv,
535 return rsi_hal_load_key(adapter->priv,
544 * rsi_mac80211_set_key() - This function sets type of key to be loaded.
545 * @hw: Pointer to the ieee80211_hw structure.
546 * @cmd: enum set_key_cmd.
547 * @vif: Pointer to the ieee80211_vif structure.
548 * @sta: Pointer to the ieee80211_sta structure.
549 * @key: Pointer to the ieee80211_key_conf structure.
551 * Return: status: 0 on success, negative error code on failure.
553 static int rsi_mac80211_set_key(struct ieee80211_hw *hw,
554 enum set_key_cmd cmd,
555 struct ieee80211_vif *vif,
556 struct ieee80211_sta *sta,
557 struct ieee80211_key_conf *key)
559 struct rsi_hw *adapter = hw->priv;
560 struct rsi_common *common = adapter->priv;
561 struct security_info *secinfo = &common->secinfo;
564 mutex_lock(&common->mutex);
567 secinfo->security_enable = true;
568 status = rsi_hal_key_config(hw, vif, key);
570 mutex_unlock(&common->mutex);
574 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
575 secinfo->ptk_cipher = key->cipher;
577 secinfo->gtk_cipher = key->cipher;
579 key->hw_key_idx = key->keyidx;
580 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
582 rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__);
586 secinfo->security_enable = false;
587 rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__);
588 memset(key, 0, sizeof(struct ieee80211_key_conf));
589 status = rsi_hal_key_config(hw, vif, key);
593 status = -EOPNOTSUPP;
597 mutex_unlock(&common->mutex);
602 * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for
603 * the corresponding mlme_action flag and
604 * informs the f/w regarding this.
605 * @hw: Pointer to the ieee80211_hw structure.
606 * @vif: Pointer to the ieee80211_vif structure.
607 * @action: ieee80211_ampdu_mlme_action enum.
608 * @sta: Pointer to the ieee80211_sta structure.
609 * @tid: Traffic identifier.
610 * @ssn: Pointer to ssn value.
611 * @buf_size: Buffer size (for kernel version > 2.6.38).
613 * Return: status: 0 on success, negative error code on failure.
615 static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw,
616 struct ieee80211_vif *vif,
617 enum ieee80211_ampdu_mlme_action action,
618 struct ieee80211_sta *sta,
621 unsigned char buf_size)
623 int status = -EOPNOTSUPP;
624 struct rsi_hw *adapter = hw->priv;
625 struct rsi_common *common = adapter->priv;
629 for (ii = 0; ii < RSI_MAX_VIFS; ii++) {
630 if (vif == adapter->vifs[ii])
634 mutex_lock(&common->mutex);
635 rsi_dbg(INFO_ZONE, "%s: AMPDU action %d called\n", __func__, action);
640 case IEEE80211_AMPDU_RX_START:
641 status = rsi_send_aggregation_params_frame(common,
648 case IEEE80211_AMPDU_RX_STOP:
649 status = rsi_send_aggregation_params_frame(common,
656 case IEEE80211_AMPDU_TX_START:
657 common->vif_info[ii].seq_start = seq_no;
658 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
661 case IEEE80211_AMPDU_TX_STOP_CONT:
662 case IEEE80211_AMPDU_TX_STOP_FLUSH:
663 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
664 status = rsi_send_aggregation_params_frame(common,
670 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
673 case IEEE80211_AMPDU_TX_OPERATIONAL:
674 status = rsi_send_aggregation_params_frame(common,
683 rsi_dbg(ERR_ZONE, "%s: Uknown AMPDU action\n", __func__);
687 mutex_unlock(&common->mutex);
692 * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value.
693 * @hw: Pointer to the ieee80211_hw structure.
694 * @value: Rts threshold value.
696 * Return: 0 on success.
698 static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw,
701 struct rsi_hw *adapter = hw->priv;
702 struct rsi_common *common = adapter->priv;
704 mutex_lock(&common->mutex);
705 common->rts_threshold = value;
706 mutex_unlock(&common->mutex);
712 * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used.
713 * @hw: Pointer to the ieee80211_hw structure
714 * @vif: Pointer to the ieee80211_vif structure.
715 * @mask: Pointer to the cfg80211_bitrate_mask structure.
717 * Return: 0 on success.
719 static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw,
720 struct ieee80211_vif *vif,
721 const struct cfg80211_bitrate_mask *mask)
723 struct rsi_hw *adapter = hw->priv;
724 struct rsi_common *common = adapter->priv;
726 mutex_lock(&common->mutex);
728 common->fixedrate_mask[IEEE80211_BAND_2GHZ] = 0;
730 if (mask->control[IEEE80211_BAND_2GHZ].legacy == 0xfff) {
731 common->fixedrate_mask[IEEE80211_BAND_2GHZ] =
732 (mask->control[IEEE80211_BAND_2GHZ].ht_mcs[0] << 12);
734 common->fixedrate_mask[IEEE80211_BAND_2GHZ] =
735 mask->control[IEEE80211_BAND_2GHZ].legacy;
737 mutex_unlock(&common->mutex);
743 * rsi_fill_rx_status() - This function fills rx status in
744 * ieee80211_rx_status structure.
745 * @hw: Pointer to the ieee80211_hw structure.
746 * @skb: Pointer to the socket buffer structure.
747 * @common: Pointer to the driver private structure.
748 * @rxs: Pointer to the ieee80211_rx_status structure.
752 static void rsi_fill_rx_status(struct ieee80211_hw *hw,
754 struct rsi_common *common,
755 struct ieee80211_rx_status *rxs)
757 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
758 struct skb_info *rx_params = (struct skb_info *)info->driver_data;
759 struct ieee80211_hdr *hdr;
760 char rssi = rx_params->rssi;
762 u8 channel = rx_params->channel;
765 hdr = ((struct ieee80211_hdr *)(skb->data));
766 hdrlen = ieee80211_hdrlen(hdr->frame_control);
768 memset(info, 0, sizeof(struct ieee80211_tx_info));
770 rxs->signal = -(rssi);
773 rxs->band = IEEE80211_BAND_2GHZ;
775 rxs->band = IEEE80211_BAND_5GHZ;
777 freq = ieee80211_channel_to_frequency(channel, rxs->band);
782 if (ieee80211_has_protected(hdr->frame_control)) {
783 if (rsi_is_cipher_wep(common)) {
784 memmove(skb->data + 4, skb->data, hdrlen);
787 memmove(skb->data + 8, skb->data, hdrlen);
789 rxs->flag |= RX_FLAG_MMIC_STRIPPED;
791 rxs->flag |= RX_FLAG_DECRYPTED;
792 rxs->flag |= RX_FLAG_IV_STRIPPED;
797 * rsi_indicate_pkt_to_os() - This function sends recieved packet to mac80211.
798 * @common: Pointer to the driver private structure.
799 * @skb: Pointer to the socket buffer structure.
803 void rsi_indicate_pkt_to_os(struct rsi_common *common,
806 struct rsi_hw *adapter = common->priv;
807 struct ieee80211_hw *hw = adapter->hw;
808 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
810 if ((common->iface_down) || (!adapter->sc_nvifs)) {
815 /* filling in the ieee80211_rx_status flags */
816 rsi_fill_rx_status(hw, skb, common, rx_status);
818 ieee80211_rx_irqsafe(hw, skb);
821 static void rsi_set_min_rate(struct ieee80211_hw *hw,
822 struct ieee80211_sta *sta,
823 struct rsi_common *common)
825 u8 band = hw->conf.chandef.chan->band;
828 bool matched = false;
830 common->bitrate_mask[band] = sta->supp_rates[band];
832 rate_bitmap = (common->fixedrate_mask[band] & sta->supp_rates[band]);
834 if (rate_bitmap & 0xfff) {
835 /* Find out the min rate */
836 for (ii = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
837 if (rate_bitmap & BIT(ii)) {
838 common->min_rate = rsi_rates[ii].hw_value;
845 common->vif_info[0].is_ht = sta->ht_cap.ht_supported;
847 if ((common->vif_info[0].is_ht) && (rate_bitmap >> 12)) {
848 for (ii = 0; ii < ARRAY_SIZE(rsi_mcsrates); ii++) {
849 if ((rate_bitmap >> 12) & BIT(ii)) {
850 common->min_rate = rsi_mcsrates[ii];
858 common->min_rate = 0xffff;
862 * rsi_mac80211_sta_add() - This function notifies driver about a peer getting
864 * @hw: pointer to the ieee80211_hw structure.
865 * @vif: Pointer to the ieee80211_vif structure.
866 * @sta: Pointer to the ieee80211_sta structure.
868 * Return: 0 on success, -1 on failure.
870 static int rsi_mac80211_sta_add(struct ieee80211_hw *hw,
871 struct ieee80211_vif *vif,
872 struct ieee80211_sta *sta)
874 struct rsi_hw *adapter = hw->priv;
875 struct rsi_common *common = adapter->priv;
877 mutex_lock(&common->mutex);
879 rsi_set_min_rate(hw, sta, common);
881 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
882 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) {
883 common->vif_info[0].sgi = true;
886 if (sta->ht_cap.ht_supported)
887 ieee80211_start_tx_ba_session(sta, 0, 0);
889 mutex_unlock(&common->mutex);
895 * rsi_mac80211_sta_remove() - This function notifies driver about a peer
896 * getting disconnected.
897 * @hw: Pointer to the ieee80211_hw structure.
898 * @vif: Pointer to the ieee80211_vif structure.
899 * @sta: Pointer to the ieee80211_sta structure.
901 * Return: 0 on success, -1 on failure.
903 static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw,
904 struct ieee80211_vif *vif,
905 struct ieee80211_sta *sta)
907 struct rsi_hw *adapter = hw->priv;
908 struct rsi_common *common = adapter->priv;
910 mutex_lock(&common->mutex);
911 /* Resetting all the fields to default values */
912 common->bitrate_mask[IEEE80211_BAND_2GHZ] = 0;
913 common->bitrate_mask[IEEE80211_BAND_5GHZ] = 0;
914 common->min_rate = 0xffff;
915 common->vif_info[0].is_ht = false;
916 common->vif_info[0].sgi = false;
917 common->vif_info[0].seq_start = 0;
918 common->secinfo.ptk_cipher = 0;
919 common->secinfo.gtk_cipher = 0;
920 mutex_unlock(&common->mutex);
925 static struct ieee80211_ops mac80211_ops = {
926 .tx = rsi_mac80211_tx,
927 .start = rsi_mac80211_start,
928 .stop = rsi_mac80211_stop,
929 .add_interface = rsi_mac80211_add_interface,
930 .remove_interface = rsi_mac80211_remove_interface,
931 .config = rsi_mac80211_config,
932 .bss_info_changed = rsi_mac80211_bss_info_changed,
933 .conf_tx = rsi_mac80211_conf_tx,
934 .configure_filter = rsi_mac80211_conf_filter,
935 .set_key = rsi_mac80211_set_key,
936 .set_rts_threshold = rsi_mac80211_set_rts_threshold,
937 .set_bitrate_mask = rsi_mac80211_set_rate_mask,
938 .ampdu_action = rsi_mac80211_ampdu_action,
939 .sta_add = rsi_mac80211_sta_add,
940 .sta_remove = rsi_mac80211_sta_remove,
944 * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack.
945 * @common: Pointer to the driver private structure.
947 * Return: 0 on success, -1 on failure.
949 int rsi_mac80211_attach(struct rsi_common *common)
952 struct ieee80211_hw *hw = NULL;
953 struct wiphy *wiphy = NULL;
954 struct rsi_hw *adapter = common->priv;
955 u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3};
957 rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__);
959 hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops);
961 rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__);
967 SET_IEEE80211_DEV(hw, adapter->device);
972 hw->flags = IEEE80211_HW_SIGNAL_DBM |
973 IEEE80211_HW_HAS_RATE_CONTROL |
974 IEEE80211_HW_AMPDU_AGGREGATION |
977 hw->queues = MAX_HW_QUEUES;
978 hw->extra_tx_headroom = RSI_NEEDED_HEADROOM;
981 hw->max_rate_tries = MAX_RETRIES;
983 hw->max_tx_aggregation_subframes = 6;
984 rsi_register_rates_channels(adapter, IEEE80211_BAND_2GHZ);
985 hw->rate_control_algorithm = "AARF";
987 SET_IEEE80211_PERM_ADDR(hw, common->mac_addr);
988 ether_addr_copy(hw->wiphy->addr_mask, addr_mask);
990 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
991 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
992 wiphy->retry_short = RETRY_SHORT;
993 wiphy->retry_long = RETRY_LONG;
994 wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
995 wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
998 wiphy->available_antennas_rx = 1;
999 wiphy->available_antennas_tx = 1;
1000 wiphy->bands[IEEE80211_BAND_2GHZ] =
1001 &adapter->sbands[IEEE80211_BAND_2GHZ];
1003 status = ieee80211_register_hw(hw);
1007 return rsi_init_dbgfs(adapter);