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"
23 static struct bootup_params boot_params_20
= {
24 .magic_number
= cpu_to_le16(0x5aa5),
25 .crystal_good_time
= 0x0,
26 .valid
= cpu_to_le32(VALID_20
),
27 .reserved_for_valids
= 0x0,
28 .bootup_mode_info
= 0x0,
29 .digital_loop_back_params
= 0x0,
30 .rtls_timestamp_en
= 0x0,
31 .host_spi_intr_cfg
= 0x0,
35 .pll_reg_1
= cpu_to_le16((TA_PLL_N_VAL_20
<< 8)|
37 .pll_reg_2
= cpu_to_le16(TA_PLL_P_VAL_20
),
40 .pll_reg_1
= cpu_to_le16((PLL960_P_VAL_20
<< 8)|
42 .pll_reg_2
= cpu_to_le16(PLL960_M_VAL_20
),
46 .pll_reg
= cpu_to_le16(0x9f0),
50 .switch_clk_info
= cpu_to_le16(0xb),
51 .bbp_lmac_clk_reg_val
= cpu_to_le16(0x111),
52 .umac_clock_reg_config
= cpu_to_le16(0x48),
53 .qspi_uart_clock_reg_config
= cpu_to_le16(0x1211)
59 .pll_reg_1
= cpu_to_le16((TA_PLL_N_VAL_20
<< 8)|
61 .pll_reg_2
= cpu_to_le16(TA_PLL_P_VAL_20
),
64 .pll_reg_1
= cpu_to_le16((PLL960_P_VAL_20
<< 8)|
66 .pll_reg_2
= cpu_to_le16(PLL960_M_VAL_20
),
70 .pll_reg
= cpu_to_le16(0x9f0),
74 .switch_clk_info
= 0x0,
75 .bbp_lmac_clk_reg_val
= 0x0,
76 .umac_clock_reg_config
= 0x0,
77 .qspi_uart_clock_reg_config
= 0x0
83 .pll_reg_1
= cpu_to_le16((TA_PLL_N_VAL_20
<< 8)|
85 .pll_reg_2
= cpu_to_le16(TA_PLL_P_VAL_20
),
88 .pll_reg_1
= cpu_to_le16((PLL960_P_VAL_20
<< 8)|
90 .pll_reg_2
= cpu_to_le16(PLL960_M_VAL_20
),
94 .pll_reg
= cpu_to_le16(0x9f0),
98 .switch_clk_info
= 0x0,
99 .bbp_lmac_clk_reg_val
= 0x0,
100 .umac_clock_reg_config
= 0x0,
101 .qspi_uart_clock_reg_config
= 0x0
104 .buckboost_wakeup_cnt
= 0x0,
105 .pmu_wakeup_wait
= 0x0,
106 .shutdown_wait_time
= 0x0,
107 .pmu_slp_clkout_sel
= 0x0,
108 .wdt_prog_value
= 0x0,
109 .wdt_soc_rst_delay
= 0x0,
110 .dcdc_operation_mode
= 0x0,
111 .soc_reset_wait_cnt
= 0x0,
112 .waiting_time_at_fresh_sleep
= 0x0,
113 .max_threshold_to_avoid_sleep
= 0x0,
114 .beacon_resedue_alg_en
= 0,
117 static struct bootup_params boot_params_40
= {
118 .magic_number
= cpu_to_le16(0x5aa5),
119 .crystal_good_time
= 0x0,
120 .valid
= cpu_to_le32(VALID_40
),
121 .reserved_for_valids
= 0x0,
122 .bootup_mode_info
= 0x0,
123 .digital_loop_back_params
= 0x0,
124 .rtls_timestamp_en
= 0x0,
125 .host_spi_intr_cfg
= 0x0,
126 .device_clk_info
= {{
129 .pll_reg_1
= cpu_to_le16((TA_PLL_N_VAL_40
<< 8)|
131 .pll_reg_2
= cpu_to_le16(TA_PLL_P_VAL_40
),
134 .pll_reg_1
= cpu_to_le16((PLL960_P_VAL_40
<< 8)|
136 .pll_reg_2
= cpu_to_le16(PLL960_M_VAL_40
),
140 .pll_reg
= cpu_to_le16(0x9f0),
144 .switch_clk_info
= cpu_to_le16(0x09),
145 .bbp_lmac_clk_reg_val
= cpu_to_le16(0x1121),
146 .umac_clock_reg_config
= cpu_to_le16(0x48),
147 .qspi_uart_clock_reg_config
= cpu_to_le16(0x1211)
153 .pll_reg_1
= cpu_to_le16((TA_PLL_N_VAL_40
<< 8)|
155 .pll_reg_2
= cpu_to_le16(TA_PLL_P_VAL_40
),
158 .pll_reg_1
= cpu_to_le16((PLL960_P_VAL_40
<< 8)|
160 .pll_reg_2
= cpu_to_le16(PLL960_M_VAL_40
),
164 .pll_reg
= cpu_to_le16(0x9f0),
168 .switch_clk_info
= 0x0,
169 .bbp_lmac_clk_reg_val
= 0x0,
170 .umac_clock_reg_config
= 0x0,
171 .qspi_uart_clock_reg_config
= 0x0
177 .pll_reg_1
= cpu_to_le16((TA_PLL_N_VAL_40
<< 8)|
179 .pll_reg_2
= cpu_to_le16(TA_PLL_P_VAL_40
),
182 .pll_reg_1
= cpu_to_le16((PLL960_P_VAL_40
<< 8)|
184 .pll_reg_2
= cpu_to_le16(PLL960_M_VAL_40
),
188 .pll_reg
= cpu_to_le16(0x9f0),
192 .switch_clk_info
= 0x0,
193 .bbp_lmac_clk_reg_val
= 0x0,
194 .umac_clock_reg_config
= 0x0,
195 .qspi_uart_clock_reg_config
= 0x0
198 .buckboost_wakeup_cnt
= 0x0,
199 .pmu_wakeup_wait
= 0x0,
200 .shutdown_wait_time
= 0x0,
201 .pmu_slp_clkout_sel
= 0x0,
202 .wdt_prog_value
= 0x0,
203 .wdt_soc_rst_delay
= 0x0,
204 .dcdc_operation_mode
= 0x0,
205 .soc_reset_wait_cnt
= 0x0,
206 .waiting_time_at_fresh_sleep
= 0x0,
207 .max_threshold_to_avoid_sleep
= 0x0,
208 .beacon_resedue_alg_en
= 0,
211 static u16 mcs
[] = {13, 26, 39, 52, 78, 104, 117, 130};
214 * rsi_set_default_parameters() - This function sets default parameters.
215 * @common: Pointer to the driver private structure.
219 static void rsi_set_default_parameters(struct rsi_common
*common
)
221 common
->band
= NL80211_BAND_2GHZ
;
222 common
->channel_width
= BW_20MHZ
;
223 common
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
225 common
->min_rate
= 0xffff;
226 common
->fsm_state
= FSM_CARD_NOT_READY
;
227 common
->iface_down
= true;
228 common
->endpoint
= EP_2GHZ_20MHZ
;
229 common
->driver_mode
= 1; /* End to end mode */
230 common
->lp_ps_handshake_mode
= 0; /* Default no handShake mode*/
231 common
->ulp_ps_handshake_mode
= 2; /* Default PKT handShake mode*/
232 common
->rf_power_val
= 0; /* Default 1.9V */
233 common
->wlan_rf_power_mode
= 0;
234 common
->obm_ant_sel_val
= 2;
235 common
->beacon_interval
= RSI_BEACON_INTERVAL
;
236 common
->dtim_cnt
= RSI_DTIM_COUNT
;
240 * rsi_set_contention_vals() - This function sets the contention values for the
242 * @common: Pointer to the driver private structure.
246 static void rsi_set_contention_vals(struct rsi_common
*common
)
250 for (; ii
< NUM_EDCA_QUEUES
; ii
++) {
251 common
->tx_qinfo
[ii
].wme_params
=
252 (((common
->edca_params
[ii
].cw_min
/ 2) +
253 (common
->edca_params
[ii
].aifs
)) *
254 WMM_SHORT_SLOT_TIME
+ SIFS_DURATION
);
255 common
->tx_qinfo
[ii
].weight
= common
->tx_qinfo
[ii
].wme_params
;
256 common
->tx_qinfo
[ii
].pkt_contended
= 0;
261 * rsi_send_internal_mgmt_frame() - This function sends management frames to
262 * firmware.Also schedules packet to queue
264 * @common: Pointer to the driver private structure.
265 * @skb: Pointer to the socket buffer structure.
267 * Return: 0 on success, -1 on failure.
269 static int rsi_send_internal_mgmt_frame(struct rsi_common
*common
,
272 struct skb_info
*tx_params
;
273 struct rsi_cmd_desc
*desc
;
276 rsi_dbg(ERR_ZONE
, "%s: Unable to allocate skb\n", __func__
);
279 desc
= (struct rsi_cmd_desc
*)skb
->data
;
280 desc
->desc_dword0
.len_qno
|= cpu_to_le16(DESC_IMMEDIATE_WAKEUP
);
281 skb
->priority
= MGMT_SOFT_Q
;
282 tx_params
= (struct skb_info
*)&IEEE80211_SKB_CB(skb
)->driver_data
;
283 tx_params
->flags
|= INTERNAL_MGMT_PKT
;
284 skb_queue_tail(&common
->tx_queue
[MGMT_SOFT_Q
], skb
);
285 rsi_set_event(&common
->tx_thread
.event
);
290 * rsi_load_radio_caps() - This function is used to send radio capabilities
291 * values to firmware.
292 * @common: Pointer to the driver private structure.
294 * Return: 0 on success, corresponding negative error code on failure.
296 static int rsi_load_radio_caps(struct rsi_common
*common
)
298 struct rsi_radio_caps
*radio_caps
;
299 struct rsi_hw
*adapter
= common
->priv
;
303 u16 gc
[20] = {0xf0, 0xf0, 0xf0, 0xf0,
304 0xf0, 0xf0, 0xf0, 0xf0,
305 0xf0, 0xf0, 0xf0, 0xf0,
306 0xf0, 0xf0, 0xf0, 0xf0,
307 0xf0, 0xf0, 0xf0, 0xf0};
309 u16 frame_len
= sizeof(struct rsi_radio_caps
);
311 rsi_dbg(INFO_ZONE
, "%s: Sending rate symbol req frame\n", __func__
);
313 skb
= dev_alloc_skb(frame_len
);
316 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
321 memset(skb
->data
, 0, frame_len
);
322 radio_caps
= (struct rsi_radio_caps
*)skb
->data
;
324 radio_caps
->desc_dword0
.frame_type
= RADIO_CAPABILITIES
;
325 radio_caps
->channel_num
= common
->channel
;
326 radio_caps
->rf_model
= RSI_RF_TYPE
;
328 if (common
->channel_width
== BW_40MHZ
) {
329 radio_caps
->radio_cfg_info
= RSI_LMAC_CLOCK_80MHZ
;
330 radio_caps
->radio_cfg_info
|= RSI_ENABLE_40MHZ
;
332 if (common
->fsm_state
== FSM_MAC_INIT_DONE
) {
333 struct ieee80211_hw
*hw
= adapter
->hw
;
334 struct ieee80211_conf
*conf
= &hw
->conf
;
336 if (conf_is_ht40_plus(conf
)) {
337 radio_caps
->radio_cfg_info
=
338 RSI_CMDDESC_LOWER_20_ENABLE
;
339 radio_caps
->radio_info
=
340 RSI_CMDDESC_LOWER_20_ENABLE
;
341 } else if (conf_is_ht40_minus(conf
)) {
342 radio_caps
->radio_cfg_info
=
343 RSI_CMDDESC_UPPER_20_ENABLE
;
344 radio_caps
->radio_info
=
345 RSI_CMDDESC_UPPER_20_ENABLE
;
347 radio_caps
->radio_cfg_info
=
349 radio_caps
->radio_info
=
350 RSI_CMDDESC_FULL_40_ENABLE
;
354 radio_caps
->radio_info
|= radio_id
;
356 radio_caps
->sifs_tx_11n
= cpu_to_le16(SIFS_TX_11N_VALUE
);
357 radio_caps
->sifs_tx_11b
= cpu_to_le16(SIFS_TX_11B_VALUE
);
358 radio_caps
->slot_rx_11n
= cpu_to_le16(SHORT_SLOT_VALUE
);
359 radio_caps
->ofdm_ack_tout
= cpu_to_le16(OFDM_ACK_TOUT_VALUE
);
360 radio_caps
->cck_ack_tout
= cpu_to_le16(CCK_ACK_TOUT_VALUE
);
361 radio_caps
->preamble_type
= cpu_to_le16(LONG_PREAMBLE
);
363 for (ii
= 0; ii
< MAX_HW_QUEUES
; ii
++) {
364 radio_caps
->qos_params
[ii
].cont_win_min_q
= cpu_to_le16(3);
365 radio_caps
->qos_params
[ii
].cont_win_max_q
= cpu_to_le16(0x3f);
366 radio_caps
->qos_params
[ii
].aifsn_val_q
= cpu_to_le16(2);
367 radio_caps
->qos_params
[ii
].txop_q
= 0;
370 for (ii
= 0; ii
< NUM_EDCA_QUEUES
; ii
++) {
371 radio_caps
->qos_params
[ii
].cont_win_min_q
=
372 cpu_to_le16(common
->edca_params
[ii
].cw_min
);
373 radio_caps
->qos_params
[ii
].cont_win_max_q
=
374 cpu_to_le16(common
->edca_params
[ii
].cw_max
);
375 radio_caps
->qos_params
[ii
].aifsn_val_q
=
376 cpu_to_le16((common
->edca_params
[ii
].aifs
) << 8);
377 radio_caps
->qos_params
[ii
].txop_q
=
378 cpu_to_le16(common
->edca_params
[ii
].txop
);
381 radio_caps
->qos_params
[BROADCAST_HW_Q
].txop_q
= cpu_to_le16(0xffff);
382 radio_caps
->qos_params
[MGMT_HW_Q
].txop_q
= 0;
383 radio_caps
->qos_params
[BEACON_HW_Q
].txop_q
= cpu_to_le16(0xffff);
385 memcpy(&common
->rate_pwr
[0], &gc
[0], 40);
386 for (ii
= 0; ii
< 20; ii
++)
387 radio_caps
->gcpd_per_rate
[inx
++] =
388 cpu_to_le16(common
->rate_pwr
[ii
] & 0x00FF);
390 rsi_set_len_qno(&radio_caps
->desc_dword0
.len_qno
,
391 (frame_len
- FRAME_DESC_SZ
), RSI_WIFI_MGMT_Q
);
393 skb_put(skb
, frame_len
);
395 return rsi_send_internal_mgmt_frame(common
, skb
);
399 * rsi_mgmt_pkt_to_core() - This function is the entry point for Mgmt module.
400 * @common: Pointer to the driver private structure.
401 * @msg: Pointer to received packet.
402 * @msg_len: Length of the recieved packet.
403 * @type: Type of recieved packet.
405 * Return: 0 on success, -1 on failure.
407 static int rsi_mgmt_pkt_to_core(struct rsi_common
*common
,
411 struct rsi_hw
*adapter
= common
->priv
;
412 struct ieee80211_tx_info
*info
;
413 struct skb_info
*rx_params
;
414 u8 pad_bytes
= msg
[4];
417 if (!adapter
->sc_nvifs
)
420 msg_len
-= pad_bytes
;
422 rsi_dbg(MGMT_RX_ZONE
,
423 "%s: Invalid rx msg of len = %d\n",
428 skb
= dev_alloc_skb(msg_len
);
433 (u8
*)(msg
+ FRAME_DESC_SZ
+ pad_bytes
),
436 info
= IEEE80211_SKB_CB(skb
);
437 rx_params
= (struct skb_info
*)info
->driver_data
;
438 rx_params
->rssi
= rsi_get_rssi(msg
);
439 rx_params
->channel
= rsi_get_channel(msg
);
440 rsi_indicate_pkt_to_os(common
, skb
);
446 * rsi_hal_send_sta_notify_frame() - This function sends the station notify
448 * @common: Pointer to the driver private structure.
449 * @opmode: Operating mode of device.
450 * @notify_event: Notification about station connection.
452 * @qos_enable: Qos is enabled.
453 * @aid: Aid (unique for all STA).
455 * Return: status: 0 on success, corresponding negative error code on failure.
457 static int rsi_hal_send_sta_notify_frame(struct rsi_common
*common
,
460 const unsigned char *bssid
,
464 struct ieee80211_vif
*vif
)
466 struct sk_buff
*skb
= NULL
;
467 struct rsi_peer_notify
*peer_notify
;
468 u16 vap_id
= ((struct vif_priv
*)vif
->drv_priv
)->vap_id
;
470 u16 frame_len
= sizeof(struct rsi_peer_notify
);
472 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending sta notify frame\n", __func__
);
474 skb
= dev_alloc_skb(frame_len
);
477 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
482 memset(skb
->data
, 0, frame_len
);
483 peer_notify
= (struct rsi_peer_notify
*)skb
->data
;
485 if (opmode
== RSI_OPMODE_STA
)
486 peer_notify
->command
= cpu_to_le16(PEER_TYPE_AP
<< 1);
487 else if (opmode
== RSI_OPMODE_AP
)
488 peer_notify
->command
= cpu_to_le16(PEER_TYPE_STA
<< 1);
490 switch (notify_event
) {
492 peer_notify
->command
|= cpu_to_le16(RSI_ADD_PEER
);
494 case STA_DISCONNECTED
:
495 peer_notify
->command
|= cpu_to_le16(RSI_DELETE_PEER
);
501 peer_notify
->command
|= cpu_to_le16((aid
& 0xfff) << 4);
502 ether_addr_copy(peer_notify
->mac_addr
, bssid
);
503 peer_notify
->mpdu_density
= cpu_to_le16(RSI_MPDU_DENSITY
);
504 peer_notify
->sta_flags
= cpu_to_le32((qos_enable
) ? 1 : 0);
506 rsi_set_len_qno(&peer_notify
->desc
.desc_dword0
.len_qno
,
507 (frame_len
- FRAME_DESC_SZ
),
509 peer_notify
->desc
.desc_dword0
.frame_type
= PEER_NOTIFY
;
510 peer_notify
->desc
.desc_dword3
.qid_tid
= sta_id
;
511 peer_notify
->desc
.desc_dword3
.sta_id
= vap_id
;
513 skb_put(skb
, frame_len
);
515 status
= rsi_send_internal_mgmt_frame(common
, skb
);
517 if ((vif
->type
== NL80211_IFTYPE_STATION
) &&
518 (!status
&& qos_enable
)) {
519 rsi_set_contention_vals(common
);
520 status
= rsi_load_radio_caps(common
);
526 * rsi_send_aggregation_params_frame() - This function sends the ampdu
527 * indication frame to firmware.
528 * @common: Pointer to the driver private structure.
529 * @tid: traffic identifier.
531 * @buf_size: buffer size.
532 * @event: notification about station connection.
534 * Return: 0 on success, corresponding negative error code on failure.
536 int rsi_send_aggregation_params_frame(struct rsi_common
*common
,
543 struct sk_buff
*skb
= NULL
;
544 struct rsi_aggr_params
*aggr_params
;
545 u16 frame_len
= sizeof(struct rsi_aggr_params
);
547 skb
= dev_alloc_skb(frame_len
);
550 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
555 memset(skb
->data
, 0, frame_len
);
556 aggr_params
= (struct rsi_aggr_params
*)skb
->data
;
558 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending AMPDU indication frame\n", __func__
);
560 rsi_set_len_qno(&aggr_params
->desc_dword0
.len_qno
, 0, RSI_WIFI_MGMT_Q
);
561 aggr_params
->desc_dword0
.frame_type
= AMPDU_IND
;
563 aggr_params
->aggr_params
= tid
& RSI_AGGR_PARAMS_TID_MASK
;
564 aggr_params
->peer_id
= sta_id
;
565 if (event
== STA_TX_ADDBA_DONE
) {
566 aggr_params
->seq_start
= cpu_to_le16(ssn
);
567 aggr_params
->baw_size
= cpu_to_le16(buf_size
);
568 aggr_params
->aggr_params
|= RSI_AGGR_PARAMS_START
;
569 } else if (event
== STA_RX_ADDBA_DONE
) {
570 aggr_params
->seq_start
= cpu_to_le16(ssn
);
571 aggr_params
->aggr_params
|= (RSI_AGGR_PARAMS_START
|
572 RSI_AGGR_PARAMS_RX_AGGR
);
573 } else if (event
== STA_RX_DELBA
) {
574 aggr_params
->aggr_params
|= RSI_AGGR_PARAMS_RX_AGGR
;
577 skb_put(skb
, frame_len
);
579 return rsi_send_internal_mgmt_frame(common
, skb
);
583 * rsi_program_bb_rf() - This function starts base band and RF programming.
584 * This is called after initial configurations are done.
585 * @common: Pointer to the driver private structure.
587 * Return: 0 on success, corresponding negative error code on failure.
589 static int rsi_program_bb_rf(struct rsi_common
*common
)
592 struct rsi_bb_rf_prog
*bb_rf_prog
;
593 u16 frame_len
= sizeof(struct rsi_bb_rf_prog
);
595 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending program BB/RF frame\n", __func__
);
597 skb
= dev_alloc_skb(frame_len
);
599 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
604 memset(skb
->data
, 0, frame_len
);
605 bb_rf_prog
= (struct rsi_bb_rf_prog
*)skb
->data
;
607 rsi_set_len_qno(&bb_rf_prog
->desc_dword0
.len_qno
, 0, RSI_WIFI_MGMT_Q
);
608 bb_rf_prog
->desc_dword0
.frame_type
= BBP_PROG_IN_TA
;
609 bb_rf_prog
->endpoint
= common
->endpoint
;
610 bb_rf_prog
->rf_power_mode
= common
->wlan_rf_power_mode
;
612 if (common
->rf_reset
) {
613 bb_rf_prog
->flags
= cpu_to_le16(RF_RESET_ENABLE
);
614 rsi_dbg(MGMT_TX_ZONE
, "%s: ===> RF RESET REQUEST SENT <===\n",
616 common
->rf_reset
= 0;
618 common
->bb_rf_prog_count
= 1;
619 bb_rf_prog
->flags
|= cpu_to_le16(PUT_BBP_RESET
| BBP_REG_WRITE
|
621 skb_put(skb
, frame_len
);
623 return rsi_send_internal_mgmt_frame(common
, skb
);
627 * rsi_set_vap_capabilities() - This function send vap capability to firmware.
628 * @common: Pointer to the driver private structure.
629 * @opmode: Operating mode of device.
631 * Return: 0 on success, corresponding negative error code on failure.
633 int rsi_set_vap_capabilities(struct rsi_common
*common
,
639 struct sk_buff
*skb
= NULL
;
640 struct rsi_vap_caps
*vap_caps
;
641 struct rsi_hw
*adapter
= common
->priv
;
642 struct ieee80211_hw
*hw
= adapter
->hw
;
643 struct ieee80211_conf
*conf
= &hw
->conf
;
644 u16 frame_len
= sizeof(struct rsi_vap_caps
);
646 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending VAP capabilities frame\n", __func__
);
648 skb
= dev_alloc_skb(frame_len
);
650 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
655 memset(skb
->data
, 0, frame_len
);
656 vap_caps
= (struct rsi_vap_caps
*)skb
->data
;
658 rsi_set_len_qno(&vap_caps
->desc_dword0
.len_qno
,
659 (frame_len
- FRAME_DESC_SZ
), RSI_WIFI_MGMT_Q
);
660 vap_caps
->desc_dword0
.frame_type
= VAP_CAPABILITIES
;
661 vap_caps
->status
= vap_status
;
662 vap_caps
->vif_type
= mode
;
663 vap_caps
->channel_bw
= common
->channel_width
;
664 vap_caps
->vap_id
= vap_id
;
665 vap_caps
->radioid_macid
= ((common
->mac_id
& 0xf) << 4) |
666 (common
->radio_id
& 0xf);
668 memcpy(vap_caps
->mac_addr
, mac_addr
, IEEE80211_ADDR_LEN
);
669 vap_caps
->keep_alive_period
= cpu_to_le16(90);
670 vap_caps
->frag_threshold
= cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD
);
672 vap_caps
->rts_threshold
= cpu_to_le16(common
->rts_threshold
);
674 if (common
->band
== NL80211_BAND_5GHZ
) {
675 vap_caps
->default_ctrl_rate
= cpu_to_le16(RSI_RATE_6
);
676 vap_caps
->default_mgmt_rate
= cpu_to_le32(RSI_RATE_6
);
678 vap_caps
->default_ctrl_rate
= cpu_to_le16(RSI_RATE_1
);
679 vap_caps
->default_mgmt_rate
= cpu_to_le32(RSI_RATE_1
);
681 if (conf_is_ht40(conf
)) {
682 if (conf_is_ht40_minus(conf
))
683 vap_caps
->ctrl_rate_flags
=
684 cpu_to_le16(UPPER_20_ENABLE
);
685 else if (conf_is_ht40_plus(conf
))
686 vap_caps
->ctrl_rate_flags
=
687 cpu_to_le16(LOWER_20_ENABLE
);
689 vap_caps
->ctrl_rate_flags
=
690 cpu_to_le16(FULL40M_ENABLE
);
693 vap_caps
->default_data_rate
= 0;
694 vap_caps
->beacon_interval
= cpu_to_le16(common
->beacon_interval
);
695 vap_caps
->dtim_period
= cpu_to_le16(common
->dtim_cnt
);
697 skb_put(skb
, frame_len
);
699 return rsi_send_internal_mgmt_frame(common
, skb
);
703 * rsi_hal_load_key() - This function is used to load keys within the firmware.
704 * @common: Pointer to the driver private structure.
705 * @data: Pointer to the key data.
706 * @key_len: Key length to be loaded.
707 * @key_type: Type of key: GROUP/PAIRWISE.
708 * @key_id: Key index.
709 * @cipher: Type of cipher used.
711 * Return: 0 on success, -1 on failure.
713 int rsi_hal_load_key(struct rsi_common
*common
,
720 struct ieee80211_vif
*vif
)
722 struct sk_buff
*skb
= NULL
;
723 struct rsi_set_key
*set_key
;
724 u16 key_descriptor
= 0;
725 u16 frame_len
= sizeof(struct rsi_set_key
);
727 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending load key frame\n", __func__
);
729 skb
= dev_alloc_skb(frame_len
);
731 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
736 memset(skb
->data
, 0, frame_len
);
737 set_key
= (struct rsi_set_key
*)skb
->data
;
739 if (key_type
== RSI_GROUP_KEY
) {
740 key_descriptor
= RSI_KEY_TYPE_BROADCAST
;
741 if (vif
->type
== NL80211_IFTYPE_AP
)
742 key_descriptor
|= RSI_KEY_MODE_AP
;
744 if ((cipher
== WLAN_CIPHER_SUITE_WEP40
) ||
745 (cipher
== WLAN_CIPHER_SUITE_WEP104
)) {
747 key_descriptor
|= RSI_WEP_KEY
;
749 key_descriptor
|= RSI_WEP_KEY_104
;
750 } else if (cipher
!= KEY_TYPE_CLEAR
) {
751 key_descriptor
|= RSI_CIPHER_WPA
;
752 if (cipher
== WLAN_CIPHER_SUITE_TKIP
)
753 key_descriptor
|= RSI_CIPHER_TKIP
;
755 key_descriptor
|= RSI_PROTECT_DATA_FRAMES
;
756 key_descriptor
|= ((key_id
<< RSI_KEY_ID_OFFSET
) & RSI_KEY_ID_MASK
);
758 rsi_set_len_qno(&set_key
->desc_dword0
.len_qno
,
759 (frame_len
- FRAME_DESC_SZ
), RSI_WIFI_MGMT_Q
);
760 set_key
->desc_dword0
.frame_type
= SET_KEY_REQ
;
761 set_key
->key_desc
= cpu_to_le16(key_descriptor
);
762 set_key
->sta_id
= sta_id
;
765 if ((cipher
== WLAN_CIPHER_SUITE_WEP40
) ||
766 (cipher
== WLAN_CIPHER_SUITE_WEP104
)) {
767 memcpy(&set_key
->key
[key_id
][1], data
, key_len
* 2);
769 memcpy(&set_key
->key
[0][0], data
, key_len
);
771 memcpy(set_key
->tx_mic_key
, &data
[16], 8);
772 memcpy(set_key
->rx_mic_key
, &data
[24], 8);
774 memset(&set_key
[FRAME_DESC_SZ
], 0, frame_len
- FRAME_DESC_SZ
);
777 skb_put(skb
, frame_len
);
779 return rsi_send_internal_mgmt_frame(common
, skb
);
783 * This function sends the common device configuration parameters to device.
784 * This frame includes the useful information to make device works on
785 * specific operating mode.
787 static int rsi_send_common_dev_params(struct rsi_common
*common
)
791 struct rsi_config_vals
*dev_cfgs
;
793 frame_len
= sizeof(struct rsi_config_vals
);
795 rsi_dbg(MGMT_TX_ZONE
, "Sending common device config params\n");
796 skb
= dev_alloc_skb(frame_len
);
798 rsi_dbg(ERR_ZONE
, "%s: Unable to allocate skb\n", __func__
);
802 memset(skb
->data
, 0, frame_len
);
804 dev_cfgs
= (struct rsi_config_vals
*)skb
->data
;
805 memset(dev_cfgs
, 0, (sizeof(struct rsi_config_vals
)));
807 rsi_set_len_qno(&dev_cfgs
->len_qno
, (frame_len
- FRAME_DESC_SZ
),
809 dev_cfgs
->pkt_type
= COMMON_DEV_CONFIG
;
811 dev_cfgs
->lp_ps_handshake
= common
->lp_ps_handshake_mode
;
812 dev_cfgs
->ulp_ps_handshake
= common
->ulp_ps_handshake_mode
;
814 dev_cfgs
->unused_ulp_gpio
= RSI_UNUSED_ULP_GPIO_BITMAP
;
815 dev_cfgs
->unused_soc_gpio_bitmap
=
816 cpu_to_le32(RSI_UNUSED_SOC_GPIO_BITMAP
);
818 dev_cfgs
->opermode
= common
->oper_mode
;
819 dev_cfgs
->wlan_rf_pwr_mode
= common
->wlan_rf_power_mode
;
820 dev_cfgs
->driver_mode
= common
->driver_mode
;
821 dev_cfgs
->region_code
= NL80211_DFS_FCC
;
822 dev_cfgs
->antenna_sel_val
= common
->obm_ant_sel_val
;
824 skb_put(skb
, frame_len
);
826 return rsi_send_internal_mgmt_frame(common
, skb
);
830 * rsi_load_bootup_params() - This function send bootup params to the firmware.
831 * @common: Pointer to the driver private structure.
833 * Return: 0 on success, corresponding error code on failure.
835 static int rsi_load_bootup_params(struct rsi_common
*common
)
838 struct rsi_boot_params
*boot_params
;
840 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending boot params frame\n", __func__
);
841 skb
= dev_alloc_skb(sizeof(struct rsi_boot_params
));
843 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
848 memset(skb
->data
, 0, sizeof(struct rsi_boot_params
));
849 boot_params
= (struct rsi_boot_params
*)skb
->data
;
851 rsi_dbg(MGMT_TX_ZONE
, "%s:\n", __func__
);
853 if (common
->channel_width
== BW_40MHZ
) {
854 memcpy(&boot_params
->bootup_params
,
856 sizeof(struct bootup_params
));
857 rsi_dbg(MGMT_TX_ZONE
, "%s: Packet 40MHZ <=== %d\n", __func__
,
859 boot_params
->desc_word
[7] = cpu_to_le16(UMAC_CLK_40BW
);
861 memcpy(&boot_params
->bootup_params
,
863 sizeof(struct bootup_params
));
864 if (boot_params_20
.valid
!= cpu_to_le32(VALID_20
)) {
865 boot_params
->desc_word
[7] = cpu_to_le16(UMAC_CLK_20BW
);
866 rsi_dbg(MGMT_TX_ZONE
,
867 "%s: Packet 20MHZ <=== %d\n", __func__
,
870 boot_params
->desc_word
[7] = cpu_to_le16(UMAC_CLK_40MHZ
);
871 rsi_dbg(MGMT_TX_ZONE
,
872 "%s: Packet 20MHZ <=== %d\n", __func__
,
878 * Bit{0:11} indicates length of the Packet
879 * Bit{12:15} indicates host queue number
881 boot_params
->desc_word
[0] = cpu_to_le16(sizeof(struct bootup_params
) |
882 (RSI_WIFI_MGMT_Q
<< 12));
883 boot_params
->desc_word
[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST
);
885 skb_put(skb
, sizeof(struct rsi_boot_params
));
887 return rsi_send_internal_mgmt_frame(common
, skb
);
891 * rsi_send_reset_mac() - This function prepares reset MAC request and sends an
892 * internal management frame to indicate it to firmware.
893 * @common: Pointer to the driver private structure.
895 * Return: 0 on success, corresponding error code on failure.
897 static int rsi_send_reset_mac(struct rsi_common
*common
)
900 struct rsi_mac_frame
*mgmt_frame
;
902 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending reset MAC frame\n", __func__
);
904 skb
= dev_alloc_skb(FRAME_DESC_SZ
);
906 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
911 memset(skb
->data
, 0, FRAME_DESC_SZ
);
912 mgmt_frame
= (struct rsi_mac_frame
*)skb
->data
;
914 mgmt_frame
->desc_word
[0] = cpu_to_le16(RSI_WIFI_MGMT_Q
<< 12);
915 mgmt_frame
->desc_word
[1] = cpu_to_le16(RESET_MAC_REQ
);
916 mgmt_frame
->desc_word
[4] = cpu_to_le16(RETRY_COUNT
<< 8);
918 skb_put(skb
, FRAME_DESC_SZ
);
920 return rsi_send_internal_mgmt_frame(common
, skb
);
924 * rsi_band_check() - This function programs the band
925 * @common: Pointer to the driver private structure.
927 * Return: 0 on success, corresponding error code on failure.
929 int rsi_band_check(struct rsi_common
*common
,
930 struct ieee80211_channel
*curchan
)
932 struct rsi_hw
*adapter
= common
->priv
;
933 struct ieee80211_hw
*hw
= adapter
->hw
;
934 u8 prev_bw
= common
->channel_width
;
935 u8 prev_ep
= common
->endpoint
;
938 if (common
->band
!= curchan
->band
) {
939 common
->rf_reset
= 1;
940 common
->band
= curchan
->band
;
943 if ((hw
->conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
) ||
944 (hw
->conf
.chandef
.width
== NL80211_CHAN_WIDTH_20
))
945 common
->channel_width
= BW_20MHZ
;
947 common
->channel_width
= BW_40MHZ
;
949 if (common
->band
== NL80211_BAND_2GHZ
) {
950 if (common
->channel_width
)
951 common
->endpoint
= EP_2GHZ_40MHZ
;
953 common
->endpoint
= EP_2GHZ_20MHZ
;
955 if (common
->channel_width
)
956 common
->endpoint
= EP_5GHZ_40MHZ
;
958 common
->endpoint
= EP_5GHZ_20MHZ
;
961 if (common
->endpoint
!= prev_ep
) {
962 status
= rsi_program_bb_rf(common
);
967 if (common
->channel_width
!= prev_bw
) {
968 status
= rsi_load_bootup_params(common
);
972 status
= rsi_load_radio_caps(common
);
981 * rsi_set_channel() - This function programs the channel.
982 * @common: Pointer to the driver private structure.
983 * @channel: Channel value to be set.
985 * Return: 0 on success, corresponding error code on failure.
987 int rsi_set_channel(struct rsi_common
*common
,
988 struct ieee80211_channel
*channel
)
990 struct sk_buff
*skb
= NULL
;
991 struct rsi_chan_config
*chan_cfg
;
992 u16 frame_len
= sizeof(struct rsi_chan_config
);
994 rsi_dbg(MGMT_TX_ZONE
,
995 "%s: Sending scan req frame\n", __func__
);
997 skb
= dev_alloc_skb(frame_len
);
999 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
1008 memset(skb
->data
, 0, frame_len
);
1009 chan_cfg
= (struct rsi_chan_config
*)skb
->data
;
1011 rsi_set_len_qno(&chan_cfg
->desc_dword0
.len_qno
, 0, RSI_WIFI_MGMT_Q
);
1012 chan_cfg
->desc_dword0
.frame_type
= SCAN_REQUEST
;
1013 chan_cfg
->channel_number
= channel
->hw_value
;
1014 chan_cfg
->antenna_gain_offset_2g
= channel
->max_antenna_gain
;
1015 chan_cfg
->antenna_gain_offset_5g
= channel
->max_antenna_gain
;
1016 chan_cfg
->region_rftype
= (RSI_RF_TYPE
& 0xf) << 4;
1018 if ((channel
->flags
& IEEE80211_CHAN_NO_IR
) ||
1019 (channel
->flags
& IEEE80211_CHAN_RADAR
)) {
1020 chan_cfg
->antenna_gain_offset_2g
|= RSI_CHAN_RADAR
;
1022 if (common
->tx_power
< channel
->max_power
)
1023 chan_cfg
->tx_power
= cpu_to_le16(common
->tx_power
);
1025 chan_cfg
->tx_power
= cpu_to_le16(channel
->max_power
);
1027 chan_cfg
->region_rftype
|= (common
->priv
->dfs_region
& 0xf);
1029 if (common
->channel_width
== BW_40MHZ
)
1030 chan_cfg
->channel_width
= 0x1;
1032 common
->channel
= channel
->hw_value
;
1034 skb_put(skb
, frame_len
);
1036 return rsi_send_internal_mgmt_frame(common
, skb
);
1040 * rsi_send_radio_params_update() - This function sends the radio
1041 * parameters update to device
1042 * @common: Pointer to the driver private structure.
1043 * @channel: Channel value to be set.
1045 * Return: 0 on success, corresponding error code on failure.
1047 int rsi_send_radio_params_update(struct rsi_common
*common
)
1049 struct rsi_mac_frame
*cmd_frame
;
1050 struct sk_buff
*skb
= NULL
;
1052 rsi_dbg(MGMT_TX_ZONE
,
1053 "%s: Sending Radio Params update frame\n", __func__
);
1055 skb
= dev_alloc_skb(FRAME_DESC_SZ
);
1057 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
1062 memset(skb
->data
, 0, FRAME_DESC_SZ
);
1063 cmd_frame
= (struct rsi_mac_frame
*)skb
->data
;
1065 cmd_frame
->desc_word
[0] = cpu_to_le16(RSI_WIFI_MGMT_Q
<< 12);
1066 cmd_frame
->desc_word
[1] = cpu_to_le16(RADIO_PARAMS_UPDATE
);
1067 cmd_frame
->desc_word
[3] = cpu_to_le16(BIT(0));
1069 cmd_frame
->desc_word
[3] |= cpu_to_le16(common
->tx_power
<< 8);
1071 skb_put(skb
, FRAME_DESC_SZ
);
1073 return rsi_send_internal_mgmt_frame(common
, skb
);
1076 /* This function programs the threshold. */
1077 int rsi_send_vap_dynamic_update(struct rsi_common
*common
)
1079 struct sk_buff
*skb
;
1080 struct rsi_dynamic_s
*dynamic_frame
;
1082 rsi_dbg(MGMT_TX_ZONE
,
1083 "%s: Sending vap update indication frame\n", __func__
);
1085 skb
= dev_alloc_skb(sizeof(struct rsi_dynamic_s
));
1089 memset(skb
->data
, 0, sizeof(struct rsi_dynamic_s
));
1090 dynamic_frame
= (struct rsi_dynamic_s
*)skb
->data
;
1091 rsi_set_len_qno(&dynamic_frame
->desc_dword0
.len_qno
,
1092 sizeof(dynamic_frame
->frame_body
), RSI_WIFI_MGMT_Q
);
1094 dynamic_frame
->desc_dword0
.frame_type
= VAP_DYNAMIC_UPDATE
;
1095 dynamic_frame
->desc_dword2
.pkt_info
=
1096 cpu_to_le32(common
->rts_threshold
);
1098 if (common
->wow_flags
& RSI_WOW_ENABLED
) {
1099 /* Beacon miss threshold */
1100 dynamic_frame
->desc_dword3
.token
=
1101 cpu_to_le16(RSI_BCN_MISS_THRESHOLD
);
1102 dynamic_frame
->frame_body
.keep_alive_period
=
1103 cpu_to_le16(RSI_WOW_KEEPALIVE
);
1105 dynamic_frame
->frame_body
.keep_alive_period
=
1106 cpu_to_le16(RSI_DEF_KEEPALIVE
);
1109 dynamic_frame
->desc_dword3
.sta_id
= 0; /* vap id */
1111 skb_put(skb
, sizeof(struct rsi_dynamic_s
));
1113 return rsi_send_internal_mgmt_frame(common
, skb
);
1117 * rsi_compare() - This function is used to compare two integers
1118 * @a: pointer to the first integer
1119 * @b: pointer to the second integer
1121 * Return: 0 if both are equal, -1 if the first is smaller, else 1
1123 static int rsi_compare(const void *a
, const void *b
)
1125 u16 _a
= *(const u16
*)(a
);
1126 u16 _b
= *(const u16
*)(b
);
1138 * rsi_map_rates() - This function is used to map selected rates to hw rates.
1139 * @rate: The standard rate to be mapped.
1140 * @offset: Offset that will be returned.
1142 * Return: 0 if it is a mcs rate, else 1
1144 static bool rsi_map_rates(u16 rate
, int *offset
)
1147 for (kk
= 0; kk
< ARRAY_SIZE(rsi_mcsrates
); kk
++) {
1148 if (rate
== mcs
[kk
]) {
1154 for (kk
= 0; kk
< ARRAY_SIZE(rsi_rates
); kk
++) {
1155 if (rate
== rsi_rates
[kk
].bitrate
/ 5) {
1164 * rsi_send_auto_rate_request() - This function is to set rates for connection
1165 * and send autorate request to firmware.
1166 * @common: Pointer to the driver private structure.
1168 * Return: 0 on success, corresponding error code on failure.
1170 static int rsi_send_auto_rate_request(struct rsi_common
*common
,
1171 struct ieee80211_sta
*sta
,
1173 struct ieee80211_vif
*vif
)
1175 struct sk_buff
*skb
;
1176 struct rsi_auto_rate
*auto_rate
;
1177 int ii
= 0, jj
= 0, kk
= 0;
1178 struct ieee80211_hw
*hw
= common
->priv
->hw
;
1179 u8 band
= hw
->conf
.chandef
.chan
->band
;
1180 u8 num_supported_rates
= 0;
1181 u8 rate_table_offset
, rate_offset
= 0;
1183 u16
*selected_rates
, min_rate
;
1184 bool is_ht
= false, is_sgi
= false;
1185 u16 frame_len
= sizeof(struct rsi_auto_rate
);
1187 rsi_dbg(MGMT_TX_ZONE
,
1188 "%s: Sending auto rate request frame\n", __func__
);
1190 skb
= dev_alloc_skb(frame_len
);
1192 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
1197 selected_rates
= kzalloc(2 * RSI_TBL_SZ
, GFP_KERNEL
);
1198 if (!selected_rates
) {
1199 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of mem\n",
1205 auto_rate
= (struct rsi_auto_rate
*)skb
->data
;
1207 auto_rate
->aarf_rssi
= cpu_to_le16(((u16
)3 << 6) | (u16
)(18 & 0x3f));
1208 auto_rate
->collision_tolerance
= cpu_to_le16(3);
1209 auto_rate
->failure_limit
= cpu_to_le16(3);
1210 auto_rate
->initial_boundary
= cpu_to_le16(3);
1211 auto_rate
->max_threshold_limt
= cpu_to_le16(27);
1213 auto_rate
->desc
.desc_dword0
.frame_type
= AUTO_RATE_IND
;
1215 if (common
->channel_width
== BW_40MHZ
)
1216 auto_rate
->desc
.desc_dword3
.qid_tid
= BW_40MHZ
;
1217 auto_rate
->desc
.desc_dword3
.sta_id
= sta_id
;
1219 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1220 rate_bitmap
= common
->bitrate_mask
[band
];
1221 is_ht
= common
->vif_info
[0].is_ht
;
1222 is_sgi
= common
->vif_info
[0].sgi
;
1224 rate_bitmap
= sta
->supp_rates
[band
];
1225 is_ht
= sta
->ht_cap
.ht_supported
;
1226 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ||
1227 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
1231 if (band
== NL80211_BAND_2GHZ
) {
1232 if ((rate_bitmap
== 0) && (is_ht
))
1233 min_rate
= RSI_RATE_MCS0
;
1235 min_rate
= RSI_RATE_1
;
1236 rate_table_offset
= 0;
1238 if ((rate_bitmap
== 0) && (is_ht
))
1239 min_rate
= RSI_RATE_MCS0
;
1241 min_rate
= RSI_RATE_6
;
1242 rate_table_offset
= 4;
1245 for (ii
= 0, jj
= 0;
1246 ii
< (ARRAY_SIZE(rsi_rates
) - rate_table_offset
); ii
++) {
1247 if (rate_bitmap
& BIT(ii
)) {
1248 selected_rates
[jj
++] =
1249 (rsi_rates
[ii
+ rate_table_offset
].bitrate
/ 5);
1253 num_supported_rates
= jj
;
1256 for (ii
= 0; ii
< ARRAY_SIZE(mcs
); ii
++)
1257 selected_rates
[jj
++] = mcs
[ii
];
1258 num_supported_rates
+= ARRAY_SIZE(mcs
);
1259 rate_offset
+= ARRAY_SIZE(mcs
);
1262 sort(selected_rates
, jj
, sizeof(u16
), &rsi_compare
, NULL
);
1264 /* mapping the rates to RSI rates */
1265 for (ii
= 0; ii
< jj
; ii
++) {
1266 if (rsi_map_rates(selected_rates
[ii
], &kk
)) {
1267 auto_rate
->supported_rates
[ii
] =
1268 cpu_to_le16(rsi_rates
[kk
].hw_value
);
1270 auto_rate
->supported_rates
[ii
] =
1271 cpu_to_le16(rsi_mcsrates
[kk
]);
1275 /* loading HT rates in the bottom half of the auto rate table */
1277 for (ii
= rate_offset
, kk
= ARRAY_SIZE(rsi_mcsrates
) - 1;
1278 ii
< rate_offset
+ 2 * ARRAY_SIZE(rsi_mcsrates
); ii
++) {
1279 if (is_sgi
|| conf_is_ht40(&common
->priv
->hw
->conf
))
1280 auto_rate
->supported_rates
[ii
++] =
1281 cpu_to_le16(rsi_mcsrates
[kk
] | BIT(9));
1283 auto_rate
->supported_rates
[ii
++] =
1284 cpu_to_le16(rsi_mcsrates
[kk
]);
1285 auto_rate
->supported_rates
[ii
] =
1286 cpu_to_le16(rsi_mcsrates
[kk
--]);
1289 for (; ii
< (RSI_TBL_SZ
- 1); ii
++) {
1290 auto_rate
->supported_rates
[ii
] =
1291 cpu_to_le16(rsi_mcsrates
[0]);
1295 for (; ii
< RSI_TBL_SZ
; ii
++)
1296 auto_rate
->supported_rates
[ii
] = cpu_to_le16(min_rate
);
1298 auto_rate
->num_supported_rates
= cpu_to_le16(num_supported_rates
* 2);
1299 auto_rate
->moderate_rate_inx
= cpu_to_le16(num_supported_rates
/ 2);
1300 num_supported_rates
*= 2;
1302 rsi_set_len_qno(&auto_rate
->desc
.desc_dword0
.len_qno
,
1303 (frame_len
- FRAME_DESC_SZ
), RSI_WIFI_MGMT_Q
);
1305 skb_put(skb
, frame_len
);
1306 kfree(selected_rates
);
1308 return rsi_send_internal_mgmt_frame(common
, skb
);
1312 * rsi_inform_bss_status() - This function informs about bss status with the
1313 * help of sta notify params by sending an internal
1314 * management frame to firmware.
1315 * @common: Pointer to the driver private structure.
1316 * @status: Bss status type.
1318 * @qos_enable: Qos is enabled.
1319 * @aid: Aid (unique for all STAs).
1323 void rsi_inform_bss_status(struct rsi_common
*common
,
1329 struct ieee80211_sta
*sta
,
1331 struct ieee80211_vif
*vif
)
1334 if (opmode
== RSI_OPMODE_STA
)
1335 common
->hw_data_qs_blocked
= true;
1336 rsi_hal_send_sta_notify_frame(common
,
1343 if (common
->min_rate
== 0xffff)
1344 rsi_send_auto_rate_request(common
, sta
, sta_id
, vif
);
1345 if (opmode
== RSI_OPMODE_STA
) {
1346 if (!rsi_send_block_unblock_frame(common
, false))
1347 common
->hw_data_qs_blocked
= false;
1350 if (opmode
== RSI_OPMODE_STA
)
1351 common
->hw_data_qs_blocked
= true;
1353 if (!(common
->wow_flags
& RSI_WOW_ENABLED
))
1354 rsi_hal_send_sta_notify_frame(common
, opmode
,
1355 STA_DISCONNECTED
, addr
,
1356 qos_enable
, aid
, sta_id
,
1358 if (opmode
== RSI_OPMODE_STA
)
1359 rsi_send_block_unblock_frame(common
, true);
1364 * rsi_eeprom_read() - This function sends a frame to read the mac address
1366 * @common: Pointer to the driver private structure.
1368 * Return: 0 on success, -1 on failure.
1370 static int rsi_eeprom_read(struct rsi_common
*common
)
1372 struct rsi_eeprom_read_frame
*mgmt_frame
;
1373 struct rsi_hw
*adapter
= common
->priv
;
1374 struct sk_buff
*skb
;
1376 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending EEPROM read req frame\n", __func__
);
1378 skb
= dev_alloc_skb(FRAME_DESC_SZ
);
1380 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
1385 memset(skb
->data
, 0, FRAME_DESC_SZ
);
1386 mgmt_frame
= (struct rsi_eeprom_read_frame
*)skb
->data
;
1389 rsi_set_len_qno(&mgmt_frame
->len_qno
, 0, RSI_WIFI_MGMT_Q
);
1390 mgmt_frame
->pkt_type
= EEPROM_READ
;
1392 /* Number of bytes to read */
1393 mgmt_frame
->pkt_info
=
1394 cpu_to_le32((adapter
->eeprom
.length
<< RSI_EEPROM_LEN_OFFSET
) &
1395 RSI_EEPROM_LEN_MASK
);
1396 mgmt_frame
->pkt_info
|= cpu_to_le32((3 << RSI_EEPROM_HDR_SIZE_OFFSET
) &
1397 RSI_EEPROM_HDR_SIZE_MASK
);
1399 /* Address to read */
1400 mgmt_frame
->eeprom_offset
= cpu_to_le32(adapter
->eeprom
.offset
);
1402 skb_put(skb
, FRAME_DESC_SZ
);
1404 return rsi_send_internal_mgmt_frame(common
, skb
);
1408 * This function sends a frame to block/unblock
1409 * data queues in the firmware
1411 * @param common Pointer to the driver private structure.
1412 * @param block event - block if true, unblock if false
1413 * @return 0 on success, -1 on failure.
1415 int rsi_send_block_unblock_frame(struct rsi_common
*common
, bool block_event
)
1417 struct rsi_block_unblock_data
*mgmt_frame
;
1418 struct sk_buff
*skb
;
1420 rsi_dbg(MGMT_TX_ZONE
, "%s: Sending block/unblock frame\n", __func__
);
1422 skb
= dev_alloc_skb(FRAME_DESC_SZ
);
1424 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
1429 memset(skb
->data
, 0, FRAME_DESC_SZ
);
1430 mgmt_frame
= (struct rsi_block_unblock_data
*)skb
->data
;
1432 rsi_set_len_qno(&mgmt_frame
->desc_dword0
.len_qno
, 0, RSI_WIFI_MGMT_Q
);
1433 mgmt_frame
->desc_dword0
.frame_type
= BLOCK_HW_QUEUE
;
1434 mgmt_frame
->host_quiet_info
= QUIET_INFO_VALID
;
1437 rsi_dbg(INFO_ZONE
, "blocking the data qs\n");
1438 mgmt_frame
->block_q_bitmap
= cpu_to_le16(0xf);
1439 mgmt_frame
->block_q_bitmap
|= cpu_to_le16(0xf << 4);
1441 rsi_dbg(INFO_ZONE
, "unblocking the data qs\n");
1442 mgmt_frame
->unblock_q_bitmap
= cpu_to_le16(0xf);
1443 mgmt_frame
->unblock_q_bitmap
|= cpu_to_le16(0xf << 4);
1446 skb_put(skb
, FRAME_DESC_SZ
);
1448 return rsi_send_internal_mgmt_frame(common
, skb
);
1452 * rsi_send_rx_filter_frame() - Sends a frame to filter the RX packets
1454 * @common: Pointer to the driver private structure.
1455 * @rx_filter_word: Flags of filter packets
1457 * @Return: 0 on success, -1 on failure.
1459 int rsi_send_rx_filter_frame(struct rsi_common
*common
, u16 rx_filter_word
)
1461 struct rsi_mac_frame
*cmd_frame
;
1462 struct sk_buff
*skb
;
1464 rsi_dbg(MGMT_TX_ZONE
, "Sending RX filter frame\n");
1466 skb
= dev_alloc_skb(FRAME_DESC_SZ
);
1468 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
1473 memset(skb
->data
, 0, FRAME_DESC_SZ
);
1474 cmd_frame
= (struct rsi_mac_frame
*)skb
->data
;
1476 cmd_frame
->desc_word
[0] = cpu_to_le16(RSI_WIFI_MGMT_Q
<< 12);
1477 cmd_frame
->desc_word
[1] = cpu_to_le16(SET_RX_FILTER
);
1478 cmd_frame
->desc_word
[4] = cpu_to_le16(rx_filter_word
);
1480 skb_put(skb
, FRAME_DESC_SZ
);
1482 return rsi_send_internal_mgmt_frame(common
, skb
);
1485 int rsi_send_ps_request(struct rsi_hw
*adapter
, bool enable
,
1486 struct ieee80211_vif
*vif
)
1488 struct rsi_common
*common
= adapter
->priv
;
1489 struct ieee80211_bss_conf
*bss
= &vif
->bss_conf
;
1490 struct rsi_request_ps
*ps
;
1491 struct rsi_ps_info
*ps_info
;
1492 struct sk_buff
*skb
;
1493 int frame_len
= sizeof(*ps
);
1495 skb
= dev_alloc_skb(frame_len
);
1498 memset(skb
->data
, 0, frame_len
);
1500 ps
= (struct rsi_request_ps
*)skb
->data
;
1501 ps_info
= &adapter
->ps_info
;
1503 rsi_set_len_qno(&ps
->desc
.desc_dword0
.len_qno
,
1504 (frame_len
- FRAME_DESC_SZ
), RSI_WIFI_MGMT_Q
);
1505 ps
->desc
.desc_dword0
.frame_type
= WAKEUP_SLEEP_REQUEST
;
1507 ps
->ps_sleep
.enable
= RSI_PS_ENABLE
;
1508 ps
->desc
.desc_dword3
.token
= cpu_to_le16(RSI_SLEEP_REQUEST
);
1510 ps
->ps_sleep
.enable
= RSI_PS_DISABLE
;
1511 ps
->desc
.desc_dword0
.len_qno
|= cpu_to_le16(RSI_PS_DISABLE_IND
);
1512 ps
->desc
.desc_dword3
.token
= cpu_to_le16(RSI_WAKEUP_REQUEST
);
1515 ps
->ps_uapsd_acs
= common
->uapsd_bitmap
;
1517 ps
->ps_sleep
.sleep_type
= ps_info
->sleep_type
;
1518 ps
->ps_sleep
.num_bcns_per_lis_int
=
1519 cpu_to_le16(ps_info
->num_bcns_per_lis_int
);
1520 ps
->ps_sleep
.sleep_duration
=
1521 cpu_to_le32(ps_info
->deep_sleep_wakeup_period
);
1524 ps
->ps_sleep
.connected_sleep
= RSI_CONNECTED_SLEEP
;
1526 ps
->ps_sleep
.connected_sleep
= RSI_DEEP_SLEEP
;
1528 ps
->ps_listen_interval
= cpu_to_le32(ps_info
->listen_interval
);
1529 ps
->ps_dtim_interval_duration
=
1530 cpu_to_le32(ps_info
->dtim_interval_duration
);
1532 if (ps_info
->listen_interval
> ps_info
->dtim_interval_duration
)
1533 ps
->ps_listen_interval
= cpu_to_le32(RSI_PS_DISABLE
);
1535 ps
->ps_num_dtim_intervals
= cpu_to_le16(ps_info
->num_dtims_per_sleep
);
1536 skb_put(skb
, frame_len
);
1538 return rsi_send_internal_mgmt_frame(common
, skb
);
1542 * rsi_set_antenna() - This fuction send antenna configuration request
1545 * @common: Pointer to the driver private structure.
1546 * @antenna: bitmap for tx antenna selection
1548 * Return: 0 on Success, negative error code on failure
1550 int rsi_set_antenna(struct rsi_common
*common
, u8 antenna
)
1552 struct rsi_ant_sel_frame
*ant_sel_frame
;
1553 struct sk_buff
*skb
;
1555 skb
= dev_alloc_skb(FRAME_DESC_SZ
);
1557 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of skb\n",
1562 memset(skb
->data
, 0, FRAME_DESC_SZ
);
1564 ant_sel_frame
= (struct rsi_ant_sel_frame
*)skb
->data
;
1565 ant_sel_frame
->desc_dword0
.frame_type
= ANT_SEL_FRAME
;
1566 ant_sel_frame
->sub_frame_type
= ANTENNA_SEL_TYPE
;
1567 ant_sel_frame
->ant_value
= cpu_to_le16(antenna
& ANTENNA_MASK_VALUE
);
1568 rsi_set_len_qno(&ant_sel_frame
->desc_dword0
.len_qno
,
1569 0, RSI_WIFI_MGMT_Q
);
1570 skb_put(skb
, FRAME_DESC_SZ
);
1572 return rsi_send_internal_mgmt_frame(common
, skb
);
1575 static int rsi_send_beacon(struct rsi_common
*common
)
1577 struct sk_buff
*skb
= NULL
;
1578 u8 dword_align_bytes
= 0;
1580 skb
= dev_alloc_skb(MAX_MGMT_PKT_SIZE
);
1584 memset(skb
->data
, 0, MAX_MGMT_PKT_SIZE
);
1586 dword_align_bytes
= ((unsigned long)skb
->data
& 0x3f);
1587 if (dword_align_bytes
)
1588 skb_pull(skb
, (64 - dword_align_bytes
));
1589 if (rsi_prepare_beacon(common
, skb
)) {
1590 rsi_dbg(ERR_ZONE
, "Failed to prepare beacon\n");
1593 skb_queue_tail(&common
->tx_queue
[MGMT_BEACON_Q
], skb
);
1594 rsi_set_event(&common
->tx_thread
.event
);
1595 rsi_dbg(DATA_TX_ZONE
, "%s: Added to beacon queue\n", __func__
);
1601 int rsi_send_wowlan_request(struct rsi_common
*common
, u16 flags
,
1604 struct rsi_wowlan_req
*cmd_frame
;
1605 struct sk_buff
*skb
;
1608 rsi_dbg(ERR_ZONE
, "%s: Sending wowlan request frame\n", __func__
);
1610 length
= sizeof(*cmd_frame
);
1611 skb
= dev_alloc_skb(length
);
1614 memset(skb
->data
, 0, length
);
1615 cmd_frame
= (struct rsi_wowlan_req
*)skb
->data
;
1617 rsi_set_len_qno(&cmd_frame
->desc
.desc_dword0
.len_qno
,
1618 (length
- FRAME_DESC_SZ
),
1620 cmd_frame
->desc
.desc_dword0
.frame_type
= WOWLAN_CONFIG_PARAMS
;
1621 cmd_frame
->host_sleep_status
= sleep_status
;
1622 if (common
->secinfo
.security_enable
&&
1623 common
->secinfo
.gtk_cipher
)
1624 flags
|= RSI_WOW_GTK_REKEY
;
1626 cmd_frame
->wow_flags
= flags
;
1627 rsi_dbg(INFO_ZONE
, "Host_Sleep_Status : %d Flags : %d\n",
1628 cmd_frame
->host_sleep_status
, cmd_frame
->wow_flags
);
1630 skb_put(skb
, length
);
1632 return rsi_send_internal_mgmt_frame(common
, skb
);
1637 * rsi_handle_ta_confirm_type() - This function handles the confirm frames.
1638 * @common: Pointer to the driver private structure.
1639 * @msg: Pointer to received packet.
1641 * Return: 0 on success, -1 on failure.
1643 static int rsi_handle_ta_confirm_type(struct rsi_common
*common
,
1646 struct rsi_hw
*adapter
= common
->priv
;
1647 u8 sub_type
= (msg
[15] & 0xff);
1648 u16 msg_len
= ((u16
*)msg
)[0] & 0xfff;
1652 case BOOTUP_PARAMS_REQUEST
:
1653 rsi_dbg(FSM_ZONE
, "%s: Boot up params confirm received\n",
1655 if (common
->fsm_state
== FSM_BOOT_PARAMS_SENT
) {
1656 adapter
->eeprom
.length
= (IEEE80211_ADDR_LEN
+
1657 WLAN_MAC_MAGIC_WORD_LEN
+
1658 WLAN_HOST_MODE_LEN
);
1659 adapter
->eeprom
.offset
= WLAN_MAC_EEPROM_ADDR
;
1660 if (rsi_eeprom_read(common
)) {
1661 common
->fsm_state
= FSM_CARD_NOT_READY
;
1664 common
->fsm_state
= FSM_EEPROM_READ_MAC_ADDR
;
1667 "%s: Received bootup params cfm in %d state\n",
1668 __func__
, common
->fsm_state
);
1674 rsi_dbg(FSM_ZONE
, "EEPROM READ confirm received\n");
1677 "%s: [EEPROM_READ] Invalid len %d\n",
1681 if (msg
[16] != MAGIC_WORD
) {
1683 "%s: [EEPROM_READ] Invalid token\n", __func__
);
1684 common
->fsm_state
= FSM_CARD_NOT_READY
;
1687 if (common
->fsm_state
== FSM_EEPROM_READ_MAC_ADDR
) {
1688 offset
= (FRAME_DESC_SZ
+ WLAN_HOST_MODE_LEN
+
1689 WLAN_MAC_MAGIC_WORD_LEN
);
1690 memcpy(common
->mac_addr
, &msg
[offset
], ETH_ALEN
);
1691 adapter
->eeprom
.length
=
1692 ((WLAN_MAC_MAGIC_WORD_LEN
+ 3) & (~3));
1693 adapter
->eeprom
.offset
= WLAN_EEPROM_RFTYPE_ADDR
;
1694 if (rsi_eeprom_read(common
)) {
1696 "%s: Failed reading RF band\n",
1698 common
->fsm_state
= FSM_CARD_NOT_READY
;
1701 common
->fsm_state
= FSM_EEPROM_READ_RF_TYPE
;
1702 } else if (common
->fsm_state
== FSM_EEPROM_READ_RF_TYPE
) {
1703 if ((msg
[17] & 0x3) == 0x3) {
1704 rsi_dbg(INIT_ZONE
, "Dual band supported\n");
1705 common
->band
= NL80211_BAND_5GHZ
;
1706 common
->num_supp_bands
= 2;
1707 } else if ((msg
[17] & 0x3) == 0x1) {
1709 "Only 2.4Ghz band supported\n");
1710 common
->band
= NL80211_BAND_2GHZ
;
1711 common
->num_supp_bands
= 1;
1713 if (rsi_send_reset_mac(common
))
1715 common
->fsm_state
= FSM_RESET_MAC_SENT
;
1717 rsi_dbg(ERR_ZONE
, "%s: Invalid EEPROM read type\n",
1724 if (common
->fsm_state
== FSM_RESET_MAC_SENT
) {
1725 rsi_dbg(FSM_ZONE
, "%s: Reset MAC cfm received\n",
1728 if (rsi_load_radio_caps(common
))
1731 common
->fsm_state
= FSM_RADIO_CAPS_SENT
;
1734 "%s: Received reset mac cfm in %d state\n",
1735 __func__
, common
->fsm_state
);
1740 case RADIO_CAPABILITIES
:
1741 if (common
->fsm_state
== FSM_RADIO_CAPS_SENT
) {
1742 common
->rf_reset
= 1;
1743 if (rsi_program_bb_rf(common
)) {
1746 common
->fsm_state
= FSM_BB_RF_PROG_SENT
;
1747 rsi_dbg(FSM_ZONE
, "%s: Radio cap cfm received\n",
1752 "%s: Received radio caps cfm in %d state\n",
1753 __func__
, common
->fsm_state
);
1758 case BB_PROG_VALUES_REQUEST
:
1759 case RF_PROG_VALUES_REQUEST
:
1760 case BBP_PROG_IN_TA
:
1761 rsi_dbg(FSM_ZONE
, "%s: BB/RF cfm received\n", __func__
);
1762 if (common
->fsm_state
== FSM_BB_RF_PROG_SENT
) {
1763 common
->bb_rf_prog_count
--;
1764 if (!common
->bb_rf_prog_count
) {
1765 common
->fsm_state
= FSM_MAC_INIT_DONE
;
1766 if (common
->reinit_hw
) {
1767 complete(&common
->wlan_init_completion
);
1769 return rsi_mac80211_attach(common
);
1774 "%s: Received bbb_rf cfm in %d state\n",
1775 __func__
, common
->fsm_state
);
1779 case WAKEUP_SLEEP_REQUEST
:
1780 rsi_dbg(INFO_ZONE
, "Wakeup/Sleep confirmation.\n");
1781 return rsi_handle_ps_confirm(adapter
, msg
);
1783 rsi_dbg(INFO_ZONE
, "%s: Invalid TA confirm pkt received\n",
1789 rsi_dbg(ERR_ZONE
, "%s: Unable to send pkt/Invalid frame received\n",
1794 static int rsi_handle_card_ready(struct rsi_common
*common
, u8
*msg
)
1796 switch (common
->fsm_state
) {
1797 case FSM_CARD_NOT_READY
:
1798 rsi_dbg(INIT_ZONE
, "Card ready indication from Common HAL\n");
1799 rsi_set_default_parameters(common
);
1800 if (rsi_send_common_dev_params(common
) < 0)
1802 common
->fsm_state
= FSM_COMMON_DEV_PARAMS_SENT
;
1804 case FSM_COMMON_DEV_PARAMS_SENT
:
1805 rsi_dbg(INIT_ZONE
, "Card ready indication from WLAN HAL\n");
1807 /* Get usb buffer status register address */
1808 common
->priv
->usb_buffer_status_reg
= *(u32
*)&msg
[8];
1809 rsi_dbg(INFO_ZONE
, "USB buffer status register = %x\n",
1810 common
->priv
->usb_buffer_status_reg
);
1812 if (rsi_load_bootup_params(common
)) {
1813 common
->fsm_state
= FSM_CARD_NOT_READY
;
1816 common
->fsm_state
= FSM_BOOT_PARAMS_SENT
;
1820 "%s: card ready indication in invalid state %d.\n",
1821 __func__
, common
->fsm_state
);
1829 * rsi_mgmt_pkt_recv() - This function processes the management packets
1830 * recieved from the hardware.
1831 * @common: Pointer to the driver private structure.
1832 * @msg: Pointer to the received packet.
1834 * Return: 0 on success, -1 on failure.
1836 int rsi_mgmt_pkt_recv(struct rsi_common
*common
, u8
*msg
)
1838 s32 msg_len
= (le16_to_cpu(*(__le16
*)&msg
[0]) & 0x0fff);
1839 u16 msg_type
= (msg
[2]);
1841 rsi_dbg(FSM_ZONE
, "%s: Msg Len: %d, Msg Type: %4x\n",
1842 __func__
, msg_len
, msg_type
);
1845 case TA_CONFIRM_TYPE
:
1846 return rsi_handle_ta_confirm_type(common
, msg
);
1847 case CARD_READY_IND
:
1848 common
->hibernate_resume
= false;
1849 rsi_dbg(FSM_ZONE
, "%s: Card ready indication received\n",
1851 return rsi_handle_card_ready(common
, msg
);
1853 if (msg
[15] == PROBEREQ_CONFIRM
) {
1854 common
->mgmt_q_block
= false;
1855 rsi_dbg(FSM_ZONE
, "%s: Probe confirm received\n",
1859 case BEACON_EVENT_IND
:
1860 rsi_dbg(INFO_ZONE
, "Beacon event\n");
1861 if (common
->fsm_state
!= FSM_MAC_INIT_DONE
)
1863 if (common
->iface_down
)
1865 if (!common
->beacon_enabled
)
1867 rsi_send_beacon(common
);
1870 return rsi_mgmt_pkt_to_core(common
, msg
, msg_len
);
1872 rsi_dbg(INFO_ZONE
, "Received packet type: 0x%x\n", msg_type
);