0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/etherdevice.h>
0018 #include <linux/timer.h>
0019 #include "rsi_mgmt.h"
0020 #include "rsi_common.h"
0021 #include "rsi_ps.h"
0022 #include "rsi_hal.h"
0023
0024 static struct bootup_params boot_params_20 = {
0025 .magic_number = cpu_to_le16(0x5aa5),
0026 .crystal_good_time = 0x0,
0027 .valid = cpu_to_le32(VALID_20),
0028 .reserved_for_valids = 0x0,
0029 .bootup_mode_info = 0x0,
0030 .digital_loop_back_params = 0x0,
0031 .rtls_timestamp_en = 0x0,
0032 .host_spi_intr_cfg = 0x0,
0033 .device_clk_info = {{
0034 .pll_config_g = {
0035 .tapll_info_g = {
0036 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
0037 (TA_PLL_M_VAL_20)),
0038 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
0039 },
0040 .pll960_info_g = {
0041 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
0042 (PLL960_N_VAL_20)),
0043 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
0044 .pll_reg_3 = 0x0,
0045 },
0046 .afepll_info_g = {
0047 .pll_reg = cpu_to_le16(0x9f0),
0048 }
0049 },
0050 .switch_clk_g = {
0051 .switch_clk_info = cpu_to_le16(0xb),
0052 .bbp_lmac_clk_reg_val = cpu_to_le16(0x111),
0053 .umac_clock_reg_config = cpu_to_le16(0x48),
0054 .qspi_uart_clock_reg_config = cpu_to_le16(0x1211)
0055 }
0056 },
0057 {
0058 .pll_config_g = {
0059 .tapll_info_g = {
0060 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
0061 (TA_PLL_M_VAL_20)),
0062 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
0063 },
0064 .pll960_info_g = {
0065 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
0066 (PLL960_N_VAL_20)),
0067 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
0068 .pll_reg_3 = 0x0,
0069 },
0070 .afepll_info_g = {
0071 .pll_reg = cpu_to_le16(0x9f0),
0072 }
0073 },
0074 .switch_clk_g = {
0075 .switch_clk_info = 0x0,
0076 .bbp_lmac_clk_reg_val = 0x0,
0077 .umac_clock_reg_config = 0x0,
0078 .qspi_uart_clock_reg_config = 0x0
0079 }
0080 },
0081 {
0082 .pll_config_g = {
0083 .tapll_info_g = {
0084 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
0085 (TA_PLL_M_VAL_20)),
0086 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
0087 },
0088 .pll960_info_g = {
0089 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
0090 (PLL960_N_VAL_20)),
0091 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
0092 .pll_reg_3 = 0x0,
0093 },
0094 .afepll_info_g = {
0095 .pll_reg = cpu_to_le16(0x9f0),
0096 }
0097 },
0098 .switch_clk_g = {
0099 .switch_clk_info = 0x0,
0100 .bbp_lmac_clk_reg_val = 0x0,
0101 .umac_clock_reg_config = 0x0,
0102 .qspi_uart_clock_reg_config = 0x0
0103 }
0104 } },
0105 .buckboost_wakeup_cnt = 0x0,
0106 .pmu_wakeup_wait = 0x0,
0107 .shutdown_wait_time = 0x0,
0108 .pmu_slp_clkout_sel = 0x0,
0109 .wdt_prog_value = 0x0,
0110 .wdt_soc_rst_delay = 0x0,
0111 .dcdc_operation_mode = 0x0,
0112 .soc_reset_wait_cnt = 0x0,
0113 .waiting_time_at_fresh_sleep = 0x0,
0114 .max_threshold_to_avoid_sleep = 0x0,
0115 .beacon_resedue_alg_en = 0,
0116 };
0117
0118 static struct bootup_params boot_params_40 = {
0119 .magic_number = cpu_to_le16(0x5aa5),
0120 .crystal_good_time = 0x0,
0121 .valid = cpu_to_le32(VALID_40),
0122 .reserved_for_valids = 0x0,
0123 .bootup_mode_info = 0x0,
0124 .digital_loop_back_params = 0x0,
0125 .rtls_timestamp_en = 0x0,
0126 .host_spi_intr_cfg = 0x0,
0127 .device_clk_info = {{
0128 .pll_config_g = {
0129 .tapll_info_g = {
0130 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
0131 (TA_PLL_M_VAL_40)),
0132 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
0133 },
0134 .pll960_info_g = {
0135 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
0136 (PLL960_N_VAL_40)),
0137 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
0138 .pll_reg_3 = 0x0,
0139 },
0140 .afepll_info_g = {
0141 .pll_reg = cpu_to_le16(0x9f0),
0142 }
0143 },
0144 .switch_clk_g = {
0145 .switch_clk_info = cpu_to_le16(0x09),
0146 .bbp_lmac_clk_reg_val = cpu_to_le16(0x1121),
0147 .umac_clock_reg_config = cpu_to_le16(0x48),
0148 .qspi_uart_clock_reg_config = cpu_to_le16(0x1211)
0149 }
0150 },
0151 {
0152 .pll_config_g = {
0153 .tapll_info_g = {
0154 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
0155 (TA_PLL_M_VAL_40)),
0156 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
0157 },
0158 .pll960_info_g = {
0159 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
0160 (PLL960_N_VAL_40)),
0161 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
0162 .pll_reg_3 = 0x0,
0163 },
0164 .afepll_info_g = {
0165 .pll_reg = cpu_to_le16(0x9f0),
0166 }
0167 },
0168 .switch_clk_g = {
0169 .switch_clk_info = 0x0,
0170 .bbp_lmac_clk_reg_val = 0x0,
0171 .umac_clock_reg_config = 0x0,
0172 .qspi_uart_clock_reg_config = 0x0
0173 }
0174 },
0175 {
0176 .pll_config_g = {
0177 .tapll_info_g = {
0178 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
0179 (TA_PLL_M_VAL_40)),
0180 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
0181 },
0182 .pll960_info_g = {
0183 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
0184 (PLL960_N_VAL_40)),
0185 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
0186 .pll_reg_3 = 0x0,
0187 },
0188 .afepll_info_g = {
0189 .pll_reg = cpu_to_le16(0x9f0),
0190 }
0191 },
0192 .switch_clk_g = {
0193 .switch_clk_info = 0x0,
0194 .bbp_lmac_clk_reg_val = 0x0,
0195 .umac_clock_reg_config = 0x0,
0196 .qspi_uart_clock_reg_config = 0x0
0197 }
0198 } },
0199 .buckboost_wakeup_cnt = 0x0,
0200 .pmu_wakeup_wait = 0x0,
0201 .shutdown_wait_time = 0x0,
0202 .pmu_slp_clkout_sel = 0x0,
0203 .wdt_prog_value = 0x0,
0204 .wdt_soc_rst_delay = 0x0,
0205 .dcdc_operation_mode = 0x0,
0206 .soc_reset_wait_cnt = 0x0,
0207 .waiting_time_at_fresh_sleep = 0x0,
0208 .max_threshold_to_avoid_sleep = 0x0,
0209 .beacon_resedue_alg_en = 0,
0210 };
0211
0212 static struct bootup_params_9116 boot_params_9116_20 = {
0213 .magic_number = cpu_to_le16(LOADED_TOKEN),
0214 .valid = cpu_to_le32(VALID_20),
0215 .device_clk_info_9116 = {{
0216 .pll_config_9116_g = {
0217 .pll_ctrl_set_reg = cpu_to_le16(0xd518),
0218 .pll_ctrl_clr_reg = cpu_to_le16(0x2ae7),
0219 .pll_modem_conig_reg = cpu_to_le16(0x2000),
0220 .soc_clk_config_reg = cpu_to_le16(0x0c18),
0221 .adc_dac_strm1_config_reg = cpu_to_le16(0x1100),
0222 .adc_dac_strm2_config_reg = cpu_to_le16(0x6600),
0223 },
0224 .switch_clk_9116_g = {
0225 .switch_clk_info =
0226 cpu_to_le32((RSI_SWITCH_TASS_CLK |
0227 RSI_SWITCH_WLAN_BBP_LMAC_CLK_REG |
0228 RSI_SWITCH_BBP_LMAC_CLK_REG)),
0229 .tass_clock_reg = cpu_to_le32(0x083C0503),
0230 .wlan_bbp_lmac_clk_reg_val = cpu_to_le32(0x01042001),
0231 .zbbt_bbp_lmac_clk_reg_val = cpu_to_le32(0x02010001),
0232 .bbp_lmac_clk_en_val = cpu_to_le32(0x0000003b),
0233 }
0234 },
0235 },
0236 };
0237
0238 static struct bootup_params_9116 boot_params_9116_40 = {
0239 .magic_number = cpu_to_le16(LOADED_TOKEN),
0240 .valid = cpu_to_le32(VALID_40),
0241 .device_clk_info_9116 = {{
0242 .pll_config_9116_g = {
0243 .pll_ctrl_set_reg = cpu_to_le16(0xd518),
0244 .pll_ctrl_clr_reg = cpu_to_le16(0x2ae7),
0245 .pll_modem_conig_reg = cpu_to_le16(0x3000),
0246 .soc_clk_config_reg = cpu_to_le16(0x0c18),
0247 .adc_dac_strm1_config_reg = cpu_to_le16(0x0000),
0248 .adc_dac_strm2_config_reg = cpu_to_le16(0x6600),
0249 },
0250 .switch_clk_9116_g = {
0251 .switch_clk_info =
0252 cpu_to_le32((RSI_SWITCH_TASS_CLK |
0253 RSI_SWITCH_WLAN_BBP_LMAC_CLK_REG |
0254 RSI_SWITCH_BBP_LMAC_CLK_REG |
0255 RSI_MODEM_CLK_160MHZ)),
0256 .tass_clock_reg = cpu_to_le32(0x083C0503),
0257 .wlan_bbp_lmac_clk_reg_val = cpu_to_le32(0x01042002),
0258 .zbbt_bbp_lmac_clk_reg_val = cpu_to_le32(0x04010002),
0259 .bbp_lmac_clk_en_val = cpu_to_le32(0x0000003b),
0260 }
0261 },
0262 },
0263 };
0264
0265 static u16 mcs[] = {13, 26, 39, 52, 78, 104, 117, 130};
0266
0267
0268
0269
0270
0271
0272
0273 static void rsi_set_default_parameters(struct rsi_common *common)
0274 {
0275 common->band = NL80211_BAND_2GHZ;
0276 common->channel_width = BW_20MHZ;
0277 common->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
0278 common->channel = 1;
0279 memset(&common->rate_config, 0, sizeof(common->rate_config));
0280 common->fsm_state = FSM_CARD_NOT_READY;
0281 common->iface_down = true;
0282 common->endpoint = EP_2GHZ_20MHZ;
0283 common->driver_mode = 1;
0284 common->lp_ps_handshake_mode = 0;
0285 common->ulp_ps_handshake_mode = 2;
0286 common->rf_power_val = 0;
0287 common->wlan_rf_power_mode = 0;
0288 common->obm_ant_sel_val = 2;
0289 common->beacon_interval = RSI_BEACON_INTERVAL;
0290 common->dtim_cnt = RSI_DTIM_COUNT;
0291 common->w9116_features.pll_mode = 0x0;
0292 common->w9116_features.rf_type = 1;
0293 common->w9116_features.wireless_mode = 0;
0294 common->w9116_features.enable_ppe = 0;
0295 common->w9116_features.afe_type = 1;
0296 common->w9116_features.dpd = 0;
0297 common->w9116_features.sifs_tx_enable = 0;
0298 common->w9116_features.ps_options = 0;
0299 }
0300
0301 void init_bgscan_params(struct rsi_common *common)
0302 {
0303 memset((u8 *)&common->bgscan, 0, sizeof(struct rsi_bgscan_params));
0304 common->bgscan.bgscan_threshold = RSI_DEF_BGSCAN_THRLD;
0305 common->bgscan.roam_threshold = RSI_DEF_ROAM_THRLD;
0306 common->bgscan.bgscan_periodicity = RSI_BGSCAN_PERIODICITY;
0307 common->bgscan.num_bgscan_channels = 0;
0308 common->bgscan.two_probe = 1;
0309 common->bgscan.active_scan_duration = RSI_ACTIVE_SCAN_TIME;
0310 common->bgscan.passive_scan_duration = RSI_PASSIVE_SCAN_TIME;
0311 }
0312
0313
0314
0315
0316
0317
0318
0319
0320 static void rsi_set_contention_vals(struct rsi_common *common)
0321 {
0322 u8 ii = 0;
0323
0324 for (; ii < NUM_EDCA_QUEUES; ii++) {
0325 common->tx_qinfo[ii].wme_params =
0326 (((common->edca_params[ii].cw_min / 2) +
0327 (common->edca_params[ii].aifs)) *
0328 WMM_SHORT_SLOT_TIME + SIFS_DURATION);
0329 common->tx_qinfo[ii].weight = common->tx_qinfo[ii].wme_params;
0330 common->tx_qinfo[ii].pkt_contended = 0;
0331 }
0332 }
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343 static int rsi_send_internal_mgmt_frame(struct rsi_common *common,
0344 struct sk_buff *skb)
0345 {
0346 struct skb_info *tx_params;
0347 struct rsi_cmd_desc *desc;
0348
0349 if (skb == NULL) {
0350 rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
0351 return -ENOMEM;
0352 }
0353 desc = (struct rsi_cmd_desc *)skb->data;
0354 desc->desc_dword0.len_qno |= cpu_to_le16(DESC_IMMEDIATE_WAKEUP);
0355 skb->priority = MGMT_SOFT_Q;
0356 tx_params = (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data;
0357 tx_params->flags |= INTERNAL_MGMT_PKT;
0358 skb_queue_tail(&common->tx_queue[MGMT_SOFT_Q], skb);
0359 rsi_set_event(&common->tx_thread.event);
0360 return 0;
0361 }
0362
0363
0364
0365
0366
0367
0368
0369
0370 static int rsi_load_radio_caps(struct rsi_common *common)
0371 {
0372 struct rsi_radio_caps *radio_caps;
0373 struct rsi_hw *adapter = common->priv;
0374 u16 inx = 0;
0375 u8 ii;
0376 u8 radio_id = 0;
0377 u16 gc[20] = {0xf0, 0xf0, 0xf0, 0xf0,
0378 0xf0, 0xf0, 0xf0, 0xf0,
0379 0xf0, 0xf0, 0xf0, 0xf0,
0380 0xf0, 0xf0, 0xf0, 0xf0,
0381 0xf0, 0xf0, 0xf0, 0xf0};
0382 struct sk_buff *skb;
0383 u16 frame_len = sizeof(struct rsi_radio_caps);
0384
0385 rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__);
0386
0387 skb = dev_alloc_skb(frame_len);
0388
0389 if (!skb) {
0390 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
0391 __func__);
0392 return -ENOMEM;
0393 }
0394
0395 memset(skb->data, 0, frame_len);
0396 radio_caps = (struct rsi_radio_caps *)skb->data;
0397
0398 radio_caps->desc_dword0.frame_type = RADIO_CAPABILITIES;
0399 radio_caps->channel_num = common->channel;
0400 radio_caps->rf_model = RSI_RF_TYPE;
0401
0402 radio_caps->radio_cfg_info = RSI_LMAC_CLOCK_80MHZ;
0403 if (common->channel_width == BW_40MHZ) {
0404 radio_caps->radio_cfg_info |= RSI_ENABLE_40MHZ;
0405
0406 if (common->fsm_state == FSM_MAC_INIT_DONE) {
0407 struct ieee80211_hw *hw = adapter->hw;
0408 struct ieee80211_conf *conf = &hw->conf;
0409
0410 if (conf_is_ht40_plus(conf)) {
0411 radio_caps->ppe_ack_rate =
0412 cpu_to_le16(LOWER_20_ENABLE |
0413 (LOWER_20_ENABLE >> 12));
0414 } else if (conf_is_ht40_minus(conf)) {
0415 radio_caps->ppe_ack_rate =
0416 cpu_to_le16(UPPER_20_ENABLE |
0417 (UPPER_20_ENABLE >> 12));
0418 } else {
0419 radio_caps->ppe_ack_rate =
0420 cpu_to_le16((BW_40MHZ << 12) |
0421 FULL40M_ENABLE);
0422 }
0423 }
0424 }
0425 radio_caps->radio_info |= radio_id;
0426
0427 if (adapter->device_model == RSI_DEV_9116 &&
0428 common->channel_width == BW_20MHZ)
0429 radio_caps->radio_cfg_info &= ~0x3;
0430
0431 radio_caps->sifs_tx_11n = cpu_to_le16(SIFS_TX_11N_VALUE);
0432 radio_caps->sifs_tx_11b = cpu_to_le16(SIFS_TX_11B_VALUE);
0433 radio_caps->slot_rx_11n = cpu_to_le16(SHORT_SLOT_VALUE);
0434 radio_caps->ofdm_ack_tout = cpu_to_le16(OFDM_ACK_TOUT_VALUE);
0435 radio_caps->cck_ack_tout = cpu_to_le16(CCK_ACK_TOUT_VALUE);
0436 radio_caps->preamble_type = cpu_to_le16(LONG_PREAMBLE);
0437
0438 for (ii = 0; ii < MAX_HW_QUEUES; ii++) {
0439 radio_caps->qos_params[ii].cont_win_min_q = cpu_to_le16(3);
0440 radio_caps->qos_params[ii].cont_win_max_q = cpu_to_le16(0x3f);
0441 radio_caps->qos_params[ii].aifsn_val_q = cpu_to_le16(2);
0442 radio_caps->qos_params[ii].txop_q = 0;
0443 }
0444
0445 for (ii = 0; ii < NUM_EDCA_QUEUES; ii++) {
0446 if (common->edca_params[ii].cw_max > 0) {
0447 radio_caps->qos_params[ii].cont_win_min_q =
0448 cpu_to_le16(common->edca_params[ii].cw_min);
0449 radio_caps->qos_params[ii].cont_win_max_q =
0450 cpu_to_le16(common->edca_params[ii].cw_max);
0451 radio_caps->qos_params[ii].aifsn_val_q =
0452 cpu_to_le16(common->edca_params[ii].aifs << 8);
0453 radio_caps->qos_params[ii].txop_q =
0454 cpu_to_le16(common->edca_params[ii].txop);
0455 }
0456 }
0457
0458 radio_caps->qos_params[BROADCAST_HW_Q].txop_q = cpu_to_le16(0xffff);
0459 radio_caps->qos_params[MGMT_HW_Q].txop_q = 0;
0460 radio_caps->qos_params[BEACON_HW_Q].txop_q = cpu_to_le16(0xffff);
0461
0462 memcpy(&common->rate_pwr[0], &gc[0], 40);
0463 for (ii = 0; ii < 20; ii++)
0464 radio_caps->gcpd_per_rate[inx++] =
0465 cpu_to_le16(common->rate_pwr[ii] & 0x00FF);
0466
0467 rsi_set_len_qno(&radio_caps->desc_dword0.len_qno,
0468 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
0469
0470 skb_put(skb, frame_len);
0471
0472 return rsi_send_internal_mgmt_frame(common, skb);
0473 }
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483 static int rsi_mgmt_pkt_to_core(struct rsi_common *common,
0484 u8 *msg,
0485 s32 msg_len)
0486 {
0487 struct rsi_hw *adapter = common->priv;
0488 struct ieee80211_tx_info *info;
0489 struct skb_info *rx_params;
0490 u8 pad_bytes = msg[4];
0491 struct sk_buff *skb;
0492
0493 if (!adapter->sc_nvifs)
0494 return -ENOLINK;
0495
0496 msg_len -= pad_bytes;
0497 if (msg_len <= 0) {
0498 rsi_dbg(MGMT_RX_ZONE,
0499 "%s: Invalid rx msg of len = %d\n",
0500 __func__, msg_len);
0501 return -EINVAL;
0502 }
0503
0504 skb = dev_alloc_skb(msg_len);
0505 if (!skb)
0506 return -ENOMEM;
0507
0508 skb_put_data(skb,
0509 (u8 *)(msg + FRAME_DESC_SZ + pad_bytes),
0510 msg_len);
0511
0512 info = IEEE80211_SKB_CB(skb);
0513 rx_params = (struct skb_info *)info->driver_data;
0514 rx_params->rssi = rsi_get_rssi(msg);
0515 rx_params->channel = rsi_get_channel(msg);
0516 rsi_indicate_pkt_to_os(common, skb);
0517
0518 return 0;
0519 }
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535 int rsi_hal_send_sta_notify_frame(struct rsi_common *common, enum opmode opmode,
0536 u8 notify_event, const unsigned char *bssid,
0537 u8 qos_enable, u16 aid, u16 sta_id,
0538 struct ieee80211_vif *vif)
0539 {
0540 struct sk_buff *skb = NULL;
0541 struct rsi_peer_notify *peer_notify;
0542 u16 vap_id = ((struct vif_priv *)vif->drv_priv)->vap_id;
0543 int status;
0544 u16 frame_len = sizeof(struct rsi_peer_notify);
0545
0546 rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__);
0547
0548 skb = dev_alloc_skb(frame_len);
0549
0550 if (!skb) {
0551 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
0552 __func__);
0553 return -ENOMEM;
0554 }
0555
0556 memset(skb->data, 0, frame_len);
0557 peer_notify = (struct rsi_peer_notify *)skb->data;
0558
0559 if (opmode == RSI_OPMODE_STA)
0560 peer_notify->command = cpu_to_le16(PEER_TYPE_AP << 1);
0561 else if (opmode == RSI_OPMODE_AP)
0562 peer_notify->command = cpu_to_le16(PEER_TYPE_STA << 1);
0563
0564 switch (notify_event) {
0565 case STA_CONNECTED:
0566 peer_notify->command |= cpu_to_le16(RSI_ADD_PEER);
0567 break;
0568 case STA_DISCONNECTED:
0569 peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER);
0570 break;
0571 default:
0572 break;
0573 }
0574
0575 peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4);
0576 ether_addr_copy(peer_notify->mac_addr, bssid);
0577 peer_notify->mpdu_density = cpu_to_le16(RSI_MPDU_DENSITY);
0578 peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0);
0579
0580 rsi_set_len_qno(&peer_notify->desc.desc_dword0.len_qno,
0581 (frame_len - FRAME_DESC_SZ),
0582 RSI_WIFI_MGMT_Q);
0583 peer_notify->desc.desc_dword0.frame_type = PEER_NOTIFY;
0584 peer_notify->desc.desc_dword3.qid_tid = sta_id;
0585 peer_notify->desc.desc_dword3.sta_id = vap_id;
0586
0587 skb_put(skb, frame_len);
0588
0589 status = rsi_send_internal_mgmt_frame(common, skb);
0590
0591 if ((vif->type == NL80211_IFTYPE_STATION) &&
0592 (!status && qos_enable)) {
0593 rsi_set_contention_vals(common);
0594 status = rsi_load_radio_caps(common);
0595 }
0596 return status;
0597 }
0598
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611 int rsi_send_aggregation_params_frame(struct rsi_common *common,
0612 u16 tid,
0613 u16 ssn,
0614 u8 buf_size,
0615 u8 event,
0616 u8 sta_id)
0617 {
0618 struct sk_buff *skb = NULL;
0619 struct rsi_aggr_params *aggr_params;
0620 u16 frame_len = sizeof(struct rsi_aggr_params);
0621
0622 skb = dev_alloc_skb(frame_len);
0623
0624 if (!skb) {
0625 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
0626 __func__);
0627 return -ENOMEM;
0628 }
0629
0630 memset(skb->data, 0, frame_len);
0631 aggr_params = (struct rsi_aggr_params *)skb->data;
0632
0633 rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__);
0634
0635 rsi_set_len_qno(&aggr_params->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q);
0636 aggr_params->desc_dword0.frame_type = AMPDU_IND;
0637
0638 aggr_params->aggr_params = tid & RSI_AGGR_PARAMS_TID_MASK;
0639 aggr_params->peer_id = sta_id;
0640 if (event == STA_TX_ADDBA_DONE) {
0641 aggr_params->seq_start = cpu_to_le16(ssn);
0642 aggr_params->baw_size = cpu_to_le16(buf_size);
0643 aggr_params->aggr_params |= RSI_AGGR_PARAMS_START;
0644 } else if (event == STA_RX_ADDBA_DONE) {
0645 aggr_params->seq_start = cpu_to_le16(ssn);
0646 aggr_params->aggr_params |= (RSI_AGGR_PARAMS_START |
0647 RSI_AGGR_PARAMS_RX_AGGR);
0648 } else if (event == STA_RX_DELBA) {
0649 aggr_params->aggr_params |= RSI_AGGR_PARAMS_RX_AGGR;
0650 }
0651
0652 skb_put(skb, frame_len);
0653
0654 return rsi_send_internal_mgmt_frame(common, skb);
0655 }
0656
0657
0658
0659
0660
0661
0662
0663
0664 static int rsi_program_bb_rf(struct rsi_common *common)
0665 {
0666 struct sk_buff *skb;
0667 struct rsi_bb_rf_prog *bb_rf_prog;
0668 u16 frame_len = sizeof(struct rsi_bb_rf_prog);
0669
0670 rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__);
0671
0672 skb = dev_alloc_skb(frame_len);
0673 if (!skb) {
0674 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
0675 __func__);
0676 return -ENOMEM;
0677 }
0678
0679 memset(skb->data, 0, frame_len);
0680 bb_rf_prog = (struct rsi_bb_rf_prog *)skb->data;
0681
0682 rsi_set_len_qno(&bb_rf_prog->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q);
0683 bb_rf_prog->desc_dword0.frame_type = BBP_PROG_IN_TA;
0684 bb_rf_prog->endpoint = common->endpoint;
0685 bb_rf_prog->rf_power_mode = common->wlan_rf_power_mode;
0686
0687 if (common->rf_reset) {
0688 bb_rf_prog->flags = cpu_to_le16(RF_RESET_ENABLE);
0689 rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n",
0690 __func__);
0691 common->rf_reset = 0;
0692 }
0693 common->bb_rf_prog_count = 1;
0694 bb_rf_prog->flags |= cpu_to_le16(PUT_BBP_RESET | BBP_REG_WRITE |
0695 (RSI_RF_TYPE << 4));
0696 skb_put(skb, frame_len);
0697
0698 return rsi_send_internal_mgmt_frame(common, skb);
0699 }
0700
0701
0702
0703
0704
0705
0706
0707
0708
0709
0710
0711 int rsi_set_vap_capabilities(struct rsi_common *common,
0712 enum opmode mode,
0713 u8 *mac_addr,
0714 u8 vap_id,
0715 u8 vap_status)
0716 {
0717 struct sk_buff *skb = NULL;
0718 struct rsi_vap_caps *vap_caps;
0719 struct rsi_hw *adapter = common->priv;
0720 struct ieee80211_hw *hw = adapter->hw;
0721 struct ieee80211_conf *conf = &hw->conf;
0722 u16 frame_len = sizeof(struct rsi_vap_caps);
0723
0724 rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__);
0725
0726 skb = dev_alloc_skb(frame_len);
0727 if (!skb) {
0728 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
0729 __func__);
0730 return -ENOMEM;
0731 }
0732
0733 memset(skb->data, 0, frame_len);
0734 vap_caps = (struct rsi_vap_caps *)skb->data;
0735
0736 rsi_set_len_qno(&vap_caps->desc_dword0.len_qno,
0737 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
0738 vap_caps->desc_dword0.frame_type = VAP_CAPABILITIES;
0739 vap_caps->status = vap_status;
0740 vap_caps->vif_type = mode;
0741 vap_caps->channel_bw = common->channel_width;
0742 vap_caps->vap_id = vap_id;
0743 vap_caps->radioid_macid = ((common->mac_id & 0xf) << 4) |
0744 (common->radio_id & 0xf);
0745
0746 memcpy(vap_caps->mac_addr, mac_addr, IEEE80211_ADDR_LEN);
0747 vap_caps->keep_alive_period = cpu_to_le16(90);
0748 vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD);
0749
0750 vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold);
0751
0752 if (common->band == NL80211_BAND_5GHZ) {
0753 vap_caps->default_ctrl_rate = cpu_to_le16(RSI_RATE_6);
0754 vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_6);
0755 } else {
0756 vap_caps->default_ctrl_rate = cpu_to_le16(RSI_RATE_1);
0757 vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_1);
0758 }
0759 if (conf_is_ht40(conf)) {
0760 if (conf_is_ht40_minus(conf))
0761 vap_caps->ctrl_rate_flags =
0762 cpu_to_le16(UPPER_20_ENABLE);
0763 else if (conf_is_ht40_plus(conf))
0764 vap_caps->ctrl_rate_flags =
0765 cpu_to_le16(LOWER_20_ENABLE);
0766 else
0767 vap_caps->ctrl_rate_flags =
0768 cpu_to_le16(FULL40M_ENABLE);
0769 }
0770
0771 vap_caps->default_data_rate = 0;
0772 vap_caps->beacon_interval = cpu_to_le16(common->beacon_interval);
0773 vap_caps->dtim_period = cpu_to_le16(common->dtim_cnt);
0774
0775 skb_put(skb, frame_len);
0776
0777 return rsi_send_internal_mgmt_frame(common, skb);
0778 }
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793 int rsi_hal_load_key(struct rsi_common *common,
0794 u8 *data,
0795 u16 key_len,
0796 u8 key_type,
0797 u8 key_id,
0798 u32 cipher,
0799 s16 sta_id,
0800 struct ieee80211_vif *vif)
0801 {
0802 struct sk_buff *skb = NULL;
0803 struct rsi_set_key *set_key;
0804 u16 key_descriptor = 0;
0805 u16 frame_len = sizeof(struct rsi_set_key);
0806
0807 rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__);
0808
0809 skb = dev_alloc_skb(frame_len);
0810 if (!skb) {
0811 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
0812 __func__);
0813 return -ENOMEM;
0814 }
0815
0816 memset(skb->data, 0, frame_len);
0817 set_key = (struct rsi_set_key *)skb->data;
0818
0819 if (key_type == RSI_GROUP_KEY) {
0820 key_descriptor = RSI_KEY_TYPE_BROADCAST;
0821 if (vif->type == NL80211_IFTYPE_AP)
0822 key_descriptor |= RSI_KEY_MODE_AP;
0823 }
0824 if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
0825 (cipher == WLAN_CIPHER_SUITE_WEP104)) {
0826 key_id = 0;
0827 key_descriptor |= RSI_WEP_KEY;
0828 if (key_len >= 13)
0829 key_descriptor |= RSI_WEP_KEY_104;
0830 } else if (cipher != KEY_TYPE_CLEAR) {
0831 key_descriptor |= RSI_CIPHER_WPA;
0832 if (cipher == WLAN_CIPHER_SUITE_TKIP)
0833 key_descriptor |= RSI_CIPHER_TKIP;
0834 }
0835 key_descriptor |= RSI_PROTECT_DATA_FRAMES;
0836 key_descriptor |= (key_id << RSI_KEY_ID_OFFSET);
0837
0838 rsi_set_len_qno(&set_key->desc_dword0.len_qno,
0839 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
0840 set_key->desc_dword0.frame_type = SET_KEY_REQ;
0841 set_key->key_desc = cpu_to_le16(key_descriptor);
0842 set_key->sta_id = sta_id;
0843
0844 if (data) {
0845 if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
0846 (cipher == WLAN_CIPHER_SUITE_WEP104)) {
0847 memcpy(&set_key->key[key_id][1], data, key_len * 2);
0848 } else {
0849 memcpy(&set_key->key[0][0], data, key_len);
0850 }
0851 memcpy(set_key->tx_mic_key, &data[16], 8);
0852 memcpy(set_key->rx_mic_key, &data[24], 8);
0853 } else {
0854 memset(&set_key[FRAME_DESC_SZ], 0, frame_len - FRAME_DESC_SZ);
0855 }
0856
0857 skb_put(skb, frame_len);
0858
0859 return rsi_send_internal_mgmt_frame(common, skb);
0860 }
0861
0862
0863
0864
0865
0866
0867 static int rsi_send_common_dev_params(struct rsi_common *common)
0868 {
0869 struct sk_buff *skb;
0870 u16 frame_len;
0871 struct rsi_config_vals *dev_cfgs;
0872
0873 frame_len = sizeof(struct rsi_config_vals);
0874
0875 rsi_dbg(MGMT_TX_ZONE, "Sending common device config params\n");
0876 skb = dev_alloc_skb(frame_len);
0877 if (!skb) {
0878 rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
0879 return -ENOMEM;
0880 }
0881
0882 memset(skb->data, 0, frame_len);
0883
0884 dev_cfgs = (struct rsi_config_vals *)skb->data;
0885 memset(dev_cfgs, 0, (sizeof(struct rsi_config_vals)));
0886
0887 rsi_set_len_qno(&dev_cfgs->len_qno, (frame_len - FRAME_DESC_SZ),
0888 RSI_COEX_Q);
0889 dev_cfgs->pkt_type = COMMON_DEV_CONFIG;
0890
0891 dev_cfgs->lp_ps_handshake = common->lp_ps_handshake_mode;
0892 dev_cfgs->ulp_ps_handshake = common->ulp_ps_handshake_mode;
0893
0894 dev_cfgs->unused_ulp_gpio = RSI_UNUSED_ULP_GPIO_BITMAP;
0895 dev_cfgs->unused_soc_gpio_bitmap =
0896 cpu_to_le32(RSI_UNUSED_SOC_GPIO_BITMAP);
0897
0898 dev_cfgs->opermode = common->oper_mode;
0899 dev_cfgs->wlan_rf_pwr_mode = common->wlan_rf_power_mode;
0900 dev_cfgs->driver_mode = common->driver_mode;
0901 dev_cfgs->region_code = NL80211_DFS_FCC;
0902 dev_cfgs->antenna_sel_val = common->obm_ant_sel_val;
0903
0904 skb_put(skb, frame_len);
0905
0906 return rsi_send_internal_mgmt_frame(common, skb);
0907 }
0908
0909
0910
0911
0912
0913
0914
0915 static int rsi_load_bootup_params(struct rsi_common *common)
0916 {
0917 struct sk_buff *skb;
0918 struct rsi_boot_params *boot_params;
0919
0920 rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
0921 skb = dev_alloc_skb(sizeof(struct rsi_boot_params));
0922 if (!skb) {
0923 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
0924 __func__);
0925 return -ENOMEM;
0926 }
0927
0928 memset(skb->data, 0, sizeof(struct rsi_boot_params));
0929 boot_params = (struct rsi_boot_params *)skb->data;
0930
0931 rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__);
0932
0933 if (common->channel_width == BW_40MHZ) {
0934 memcpy(&boot_params->bootup_params,
0935 &boot_params_40,
0936 sizeof(struct bootup_params));
0937 rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
0938 UMAC_CLK_40BW);
0939 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW);
0940 } else {
0941 memcpy(&boot_params->bootup_params,
0942 &boot_params_20,
0943 sizeof(struct bootup_params));
0944 if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
0945 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW);
0946 rsi_dbg(MGMT_TX_ZONE,
0947 "%s: Packet 20MHZ <=== %d\n", __func__,
0948 UMAC_CLK_20BW);
0949 } else {
0950 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ);
0951 rsi_dbg(MGMT_TX_ZONE,
0952 "%s: Packet 20MHZ <=== %d\n", __func__,
0953 UMAC_CLK_40MHZ);
0954 }
0955 }
0956
0957
0958
0959
0960
0961 boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) |
0962 (RSI_WIFI_MGMT_Q << 12));
0963 boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST);
0964
0965 skb_put(skb, sizeof(struct rsi_boot_params));
0966
0967 return rsi_send_internal_mgmt_frame(common, skb);
0968 }
0969
0970 static int rsi_load_9116_bootup_params(struct rsi_common *common)
0971 {
0972 struct sk_buff *skb;
0973 struct rsi_boot_params_9116 *boot_params;
0974
0975 rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
0976
0977 skb = dev_alloc_skb(sizeof(struct rsi_boot_params_9116));
0978 if (!skb)
0979 return -ENOMEM;
0980 memset(skb->data, 0, sizeof(struct rsi_boot_params));
0981 boot_params = (struct rsi_boot_params_9116 *)skb->data;
0982
0983 if (common->channel_width == BW_40MHZ) {
0984 memcpy(&boot_params->bootup_params,
0985 &boot_params_9116_40,
0986 sizeof(struct bootup_params_9116));
0987 rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
0988 UMAC_CLK_40BW);
0989 boot_params->umac_clk = cpu_to_le16(UMAC_CLK_40BW);
0990 } else {
0991 memcpy(&boot_params->bootup_params,
0992 &boot_params_9116_20,
0993 sizeof(struct bootup_params_9116));
0994 if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
0995 boot_params->umac_clk = cpu_to_le16(UMAC_CLK_20BW);
0996 rsi_dbg(MGMT_TX_ZONE,
0997 "%s: Packet 20MHZ <=== %d\n", __func__,
0998 UMAC_CLK_20BW);
0999 } else {
1000 boot_params->umac_clk = cpu_to_le16(UMAC_CLK_40MHZ);
1001 rsi_dbg(MGMT_TX_ZONE,
1002 "%s: Packet 20MHZ <=== %d\n", __func__,
1003 UMAC_CLK_40MHZ);
1004 }
1005 }
1006 rsi_set_len_qno(&boot_params->desc_dword0.len_qno,
1007 sizeof(struct bootup_params_9116), RSI_WIFI_MGMT_Q);
1008 boot_params->desc_dword0.frame_type = BOOTUP_PARAMS_REQUEST;
1009 skb_put(skb, sizeof(struct rsi_boot_params_9116));
1010
1011 return rsi_send_internal_mgmt_frame(common, skb);
1012 }
1013
1014
1015
1016
1017
1018
1019
1020
1021 static int rsi_send_reset_mac(struct rsi_common *common)
1022 {
1023 struct sk_buff *skb;
1024 struct rsi_mac_frame *mgmt_frame;
1025
1026 rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__);
1027
1028 skb = dev_alloc_skb(FRAME_DESC_SZ);
1029 if (!skb) {
1030 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1031 __func__);
1032 return -ENOMEM;
1033 }
1034
1035 memset(skb->data, 0, FRAME_DESC_SZ);
1036 mgmt_frame = (struct rsi_mac_frame *)skb->data;
1037
1038 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
1039 mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ);
1040 mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8);
1041
1042 #define RSI_9116_DEF_TA_AGGR 3
1043 if (common->priv->device_model == RSI_DEV_9116)
1044 mgmt_frame->desc_word[3] |=
1045 cpu_to_le16(RSI_9116_DEF_TA_AGGR << 8);
1046
1047 skb_put(skb, FRAME_DESC_SZ);
1048
1049 return rsi_send_internal_mgmt_frame(common, skb);
1050 }
1051
1052
1053
1054
1055
1056
1057
1058
1059 int rsi_band_check(struct rsi_common *common,
1060 struct ieee80211_channel *curchan)
1061 {
1062 struct rsi_hw *adapter = common->priv;
1063 struct ieee80211_hw *hw = adapter->hw;
1064 u8 prev_bw = common->channel_width;
1065 u8 prev_ep = common->endpoint;
1066 int status = 0;
1067
1068 if (common->band != curchan->band) {
1069 common->rf_reset = 1;
1070 common->band = curchan->band;
1071 }
1072
1073 if ((hw->conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) ||
1074 (hw->conf.chandef.width == NL80211_CHAN_WIDTH_20))
1075 common->channel_width = BW_20MHZ;
1076 else
1077 common->channel_width = BW_40MHZ;
1078
1079 if (common->band == NL80211_BAND_2GHZ) {
1080 if (common->channel_width)
1081 common->endpoint = EP_2GHZ_40MHZ;
1082 else
1083 common->endpoint = EP_2GHZ_20MHZ;
1084 } else {
1085 if (common->channel_width)
1086 common->endpoint = EP_5GHZ_40MHZ;
1087 else
1088 common->endpoint = EP_5GHZ_20MHZ;
1089 }
1090
1091 if (common->endpoint != prev_ep) {
1092 status = rsi_program_bb_rf(common);
1093 if (status)
1094 return status;
1095 }
1096
1097 if (common->channel_width != prev_bw) {
1098 if (adapter->device_model == RSI_DEV_9116)
1099 status = rsi_load_9116_bootup_params(common);
1100 else
1101 status = rsi_load_bootup_params(common);
1102 if (status)
1103 return status;
1104
1105 status = rsi_load_radio_caps(common);
1106 if (status)
1107 return status;
1108 }
1109
1110 return status;
1111 }
1112
1113
1114
1115
1116
1117
1118
1119
1120 int rsi_set_channel(struct rsi_common *common,
1121 struct ieee80211_channel *channel)
1122 {
1123 struct sk_buff *skb = NULL;
1124 struct rsi_chan_config *chan_cfg;
1125 u16 frame_len = sizeof(struct rsi_chan_config);
1126
1127 rsi_dbg(MGMT_TX_ZONE,
1128 "%s: Sending scan req frame\n", __func__);
1129
1130 skb = dev_alloc_skb(frame_len);
1131 if (!skb) {
1132 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1133 __func__);
1134 return -ENOMEM;
1135 }
1136
1137 if (!channel) {
1138 dev_kfree_skb(skb);
1139 return 0;
1140 }
1141 memset(skb->data, 0, frame_len);
1142 chan_cfg = (struct rsi_chan_config *)skb->data;
1143
1144 rsi_set_len_qno(&chan_cfg->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q);
1145 chan_cfg->desc_dword0.frame_type = SCAN_REQUEST;
1146 chan_cfg->channel_number = channel->hw_value;
1147 chan_cfg->antenna_gain_offset_2g = channel->max_antenna_gain;
1148 chan_cfg->antenna_gain_offset_5g = channel->max_antenna_gain;
1149 chan_cfg->region_rftype = (RSI_RF_TYPE & 0xf) << 4;
1150
1151 if ((channel->flags & IEEE80211_CHAN_NO_IR) ||
1152 (channel->flags & IEEE80211_CHAN_RADAR)) {
1153 chan_cfg->antenna_gain_offset_2g |= RSI_CHAN_RADAR;
1154 } else {
1155 if (common->tx_power < channel->max_power)
1156 chan_cfg->tx_power = cpu_to_le16(common->tx_power);
1157 else
1158 chan_cfg->tx_power = cpu_to_le16(channel->max_power);
1159 }
1160 chan_cfg->region_rftype |= (common->priv->dfs_region & 0xf);
1161
1162 if (common->channel_width == BW_40MHZ)
1163 chan_cfg->channel_width = 0x1;
1164
1165 common->channel = channel->hw_value;
1166
1167 skb_put(skb, frame_len);
1168
1169 return rsi_send_internal_mgmt_frame(common, skb);
1170 }
1171
1172
1173
1174
1175
1176
1177
1178
1179 int rsi_send_radio_params_update(struct rsi_common *common)
1180 {
1181 struct rsi_mac_frame *cmd_frame;
1182 struct sk_buff *skb = NULL;
1183
1184 rsi_dbg(MGMT_TX_ZONE,
1185 "%s: Sending Radio Params update frame\n", __func__);
1186
1187 skb = dev_alloc_skb(FRAME_DESC_SZ);
1188 if (!skb) {
1189 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1190 __func__);
1191 return -ENOMEM;
1192 }
1193
1194 memset(skb->data, 0, FRAME_DESC_SZ);
1195 cmd_frame = (struct rsi_mac_frame *)skb->data;
1196
1197 cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
1198 cmd_frame->desc_word[1] = cpu_to_le16(RADIO_PARAMS_UPDATE);
1199 cmd_frame->desc_word[3] = cpu_to_le16(BIT(0));
1200
1201 cmd_frame->desc_word[3] |= cpu_to_le16(common->tx_power << 8);
1202
1203 skb_put(skb, FRAME_DESC_SZ);
1204
1205 return rsi_send_internal_mgmt_frame(common, skb);
1206 }
1207
1208
1209 int rsi_send_vap_dynamic_update(struct rsi_common *common)
1210 {
1211 struct sk_buff *skb;
1212 struct rsi_dynamic_s *dynamic_frame;
1213
1214 rsi_dbg(MGMT_TX_ZONE,
1215 "%s: Sending vap update indication frame\n", __func__);
1216
1217 skb = dev_alloc_skb(sizeof(struct rsi_dynamic_s));
1218 if (!skb)
1219 return -ENOMEM;
1220
1221 memset(skb->data, 0, sizeof(struct rsi_dynamic_s));
1222 dynamic_frame = (struct rsi_dynamic_s *)skb->data;
1223 rsi_set_len_qno(&dynamic_frame->desc_dword0.len_qno,
1224 sizeof(dynamic_frame->frame_body), RSI_WIFI_MGMT_Q);
1225
1226 dynamic_frame->desc_dword0.frame_type = VAP_DYNAMIC_UPDATE;
1227 dynamic_frame->desc_dword2.pkt_info =
1228 cpu_to_le32(common->rts_threshold);
1229
1230 if (common->wow_flags & RSI_WOW_ENABLED) {
1231
1232 dynamic_frame->desc_dword3.token =
1233 cpu_to_le16(RSI_BCN_MISS_THRESHOLD);
1234 dynamic_frame->frame_body.keep_alive_period =
1235 cpu_to_le16(RSI_WOW_KEEPALIVE);
1236 } else {
1237 dynamic_frame->frame_body.keep_alive_period =
1238 cpu_to_le16(RSI_DEF_KEEPALIVE);
1239 }
1240
1241 dynamic_frame->desc_dword3.sta_id = 0;
1242
1243 skb_put(skb, sizeof(struct rsi_dynamic_s));
1244
1245 return rsi_send_internal_mgmt_frame(common, skb);
1246 }
1247
1248
1249
1250
1251
1252
1253
1254
1255 static int rsi_compare(const void *a, const void *b)
1256 {
1257 u16 _a = *(const u16 *)(a);
1258 u16 _b = *(const u16 *)(b);
1259
1260 if (_a > _b)
1261 return -1;
1262
1263 if (_a < _b)
1264 return 1;
1265
1266 return 0;
1267 }
1268
1269
1270
1271
1272
1273
1274
1275
1276 static bool rsi_map_rates(u16 rate, int *offset)
1277 {
1278 int kk;
1279 for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) {
1280 if (rate == mcs[kk]) {
1281 *offset = kk;
1282 return false;
1283 }
1284 }
1285
1286 for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) {
1287 if (rate == rsi_rates[kk].bitrate / 5) {
1288 *offset = kk;
1289 break;
1290 }
1291 }
1292 return true;
1293 }
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305 static int rsi_send_auto_rate_request(struct rsi_common *common,
1306 struct ieee80211_sta *sta,
1307 u16 sta_id,
1308 struct ieee80211_vif *vif)
1309 {
1310 struct sk_buff *skb;
1311 struct rsi_auto_rate *auto_rate;
1312 int ii = 0, jj = 0, kk = 0;
1313 struct ieee80211_hw *hw = common->priv->hw;
1314 u8 band = hw->conf.chandef.chan->band;
1315 u8 num_supported_rates = 0;
1316 u8 rate_table_offset, rate_offset = 0;
1317 u32 rate_bitmap, configured_rates;
1318 u16 *selected_rates, min_rate;
1319 bool is_ht = false, is_sgi = false;
1320 u16 frame_len = sizeof(struct rsi_auto_rate);
1321
1322 rsi_dbg(MGMT_TX_ZONE,
1323 "%s: Sending auto rate request frame\n", __func__);
1324
1325 skb = dev_alloc_skb(frame_len);
1326 if (!skb) {
1327 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1328 __func__);
1329 return -ENOMEM;
1330 }
1331
1332 memset(skb->data, 0, frame_len);
1333 selected_rates = kzalloc(2 * RSI_TBL_SZ, GFP_KERNEL);
1334 if (!selected_rates) {
1335 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n",
1336 __func__);
1337 dev_kfree_skb(skb);
1338 return -ENOMEM;
1339 }
1340
1341 auto_rate = (struct rsi_auto_rate *)skb->data;
1342
1343 auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f));
1344 auto_rate->collision_tolerance = cpu_to_le16(3);
1345 auto_rate->failure_limit = cpu_to_le16(3);
1346 auto_rate->initial_boundary = cpu_to_le16(3);
1347 auto_rate->max_threshold_limt = cpu_to_le16(27);
1348
1349 auto_rate->desc.desc_dword0.frame_type = AUTO_RATE_IND;
1350
1351 if (common->channel_width == BW_40MHZ)
1352 auto_rate->desc.desc_dword3.qid_tid = BW_40MHZ;
1353 auto_rate->desc.desc_dword3.sta_id = sta_id;
1354
1355 if (vif->type == NL80211_IFTYPE_STATION) {
1356 rate_bitmap = common->bitrate_mask[band];
1357 is_ht = common->vif_info[0].is_ht;
1358 is_sgi = common->vif_info[0].sgi;
1359 } else {
1360 rate_bitmap = sta->deflink.supp_rates[band];
1361 is_ht = sta->deflink.ht_cap.ht_supported;
1362 if ((sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
1363 (sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
1364 is_sgi = true;
1365 }
1366
1367
1368 configured_rates = common->rate_config[band].configured_mask ?: 0xffffffff;
1369 rate_bitmap &= configured_rates;
1370
1371 if (band == NL80211_BAND_2GHZ) {
1372 if ((rate_bitmap == 0) && (is_ht))
1373 min_rate = RSI_RATE_MCS0;
1374 else
1375 min_rate = RSI_RATE_1;
1376 rate_table_offset = 0;
1377 } else {
1378 if ((rate_bitmap == 0) && (is_ht))
1379 min_rate = RSI_RATE_MCS0;
1380 else
1381 min_rate = RSI_RATE_6;
1382 rate_table_offset = 4;
1383 }
1384
1385 for (ii = 0, jj = 0;
1386 ii < (ARRAY_SIZE(rsi_rates) - rate_table_offset); ii++) {
1387 if (rate_bitmap & BIT(ii)) {
1388 selected_rates[jj++] =
1389 (rsi_rates[ii + rate_table_offset].bitrate / 5);
1390 rate_offset++;
1391 }
1392 }
1393 num_supported_rates = jj;
1394
1395 if (is_ht) {
1396 for (ii = 0; ii < ARRAY_SIZE(mcs); ii++) {
1397 if (configured_rates & BIT(ii + ARRAY_SIZE(rsi_rates))) {
1398 selected_rates[jj++] = mcs[ii];
1399 num_supported_rates++;
1400 rate_offset++;
1401 }
1402 }
1403 }
1404
1405 sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL);
1406
1407
1408 for (ii = 0; ii < jj; ii++) {
1409 if (rsi_map_rates(selected_rates[ii], &kk)) {
1410 auto_rate->supported_rates[ii] =
1411 cpu_to_le16(rsi_rates[kk].hw_value);
1412 } else {
1413 auto_rate->supported_rates[ii] =
1414 cpu_to_le16(rsi_mcsrates[kk]);
1415 }
1416 }
1417
1418
1419 if (is_ht) {
1420 for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1;
1421 ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) {
1422 if (is_sgi || conf_is_ht40(&common->priv->hw->conf))
1423 auto_rate->supported_rates[ii++] =
1424 cpu_to_le16(rsi_mcsrates[kk] | BIT(9));
1425 else
1426 auto_rate->supported_rates[ii++] =
1427 cpu_to_le16(rsi_mcsrates[kk]);
1428 auto_rate->supported_rates[ii] =
1429 cpu_to_le16(rsi_mcsrates[kk--]);
1430 }
1431
1432 for (; ii < (RSI_TBL_SZ - 1); ii++) {
1433 auto_rate->supported_rates[ii] =
1434 cpu_to_le16(rsi_mcsrates[0]);
1435 }
1436 }
1437
1438 for (; ii < RSI_TBL_SZ; ii++)
1439 auto_rate->supported_rates[ii] = cpu_to_le16(min_rate);
1440
1441 auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2);
1442 auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2);
1443 num_supported_rates *= 2;
1444
1445 rsi_set_len_qno(&auto_rate->desc.desc_dword0.len_qno,
1446 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
1447
1448 skb_put(skb, frame_len);
1449 kfree(selected_rates);
1450
1451 return rsi_send_internal_mgmt_frame(common, skb);
1452 }
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471 void rsi_inform_bss_status(struct rsi_common *common,
1472 enum opmode opmode,
1473 u8 status,
1474 const u8 *addr,
1475 u8 qos_enable,
1476 u16 aid,
1477 struct ieee80211_sta *sta,
1478 u16 sta_id,
1479 u16 assoc_cap,
1480 struct ieee80211_vif *vif)
1481 {
1482 if (status) {
1483 if (opmode == RSI_OPMODE_STA)
1484 common->hw_data_qs_blocked = true;
1485 rsi_hal_send_sta_notify_frame(common,
1486 opmode,
1487 STA_CONNECTED,
1488 addr,
1489 qos_enable,
1490 aid, sta_id,
1491 vif);
1492 if (!common->rate_config[common->band].fixed_enabled)
1493 rsi_send_auto_rate_request(common, sta, sta_id, vif);
1494 if (opmode == RSI_OPMODE_STA &&
1495 !(assoc_cap & WLAN_CAPABILITY_PRIVACY) &&
1496 !rsi_send_block_unblock_frame(common, false))
1497 common->hw_data_qs_blocked = false;
1498 } else {
1499 if (opmode == RSI_OPMODE_STA)
1500 common->hw_data_qs_blocked = true;
1501
1502 if (!(common->wow_flags & RSI_WOW_ENABLED))
1503 rsi_hal_send_sta_notify_frame(common, opmode,
1504 STA_DISCONNECTED, addr,
1505 qos_enable, aid, sta_id,
1506 vif);
1507 if (opmode == RSI_OPMODE_STA)
1508 rsi_send_block_unblock_frame(common, true);
1509 }
1510 }
1511
1512
1513
1514
1515
1516
1517
1518
1519 static int rsi_eeprom_read(struct rsi_common *common)
1520 {
1521 struct rsi_eeprom_read_frame *mgmt_frame;
1522 struct rsi_hw *adapter = common->priv;
1523 struct sk_buff *skb;
1524
1525 rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__);
1526
1527 skb = dev_alloc_skb(FRAME_DESC_SZ);
1528 if (!skb) {
1529 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1530 __func__);
1531 return -ENOMEM;
1532 }
1533
1534 memset(skb->data, 0, FRAME_DESC_SZ);
1535 mgmt_frame = (struct rsi_eeprom_read_frame *)skb->data;
1536
1537
1538 rsi_set_len_qno(&mgmt_frame->len_qno, 0, RSI_WIFI_MGMT_Q);
1539 mgmt_frame->pkt_type = EEPROM_READ;
1540
1541
1542 mgmt_frame->pkt_info =
1543 cpu_to_le32((adapter->eeprom.length << RSI_EEPROM_LEN_OFFSET) &
1544 RSI_EEPROM_LEN_MASK);
1545 mgmt_frame->pkt_info |= cpu_to_le32((3 << RSI_EEPROM_HDR_SIZE_OFFSET) &
1546 RSI_EEPROM_HDR_SIZE_MASK);
1547
1548
1549 mgmt_frame->eeprom_offset = cpu_to_le32(adapter->eeprom.offset);
1550
1551 skb_put(skb, FRAME_DESC_SZ);
1552
1553 return rsi_send_internal_mgmt_frame(common, skb);
1554 }
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564 int rsi_send_block_unblock_frame(struct rsi_common *common, bool block_event)
1565 {
1566 struct rsi_block_unblock_data *mgmt_frame;
1567 struct sk_buff *skb;
1568
1569 rsi_dbg(MGMT_TX_ZONE, "%s: Sending block/unblock frame\n", __func__);
1570
1571 skb = dev_alloc_skb(FRAME_DESC_SZ);
1572 if (!skb) {
1573 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1574 __func__);
1575 return -ENOMEM;
1576 }
1577
1578 memset(skb->data, 0, FRAME_DESC_SZ);
1579 mgmt_frame = (struct rsi_block_unblock_data *)skb->data;
1580
1581 rsi_set_len_qno(&mgmt_frame->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q);
1582 mgmt_frame->desc_dword0.frame_type = BLOCK_HW_QUEUE;
1583 mgmt_frame->host_quiet_info = QUIET_INFO_VALID;
1584
1585 if (block_event) {
1586 rsi_dbg(INFO_ZONE, "blocking the data qs\n");
1587 mgmt_frame->block_q_bitmap = cpu_to_le16(0xf);
1588 mgmt_frame->block_q_bitmap |= cpu_to_le16(0xf << 4);
1589 } else {
1590 rsi_dbg(INFO_ZONE, "unblocking the data qs\n");
1591 mgmt_frame->unblock_q_bitmap = cpu_to_le16(0xf);
1592 mgmt_frame->unblock_q_bitmap |= cpu_to_le16(0xf << 4);
1593 }
1594
1595 skb_put(skb, FRAME_DESC_SZ);
1596
1597 return rsi_send_internal_mgmt_frame(common, skb);
1598 }
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608 int rsi_send_rx_filter_frame(struct rsi_common *common, u16 rx_filter_word)
1609 {
1610 struct rsi_mac_frame *cmd_frame;
1611 struct sk_buff *skb;
1612
1613 rsi_dbg(MGMT_TX_ZONE, "Sending RX filter frame\n");
1614
1615 skb = dev_alloc_skb(FRAME_DESC_SZ);
1616 if (!skb) {
1617 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1618 __func__);
1619 return -ENOMEM;
1620 }
1621
1622 memset(skb->data, 0, FRAME_DESC_SZ);
1623 cmd_frame = (struct rsi_mac_frame *)skb->data;
1624
1625 cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
1626 cmd_frame->desc_word[1] = cpu_to_le16(SET_RX_FILTER);
1627 cmd_frame->desc_word[4] = cpu_to_le16(rx_filter_word);
1628
1629 skb_put(skb, FRAME_DESC_SZ);
1630
1631 return rsi_send_internal_mgmt_frame(common, skb);
1632 }
1633
1634 int rsi_send_ps_request(struct rsi_hw *adapter, bool enable,
1635 struct ieee80211_vif *vif)
1636 {
1637 struct rsi_common *common = adapter->priv;
1638 struct rsi_request_ps *ps;
1639 struct rsi_ps_info *ps_info;
1640 struct sk_buff *skb;
1641 int frame_len = sizeof(*ps);
1642
1643 skb = dev_alloc_skb(frame_len);
1644 if (!skb)
1645 return -ENOMEM;
1646 memset(skb->data, 0, frame_len);
1647
1648 ps = (struct rsi_request_ps *)skb->data;
1649 ps_info = &adapter->ps_info;
1650
1651 rsi_set_len_qno(&ps->desc.desc_dword0.len_qno,
1652 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
1653 ps->desc.desc_dword0.frame_type = WAKEUP_SLEEP_REQUEST;
1654 if (enable) {
1655 ps->ps_sleep.enable = RSI_PS_ENABLE;
1656 ps->desc.desc_dword3.token = cpu_to_le16(RSI_SLEEP_REQUEST);
1657 } else {
1658 ps->ps_sleep.enable = RSI_PS_DISABLE;
1659 ps->desc.desc_dword0.len_qno |= cpu_to_le16(RSI_PS_DISABLE_IND);
1660 ps->desc.desc_dword3.token = cpu_to_le16(RSI_WAKEUP_REQUEST);
1661 }
1662
1663 ps->ps_uapsd_acs = common->uapsd_bitmap;
1664
1665 ps->ps_sleep.sleep_type = ps_info->sleep_type;
1666 ps->ps_sleep.num_bcns_per_lis_int =
1667 cpu_to_le16(ps_info->num_bcns_per_lis_int);
1668 ps->ps_sleep.sleep_duration =
1669 cpu_to_le32(ps_info->deep_sleep_wakeup_period);
1670
1671 if (vif->cfg.assoc)
1672 ps->ps_sleep.connected_sleep = RSI_CONNECTED_SLEEP;
1673 else
1674 ps->ps_sleep.connected_sleep = RSI_DEEP_SLEEP;
1675
1676 ps->ps_listen_interval = cpu_to_le32(ps_info->listen_interval);
1677 ps->ps_dtim_interval_duration =
1678 cpu_to_le32(ps_info->dtim_interval_duration);
1679
1680 if (ps_info->listen_interval > ps_info->dtim_interval_duration)
1681 ps->ps_listen_interval = cpu_to_le32(RSI_PS_DISABLE);
1682
1683 ps->ps_num_dtim_intervals = cpu_to_le16(ps_info->num_dtims_per_sleep);
1684 skb_put(skb, frame_len);
1685
1686 return rsi_send_internal_mgmt_frame(common, skb);
1687 }
1688
1689 static int rsi_send_w9116_features(struct rsi_common *common)
1690 {
1691 struct rsi_wlan_9116_features *w9116_features;
1692 u16 frame_len = sizeof(struct rsi_wlan_9116_features);
1693 struct sk_buff *skb;
1694
1695 rsi_dbg(MGMT_TX_ZONE,
1696 "%s: Sending wlan 9116 features\n", __func__);
1697
1698 skb = dev_alloc_skb(frame_len);
1699 if (!skb)
1700 return -ENOMEM;
1701 memset(skb->data, 0, frame_len);
1702
1703 w9116_features = (struct rsi_wlan_9116_features *)skb->data;
1704
1705 w9116_features->pll_mode = common->w9116_features.pll_mode;
1706 w9116_features->rf_type = common->w9116_features.rf_type;
1707 w9116_features->wireless_mode = common->w9116_features.wireless_mode;
1708 w9116_features->enable_ppe = common->w9116_features.enable_ppe;
1709 w9116_features->afe_type = common->w9116_features.afe_type;
1710 if (common->w9116_features.dpd)
1711 w9116_features->feature_enable |= cpu_to_le32(RSI_DPD);
1712 if (common->w9116_features.sifs_tx_enable)
1713 w9116_features->feature_enable |=
1714 cpu_to_le32(RSI_SIFS_TX_ENABLE);
1715 if (common->w9116_features.ps_options & RSI_DUTY_CYCLING)
1716 w9116_features->feature_enable |= cpu_to_le32(RSI_DUTY_CYCLING);
1717 if (common->w9116_features.ps_options & RSI_END_OF_FRAME)
1718 w9116_features->feature_enable |= cpu_to_le32(RSI_END_OF_FRAME);
1719 w9116_features->feature_enable |=
1720 cpu_to_le32((common->w9116_features.ps_options & ~0x3) << 2);
1721
1722 rsi_set_len_qno(&w9116_features->desc.desc_dword0.len_qno,
1723 frame_len - FRAME_DESC_SZ, RSI_WIFI_MGMT_Q);
1724 w9116_features->desc.desc_dword0.frame_type = FEATURES_ENABLE;
1725 skb_put(skb, frame_len);
1726
1727 return rsi_send_internal_mgmt_frame(common, skb);
1728 }
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739 int rsi_set_antenna(struct rsi_common *common, u8 antenna)
1740 {
1741 struct rsi_ant_sel_frame *ant_sel_frame;
1742 struct sk_buff *skb;
1743
1744 skb = dev_alloc_skb(FRAME_DESC_SZ);
1745 if (!skb) {
1746 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
1747 __func__);
1748 return -ENOMEM;
1749 }
1750
1751 memset(skb->data, 0, FRAME_DESC_SZ);
1752
1753 ant_sel_frame = (struct rsi_ant_sel_frame *)skb->data;
1754 ant_sel_frame->desc_dword0.frame_type = ANT_SEL_FRAME;
1755 ant_sel_frame->sub_frame_type = ANTENNA_SEL_TYPE;
1756 ant_sel_frame->ant_value = cpu_to_le16(antenna & ANTENNA_MASK_VALUE);
1757 rsi_set_len_qno(&ant_sel_frame->desc_dword0.len_qno,
1758 0, RSI_WIFI_MGMT_Q);
1759 skb_put(skb, FRAME_DESC_SZ);
1760
1761 return rsi_send_internal_mgmt_frame(common, skb);
1762 }
1763
1764 static int rsi_send_beacon(struct rsi_common *common)
1765 {
1766 struct sk_buff *skb = NULL;
1767 u8 dword_align_bytes = 0;
1768
1769 skb = dev_alloc_skb(MAX_MGMT_PKT_SIZE);
1770 if (!skb)
1771 return -ENOMEM;
1772
1773 memset(skb->data, 0, MAX_MGMT_PKT_SIZE);
1774
1775 dword_align_bytes = ((unsigned long)skb->data & 0x3f);
1776 if (dword_align_bytes)
1777 skb_pull(skb, (64 - dword_align_bytes));
1778 if (rsi_prepare_beacon(common, skb)) {
1779 rsi_dbg(ERR_ZONE, "Failed to prepare beacon\n");
1780 dev_kfree_skb(skb);
1781 return -EINVAL;
1782 }
1783 skb_queue_tail(&common->tx_queue[MGMT_BEACON_Q], skb);
1784 rsi_set_event(&common->tx_thread.event);
1785 rsi_dbg(DATA_TX_ZONE, "%s: Added to beacon queue\n", __func__);
1786
1787 return 0;
1788 }
1789
1790 #ifdef CONFIG_PM
1791 int rsi_send_wowlan_request(struct rsi_common *common, u16 flags,
1792 u16 sleep_status)
1793 {
1794 struct rsi_wowlan_req *cmd_frame;
1795 struct sk_buff *skb;
1796 u8 length;
1797
1798 rsi_dbg(ERR_ZONE, "%s: Sending wowlan request frame\n", __func__);
1799
1800 length = sizeof(*cmd_frame);
1801 skb = dev_alloc_skb(length);
1802 if (!skb)
1803 return -ENOMEM;
1804 memset(skb->data, 0, length);
1805 cmd_frame = (struct rsi_wowlan_req *)skb->data;
1806
1807 rsi_set_len_qno(&cmd_frame->desc.desc_dword0.len_qno,
1808 (length - FRAME_DESC_SZ),
1809 RSI_WIFI_MGMT_Q);
1810 cmd_frame->desc.desc_dword0.frame_type = WOWLAN_CONFIG_PARAMS;
1811 cmd_frame->host_sleep_status = sleep_status;
1812 if (common->secinfo.gtk_cipher)
1813 flags |= RSI_WOW_GTK_REKEY;
1814 if (sleep_status)
1815 cmd_frame->wow_flags = flags;
1816 rsi_dbg(INFO_ZONE, "Host_Sleep_Status : %d Flags : %d\n",
1817 cmd_frame->host_sleep_status, cmd_frame->wow_flags);
1818
1819 skb_put(skb, length);
1820
1821 return rsi_send_internal_mgmt_frame(common, skb);
1822 }
1823 #endif
1824
1825 int rsi_send_bgscan_params(struct rsi_common *common, int enable)
1826 {
1827 struct rsi_bgscan_params *params = &common->bgscan;
1828 struct cfg80211_scan_request *scan_req = common->hwscan;
1829 struct rsi_bgscan_config *bgscan;
1830 struct sk_buff *skb;
1831 u16 frame_len = sizeof(*bgscan);
1832 u8 i;
1833
1834 rsi_dbg(MGMT_TX_ZONE, "%s: Sending bgscan params frame\n", __func__);
1835
1836 skb = dev_alloc_skb(frame_len);
1837 if (!skb)
1838 return -ENOMEM;
1839 memset(skb->data, 0, frame_len);
1840
1841 bgscan = (struct rsi_bgscan_config *)skb->data;
1842 rsi_set_len_qno(&bgscan->desc_dword0.len_qno,
1843 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
1844 bgscan->desc_dword0.frame_type = BG_SCAN_PARAMS;
1845 bgscan->bgscan_threshold = cpu_to_le16(params->bgscan_threshold);
1846 bgscan->roam_threshold = cpu_to_le16(params->roam_threshold);
1847 if (enable)
1848 bgscan->bgscan_periodicity =
1849 cpu_to_le16(params->bgscan_periodicity);
1850 bgscan->active_scan_duration =
1851 cpu_to_le16(params->active_scan_duration);
1852 bgscan->passive_scan_duration =
1853 cpu_to_le16(params->passive_scan_duration);
1854 bgscan->two_probe = params->two_probe;
1855
1856 bgscan->num_bgscan_channels = scan_req->n_channels;
1857 for (i = 0; i < bgscan->num_bgscan_channels; i++)
1858 bgscan->channels2scan[i] =
1859 cpu_to_le16(scan_req->channels[i]->hw_value);
1860
1861 skb_put(skb, frame_len);
1862
1863 return rsi_send_internal_mgmt_frame(common, skb);
1864 }
1865
1866
1867
1868
1869 int rsi_send_bgscan_probe_req(struct rsi_common *common,
1870 struct ieee80211_vif *vif)
1871 {
1872 struct cfg80211_scan_request *scan_req = common->hwscan;
1873 struct rsi_bgscan_probe *bgscan;
1874 struct sk_buff *skb;
1875 struct sk_buff *probereq_skb;
1876 u16 frame_len = sizeof(*bgscan);
1877 size_t ssid_len = 0;
1878 u8 *ssid = NULL;
1879
1880 rsi_dbg(MGMT_TX_ZONE,
1881 "%s: Sending bgscan probe req frame\n", __func__);
1882
1883 if (common->priv->sc_nvifs <= 0)
1884 return -ENODEV;
1885
1886 if (scan_req->n_ssids) {
1887 ssid = scan_req->ssids[0].ssid;
1888 ssid_len = scan_req->ssids[0].ssid_len;
1889 }
1890
1891 skb = dev_alloc_skb(frame_len + MAX_BGSCAN_PROBE_REQ_LEN);
1892 if (!skb)
1893 return -ENOMEM;
1894 memset(skb->data, 0, frame_len + MAX_BGSCAN_PROBE_REQ_LEN);
1895
1896 bgscan = (struct rsi_bgscan_probe *)skb->data;
1897 bgscan->desc_dword0.frame_type = BG_SCAN_PROBE_REQ;
1898 bgscan->flags = cpu_to_le16(HOST_BG_SCAN_TRIG);
1899 if (common->band == NL80211_BAND_5GHZ) {
1900 bgscan->mgmt_rate = cpu_to_le16(RSI_RATE_6);
1901 bgscan->def_chan = cpu_to_le16(40);
1902 } else {
1903 bgscan->mgmt_rate = cpu_to_le16(RSI_RATE_1);
1904 bgscan->def_chan = cpu_to_le16(11);
1905 }
1906 bgscan->channel_scan_time = cpu_to_le16(RSI_CHANNEL_SCAN_TIME);
1907
1908 probereq_skb = ieee80211_probereq_get(common->priv->hw, vif->addr, ssid,
1909 ssid_len, scan_req->ie_len);
1910 if (!probereq_skb) {
1911 dev_kfree_skb(skb);
1912 return -ENOMEM;
1913 }
1914
1915 memcpy(&skb->data[frame_len], probereq_skb->data, probereq_skb->len);
1916
1917 bgscan->probe_req_length = cpu_to_le16(probereq_skb->len);
1918
1919 rsi_set_len_qno(&bgscan->desc_dword0.len_qno,
1920 (frame_len - FRAME_DESC_SZ + probereq_skb->len),
1921 RSI_WIFI_MGMT_Q);
1922
1923 skb_put(skb, frame_len + probereq_skb->len);
1924
1925 dev_kfree_skb(probereq_skb);
1926
1927 return rsi_send_internal_mgmt_frame(common, skb);
1928 }
1929
1930
1931
1932
1933
1934
1935
1936
1937 static int rsi_handle_ta_confirm_type(struct rsi_common *common,
1938 u8 *msg)
1939 {
1940 struct rsi_hw *adapter = common->priv;
1941 u8 sub_type = (msg[15] & 0xff);
1942 u16 msg_len = ((u16 *)msg)[0] & 0xfff;
1943 u8 offset;
1944
1945 switch (sub_type) {
1946 case BOOTUP_PARAMS_REQUEST:
1947 rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n",
1948 __func__);
1949 if (common->fsm_state == FSM_BOOT_PARAMS_SENT) {
1950 if (adapter->device_model == RSI_DEV_9116) {
1951 common->band = NL80211_BAND_5GHZ;
1952 common->num_supp_bands = 2;
1953
1954 if (rsi_send_reset_mac(common))
1955 goto out;
1956 else
1957 common->fsm_state = FSM_RESET_MAC_SENT;
1958 } else {
1959 adapter->eeprom.length =
1960 (IEEE80211_ADDR_LEN +
1961 WLAN_MAC_MAGIC_WORD_LEN +
1962 WLAN_HOST_MODE_LEN);
1963 adapter->eeprom.offset = WLAN_MAC_EEPROM_ADDR;
1964 if (rsi_eeprom_read(common)) {
1965 common->fsm_state = FSM_CARD_NOT_READY;
1966 goto out;
1967 }
1968 common->fsm_state = FSM_EEPROM_READ_MAC_ADDR;
1969 }
1970 } else {
1971 rsi_dbg(INFO_ZONE,
1972 "%s: Received bootup params cfm in %d state\n",
1973 __func__, common->fsm_state);
1974 return 0;
1975 }
1976 break;
1977
1978 case EEPROM_READ:
1979 rsi_dbg(FSM_ZONE, "EEPROM READ confirm received\n");
1980 if (msg_len <= 0) {
1981 rsi_dbg(FSM_ZONE,
1982 "%s: [EEPROM_READ] Invalid len %d\n",
1983 __func__, msg_len);
1984 goto out;
1985 }
1986 if (msg[16] != MAGIC_WORD) {
1987 rsi_dbg(FSM_ZONE,
1988 "%s: [EEPROM_READ] Invalid token\n", __func__);
1989 common->fsm_state = FSM_CARD_NOT_READY;
1990 goto out;
1991 }
1992 if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) {
1993 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN +
1994 WLAN_MAC_MAGIC_WORD_LEN);
1995 memcpy(common->mac_addr, &msg[offset], ETH_ALEN);
1996 adapter->eeprom.length =
1997 ((WLAN_MAC_MAGIC_WORD_LEN + 3) & (~3));
1998 adapter->eeprom.offset = WLAN_EEPROM_RFTYPE_ADDR;
1999 if (rsi_eeprom_read(common)) {
2000 rsi_dbg(ERR_ZONE,
2001 "%s: Failed reading RF band\n",
2002 __func__);
2003 common->fsm_state = FSM_CARD_NOT_READY;
2004 goto out;
2005 }
2006 common->fsm_state = FSM_EEPROM_READ_RF_TYPE;
2007 } else if (common->fsm_state == FSM_EEPROM_READ_RF_TYPE) {
2008 if ((msg[17] & 0x3) == 0x3) {
2009 rsi_dbg(INIT_ZONE, "Dual band supported\n");
2010 common->band = NL80211_BAND_5GHZ;
2011 common->num_supp_bands = 2;
2012 } else if ((msg[17] & 0x3) == 0x1) {
2013 rsi_dbg(INIT_ZONE,
2014 "Only 2.4Ghz band supported\n");
2015 common->band = NL80211_BAND_2GHZ;
2016 common->num_supp_bands = 1;
2017 }
2018 if (rsi_send_reset_mac(common))
2019 goto out;
2020 common->fsm_state = FSM_RESET_MAC_SENT;
2021 } else {
2022 rsi_dbg(ERR_ZONE, "%s: Invalid EEPROM read type\n",
2023 __func__);
2024 return 0;
2025 }
2026 break;
2027
2028 case RESET_MAC_REQ:
2029 if (common->fsm_state == FSM_RESET_MAC_SENT) {
2030 rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n",
2031 __func__);
2032
2033 if (rsi_load_radio_caps(common))
2034 goto out;
2035 else
2036 common->fsm_state = FSM_RADIO_CAPS_SENT;
2037 } else {
2038 rsi_dbg(ERR_ZONE,
2039 "%s: Received reset mac cfm in %d state\n",
2040 __func__, common->fsm_state);
2041 return 0;
2042 }
2043 break;
2044
2045 case RADIO_CAPABILITIES:
2046 if (common->fsm_state == FSM_RADIO_CAPS_SENT) {
2047 common->rf_reset = 1;
2048 if (adapter->device_model == RSI_DEV_9116 &&
2049 rsi_send_w9116_features(common)) {
2050 rsi_dbg(ERR_ZONE,
2051 "Failed to send 9116 features\n");
2052 goto out;
2053 }
2054 if (rsi_program_bb_rf(common)) {
2055 goto out;
2056 } else {
2057 common->fsm_state = FSM_BB_RF_PROG_SENT;
2058 rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n",
2059 __func__);
2060 }
2061 } else {
2062 rsi_dbg(INFO_ZONE,
2063 "%s: Received radio caps cfm in %d state\n",
2064 __func__, common->fsm_state);
2065 return 0;
2066 }
2067 break;
2068
2069 case BB_PROG_VALUES_REQUEST:
2070 case RF_PROG_VALUES_REQUEST:
2071 case BBP_PROG_IN_TA:
2072 rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__);
2073 if (common->fsm_state == FSM_BB_RF_PROG_SENT) {
2074 common->bb_rf_prog_count--;
2075 if (!common->bb_rf_prog_count) {
2076 common->fsm_state = FSM_MAC_INIT_DONE;
2077 if (common->reinit_hw) {
2078 complete(&common->wlan_init_completion);
2079 } else {
2080 if (common->bt_defer_attach)
2081 rsi_attach_bt(common);
2082
2083 return rsi_mac80211_attach(common);
2084 }
2085 }
2086 } else {
2087 rsi_dbg(INFO_ZONE,
2088 "%s: Received bbb_rf cfm in %d state\n",
2089 __func__, common->fsm_state);
2090 return 0;
2091 }
2092 break;
2093
2094 case SCAN_REQUEST:
2095 rsi_dbg(INFO_ZONE, "Set channel confirm\n");
2096 break;
2097
2098 case WAKEUP_SLEEP_REQUEST:
2099 rsi_dbg(INFO_ZONE, "Wakeup/Sleep confirmation.\n");
2100 return rsi_handle_ps_confirm(adapter, msg);
2101
2102 case BG_SCAN_PROBE_REQ:
2103 rsi_dbg(INFO_ZONE, "BG scan complete event\n");
2104 if (common->bgscan_en) {
2105 struct cfg80211_scan_info info;
2106
2107 if (!rsi_send_bgscan_params(common, RSI_STOP_BGSCAN))
2108 common->bgscan_en = 0;
2109 info.aborted = false;
2110 ieee80211_scan_completed(adapter->hw, &info);
2111 }
2112 rsi_dbg(INFO_ZONE, "Background scan completed\n");
2113 break;
2114
2115 default:
2116 rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
2117 __func__);
2118 break;
2119 }
2120 return 0;
2121 out:
2122 rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n",
2123 __func__);
2124 return -EINVAL;
2125 }
2126
2127 int rsi_handle_card_ready(struct rsi_common *common, u8 *msg)
2128 {
2129 int status;
2130
2131 switch (common->fsm_state) {
2132 case FSM_CARD_NOT_READY:
2133 rsi_dbg(INIT_ZONE, "Card ready indication from Common HAL\n");
2134 rsi_set_default_parameters(common);
2135 if (rsi_send_common_dev_params(common) < 0)
2136 return -EINVAL;
2137 common->fsm_state = FSM_COMMON_DEV_PARAMS_SENT;
2138 break;
2139 case FSM_COMMON_DEV_PARAMS_SENT:
2140 rsi_dbg(INIT_ZONE, "Card ready indication from WLAN HAL\n");
2141
2142 if (common->priv->device_model == RSI_DEV_9116) {
2143 if (msg[16] != MAGIC_WORD) {
2144 rsi_dbg(FSM_ZONE,
2145 "%s: [EEPROM_READ] Invalid token\n",
2146 __func__);
2147 common->fsm_state = FSM_CARD_NOT_READY;
2148 return -EINVAL;
2149 }
2150 memcpy(common->mac_addr, &msg[20], ETH_ALEN);
2151 rsi_dbg(INIT_ZONE, "MAC Addr %pM", common->mac_addr);
2152 }
2153
2154 common->priv->usb_buffer_status_reg = *(u32 *)&msg[8];
2155 rsi_dbg(INFO_ZONE, "USB buffer status register = %x\n",
2156 common->priv->usb_buffer_status_reg);
2157
2158 if (common->priv->device_model == RSI_DEV_9116)
2159 status = rsi_load_9116_bootup_params(common);
2160 else
2161 status = rsi_load_bootup_params(common);
2162 if (status < 0) {
2163 common->fsm_state = FSM_CARD_NOT_READY;
2164 return status;
2165 }
2166 common->fsm_state = FSM_BOOT_PARAMS_SENT;
2167 break;
2168 default:
2169 rsi_dbg(ERR_ZONE,
2170 "%s: card ready indication in invalid state %d.\n",
2171 __func__, common->fsm_state);
2172 return -EINVAL;
2173 }
2174
2175 return 0;
2176 }
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186 int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg)
2187 {
2188 s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff);
2189 u16 msg_type = (msg[2]);
2190
2191 rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n",
2192 __func__, msg_len, msg_type);
2193
2194 switch (msg_type) {
2195 case TA_CONFIRM_TYPE:
2196 return rsi_handle_ta_confirm_type(common, msg);
2197 case CARD_READY_IND:
2198 common->hibernate_resume = false;
2199 rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n",
2200 __func__);
2201 return rsi_handle_card_ready(common, msg);
2202 case TX_STATUS_IND:
2203 switch (msg[RSI_TX_STATUS_TYPE]) {
2204 case PROBEREQ_CONFIRM:
2205 common->mgmt_q_block = false;
2206 rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n",
2207 __func__);
2208 break;
2209 case EAPOL4_CONFIRM:
2210 if (msg[RSI_TX_STATUS]) {
2211 common->eapol4_confirm = true;
2212 if (!rsi_send_block_unblock_frame(common,
2213 false))
2214 common->hw_data_qs_blocked = false;
2215 }
2216 }
2217 break;
2218 case BEACON_EVENT_IND:
2219 rsi_dbg(INFO_ZONE, "Beacon event\n");
2220 if (common->fsm_state != FSM_MAC_INIT_DONE)
2221 return -1;
2222 if (common->iface_down)
2223 return -1;
2224 if (!common->beacon_enabled)
2225 return -1;
2226 rsi_send_beacon(common);
2227 break;
2228 case WOWLAN_WAKEUP_REASON:
2229 rsi_dbg(ERR_ZONE, "\n\nWakeup Type: %x\n", msg[15]);
2230 switch (msg[15]) {
2231 case RSI_UNICAST_MAGIC_PKT:
2232 rsi_dbg(ERR_ZONE,
2233 "*** Wakeup for Unicast magic packet ***\n");
2234 break;
2235 case RSI_BROADCAST_MAGICPKT:
2236 rsi_dbg(ERR_ZONE,
2237 "*** Wakeup for Broadcast magic packet ***\n");
2238 break;
2239 case RSI_EAPOL_PKT:
2240 rsi_dbg(ERR_ZONE,
2241 "*** Wakeup for GTK renewal ***\n");
2242 break;
2243 case RSI_DISCONNECT_PKT:
2244 rsi_dbg(ERR_ZONE,
2245 "*** Wakeup for Disconnect ***\n");
2246 break;
2247 case RSI_HW_BMISS_PKT:
2248 rsi_dbg(ERR_ZONE,
2249 "*** Wakeup for HW Beacon miss ***\n");
2250 break;
2251 default:
2252 rsi_dbg(ERR_ZONE,
2253 "##### Un-intentional Wakeup #####\n");
2254 break;
2255 }
2256 break;
2257 case RX_DOT11_MGMT:
2258 return rsi_mgmt_pkt_to_core(common, msg, msg_len);
2259 default:
2260 rsi_dbg(INFO_ZONE, "Received packet type: 0x%x\n", msg_type);
2261 }
2262 return 0;
2263 }