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>
19 #include "rsi_common.h"
21 static struct bootup_params boot_params_20 = {
22 .magic_number = cpu_to_le16(0x5aa5),
23 .crystal_good_time = 0x0,
24 .valid = cpu_to_le32(VALID_20),
25 .reserved_for_valids = 0x0,
26 .bootup_mode_info = 0x0,
27 .digital_loop_back_params = 0x0,
28 .rtls_timestamp_en = 0x0,
29 .host_spi_intr_cfg = 0x0,
33 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
35 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
38 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
40 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
44 .pll_reg = cpu_to_le16(0x9f0),
48 .switch_clk_info = cpu_to_le16(BIT(3)),
49 .bbp_lmac_clk_reg_val = cpu_to_le16(0x121),
50 .umac_clock_reg_config = 0x0,
51 .qspi_uart_clock_reg_config = 0x0
57 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
59 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
62 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
64 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
68 .pll_reg = cpu_to_le16(0x9f0),
72 .switch_clk_info = 0x0,
73 .bbp_lmac_clk_reg_val = 0x0,
74 .umac_clock_reg_config = 0x0,
75 .qspi_uart_clock_reg_config = 0x0
81 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
83 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
86 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
88 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
92 .pll_reg = cpu_to_le16(0x9f0),
96 .switch_clk_info = 0x0,
97 .bbp_lmac_clk_reg_val = 0x0,
98 .umac_clock_reg_config = 0x0,
99 .qspi_uart_clock_reg_config = 0x0
102 .buckboost_wakeup_cnt = 0x0,
103 .pmu_wakeup_wait = 0x0,
104 .shutdown_wait_time = 0x0,
105 .pmu_slp_clkout_sel = 0x0,
106 .wdt_prog_value = 0x0,
107 .wdt_soc_rst_delay = 0x0,
108 .dcdc_operation_mode = 0x0,
109 .soc_reset_wait_cnt = 0x0
112 static struct bootup_params boot_params_40 = {
113 .magic_number = cpu_to_le16(0x5aa5),
114 .crystal_good_time = 0x0,
115 .valid = cpu_to_le32(VALID_40),
116 .reserved_for_valids = 0x0,
117 .bootup_mode_info = 0x0,
118 .digital_loop_back_params = 0x0,
119 .rtls_timestamp_en = 0x0,
120 .host_spi_intr_cfg = 0x0,
121 .device_clk_info = {{
124 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
126 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
129 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
131 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
135 .pll_reg = cpu_to_le16(0x9f0),
139 .switch_clk_info = cpu_to_le16(0x09),
140 .bbp_lmac_clk_reg_val = cpu_to_le16(0x1121),
141 .umac_clock_reg_config = cpu_to_le16(0x48),
142 .qspi_uart_clock_reg_config = 0x0
148 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
150 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
153 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
155 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
159 .pll_reg = cpu_to_le16(0x9f0),
163 .switch_clk_info = 0x0,
164 .bbp_lmac_clk_reg_val = 0x0,
165 .umac_clock_reg_config = 0x0,
166 .qspi_uart_clock_reg_config = 0x0
172 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
174 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
177 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
179 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
183 .pll_reg = cpu_to_le16(0x9f0),
187 .switch_clk_info = 0x0,
188 .bbp_lmac_clk_reg_val = 0x0,
189 .umac_clock_reg_config = 0x0,
190 .qspi_uart_clock_reg_config = 0x0
193 .buckboost_wakeup_cnt = 0x0,
194 .pmu_wakeup_wait = 0x0,
195 .shutdown_wait_time = 0x0,
196 .pmu_slp_clkout_sel = 0x0,
197 .wdt_prog_value = 0x0,
198 .wdt_soc_rst_delay = 0x0,
199 .dcdc_operation_mode = 0x0,
200 .soc_reset_wait_cnt = 0x0
203 static u16 mcs[] = {13, 26, 39, 52, 78, 104, 117, 130};
206 * rsi_set_default_parameters() - This function sets default parameters.
207 * @common: Pointer to the driver private structure.
211 static void rsi_set_default_parameters(struct rsi_common *common)
213 common->band = IEEE80211_BAND_2GHZ;
214 common->channel_width = BW_20MHZ;
215 common->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
217 common->min_rate = 0xffff;
218 common->fsm_state = FSM_CARD_NOT_READY;
219 common->iface_down = true;
223 * rsi_set_contention_vals() - This function sets the contention values for the
225 * @common: Pointer to the driver private structure.
229 static void rsi_set_contention_vals(struct rsi_common *common)
233 for (; ii < NUM_EDCA_QUEUES; ii++) {
234 common->tx_qinfo[ii].wme_params =
235 (((common->edca_params[ii].cw_min / 2) +
236 (common->edca_params[ii].aifs)) *
237 WMM_SHORT_SLOT_TIME + SIFS_DURATION);
238 common->tx_qinfo[ii].weight = common->tx_qinfo[ii].wme_params;
239 common->tx_qinfo[ii].pkt_contended = 0;
244 * rsi_send_internal_mgmt_frame() - This function sends management frames to
245 * firmware.Also schedules packet to queue
247 * @common: Pointer to the driver private structure.
248 * @skb: Pointer to the socket buffer structure.
250 * Return: 0 on success, -1 on failure.
252 static int rsi_send_internal_mgmt_frame(struct rsi_common *common,
255 struct skb_info *tx_params;
258 rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
261 tx_params = (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data;
262 tx_params->flags |= INTERNAL_MGMT_PKT;
263 skb_queue_tail(&common->tx_queue[MGMT_SOFT_Q], skb);
264 rsi_set_event(&common->tx_thread.event);
269 * rsi_load_radio_caps() - This function is used to send radio capabilities
270 * values to firmware.
271 * @common: Pointer to the driver private structure.
273 * Return: 0 on success, corresponding negative error code on failure.
275 static int rsi_load_radio_caps(struct rsi_common *common)
277 struct rsi_radio_caps *radio_caps;
278 struct rsi_hw *adapter = common->priv;
279 struct ieee80211_hw *hw = adapter->hw;
283 u16 gc[20] = {0xf0, 0xf0, 0xf0, 0xf0,
284 0xf0, 0xf0, 0xf0, 0xf0,
285 0xf0, 0xf0, 0xf0, 0xf0,
286 0xf0, 0xf0, 0xf0, 0xf0,
287 0xf0, 0xf0, 0xf0, 0xf0};
288 struct ieee80211_conf *conf = &hw->conf;
291 rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__);
293 skb = dev_alloc_skb(sizeof(struct rsi_radio_caps));
296 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
301 memset(skb->data, 0, sizeof(struct rsi_radio_caps));
302 radio_caps = (struct rsi_radio_caps *)skb->data;
304 radio_caps->desc_word[1] = cpu_to_le16(RADIO_CAPABILITIES);
305 radio_caps->desc_word[4] = cpu_to_le16(RSI_RF_TYPE << 8);
307 if (common->channel_width == BW_40MHZ) {
308 radio_caps->desc_word[7] |= cpu_to_le16(RSI_LMAC_CLOCK_80MHZ);
309 radio_caps->desc_word[7] |= cpu_to_le16(RSI_ENABLE_40MHZ);
310 if (common->channel_width) {
311 radio_caps->desc_word[5] =
312 cpu_to_le16(common->channel_width << 12);
313 radio_caps->desc_word[5] |= cpu_to_le16(FULL40M_ENABLE);
316 if (conf_is_ht40_minus(conf)) {
317 radio_caps->desc_word[5] = 0;
318 radio_caps->desc_word[5] |=
319 cpu_to_le16(LOWER_20_ENABLE);
320 radio_caps->desc_word[5] |=
321 cpu_to_le16(LOWER_20_ENABLE >> 12);
324 if (conf_is_ht40_plus(conf)) {
325 radio_caps->desc_word[5] = 0;
326 radio_caps->desc_word[5] |=
327 cpu_to_le16(UPPER_20_ENABLE);
328 radio_caps->desc_word[5] |=
329 cpu_to_le16(UPPER_20_ENABLE >> 12);
333 radio_caps->desc_word[7] |= cpu_to_le16(radio_id << 8);
335 for (ii = 0; ii < MAX_HW_QUEUES; ii++) {
336 radio_caps->qos_params[ii].cont_win_min_q = cpu_to_le16(3);
337 radio_caps->qos_params[ii].cont_win_max_q = cpu_to_le16(0x3f);
338 radio_caps->qos_params[ii].aifsn_val_q = cpu_to_le16(2);
339 radio_caps->qos_params[ii].txop_q = 0;
342 for (ii = 0; ii < MAX_HW_QUEUES - 4; ii++) {
343 radio_caps->qos_params[ii].cont_win_min_q =
344 cpu_to_le16(common->edca_params[ii].cw_min);
345 radio_caps->qos_params[ii].cont_win_max_q =
346 cpu_to_le16(common->edca_params[ii].cw_max);
347 radio_caps->qos_params[ii].aifsn_val_q =
348 cpu_to_le16((common->edca_params[ii].aifs) << 8);
349 radio_caps->qos_params[ii].txop_q =
350 cpu_to_le16(common->edca_params[ii].txop);
353 memcpy(&common->rate_pwr[0], &gc[0], 40);
354 for (ii = 0; ii < 20; ii++)
355 radio_caps->gcpd_per_rate[inx++] =
356 cpu_to_le16(common->rate_pwr[ii] & 0x00FF);
358 radio_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_radio_caps) -
360 (RSI_WIFI_MGMT_Q << 12));
363 skb_put(skb, (sizeof(struct rsi_radio_caps)));
365 return rsi_send_internal_mgmt_frame(common, skb);
369 * rsi_mgmt_pkt_to_core() - This function is the entry point for Mgmt module.
370 * @common: Pointer to the driver private structure.
371 * @msg: Pointer to received packet.
372 * @msg_len: Length of the recieved packet.
373 * @type: Type of recieved packet.
375 * Return: 0 on success, -1 on failure.
377 static int rsi_mgmt_pkt_to_core(struct rsi_common *common,
382 struct rsi_hw *adapter = common->priv;
383 struct ieee80211_tx_info *info;
384 struct skb_info *rx_params;
385 u8 pad_bytes = msg[4];
390 if (type == RX_DOT11_MGMT) {
391 if (!adapter->sc_nvifs)
394 msg_len -= pad_bytes;
395 if ((msg_len <= 0) || (!msg)) {
396 rsi_dbg(MGMT_RX_ZONE,
397 "%s: Invalid rx msg of len = %d\n",
402 skb = dev_alloc_skb(msg_len);
404 rsi_dbg(ERR_ZONE, "%s: Failed to allocate skb\n",
409 buffer = skb_put(skb, msg_len);
412 (u8 *)(msg + FRAME_DESC_SZ + pad_bytes),
415 pkt_recv = buffer[0];
417 info = IEEE80211_SKB_CB(skb);
418 rx_params = (struct skb_info *)info->driver_data;
419 rx_params->rssi = rsi_get_rssi(msg);
420 rx_params->channel = rsi_get_channel(msg);
421 rsi_indicate_pkt_to_os(common, skb);
423 rsi_dbg(MGMT_TX_ZONE, "%s: Internal Packet\n", __func__);
430 * rsi_hal_send_sta_notify_frame() - This function sends the station notify
432 * @common: Pointer to the driver private structure.
433 * @opmode: Operating mode of device.
434 * @notify_event: Notification about station connection.
436 * @qos_enable: Qos is enabled.
437 * @aid: Aid (unique for all STA).
439 * Return: status: 0 on success, corresponding negative error code on failure.
441 static int rsi_hal_send_sta_notify_frame(struct rsi_common *common,
444 const unsigned char *bssid,
448 struct sk_buff *skb = NULL;
449 struct rsi_peer_notify *peer_notify;
453 rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__);
455 skb = dev_alloc_skb(sizeof(struct rsi_peer_notify));
458 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
463 memset(skb->data, 0, sizeof(struct rsi_peer_notify));
464 peer_notify = (struct rsi_peer_notify *)skb->data;
466 peer_notify->command = cpu_to_le16(opmode << 1);
468 switch (notify_event) {
470 peer_notify->command |= cpu_to_le16(RSI_ADD_PEER);
472 case STA_DISCONNECTED:
473 peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER);
479 peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4);
480 ether_addr_copy(peer_notify->mac_addr, bssid);
482 peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0);
484 peer_notify->desc_word[0] =
485 cpu_to_le16((sizeof(struct rsi_peer_notify) - FRAME_DESC_SZ) |
486 (RSI_WIFI_MGMT_Q << 12));
487 peer_notify->desc_word[1] = cpu_to_le16(PEER_NOTIFY);
488 peer_notify->desc_word[7] |= cpu_to_le16(vap_id << 8);
490 skb_put(skb, sizeof(struct rsi_peer_notify));
492 status = rsi_send_internal_mgmt_frame(common, skb);
494 if (!status && qos_enable) {
495 rsi_set_contention_vals(common);
496 status = rsi_load_radio_caps(common);
502 * rsi_send_aggregation_params_frame() - This function sends the ampdu
503 * indication frame to firmware.
504 * @common: Pointer to the driver private structure.
505 * @tid: traffic identifier.
507 * @buf_size: buffer size.
508 * @event: notification about station connection.
510 * Return: 0 on success, corresponding negative error code on failure.
512 int rsi_send_aggregation_params_frame(struct rsi_common *common,
518 struct sk_buff *skb = NULL;
519 struct rsi_mac_frame *mgmt_frame;
522 skb = dev_alloc_skb(FRAME_DESC_SZ);
525 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
530 memset(skb->data, 0, FRAME_DESC_SZ);
531 mgmt_frame = (struct rsi_mac_frame *)skb->data;
533 rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__);
535 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
536 mgmt_frame->desc_word[1] = cpu_to_le16(AMPDU_IND);
538 if (event == STA_TX_ADDBA_DONE) {
539 mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
540 mgmt_frame->desc_word[5] = cpu_to_le16(buf_size);
541 mgmt_frame->desc_word[7] =
542 cpu_to_le16((tid | (START_AMPDU_AGGR << 4) | (peer_id << 8)));
543 } else if (event == STA_RX_ADDBA_DONE) {
544 mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
545 mgmt_frame->desc_word[7] = cpu_to_le16(tid |
546 (START_AMPDU_AGGR << 4) |
547 (RX_BA_INDICATION << 5) |
549 } else if (event == STA_TX_DELBA) {
550 mgmt_frame->desc_word[7] = cpu_to_le16(tid |
551 (STOP_AMPDU_AGGR << 4) |
553 } else if (event == STA_RX_DELBA) {
554 mgmt_frame->desc_word[7] = cpu_to_le16(tid |
555 (STOP_AMPDU_AGGR << 4) |
556 (RX_BA_INDICATION << 5) |
560 skb_put(skb, FRAME_DESC_SZ);
562 return rsi_send_internal_mgmt_frame(common, skb);
566 * rsi_program_bb_rf() - This function starts base band and RF programming.
567 * This is called after initial configurations are done.
568 * @common: Pointer to the driver private structure.
570 * Return: 0 on success, corresponding negative error code on failure.
572 static int rsi_program_bb_rf(struct rsi_common *common)
575 struct rsi_mac_frame *mgmt_frame;
577 rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__);
579 skb = dev_alloc_skb(FRAME_DESC_SZ);
581 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
586 memset(skb->data, 0, FRAME_DESC_SZ);
587 mgmt_frame = (struct rsi_mac_frame *)skb->data;
589 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
590 mgmt_frame->desc_word[1] = cpu_to_le16(BBP_PROG_IN_TA);
591 mgmt_frame->desc_word[4] = cpu_to_le16(common->endpoint << 8);
593 if (common->rf_reset) {
594 mgmt_frame->desc_word[7] = cpu_to_le16(RF_RESET_ENABLE);
595 rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n",
597 common->rf_reset = 0;
599 common->bb_rf_prog_count = 1;
600 mgmt_frame->desc_word[7] |= cpu_to_le16(PUT_BBP_RESET |
601 BBP_REG_WRITE | (RSI_RF_TYPE << 4));
602 skb_put(skb, FRAME_DESC_SZ);
604 return rsi_send_internal_mgmt_frame(common, skb);
608 * rsi_set_vap_capabilities() - This function send vap capability to firmware.
609 * @common: Pointer to the driver private structure.
610 * @opmode: Operating mode of device.
612 * Return: 0 on success, corresponding negative error code on failure.
614 int rsi_set_vap_capabilities(struct rsi_common *common, enum opmode mode)
616 struct sk_buff *skb = NULL;
617 struct rsi_vap_caps *vap_caps;
620 rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__);
622 skb = dev_alloc_skb(sizeof(struct rsi_vap_caps));
624 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
629 memset(skb->data, 0, sizeof(struct rsi_vap_caps));
630 vap_caps = (struct rsi_vap_caps *)skb->data;
632 vap_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_vap_caps) -
634 (RSI_WIFI_MGMT_Q << 12));
635 vap_caps->desc_word[1] = cpu_to_le16(VAP_CAPABILITIES);
636 vap_caps->desc_word[4] = cpu_to_le16(mode |
637 (common->channel_width << 8));
638 vap_caps->desc_word[7] = cpu_to_le16((vap_id << 8) |
639 (common->mac_id << 4) |
642 memcpy(vap_caps->mac_addr, common->mac_addr, IEEE80211_ADDR_LEN);
643 vap_caps->keep_alive_period = cpu_to_le16(90);
644 vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD);
646 vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold);
647 vap_caps->default_mgmt_rate = 0;
648 if (conf_is_ht40(&common->priv->hw->conf)) {
649 vap_caps->default_ctrl_rate =
650 cpu_to_le32(RSI_RATE_6 | FULL40M_ENABLE << 16);
652 vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_6);
654 vap_caps->default_data_rate = 0;
655 vap_caps->beacon_interval = cpu_to_le16(200);
656 vap_caps->dtim_period = cpu_to_le16(4);
658 skb_put(skb, sizeof(*vap_caps));
660 return rsi_send_internal_mgmt_frame(common, skb);
664 * rsi_hal_load_key() - This function is used to load keys within the firmware.
665 * @common: Pointer to the driver private structure.
666 * @data: Pointer to the key data.
667 * @key_len: Key length to be loaded.
668 * @key_type: Type of key: GROUP/PAIRWISE.
669 * @key_id: Key index.
670 * @cipher: Type of cipher used.
672 * Return: 0 on success, -1 on failure.
674 int rsi_hal_load_key(struct rsi_common *common,
681 struct sk_buff *skb = NULL;
682 struct rsi_set_key *set_key;
683 u16 key_descriptor = 0;
685 rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__);
687 skb = dev_alloc_skb(sizeof(struct rsi_set_key));
689 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
694 memset(skb->data, 0, sizeof(struct rsi_set_key));
695 set_key = (struct rsi_set_key *)skb->data;
697 if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
698 (cipher == WLAN_CIPHER_SUITE_WEP104)) {
700 key_descriptor |= BIT(2);
702 key_descriptor |= BIT(3);
703 } else if (cipher != KEY_TYPE_CLEAR) {
704 key_descriptor |= BIT(4);
705 if (key_type == RSI_PAIRWISE_KEY)
707 if (cipher == WLAN_CIPHER_SUITE_TKIP)
708 key_descriptor |= BIT(5);
710 key_descriptor |= (key_type | BIT(13) | (key_id << 14));
712 set_key->desc_word[0] = cpu_to_le16((sizeof(struct rsi_set_key) -
714 (RSI_WIFI_MGMT_Q << 12));
715 set_key->desc_word[1] = cpu_to_le16(SET_KEY_REQ);
716 set_key->desc_word[4] = cpu_to_le16(key_descriptor);
718 if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
719 (cipher == WLAN_CIPHER_SUITE_WEP104)) {
720 memcpy(&set_key->key[key_id][1],
724 memcpy(&set_key->key[0][0], data, key_len);
727 memcpy(set_key->tx_mic_key, &data[16], 8);
728 memcpy(set_key->rx_mic_key, &data[24], 8);
730 skb_put(skb, sizeof(struct rsi_set_key));
732 return rsi_send_internal_mgmt_frame(common, skb);
736 * rsi_load_bootup_params() - This function send bootup params to the firmware.
737 * @common: Pointer to the driver private structure.
739 * Return: 0 on success, corresponding error code on failure.
741 static int rsi_load_bootup_params(struct rsi_common *common)
744 struct rsi_boot_params *boot_params;
746 rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
747 skb = dev_alloc_skb(sizeof(struct rsi_boot_params));
749 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
754 memset(skb->data, 0, sizeof(struct rsi_boot_params));
755 boot_params = (struct rsi_boot_params *)skb->data;
757 rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__);
759 if (common->channel_width == BW_40MHZ) {
760 memcpy(&boot_params->bootup_params,
762 sizeof(struct bootup_params));
763 rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
765 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW);
767 memcpy(&boot_params->bootup_params,
769 sizeof(struct bootup_params));
770 if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
771 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW);
772 rsi_dbg(MGMT_TX_ZONE,
773 "%s: Packet 20MHZ <=== %d\n", __func__,
776 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ);
777 rsi_dbg(MGMT_TX_ZONE,
778 "%s: Packet 20MHZ <=== %d\n", __func__,
784 * Bit{0:11} indicates length of the Packet
785 * Bit{12:15} indicates host queue number
787 boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) |
788 (RSI_WIFI_MGMT_Q << 12));
789 boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST);
791 skb_put(skb, sizeof(struct rsi_boot_params));
793 return rsi_send_internal_mgmt_frame(common, skb);
797 * rsi_send_reset_mac() - This function prepares reset MAC request and sends an
798 * internal management frame to indicate it to firmware.
799 * @common: Pointer to the driver private structure.
801 * Return: 0 on success, corresponding error code on failure.
803 static int rsi_send_reset_mac(struct rsi_common *common)
806 struct rsi_mac_frame *mgmt_frame;
808 rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__);
810 skb = dev_alloc_skb(FRAME_DESC_SZ);
812 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
817 memset(skb->data, 0, FRAME_DESC_SZ);
818 mgmt_frame = (struct rsi_mac_frame *)skb->data;
820 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
821 mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ);
822 mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8);
824 skb_put(skb, FRAME_DESC_SZ);
826 return rsi_send_internal_mgmt_frame(common, skb);
830 * rsi_set_channel() - This function programs the channel.
831 * @common: Pointer to the driver private structure.
832 * @channel: Channel value to be set.
834 * Return: 0 on success, corresponding error code on failure.
836 int rsi_set_channel(struct rsi_common *common, u16 channel)
838 struct sk_buff *skb = NULL;
839 struct rsi_mac_frame *mgmt_frame;
841 rsi_dbg(MGMT_TX_ZONE,
842 "%s: Sending scan req frame\n", __func__);
844 if (common->band == IEEE80211_BAND_5GHZ) {
845 if ((channel >= 36) && (channel <= 64))
846 channel = ((channel - 32) / 4);
847 else if ((channel > 64) && (channel <= 140))
848 channel = ((channel - 102) / 4) + 8;
849 else if (channel >= 149)
850 channel = ((channel - 151) / 4) + 18;
855 rsi_dbg(ERR_ZONE, "%s: Invalid chno %d, band = %d\n",
856 __func__, channel, common->band);
861 skb = dev_alloc_skb(FRAME_DESC_SZ);
863 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
868 memset(skb->data, 0, FRAME_DESC_SZ);
869 mgmt_frame = (struct rsi_mac_frame *)skb->data;
871 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
872 mgmt_frame->desc_word[1] = cpu_to_le16(SCAN_REQUEST);
873 mgmt_frame->desc_word[4] = cpu_to_le16(channel);
875 mgmt_frame->desc_word[7] = cpu_to_le16(PUT_BBP_RESET |
879 mgmt_frame->desc_word[5] = cpu_to_le16(0x01);
881 if (common->channel_width == BW_40MHZ)
882 mgmt_frame->desc_word[5] |= cpu_to_le16(0x1 << 8);
884 common->channel = channel;
886 skb_put(skb, FRAME_DESC_SZ);
888 return rsi_send_internal_mgmt_frame(common, skb);
892 * rsi_compare() - This function is used to compare two integers
893 * @a: pointer to the first integer
894 * @b: pointer to the second integer
896 * Return: 0 if both are equal, -1 if the first is smaller, else 1
898 static int rsi_compare(const void *a, const void *b)
900 u16 _a = *(const u16 *)(a);
901 u16 _b = *(const u16 *)(b);
913 * rsi_map_rates() - This function is used to map selected rates to hw rates.
914 * @rate: The standard rate to be mapped.
915 * @offset: Offset that will be returned.
917 * Return: 0 if it is a mcs rate, else 1
919 static bool rsi_map_rates(u16 rate, int *offset)
922 for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) {
923 if (rate == mcs[kk]) {
929 for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) {
930 if (rate == rsi_rates[kk].bitrate / 5) {
939 * rsi_send_auto_rate_request() - This function is to set rates for connection
940 * and send autorate request to firmware.
941 * @common: Pointer to the driver private structure.
943 * Return: 0 on success, corresponding error code on failure.
945 static int rsi_send_auto_rate_request(struct rsi_common *common)
948 struct rsi_auto_rate *auto_rate;
949 int ii = 0, jj = 0, kk = 0;
950 struct ieee80211_hw *hw = common->priv->hw;
951 u8 band = hw->conf.chandef.chan->band;
952 u8 num_supported_rates = 0;
954 u32 rate_bitmap = common->bitrate_mask[band];
956 u16 *selected_rates, min_rate;
958 skb = dev_alloc_skb(sizeof(struct rsi_auto_rate));
960 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
965 selected_rates = kmalloc(2 * RSI_TBL_SZ, GFP_KERNEL);
966 if (!selected_rates) {
967 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n",
973 memset(skb->data, 0, sizeof(struct rsi_auto_rate));
974 memset(selected_rates, 0, 2 * RSI_TBL_SZ);
976 auto_rate = (struct rsi_auto_rate *)skb->data;
978 auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f));
979 auto_rate->collision_tolerance = cpu_to_le16(3);
980 auto_rate->failure_limit = cpu_to_le16(3);
981 auto_rate->initial_boundary = cpu_to_le16(3);
982 auto_rate->max_threshold_limt = cpu_to_le16(27);
984 auto_rate->desc_word[1] = cpu_to_le16(AUTO_RATE_IND);
986 if (common->channel_width == BW_40MHZ)
987 auto_rate->desc_word[7] |= cpu_to_le16(1);
989 if (band == IEEE80211_BAND_2GHZ)
990 min_rate = STD_RATE_01;
992 min_rate = STD_RATE_06;
994 for (ii = 0, jj = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
995 if (rate_bitmap & BIT(ii)) {
996 selected_rates[jj++] = (rsi_rates[ii].bitrate / 5);
1000 num_supported_rates = jj;
1002 if (common->vif_info[0].is_ht) {
1003 for (ii = 0; ii < ARRAY_SIZE(mcs); ii++)
1004 selected_rates[jj++] = mcs[ii];
1005 num_supported_rates += ARRAY_SIZE(mcs);
1006 rate_offset += ARRAY_SIZE(mcs);
1009 if (rate_offset < (RSI_TBL_SZ / 2) - 1) {
1010 for (ii = jj; ii < (RSI_TBL_SZ / 2); ii++) {
1011 selected_rates[jj++] = min_rate;
1016 sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL);
1018 /* mapping the rates to RSI rates */
1019 for (ii = 0; ii < jj; ii++) {
1020 if (rsi_map_rates(selected_rates[ii], &kk)) {
1021 auto_rate->supported_rates[ii] =
1022 cpu_to_le16(rsi_rates[kk].hw_value);
1024 auto_rate->supported_rates[ii] =
1025 cpu_to_le16(rsi_mcsrates[kk]);
1029 /* loading HT rates in the bottom half of the auto rate table */
1030 if (common->vif_info[0].is_ht) {
1031 if (common->vif_info[0].sgi)
1032 auto_rate->supported_rates[rate_offset++] =
1033 cpu_to_le16(RSI_RATE_MCS7_SG);
1035 for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1;
1036 ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) {
1037 if (common->vif_info[0].sgi)
1038 auto_rate->supported_rates[ii++] =
1039 cpu_to_le16(rsi_mcsrates[kk] | BIT(9));
1040 auto_rate->supported_rates[ii] =
1041 cpu_to_le16(rsi_mcsrates[kk--]);
1044 for (; ii < RSI_TBL_SZ; ii++) {
1045 auto_rate->supported_rates[ii] =
1046 cpu_to_le16(rsi_mcsrates[0]);
1050 auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2);
1051 auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2);
1052 auto_rate->desc_word[7] |= cpu_to_le16(0 << 8);
1053 num_supported_rates *= 2;
1055 auto_rate->desc_word[0] = cpu_to_le16((sizeof(*auto_rate) -
1057 (RSI_WIFI_MGMT_Q << 12));
1060 sizeof(struct rsi_auto_rate));
1061 kfree(selected_rates);
1063 return rsi_send_internal_mgmt_frame(common, skb);
1067 * rsi_inform_bss_status() - This function informs about bss status with the
1068 * help of sta notify params by sending an internal
1069 * management frame to firmware.
1070 * @common: Pointer to the driver private structure.
1071 * @status: Bss status type.
1073 * @qos_enable: Qos is enabled.
1074 * @aid: Aid (unique for all STAs).
1078 void rsi_inform_bss_status(struct rsi_common *common,
1080 const unsigned char *bssid,
1085 rsi_hal_send_sta_notify_frame(common,
1086 NL80211_IFTYPE_STATION,
1091 if (common->min_rate == 0xffff)
1092 rsi_send_auto_rate_request(common);
1094 rsi_hal_send_sta_notify_frame(common,
1095 NL80211_IFTYPE_STATION,
1104 * rsi_eeprom_read() - This function sends a frame to read the mac address
1106 * @common: Pointer to the driver private structure.
1108 * Return: 0 on success, -1 on failure.
1110 static int rsi_eeprom_read(struct rsi_common *common)
1112 struct rsi_mac_frame *mgmt_frame;
1113 struct sk_buff *skb;
1115 rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__);
1117 skb = dev_alloc_skb(FRAME_DESC_SZ);
1119 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1124 memset(skb->data, 0, FRAME_DESC_SZ);
1125 mgmt_frame = (struct rsi_mac_frame *)skb->data;
1128 mgmt_frame->desc_word[1] = cpu_to_le16(EEPROM_READ_TYPE);
1129 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
1130 /* Number of bytes to read */
1131 mgmt_frame->desc_word[3] = cpu_to_le16(ETH_ALEN +
1132 WLAN_MAC_MAGIC_WORD_LEN +
1133 WLAN_HOST_MODE_LEN +
1134 WLAN_FW_VERSION_LEN);
1135 /* Address to read */
1136 mgmt_frame->desc_word[4] = cpu_to_le16(WLAN_MAC_EEPROM_ADDR);
1138 skb_put(skb, FRAME_DESC_SZ);
1140 return rsi_send_internal_mgmt_frame(common, skb);
1144 * rsi_handle_ta_confirm_type() - This function handles the confirm frames.
1145 * @common: Pointer to the driver private structure.
1146 * @msg: Pointer to received packet.
1148 * Return: 0 on success, -1 on failure.
1150 static int rsi_handle_ta_confirm_type(struct rsi_common *common,
1153 u8 sub_type = (msg[15] & 0xff);
1156 case BOOTUP_PARAMS_REQUEST:
1157 rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n",
1159 if (common->fsm_state == FSM_BOOT_PARAMS_SENT) {
1160 if (rsi_eeprom_read(common)) {
1161 common->fsm_state = FSM_CARD_NOT_READY;
1164 common->fsm_state = FSM_EEPROM_READ_MAC_ADDR;
1168 "%s: Received bootup params cfm in %d state\n",
1169 __func__, common->fsm_state);
1174 case EEPROM_READ_TYPE:
1175 if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) {
1176 if (msg[16] == MAGIC_WORD) {
1177 u8 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN
1178 + WLAN_MAC_MAGIC_WORD_LEN);
1179 memcpy(common->mac_addr,
1182 memcpy(&common->fw_ver,
1183 &msg[offset + ETH_ALEN],
1184 sizeof(struct version_info));
1187 common->fsm_state = FSM_CARD_NOT_READY;
1190 if (rsi_send_reset_mac(common))
1193 common->fsm_state = FSM_RESET_MAC_SENT;
1196 "%s: Received eeprom mac addr in %d state\n",
1197 __func__, common->fsm_state);
1203 if (common->fsm_state == FSM_RESET_MAC_SENT) {
1204 rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n",
1207 if (rsi_load_radio_caps(common))
1210 common->fsm_state = FSM_RADIO_CAPS_SENT;
1213 "%s: Received reset mac cfm in %d state\n",
1214 __func__, common->fsm_state);
1219 case RADIO_CAPABILITIES:
1220 if (common->fsm_state == FSM_RADIO_CAPS_SENT) {
1221 common->rf_reset = 1;
1222 if (rsi_program_bb_rf(common)) {
1225 common->fsm_state = FSM_BB_RF_PROG_SENT;
1226 rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n",
1231 "%s: Received radio caps cfm in %d state\n",
1232 __func__, common->fsm_state);
1237 case BB_PROG_VALUES_REQUEST:
1238 case RF_PROG_VALUES_REQUEST:
1239 case BBP_PROG_IN_TA:
1240 rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__);
1241 if (common->fsm_state == FSM_BB_RF_PROG_SENT) {
1242 common->bb_rf_prog_count--;
1243 if (!common->bb_rf_prog_count) {
1244 common->fsm_state = FSM_MAC_INIT_DONE;
1245 return rsi_mac80211_attach(common);
1253 rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
1259 rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n",
1265 * rsi_mgmt_pkt_recv() - This function processes the management packets
1266 * recieved from the hardware.
1267 * @common: Pointer to the driver private structure.
1268 * @msg: Pointer to the received packet.
1270 * Return: 0 on success, -1 on failure.
1272 int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg)
1274 s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff);
1275 u16 msg_type = (msg[2]);
1278 rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n",
1279 __func__, msg_len, msg_type);
1281 if (msg_type == TA_CONFIRM_TYPE) {
1282 return rsi_handle_ta_confirm_type(common, msg);
1283 } else if (msg_type == CARD_READY_IND) {
1284 rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n",
1286 if (common->fsm_state == FSM_CARD_NOT_READY) {
1287 rsi_set_default_parameters(common);
1289 ret = rsi_load_bootup_params(common);
1293 common->fsm_state = FSM_BOOT_PARAMS_SENT;
1297 } else if (msg_type == TX_STATUS_IND) {
1298 if (msg[15] == PROBEREQ_CONFIRM) {
1299 common->mgmt_q_block = false;
1300 rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n",
1304 return rsi_mgmt_pkt_to_core(common, msg, msg_len, msg_type);