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;
220 common->endpoint = EP_2GHZ_20MHZ;
224 * rsi_set_contention_vals() - This function sets the contention values for the
226 * @common: Pointer to the driver private structure.
230 static void rsi_set_contention_vals(struct rsi_common *common)
234 for (; ii < NUM_EDCA_QUEUES; ii++) {
235 common->tx_qinfo[ii].wme_params =
236 (((common->edca_params[ii].cw_min / 2) +
237 (common->edca_params[ii].aifs)) *
238 WMM_SHORT_SLOT_TIME + SIFS_DURATION);
239 common->tx_qinfo[ii].weight = common->tx_qinfo[ii].wme_params;
240 common->tx_qinfo[ii].pkt_contended = 0;
245 * rsi_send_internal_mgmt_frame() - This function sends management frames to
246 * firmware.Also schedules packet to queue
248 * @common: Pointer to the driver private structure.
249 * @skb: Pointer to the socket buffer structure.
251 * Return: 0 on success, -1 on failure.
253 static int rsi_send_internal_mgmt_frame(struct rsi_common *common,
256 struct skb_info *tx_params;
259 rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
262 tx_params = (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data;
263 tx_params->flags |= INTERNAL_MGMT_PKT;
264 skb_queue_tail(&common->tx_queue[MGMT_SOFT_Q], skb);
265 rsi_set_event(&common->tx_thread.event);
270 * rsi_load_radio_caps() - This function is used to send radio capabilities
271 * values to firmware.
272 * @common: Pointer to the driver private structure.
274 * Return: 0 on success, corresponding negative error code on failure.
276 static int rsi_load_radio_caps(struct rsi_common *common)
278 struct rsi_radio_caps *radio_caps;
279 struct rsi_hw *adapter = common->priv;
280 struct ieee80211_hw *hw = adapter->hw;
284 u16 gc[20] = {0xf0, 0xf0, 0xf0, 0xf0,
285 0xf0, 0xf0, 0xf0, 0xf0,
286 0xf0, 0xf0, 0xf0, 0xf0,
287 0xf0, 0xf0, 0xf0, 0xf0,
288 0xf0, 0xf0, 0xf0, 0xf0};
289 struct ieee80211_conf *conf = &hw->conf;
292 rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__);
294 skb = dev_alloc_skb(sizeof(struct rsi_radio_caps));
297 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
302 memset(skb->data, 0, sizeof(struct rsi_radio_caps));
303 radio_caps = (struct rsi_radio_caps *)skb->data;
305 radio_caps->desc_word[1] = cpu_to_le16(RADIO_CAPABILITIES);
306 radio_caps->desc_word[4] = cpu_to_le16(RSI_RF_TYPE << 8);
308 if (common->channel_width == BW_40MHZ) {
309 radio_caps->desc_word[7] |= cpu_to_le16(RSI_LMAC_CLOCK_80MHZ);
310 radio_caps->desc_word[7] |= cpu_to_le16(RSI_ENABLE_40MHZ);
311 if (common->channel_width) {
312 radio_caps->desc_word[5] =
313 cpu_to_le16(common->channel_width << 12);
314 radio_caps->desc_word[5] |= cpu_to_le16(FULL40M_ENABLE);
317 if (conf_is_ht40_minus(conf)) {
318 radio_caps->desc_word[5] = 0;
319 radio_caps->desc_word[5] |=
320 cpu_to_le16(LOWER_20_ENABLE);
321 radio_caps->desc_word[5] |=
322 cpu_to_le16(LOWER_20_ENABLE >> 12);
325 if (conf_is_ht40_plus(conf)) {
326 radio_caps->desc_word[5] = 0;
327 radio_caps->desc_word[5] |=
328 cpu_to_le16(UPPER_20_ENABLE);
329 radio_caps->desc_word[5] |=
330 cpu_to_le16(UPPER_20_ENABLE >> 12);
334 radio_caps->sifs_tx_11n = cpu_to_le16(SIFS_TX_11N_VALUE);
335 radio_caps->sifs_tx_11b = cpu_to_le16(SIFS_TX_11B_VALUE);
336 radio_caps->slot_rx_11n = cpu_to_le16(SHORT_SLOT_VALUE);
337 radio_caps->ofdm_ack_tout = cpu_to_le16(OFDM_ACK_TOUT_VALUE);
338 radio_caps->cck_ack_tout = cpu_to_le16(CCK_ACK_TOUT_VALUE);
339 radio_caps->preamble_type = cpu_to_le16(LONG_PREAMBLE);
341 radio_caps->desc_word[7] |= cpu_to_le16(radio_id << 8);
343 for (ii = 0; ii < MAX_HW_QUEUES; ii++) {
344 radio_caps->qos_params[ii].cont_win_min_q = cpu_to_le16(3);
345 radio_caps->qos_params[ii].cont_win_max_q = cpu_to_le16(0x3f);
346 radio_caps->qos_params[ii].aifsn_val_q = cpu_to_le16(2);
347 radio_caps->qos_params[ii].txop_q = 0;
350 for (ii = 0; ii < MAX_HW_QUEUES - 4; ii++) {
351 radio_caps->qos_params[ii].cont_win_min_q =
352 cpu_to_le16(common->edca_params[ii].cw_min);
353 radio_caps->qos_params[ii].cont_win_max_q =
354 cpu_to_le16(common->edca_params[ii].cw_max);
355 radio_caps->qos_params[ii].aifsn_val_q =
356 cpu_to_le16((common->edca_params[ii].aifs) << 8);
357 radio_caps->qos_params[ii].txop_q =
358 cpu_to_le16(common->edca_params[ii].txop);
361 memcpy(&common->rate_pwr[0], &gc[0], 40);
362 for (ii = 0; ii < 20; ii++)
363 radio_caps->gcpd_per_rate[inx++] =
364 cpu_to_le16(common->rate_pwr[ii] & 0x00FF);
366 radio_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_radio_caps) -
368 (RSI_WIFI_MGMT_Q << 12));
371 skb_put(skb, (sizeof(struct rsi_radio_caps)));
373 return rsi_send_internal_mgmt_frame(common, skb);
377 * rsi_mgmt_pkt_to_core() - This function is the entry point for Mgmt module.
378 * @common: Pointer to the driver private structure.
379 * @msg: Pointer to received packet.
380 * @msg_len: Length of the recieved packet.
381 * @type: Type of recieved packet.
383 * Return: 0 on success, -1 on failure.
385 static int rsi_mgmt_pkt_to_core(struct rsi_common *common,
390 struct rsi_hw *adapter = common->priv;
391 struct ieee80211_tx_info *info;
392 struct skb_info *rx_params;
393 u8 pad_bytes = msg[4];
398 if (type == RX_DOT11_MGMT) {
399 if (!adapter->sc_nvifs)
402 msg_len -= pad_bytes;
403 if ((msg_len <= 0) || (!msg)) {
404 rsi_dbg(MGMT_RX_ZONE,
405 "%s: Invalid rx msg of len = %d\n",
410 skb = dev_alloc_skb(msg_len);
412 rsi_dbg(ERR_ZONE, "%s: Failed to allocate skb\n",
417 buffer = skb_put(skb, msg_len);
420 (u8 *)(msg + FRAME_DESC_SZ + pad_bytes),
423 pkt_recv = buffer[0];
425 info = IEEE80211_SKB_CB(skb);
426 rx_params = (struct skb_info *)info->driver_data;
427 rx_params->rssi = rsi_get_rssi(msg);
428 rx_params->channel = rsi_get_channel(msg);
429 rsi_indicate_pkt_to_os(common, skb);
431 rsi_dbg(MGMT_TX_ZONE, "%s: Internal Packet\n", __func__);
438 * rsi_hal_send_sta_notify_frame() - This function sends the station notify
440 * @common: Pointer to the driver private structure.
441 * @opmode: Operating mode of device.
442 * @notify_event: Notification about station connection.
444 * @qos_enable: Qos is enabled.
445 * @aid: Aid (unique for all STA).
447 * Return: status: 0 on success, corresponding negative error code on failure.
449 static int rsi_hal_send_sta_notify_frame(struct rsi_common *common,
452 const unsigned char *bssid,
456 struct sk_buff *skb = NULL;
457 struct rsi_peer_notify *peer_notify;
461 rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__);
463 skb = dev_alloc_skb(sizeof(struct rsi_peer_notify));
466 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
471 memset(skb->data, 0, sizeof(struct rsi_peer_notify));
472 peer_notify = (struct rsi_peer_notify *)skb->data;
474 peer_notify->command = cpu_to_le16(opmode << 1);
476 switch (notify_event) {
478 peer_notify->command |= cpu_to_le16(RSI_ADD_PEER);
480 case STA_DISCONNECTED:
481 peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER);
487 peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4);
488 ether_addr_copy(peer_notify->mac_addr, bssid);
490 peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0);
492 peer_notify->desc_word[0] =
493 cpu_to_le16((sizeof(struct rsi_peer_notify) - FRAME_DESC_SZ) |
494 (RSI_WIFI_MGMT_Q << 12));
495 peer_notify->desc_word[1] = cpu_to_le16(PEER_NOTIFY);
496 peer_notify->desc_word[7] |= cpu_to_le16(vap_id << 8);
498 skb_put(skb, sizeof(struct rsi_peer_notify));
500 status = rsi_send_internal_mgmt_frame(common, skb);
502 if (!status && qos_enable) {
503 rsi_set_contention_vals(common);
504 status = rsi_load_radio_caps(common);
510 * rsi_send_aggregation_params_frame() - This function sends the ampdu
511 * indication frame to firmware.
512 * @common: Pointer to the driver private structure.
513 * @tid: traffic identifier.
515 * @buf_size: buffer size.
516 * @event: notification about station connection.
518 * Return: 0 on success, corresponding negative error code on failure.
520 int rsi_send_aggregation_params_frame(struct rsi_common *common,
526 struct sk_buff *skb = NULL;
527 struct rsi_mac_frame *mgmt_frame;
530 skb = dev_alloc_skb(FRAME_DESC_SZ);
533 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
538 memset(skb->data, 0, FRAME_DESC_SZ);
539 mgmt_frame = (struct rsi_mac_frame *)skb->data;
541 rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__);
543 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
544 mgmt_frame->desc_word[1] = cpu_to_le16(AMPDU_IND);
546 if (event == STA_TX_ADDBA_DONE) {
547 mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
548 mgmt_frame->desc_word[5] = cpu_to_le16(buf_size);
549 mgmt_frame->desc_word[7] =
550 cpu_to_le16((tid | (START_AMPDU_AGGR << 4) | (peer_id << 8)));
551 } else if (event == STA_RX_ADDBA_DONE) {
552 mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
553 mgmt_frame->desc_word[7] = cpu_to_le16(tid |
554 (START_AMPDU_AGGR << 4) |
555 (RX_BA_INDICATION << 5) |
557 } else if (event == STA_TX_DELBA) {
558 mgmt_frame->desc_word[7] = cpu_to_le16(tid |
559 (STOP_AMPDU_AGGR << 4) |
561 } else if (event == STA_RX_DELBA) {
562 mgmt_frame->desc_word[7] = cpu_to_le16(tid |
563 (STOP_AMPDU_AGGR << 4) |
564 (RX_BA_INDICATION << 5) |
568 skb_put(skb, FRAME_DESC_SZ);
570 return rsi_send_internal_mgmt_frame(common, skb);
574 * rsi_program_bb_rf() - This function starts base band and RF programming.
575 * This is called after initial configurations are done.
576 * @common: Pointer to the driver private structure.
578 * Return: 0 on success, corresponding negative error code on failure.
580 static int rsi_program_bb_rf(struct rsi_common *common)
583 struct rsi_mac_frame *mgmt_frame;
585 rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__);
587 skb = dev_alloc_skb(FRAME_DESC_SZ);
589 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
594 memset(skb->data, 0, FRAME_DESC_SZ);
595 mgmt_frame = (struct rsi_mac_frame *)skb->data;
597 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
598 mgmt_frame->desc_word[1] = cpu_to_le16(BBP_PROG_IN_TA);
599 mgmt_frame->desc_word[4] = cpu_to_le16(common->endpoint);
601 if (common->rf_reset) {
602 mgmt_frame->desc_word[7] = cpu_to_le16(RF_RESET_ENABLE);
603 rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n",
605 common->rf_reset = 0;
607 common->bb_rf_prog_count = 1;
608 mgmt_frame->desc_word[7] |= cpu_to_le16(PUT_BBP_RESET |
609 BBP_REG_WRITE | (RSI_RF_TYPE << 4));
610 skb_put(skb, FRAME_DESC_SZ);
612 return rsi_send_internal_mgmt_frame(common, skb);
616 * rsi_set_vap_capabilities() - This function send vap capability to firmware.
617 * @common: Pointer to the driver private structure.
618 * @opmode: Operating mode of device.
620 * Return: 0 on success, corresponding negative error code on failure.
622 int rsi_set_vap_capabilities(struct rsi_common *common, enum opmode mode)
624 struct sk_buff *skb = NULL;
625 struct rsi_vap_caps *vap_caps;
628 rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__);
630 skb = dev_alloc_skb(sizeof(struct rsi_vap_caps));
632 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
637 memset(skb->data, 0, sizeof(struct rsi_vap_caps));
638 vap_caps = (struct rsi_vap_caps *)skb->data;
640 vap_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_vap_caps) -
642 (RSI_WIFI_MGMT_Q << 12));
643 vap_caps->desc_word[1] = cpu_to_le16(VAP_CAPABILITIES);
644 vap_caps->desc_word[4] = cpu_to_le16(mode |
645 (common->channel_width << 8));
646 vap_caps->desc_word[7] = cpu_to_le16((vap_id << 8) |
647 (common->mac_id << 4) |
650 memcpy(vap_caps->mac_addr, common->mac_addr, IEEE80211_ADDR_LEN);
651 vap_caps->keep_alive_period = cpu_to_le16(90);
652 vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD);
654 vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold);
655 vap_caps->default_mgmt_rate = 0;
656 if (conf_is_ht40(&common->priv->hw->conf)) {
657 vap_caps->default_ctrl_rate =
658 cpu_to_le32(RSI_RATE_6 | FULL40M_ENABLE << 16);
660 vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_6);
662 vap_caps->default_data_rate = 0;
663 vap_caps->beacon_interval = cpu_to_le16(200);
664 vap_caps->dtim_period = cpu_to_le16(4);
666 skb_put(skb, sizeof(*vap_caps));
668 return rsi_send_internal_mgmt_frame(common, skb);
672 * rsi_hal_load_key() - This function is used to load keys within the firmware.
673 * @common: Pointer to the driver private structure.
674 * @data: Pointer to the key data.
675 * @key_len: Key length to be loaded.
676 * @key_type: Type of key: GROUP/PAIRWISE.
677 * @key_id: Key index.
678 * @cipher: Type of cipher used.
680 * Return: 0 on success, -1 on failure.
682 int rsi_hal_load_key(struct rsi_common *common,
689 struct sk_buff *skb = NULL;
690 struct rsi_set_key *set_key;
691 u16 key_descriptor = 0;
693 rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__);
695 skb = dev_alloc_skb(sizeof(struct rsi_set_key));
697 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
702 memset(skb->data, 0, sizeof(struct rsi_set_key));
703 set_key = (struct rsi_set_key *)skb->data;
705 if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
706 (cipher == WLAN_CIPHER_SUITE_WEP104)) {
708 key_descriptor |= BIT(2);
710 key_descriptor |= BIT(3);
711 } else if (cipher != KEY_TYPE_CLEAR) {
712 key_descriptor |= BIT(4);
713 if (key_type == RSI_PAIRWISE_KEY)
715 if (cipher == WLAN_CIPHER_SUITE_TKIP)
716 key_descriptor |= BIT(5);
718 key_descriptor |= (key_type | BIT(13) | (key_id << 14));
720 set_key->desc_word[0] = cpu_to_le16((sizeof(struct rsi_set_key) -
722 (RSI_WIFI_MGMT_Q << 12));
723 set_key->desc_word[1] = cpu_to_le16(SET_KEY_REQ);
724 set_key->desc_word[4] = cpu_to_le16(key_descriptor);
726 if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
727 (cipher == WLAN_CIPHER_SUITE_WEP104)) {
728 memcpy(&set_key->key[key_id][1],
732 memcpy(&set_key->key[0][0], data, key_len);
735 memcpy(set_key->tx_mic_key, &data[16], 8);
736 memcpy(set_key->rx_mic_key, &data[24], 8);
738 skb_put(skb, sizeof(struct rsi_set_key));
740 return rsi_send_internal_mgmt_frame(common, skb);
744 * rsi_load_bootup_params() - This function send bootup params to the firmware.
745 * @common: Pointer to the driver private structure.
747 * Return: 0 on success, corresponding error code on failure.
749 static int rsi_load_bootup_params(struct rsi_common *common)
752 struct rsi_boot_params *boot_params;
754 rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
755 skb = dev_alloc_skb(sizeof(struct rsi_boot_params));
757 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
762 memset(skb->data, 0, sizeof(struct rsi_boot_params));
763 boot_params = (struct rsi_boot_params *)skb->data;
765 rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__);
767 if (common->channel_width == BW_40MHZ) {
768 memcpy(&boot_params->bootup_params,
770 sizeof(struct bootup_params));
771 rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
773 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW);
775 memcpy(&boot_params->bootup_params,
777 sizeof(struct bootup_params));
778 if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
779 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW);
780 rsi_dbg(MGMT_TX_ZONE,
781 "%s: Packet 20MHZ <=== %d\n", __func__,
784 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ);
785 rsi_dbg(MGMT_TX_ZONE,
786 "%s: Packet 20MHZ <=== %d\n", __func__,
792 * Bit{0:11} indicates length of the Packet
793 * Bit{12:15} indicates host queue number
795 boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) |
796 (RSI_WIFI_MGMT_Q << 12));
797 boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST);
799 skb_put(skb, sizeof(struct rsi_boot_params));
801 return rsi_send_internal_mgmt_frame(common, skb);
805 * rsi_send_reset_mac() - This function prepares reset MAC request and sends an
806 * internal management frame to indicate it to firmware.
807 * @common: Pointer to the driver private structure.
809 * Return: 0 on success, corresponding error code on failure.
811 static int rsi_send_reset_mac(struct rsi_common *common)
814 struct rsi_mac_frame *mgmt_frame;
816 rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__);
818 skb = dev_alloc_skb(FRAME_DESC_SZ);
820 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
825 memset(skb->data, 0, FRAME_DESC_SZ);
826 mgmt_frame = (struct rsi_mac_frame *)skb->data;
828 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
829 mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ);
830 mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8);
832 skb_put(skb, FRAME_DESC_SZ);
834 return rsi_send_internal_mgmt_frame(common, skb);
838 * rsi_set_channel() - This function programs the channel.
839 * @common: Pointer to the driver private structure.
840 * @channel: Channel value to be set.
842 * Return: 0 on success, corresponding error code on failure.
844 int rsi_set_channel(struct rsi_common *common, u16 channel)
846 struct sk_buff *skb = NULL;
847 struct rsi_mac_frame *mgmt_frame;
849 rsi_dbg(MGMT_TX_ZONE,
850 "%s: Sending scan req frame\n", __func__);
852 skb = dev_alloc_skb(FRAME_DESC_SZ);
854 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
859 memset(skb->data, 0, FRAME_DESC_SZ);
860 mgmt_frame = (struct rsi_mac_frame *)skb->data;
862 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
863 mgmt_frame->desc_word[1] = cpu_to_le16(SCAN_REQUEST);
864 mgmt_frame->desc_word[4] = cpu_to_le16(channel);
866 mgmt_frame->desc_word[7] = cpu_to_le16(PUT_BBP_RESET |
870 mgmt_frame->desc_word[5] = cpu_to_le16(0x01);
871 mgmt_frame->desc_word[6] = cpu_to_le16(0x12);
873 if (common->channel_width == BW_40MHZ)
874 mgmt_frame->desc_word[5] |= cpu_to_le16(0x1 << 8);
876 common->channel = channel;
878 skb_put(skb, FRAME_DESC_SZ);
880 return rsi_send_internal_mgmt_frame(common, skb);
884 * rsi_compare() - This function is used to compare two integers
885 * @a: pointer to the first integer
886 * @b: pointer to the second integer
888 * Return: 0 if both are equal, -1 if the first is smaller, else 1
890 static int rsi_compare(const void *a, const void *b)
892 u16 _a = *(const u16 *)(a);
893 u16 _b = *(const u16 *)(b);
905 * rsi_map_rates() - This function is used to map selected rates to hw rates.
906 * @rate: The standard rate to be mapped.
907 * @offset: Offset that will be returned.
909 * Return: 0 if it is a mcs rate, else 1
911 static bool rsi_map_rates(u16 rate, int *offset)
914 for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) {
915 if (rate == mcs[kk]) {
921 for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) {
922 if (rate == rsi_rates[kk].bitrate / 5) {
931 * rsi_send_auto_rate_request() - This function is to set rates for connection
932 * and send autorate request to firmware.
933 * @common: Pointer to the driver private structure.
935 * Return: 0 on success, corresponding error code on failure.
937 static int rsi_send_auto_rate_request(struct rsi_common *common)
940 struct rsi_auto_rate *auto_rate;
941 int ii = 0, jj = 0, kk = 0;
942 struct ieee80211_hw *hw = common->priv->hw;
943 u8 band = hw->conf.chandef.chan->band;
944 u8 num_supported_rates = 0;
946 u32 rate_bitmap = common->bitrate_mask[band];
948 u16 *selected_rates, min_rate;
950 skb = dev_alloc_skb(sizeof(struct rsi_auto_rate));
952 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
957 selected_rates = kmalloc(2 * RSI_TBL_SZ, GFP_KERNEL);
958 if (!selected_rates) {
959 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n",
965 memset(skb->data, 0, sizeof(struct rsi_auto_rate));
966 memset(selected_rates, 0, 2 * RSI_TBL_SZ);
968 auto_rate = (struct rsi_auto_rate *)skb->data;
970 auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f));
971 auto_rate->collision_tolerance = cpu_to_le16(3);
972 auto_rate->failure_limit = cpu_to_le16(3);
973 auto_rate->initial_boundary = cpu_to_le16(3);
974 auto_rate->max_threshold_limt = cpu_to_le16(27);
976 auto_rate->desc_word[1] = cpu_to_le16(AUTO_RATE_IND);
978 if (common->channel_width == BW_40MHZ)
979 auto_rate->desc_word[7] |= cpu_to_le16(1);
981 if (band == IEEE80211_BAND_2GHZ)
982 min_rate = STD_RATE_01;
984 min_rate = STD_RATE_06;
986 for (ii = 0, jj = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
987 if (rate_bitmap & BIT(ii)) {
988 selected_rates[jj++] = (rsi_rates[ii].bitrate / 5);
992 num_supported_rates = jj;
994 if (common->vif_info[0].is_ht) {
995 for (ii = 0; ii < ARRAY_SIZE(mcs); ii++)
996 selected_rates[jj++] = mcs[ii];
997 num_supported_rates += ARRAY_SIZE(mcs);
998 rate_offset += ARRAY_SIZE(mcs);
1001 if (rate_offset < (RSI_TBL_SZ / 2) - 1) {
1002 for (ii = jj; ii < (RSI_TBL_SZ / 2); ii++) {
1003 selected_rates[jj++] = min_rate;
1008 sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL);
1010 /* mapping the rates to RSI rates */
1011 for (ii = 0; ii < jj; ii++) {
1012 if (rsi_map_rates(selected_rates[ii], &kk)) {
1013 auto_rate->supported_rates[ii] =
1014 cpu_to_le16(rsi_rates[kk].hw_value);
1016 auto_rate->supported_rates[ii] =
1017 cpu_to_le16(rsi_mcsrates[kk]);
1021 /* loading HT rates in the bottom half of the auto rate table */
1022 if (common->vif_info[0].is_ht) {
1023 if (common->vif_info[0].sgi)
1024 auto_rate->supported_rates[rate_offset++] =
1025 cpu_to_le16(RSI_RATE_MCS7_SG);
1027 for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1;
1028 ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) {
1029 if (common->vif_info[0].sgi)
1030 auto_rate->supported_rates[ii++] =
1031 cpu_to_le16(rsi_mcsrates[kk] | BIT(9));
1032 auto_rate->supported_rates[ii] =
1033 cpu_to_le16(rsi_mcsrates[kk--]);
1036 for (; ii < RSI_TBL_SZ; ii++) {
1037 auto_rate->supported_rates[ii] =
1038 cpu_to_le16(rsi_mcsrates[0]);
1042 auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2);
1043 auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2);
1044 auto_rate->desc_word[7] |= cpu_to_le16(0 << 8);
1045 num_supported_rates *= 2;
1047 auto_rate->desc_word[0] = cpu_to_le16((sizeof(*auto_rate) -
1049 (RSI_WIFI_MGMT_Q << 12));
1052 sizeof(struct rsi_auto_rate));
1053 kfree(selected_rates);
1055 return rsi_send_internal_mgmt_frame(common, skb);
1059 * rsi_inform_bss_status() - This function informs about bss status with the
1060 * help of sta notify params by sending an internal
1061 * management frame to firmware.
1062 * @common: Pointer to the driver private structure.
1063 * @status: Bss status type.
1065 * @qos_enable: Qos is enabled.
1066 * @aid: Aid (unique for all STAs).
1070 void rsi_inform_bss_status(struct rsi_common *common,
1072 const unsigned char *bssid,
1077 rsi_hal_send_sta_notify_frame(common,
1083 if (common->min_rate == 0xffff)
1084 rsi_send_auto_rate_request(common);
1086 rsi_hal_send_sta_notify_frame(common,
1096 * rsi_eeprom_read() - This function sends a frame to read the mac address
1098 * @common: Pointer to the driver private structure.
1100 * Return: 0 on success, -1 on failure.
1102 static int rsi_eeprom_read(struct rsi_common *common)
1104 struct rsi_mac_frame *mgmt_frame;
1105 struct sk_buff *skb;
1107 rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__);
1109 skb = dev_alloc_skb(FRAME_DESC_SZ);
1111 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1116 memset(skb->data, 0, FRAME_DESC_SZ);
1117 mgmt_frame = (struct rsi_mac_frame *)skb->data;
1120 mgmt_frame->desc_word[1] = cpu_to_le16(EEPROM_READ_TYPE);
1121 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
1122 /* Number of bytes to read */
1123 mgmt_frame->desc_word[3] = cpu_to_le16(ETH_ALEN +
1124 WLAN_MAC_MAGIC_WORD_LEN +
1125 WLAN_HOST_MODE_LEN +
1126 WLAN_FW_VERSION_LEN);
1127 /* Address to read */
1128 mgmt_frame->desc_word[4] = cpu_to_le16(WLAN_MAC_EEPROM_ADDR);
1130 skb_put(skb, FRAME_DESC_SZ);
1132 return rsi_send_internal_mgmt_frame(common, skb);
1136 * rsi_handle_ta_confirm_type() - This function handles the confirm frames.
1137 * @common: Pointer to the driver private structure.
1138 * @msg: Pointer to received packet.
1140 * Return: 0 on success, -1 on failure.
1142 static int rsi_handle_ta_confirm_type(struct rsi_common *common,
1145 u8 sub_type = (msg[15] & 0xff);
1148 case BOOTUP_PARAMS_REQUEST:
1149 rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n",
1151 if (common->fsm_state == FSM_BOOT_PARAMS_SENT) {
1152 if (rsi_eeprom_read(common)) {
1153 common->fsm_state = FSM_CARD_NOT_READY;
1156 common->fsm_state = FSM_EEPROM_READ_MAC_ADDR;
1160 "%s: Received bootup params cfm in %d state\n",
1161 __func__, common->fsm_state);
1166 case EEPROM_READ_TYPE:
1167 if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) {
1168 if (msg[16] == MAGIC_WORD) {
1169 u8 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN
1170 + WLAN_MAC_MAGIC_WORD_LEN);
1171 memcpy(common->mac_addr,
1174 memcpy(&common->fw_ver,
1175 &msg[offset + ETH_ALEN],
1176 sizeof(struct version_info));
1179 common->fsm_state = FSM_CARD_NOT_READY;
1182 if (rsi_send_reset_mac(common))
1185 common->fsm_state = FSM_RESET_MAC_SENT;
1188 "%s: Received eeprom mac addr in %d state\n",
1189 __func__, common->fsm_state);
1195 if (common->fsm_state == FSM_RESET_MAC_SENT) {
1196 rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n",
1199 if (rsi_load_radio_caps(common))
1202 common->fsm_state = FSM_RADIO_CAPS_SENT;
1205 "%s: Received reset mac cfm in %d state\n",
1206 __func__, common->fsm_state);
1211 case RADIO_CAPABILITIES:
1212 if (common->fsm_state == FSM_RADIO_CAPS_SENT) {
1213 common->rf_reset = 1;
1214 if (rsi_program_bb_rf(common)) {
1217 common->fsm_state = FSM_BB_RF_PROG_SENT;
1218 rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n",
1223 "%s: Received radio caps cfm in %d state\n",
1224 __func__, common->fsm_state);
1229 case BB_PROG_VALUES_REQUEST:
1230 case RF_PROG_VALUES_REQUEST:
1231 case BBP_PROG_IN_TA:
1232 rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__);
1233 if (common->fsm_state == FSM_BB_RF_PROG_SENT) {
1234 common->bb_rf_prog_count--;
1235 if (!common->bb_rf_prog_count) {
1236 common->fsm_state = FSM_MAC_INIT_DONE;
1237 return rsi_mac80211_attach(common);
1245 rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
1251 rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n",
1257 * rsi_mgmt_pkt_recv() - This function processes the management packets
1258 * recieved from the hardware.
1259 * @common: Pointer to the driver private structure.
1260 * @msg: Pointer to the received packet.
1262 * Return: 0 on success, -1 on failure.
1264 int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg)
1266 s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff);
1267 u16 msg_type = (msg[2]);
1270 rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n",
1271 __func__, msg_len, msg_type);
1273 if (msg_type == TA_CONFIRM_TYPE) {
1274 return rsi_handle_ta_confirm_type(common, msg);
1275 } else if (msg_type == CARD_READY_IND) {
1276 rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n",
1278 if (common->fsm_state == FSM_CARD_NOT_READY) {
1279 rsi_set_default_parameters(common);
1281 ret = rsi_load_bootup_params(common);
1285 common->fsm_state = FSM_BOOT_PARAMS_SENT;
1289 } else if (msg_type == TX_STATUS_IND) {
1290 if (msg[15] == PROBEREQ_CONFIRM) {
1291 common->mgmt_q_block = false;
1292 rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n",
1296 return rsi_mgmt_pkt_to_core(common, msg, msg_len, msg_type);