1 /** 2 * Copyright (c) 2014 Redpine Signals Inc. 3 * 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. 7 * 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. 15 */ 16 17 #include <linux/etherdevice.h> 18 #include "rsi_mgmt.h" 19 #include "rsi_common.h" 20 #include "rsi_ps.h" 21 #include "rsi_hal.h" 22 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, 32 .device_clk_info = {{ 33 .pll_config_g = { 34 .tapll_info_g = { 35 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)| 36 (TA_PLL_M_VAL_20)), 37 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20), 38 }, 39 .pll960_info_g = { 40 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)| 41 (PLL960_N_VAL_20)), 42 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20), 43 .pll_reg_3 = 0x0, 44 }, 45 .afepll_info_g = { 46 .pll_reg = cpu_to_le16(0x9f0), 47 } 48 }, 49 .switch_clk_g = { 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) 54 } 55 }, 56 { 57 .pll_config_g = { 58 .tapll_info_g = { 59 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)| 60 (TA_PLL_M_VAL_20)), 61 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20), 62 }, 63 .pll960_info_g = { 64 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)| 65 (PLL960_N_VAL_20)), 66 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20), 67 .pll_reg_3 = 0x0, 68 }, 69 .afepll_info_g = { 70 .pll_reg = cpu_to_le16(0x9f0), 71 } 72 }, 73 .switch_clk_g = { 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 78 } 79 }, 80 { 81 .pll_config_g = { 82 .tapll_info_g = { 83 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)| 84 (TA_PLL_M_VAL_20)), 85 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20), 86 }, 87 .pll960_info_g = { 88 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)| 89 (PLL960_N_VAL_20)), 90 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20), 91 .pll_reg_3 = 0x0, 92 }, 93 .afepll_info_g = { 94 .pll_reg = cpu_to_le16(0x9f0), 95 } 96 }, 97 .switch_clk_g = { 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 102 } 103 } }, 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, 115 }; 116 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 = {{ 127 .pll_config_g = { 128 .tapll_info_g = { 129 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)| 130 (TA_PLL_M_VAL_40)), 131 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40), 132 }, 133 .pll960_info_g = { 134 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)| 135 (PLL960_N_VAL_40)), 136 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40), 137 .pll_reg_3 = 0x0, 138 }, 139 .afepll_info_g = { 140 .pll_reg = cpu_to_le16(0x9f0), 141 } 142 }, 143 .switch_clk_g = { 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) 148 } 149 }, 150 { 151 .pll_config_g = { 152 .tapll_info_g = { 153 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)| 154 (TA_PLL_M_VAL_40)), 155 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40), 156 }, 157 .pll960_info_g = { 158 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)| 159 (PLL960_N_VAL_40)), 160 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40), 161 .pll_reg_3 = 0x0, 162 }, 163 .afepll_info_g = { 164 .pll_reg = cpu_to_le16(0x9f0), 165 } 166 }, 167 .switch_clk_g = { 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 172 } 173 }, 174 { 175 .pll_config_g = { 176 .tapll_info_g = { 177 .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)| 178 (TA_PLL_M_VAL_40)), 179 .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40), 180 }, 181 .pll960_info_g = { 182 .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)| 183 (PLL960_N_VAL_40)), 184 .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40), 185 .pll_reg_3 = 0x0, 186 }, 187 .afepll_info_g = { 188 .pll_reg = cpu_to_le16(0x9f0), 189 } 190 }, 191 .switch_clk_g = { 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 196 } 197 } }, 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, 209 }; 210 211 static u16 mcs[] = {13, 26, 39, 52, 78, 104, 117, 130}; 212 213 /** 214 * rsi_set_default_parameters() - This function sets default parameters. 215 * @common: Pointer to the driver private structure. 216 * 217 * Return: none 218 */ 219 static void rsi_set_default_parameters(struct rsi_common *common) 220 { 221 common->band = NL80211_BAND_2GHZ; 222 common->channel_width = BW_20MHZ; 223 common->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 224 common->channel = 1; 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; 237 } 238 239 /** 240 * rsi_set_contention_vals() - This function sets the contention values for the 241 * backoff procedure. 242 * @common: Pointer to the driver private structure. 243 * 244 * Return: None. 245 */ 246 static void rsi_set_contention_vals(struct rsi_common *common) 247 { 248 u8 ii = 0; 249 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; 257 } 258 } 259 260 /** 261 * rsi_send_internal_mgmt_frame() - This function sends management frames to 262 * firmware.Also schedules packet to queue 263 * for transmission. 264 * @common: Pointer to the driver private structure. 265 * @skb: Pointer to the socket buffer structure. 266 * 267 * Return: 0 on success, -1 on failure. 268 */ 269 static int rsi_send_internal_mgmt_frame(struct rsi_common *common, 270 struct sk_buff *skb) 271 { 272 struct skb_info *tx_params; 273 struct rsi_cmd_desc *desc; 274 275 if (skb == NULL) { 276 rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__); 277 return -ENOMEM; 278 } 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); 286 return 0; 287 } 288 289 /** 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. 293 * 294 * Return: 0 on success, corresponding negative error code on failure. 295 */ 296 static int rsi_load_radio_caps(struct rsi_common *common) 297 { 298 struct rsi_radio_caps *radio_caps; 299 struct rsi_hw *adapter = common->priv; 300 u16 inx = 0; 301 u8 ii; 302 u8 radio_id = 0; 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}; 308 struct sk_buff *skb; 309 u16 frame_len = sizeof(struct rsi_radio_caps); 310 311 rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__); 312 313 skb = dev_alloc_skb(frame_len); 314 315 if (!skb) { 316 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 317 __func__); 318 return -ENOMEM; 319 } 320 321 memset(skb->data, 0, frame_len); 322 radio_caps = (struct rsi_radio_caps *)skb->data; 323 324 radio_caps->desc_dword0.frame_type = RADIO_CAPABILITIES; 325 radio_caps->channel_num = common->channel; 326 radio_caps->rf_model = RSI_RF_TYPE; 327 328 radio_caps->radio_cfg_info = RSI_LMAC_CLOCK_80MHZ; 329 if (common->channel_width == BW_40MHZ) { 330 radio_caps->radio_cfg_info |= RSI_ENABLE_40MHZ; 331 332 if (common->fsm_state == FSM_MAC_INIT_DONE) { 333 struct ieee80211_hw *hw = adapter->hw; 334 struct ieee80211_conf *conf = &hw->conf; 335 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; 346 } else { 347 radio_caps->radio_cfg_info = 348 RSI_CMDDESC_40MHZ; 349 radio_caps->radio_info = 350 RSI_CMDDESC_FULL_40_ENABLE; 351 } 352 } 353 } 354 radio_caps->radio_info |= radio_id; 355 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); 362 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; 368 } 369 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); 379 } 380 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); 384 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); 389 390 rsi_set_len_qno(&radio_caps->desc_dword0.len_qno, 391 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q); 392 393 skb_put(skb, frame_len); 394 395 return rsi_send_internal_mgmt_frame(common, skb); 396 } 397 398 /** 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. 404 * 405 * Return: 0 on success, -1 on failure. 406 */ 407 static int rsi_mgmt_pkt_to_core(struct rsi_common *common, 408 u8 *msg, 409 s32 msg_len) 410 { 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]; 415 struct sk_buff *skb; 416 417 if (!adapter->sc_nvifs) 418 return -ENOLINK; 419 420 msg_len -= pad_bytes; 421 if (msg_len <= 0) { 422 rsi_dbg(MGMT_RX_ZONE, 423 "%s: Invalid rx msg of len = %d\n", 424 __func__, msg_len); 425 return -EINVAL; 426 } 427 428 skb = dev_alloc_skb(msg_len); 429 if (!skb) 430 return -ENOMEM; 431 432 skb_put_data(skb, 433 (u8 *)(msg + FRAME_DESC_SZ + pad_bytes), 434 msg_len); 435 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); 441 442 return 0; 443 } 444 445 /** 446 * rsi_hal_send_sta_notify_frame() - This function sends the station notify 447 * frame to firmware. 448 * @common: Pointer to the driver private structure. 449 * @opmode: Operating mode of device. 450 * @notify_event: Notification about station connection. 451 * @bssid: bssid. 452 * @qos_enable: Qos is enabled. 453 * @aid: Aid (unique for all STA). 454 * 455 * Return: status: 0 on success, corresponding negative error code on failure. 456 */ 457 int rsi_hal_send_sta_notify_frame(struct rsi_common *common, enum opmode opmode, 458 u8 notify_event, const unsigned char *bssid, 459 u8 qos_enable, u16 aid, u16 sta_id, 460 struct ieee80211_vif *vif) 461 { 462 struct sk_buff *skb = NULL; 463 struct rsi_peer_notify *peer_notify; 464 u16 vap_id = ((struct vif_priv *)vif->drv_priv)->vap_id; 465 int status; 466 u16 frame_len = sizeof(struct rsi_peer_notify); 467 468 rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__); 469 470 skb = dev_alloc_skb(frame_len); 471 472 if (!skb) { 473 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 474 __func__); 475 return -ENOMEM; 476 } 477 478 memset(skb->data, 0, frame_len); 479 peer_notify = (struct rsi_peer_notify *)skb->data; 480 481 if (opmode == RSI_OPMODE_STA) 482 peer_notify->command = cpu_to_le16(PEER_TYPE_AP << 1); 483 else if (opmode == RSI_OPMODE_AP) 484 peer_notify->command = cpu_to_le16(PEER_TYPE_STA << 1); 485 486 switch (notify_event) { 487 case STA_CONNECTED: 488 peer_notify->command |= cpu_to_le16(RSI_ADD_PEER); 489 break; 490 case STA_DISCONNECTED: 491 peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER); 492 break; 493 default: 494 break; 495 } 496 497 peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4); 498 ether_addr_copy(peer_notify->mac_addr, bssid); 499 peer_notify->mpdu_density = cpu_to_le16(RSI_MPDU_DENSITY); 500 peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0); 501 502 rsi_set_len_qno(&peer_notify->desc.desc_dword0.len_qno, 503 (frame_len - FRAME_DESC_SZ), 504 RSI_WIFI_MGMT_Q); 505 peer_notify->desc.desc_dword0.frame_type = PEER_NOTIFY; 506 peer_notify->desc.desc_dword3.qid_tid = sta_id; 507 peer_notify->desc.desc_dword3.sta_id = vap_id; 508 509 skb_put(skb, frame_len); 510 511 status = rsi_send_internal_mgmt_frame(common, skb); 512 513 if ((vif->type == NL80211_IFTYPE_STATION) && 514 (!status && qos_enable)) { 515 rsi_set_contention_vals(common); 516 status = rsi_load_radio_caps(common); 517 } 518 return status; 519 } 520 521 /** 522 * rsi_send_aggregation_params_frame() - This function sends the ampdu 523 * indication frame to firmware. 524 * @common: Pointer to the driver private structure. 525 * @tid: traffic identifier. 526 * @ssn: ssn. 527 * @buf_size: buffer size. 528 * @event: notification about station connection. 529 * 530 * Return: 0 on success, corresponding negative error code on failure. 531 */ 532 int rsi_send_aggregation_params_frame(struct rsi_common *common, 533 u16 tid, 534 u16 ssn, 535 u8 buf_size, 536 u8 event, 537 u8 sta_id) 538 { 539 struct sk_buff *skb = NULL; 540 struct rsi_aggr_params *aggr_params; 541 u16 frame_len = sizeof(struct rsi_aggr_params); 542 543 skb = dev_alloc_skb(frame_len); 544 545 if (!skb) { 546 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 547 __func__); 548 return -ENOMEM; 549 } 550 551 memset(skb->data, 0, frame_len); 552 aggr_params = (struct rsi_aggr_params *)skb->data; 553 554 rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__); 555 556 rsi_set_len_qno(&aggr_params->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q); 557 aggr_params->desc_dword0.frame_type = AMPDU_IND; 558 559 aggr_params->aggr_params = tid & RSI_AGGR_PARAMS_TID_MASK; 560 aggr_params->peer_id = sta_id; 561 if (event == STA_TX_ADDBA_DONE) { 562 aggr_params->seq_start = cpu_to_le16(ssn); 563 aggr_params->baw_size = cpu_to_le16(buf_size); 564 aggr_params->aggr_params |= RSI_AGGR_PARAMS_START; 565 } else if (event == STA_RX_ADDBA_DONE) { 566 aggr_params->seq_start = cpu_to_le16(ssn); 567 aggr_params->aggr_params |= (RSI_AGGR_PARAMS_START | 568 RSI_AGGR_PARAMS_RX_AGGR); 569 } else if (event == STA_RX_DELBA) { 570 aggr_params->aggr_params |= RSI_AGGR_PARAMS_RX_AGGR; 571 } 572 573 skb_put(skb, frame_len); 574 575 return rsi_send_internal_mgmt_frame(common, skb); 576 } 577 578 /** 579 * rsi_program_bb_rf() - This function starts base band and RF programming. 580 * This is called after initial configurations are done. 581 * @common: Pointer to the driver private structure. 582 * 583 * Return: 0 on success, corresponding negative error code on failure. 584 */ 585 static int rsi_program_bb_rf(struct rsi_common *common) 586 { 587 struct sk_buff *skb; 588 struct rsi_bb_rf_prog *bb_rf_prog; 589 u16 frame_len = sizeof(struct rsi_bb_rf_prog); 590 591 rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__); 592 593 skb = dev_alloc_skb(frame_len); 594 if (!skb) { 595 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 596 __func__); 597 return -ENOMEM; 598 } 599 600 memset(skb->data, 0, frame_len); 601 bb_rf_prog = (struct rsi_bb_rf_prog *)skb->data; 602 603 rsi_set_len_qno(&bb_rf_prog->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q); 604 bb_rf_prog->desc_dword0.frame_type = BBP_PROG_IN_TA; 605 bb_rf_prog->endpoint = common->endpoint; 606 bb_rf_prog->rf_power_mode = common->wlan_rf_power_mode; 607 608 if (common->rf_reset) { 609 bb_rf_prog->flags = cpu_to_le16(RF_RESET_ENABLE); 610 rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n", 611 __func__); 612 common->rf_reset = 0; 613 } 614 common->bb_rf_prog_count = 1; 615 bb_rf_prog->flags |= cpu_to_le16(PUT_BBP_RESET | BBP_REG_WRITE | 616 (RSI_RF_TYPE << 4)); 617 skb_put(skb, frame_len); 618 619 return rsi_send_internal_mgmt_frame(common, skb); 620 } 621 622 /** 623 * rsi_set_vap_capabilities() - This function send vap capability to firmware. 624 * @common: Pointer to the driver private structure. 625 * @opmode: Operating mode of device. 626 * 627 * Return: 0 on success, corresponding negative error code on failure. 628 */ 629 int rsi_set_vap_capabilities(struct rsi_common *common, 630 enum opmode mode, 631 u8 *mac_addr, 632 u8 vap_id, 633 u8 vap_status) 634 { 635 struct sk_buff *skb = NULL; 636 struct rsi_vap_caps *vap_caps; 637 struct rsi_hw *adapter = common->priv; 638 struct ieee80211_hw *hw = adapter->hw; 639 struct ieee80211_conf *conf = &hw->conf; 640 u16 frame_len = sizeof(struct rsi_vap_caps); 641 642 rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__); 643 644 skb = dev_alloc_skb(frame_len); 645 if (!skb) { 646 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 647 __func__); 648 return -ENOMEM; 649 } 650 651 memset(skb->data, 0, frame_len); 652 vap_caps = (struct rsi_vap_caps *)skb->data; 653 654 rsi_set_len_qno(&vap_caps->desc_dword0.len_qno, 655 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q); 656 vap_caps->desc_dword0.frame_type = VAP_CAPABILITIES; 657 vap_caps->status = vap_status; 658 vap_caps->vif_type = mode; 659 vap_caps->channel_bw = common->channel_width; 660 vap_caps->vap_id = vap_id; 661 vap_caps->radioid_macid = ((common->mac_id & 0xf) << 4) | 662 (common->radio_id & 0xf); 663 664 memcpy(vap_caps->mac_addr, mac_addr, IEEE80211_ADDR_LEN); 665 vap_caps->keep_alive_period = cpu_to_le16(90); 666 vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD); 667 668 vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold); 669 670 if (common->band == NL80211_BAND_5GHZ) { 671 vap_caps->default_ctrl_rate = cpu_to_le16(RSI_RATE_6); 672 vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_6); 673 } else { 674 vap_caps->default_ctrl_rate = cpu_to_le16(RSI_RATE_1); 675 vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_1); 676 } 677 if (conf_is_ht40(conf)) { 678 if (conf_is_ht40_minus(conf)) 679 vap_caps->ctrl_rate_flags = 680 cpu_to_le16(UPPER_20_ENABLE); 681 else if (conf_is_ht40_plus(conf)) 682 vap_caps->ctrl_rate_flags = 683 cpu_to_le16(LOWER_20_ENABLE); 684 else 685 vap_caps->ctrl_rate_flags = 686 cpu_to_le16(FULL40M_ENABLE); 687 } 688 689 vap_caps->default_data_rate = 0; 690 vap_caps->beacon_interval = cpu_to_le16(common->beacon_interval); 691 vap_caps->dtim_period = cpu_to_le16(common->dtim_cnt); 692 693 skb_put(skb, frame_len); 694 695 return rsi_send_internal_mgmt_frame(common, skb); 696 } 697 698 /** 699 * rsi_hal_load_key() - This function is used to load keys within the firmware. 700 * @common: Pointer to the driver private structure. 701 * @data: Pointer to the key data. 702 * @key_len: Key length to be loaded. 703 * @key_type: Type of key: GROUP/PAIRWISE. 704 * @key_id: Key index. 705 * @cipher: Type of cipher used. 706 * 707 * Return: 0 on success, -1 on failure. 708 */ 709 int rsi_hal_load_key(struct rsi_common *common, 710 u8 *data, 711 u16 key_len, 712 u8 key_type, 713 u8 key_id, 714 u32 cipher, 715 s16 sta_id, 716 struct ieee80211_vif *vif) 717 { 718 struct sk_buff *skb = NULL; 719 struct rsi_set_key *set_key; 720 u16 key_descriptor = 0; 721 u16 frame_len = sizeof(struct rsi_set_key); 722 723 rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__); 724 725 skb = dev_alloc_skb(frame_len); 726 if (!skb) { 727 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 728 __func__); 729 return -ENOMEM; 730 } 731 732 memset(skb->data, 0, frame_len); 733 set_key = (struct rsi_set_key *)skb->data; 734 735 if (key_type == RSI_GROUP_KEY) { 736 key_descriptor = RSI_KEY_TYPE_BROADCAST; 737 if (vif->type == NL80211_IFTYPE_AP) 738 key_descriptor |= RSI_KEY_MODE_AP; 739 } 740 if ((cipher == WLAN_CIPHER_SUITE_WEP40) || 741 (cipher == WLAN_CIPHER_SUITE_WEP104)) { 742 key_id = 0; 743 key_descriptor |= RSI_WEP_KEY; 744 if (key_len >= 13) 745 key_descriptor |= RSI_WEP_KEY_104; 746 } else if (cipher != KEY_TYPE_CLEAR) { 747 key_descriptor |= RSI_CIPHER_WPA; 748 if (cipher == WLAN_CIPHER_SUITE_TKIP) 749 key_descriptor |= RSI_CIPHER_TKIP; 750 } 751 key_descriptor |= RSI_PROTECT_DATA_FRAMES; 752 key_descriptor |= ((key_id << RSI_KEY_ID_OFFSET) & RSI_KEY_ID_MASK); 753 754 rsi_set_len_qno(&set_key->desc_dword0.len_qno, 755 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q); 756 set_key->desc_dword0.frame_type = SET_KEY_REQ; 757 set_key->key_desc = cpu_to_le16(key_descriptor); 758 set_key->sta_id = sta_id; 759 760 if (data) { 761 if ((cipher == WLAN_CIPHER_SUITE_WEP40) || 762 (cipher == WLAN_CIPHER_SUITE_WEP104)) { 763 memcpy(&set_key->key[key_id][1], data, key_len * 2); 764 } else { 765 memcpy(&set_key->key[0][0], data, key_len); 766 } 767 memcpy(set_key->tx_mic_key, &data[16], 8); 768 memcpy(set_key->rx_mic_key, &data[24], 8); 769 } else { 770 memset(&set_key[FRAME_DESC_SZ], 0, frame_len - FRAME_DESC_SZ); 771 } 772 773 skb_put(skb, frame_len); 774 775 return rsi_send_internal_mgmt_frame(common, skb); 776 } 777 778 /* 779 * This function sends the common device configuration parameters to device. 780 * This frame includes the useful information to make device works on 781 * specific operating mode. 782 */ 783 static int rsi_send_common_dev_params(struct rsi_common *common) 784 { 785 struct sk_buff *skb; 786 u16 frame_len; 787 struct rsi_config_vals *dev_cfgs; 788 789 frame_len = sizeof(struct rsi_config_vals); 790 791 rsi_dbg(MGMT_TX_ZONE, "Sending common device config params\n"); 792 skb = dev_alloc_skb(frame_len); 793 if (!skb) { 794 rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__); 795 return -ENOMEM; 796 } 797 798 memset(skb->data, 0, frame_len); 799 800 dev_cfgs = (struct rsi_config_vals *)skb->data; 801 memset(dev_cfgs, 0, (sizeof(struct rsi_config_vals))); 802 803 rsi_set_len_qno(&dev_cfgs->len_qno, (frame_len - FRAME_DESC_SZ), 804 RSI_COEX_Q); 805 dev_cfgs->pkt_type = COMMON_DEV_CONFIG; 806 807 dev_cfgs->lp_ps_handshake = common->lp_ps_handshake_mode; 808 dev_cfgs->ulp_ps_handshake = common->ulp_ps_handshake_mode; 809 810 dev_cfgs->unused_ulp_gpio = RSI_UNUSED_ULP_GPIO_BITMAP; 811 dev_cfgs->unused_soc_gpio_bitmap = 812 cpu_to_le32(RSI_UNUSED_SOC_GPIO_BITMAP); 813 814 dev_cfgs->opermode = common->oper_mode; 815 dev_cfgs->wlan_rf_pwr_mode = common->wlan_rf_power_mode; 816 dev_cfgs->driver_mode = common->driver_mode; 817 dev_cfgs->region_code = NL80211_DFS_FCC; 818 dev_cfgs->antenna_sel_val = common->obm_ant_sel_val; 819 820 skb_put(skb, frame_len); 821 822 return rsi_send_internal_mgmt_frame(common, skb); 823 } 824 825 /* 826 * rsi_load_bootup_params() - This function send bootup params to the firmware. 827 * @common: Pointer to the driver private structure. 828 * 829 * Return: 0 on success, corresponding error code on failure. 830 */ 831 static int rsi_load_bootup_params(struct rsi_common *common) 832 { 833 struct sk_buff *skb; 834 struct rsi_boot_params *boot_params; 835 836 rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__); 837 skb = dev_alloc_skb(sizeof(struct rsi_boot_params)); 838 if (!skb) { 839 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 840 __func__); 841 return -ENOMEM; 842 } 843 844 memset(skb->data, 0, sizeof(struct rsi_boot_params)); 845 boot_params = (struct rsi_boot_params *)skb->data; 846 847 rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__); 848 849 if (common->channel_width == BW_40MHZ) { 850 memcpy(&boot_params->bootup_params, 851 &boot_params_40, 852 sizeof(struct bootup_params)); 853 rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__, 854 UMAC_CLK_40BW); 855 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW); 856 } else { 857 memcpy(&boot_params->bootup_params, 858 &boot_params_20, 859 sizeof(struct bootup_params)); 860 if (boot_params_20.valid != cpu_to_le32(VALID_20)) { 861 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW); 862 rsi_dbg(MGMT_TX_ZONE, 863 "%s: Packet 20MHZ <=== %d\n", __func__, 864 UMAC_CLK_20BW); 865 } else { 866 boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ); 867 rsi_dbg(MGMT_TX_ZONE, 868 "%s: Packet 20MHZ <=== %d\n", __func__, 869 UMAC_CLK_40MHZ); 870 } 871 } 872 873 /** 874 * Bit{0:11} indicates length of the Packet 875 * Bit{12:15} indicates host queue number 876 */ 877 boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) | 878 (RSI_WIFI_MGMT_Q << 12)); 879 boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST); 880 881 skb_put(skb, sizeof(struct rsi_boot_params)); 882 883 return rsi_send_internal_mgmt_frame(common, skb); 884 } 885 886 /** 887 * rsi_send_reset_mac() - This function prepares reset MAC request and sends an 888 * internal management frame to indicate it to firmware. 889 * @common: Pointer to the driver private structure. 890 * 891 * Return: 0 on success, corresponding error code on failure. 892 */ 893 static int rsi_send_reset_mac(struct rsi_common *common) 894 { 895 struct sk_buff *skb; 896 struct rsi_mac_frame *mgmt_frame; 897 898 rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__); 899 900 skb = dev_alloc_skb(FRAME_DESC_SZ); 901 if (!skb) { 902 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 903 __func__); 904 return -ENOMEM; 905 } 906 907 memset(skb->data, 0, FRAME_DESC_SZ); 908 mgmt_frame = (struct rsi_mac_frame *)skb->data; 909 910 mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12); 911 mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ); 912 mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8); 913 914 skb_put(skb, FRAME_DESC_SZ); 915 916 return rsi_send_internal_mgmt_frame(common, skb); 917 } 918 919 /** 920 * rsi_band_check() - This function programs the band 921 * @common: Pointer to the driver private structure. 922 * 923 * Return: 0 on success, corresponding error code on failure. 924 */ 925 int rsi_band_check(struct rsi_common *common, 926 struct ieee80211_channel *curchan) 927 { 928 struct rsi_hw *adapter = common->priv; 929 struct ieee80211_hw *hw = adapter->hw; 930 u8 prev_bw = common->channel_width; 931 u8 prev_ep = common->endpoint; 932 int status = 0; 933 934 if (common->band != curchan->band) { 935 common->rf_reset = 1; 936 common->band = curchan->band; 937 } 938 939 if ((hw->conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) || 940 (hw->conf.chandef.width == NL80211_CHAN_WIDTH_20)) 941 common->channel_width = BW_20MHZ; 942 else 943 common->channel_width = BW_40MHZ; 944 945 if (common->band == NL80211_BAND_2GHZ) { 946 if (common->channel_width) 947 common->endpoint = EP_2GHZ_40MHZ; 948 else 949 common->endpoint = EP_2GHZ_20MHZ; 950 } else { 951 if (common->channel_width) 952 common->endpoint = EP_5GHZ_40MHZ; 953 else 954 common->endpoint = EP_5GHZ_20MHZ; 955 } 956 957 if (common->endpoint != prev_ep) { 958 status = rsi_program_bb_rf(common); 959 if (status) 960 return status; 961 } 962 963 if (common->channel_width != prev_bw) { 964 status = rsi_load_bootup_params(common); 965 if (status) 966 return status; 967 968 status = rsi_load_radio_caps(common); 969 if (status) 970 return status; 971 } 972 973 return status; 974 } 975 976 /** 977 * rsi_set_channel() - This function programs the channel. 978 * @common: Pointer to the driver private structure. 979 * @channel: Channel value to be set. 980 * 981 * Return: 0 on success, corresponding error code on failure. 982 */ 983 int rsi_set_channel(struct rsi_common *common, 984 struct ieee80211_channel *channel) 985 { 986 struct sk_buff *skb = NULL; 987 struct rsi_chan_config *chan_cfg; 988 u16 frame_len = sizeof(struct rsi_chan_config); 989 990 rsi_dbg(MGMT_TX_ZONE, 991 "%s: Sending scan req frame\n", __func__); 992 993 skb = dev_alloc_skb(frame_len); 994 if (!skb) { 995 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 996 __func__); 997 return -ENOMEM; 998 } 999 1000 if (!channel) { 1001 dev_kfree_skb(skb); 1002 return 0; 1003 } 1004 memset(skb->data, 0, frame_len); 1005 chan_cfg = (struct rsi_chan_config *)skb->data; 1006 1007 rsi_set_len_qno(&chan_cfg->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q); 1008 chan_cfg->desc_dword0.frame_type = SCAN_REQUEST; 1009 chan_cfg->channel_number = channel->hw_value; 1010 chan_cfg->antenna_gain_offset_2g = channel->max_antenna_gain; 1011 chan_cfg->antenna_gain_offset_5g = channel->max_antenna_gain; 1012 chan_cfg->region_rftype = (RSI_RF_TYPE & 0xf) << 4; 1013 1014 if ((channel->flags & IEEE80211_CHAN_NO_IR) || 1015 (channel->flags & IEEE80211_CHAN_RADAR)) { 1016 chan_cfg->antenna_gain_offset_2g |= RSI_CHAN_RADAR; 1017 } else { 1018 if (common->tx_power < channel->max_power) 1019 chan_cfg->tx_power = cpu_to_le16(common->tx_power); 1020 else 1021 chan_cfg->tx_power = cpu_to_le16(channel->max_power); 1022 } 1023 chan_cfg->region_rftype |= (common->priv->dfs_region & 0xf); 1024 1025 if (common->channel_width == BW_40MHZ) 1026 chan_cfg->channel_width = 0x1; 1027 1028 common->channel = channel->hw_value; 1029 1030 skb_put(skb, frame_len); 1031 1032 return rsi_send_internal_mgmt_frame(common, skb); 1033 } 1034 1035 /** 1036 * rsi_send_radio_params_update() - This function sends the radio 1037 * parameters update to device 1038 * @common: Pointer to the driver private structure. 1039 * @channel: Channel value to be set. 1040 * 1041 * Return: 0 on success, corresponding error code on failure. 1042 */ 1043 int rsi_send_radio_params_update(struct rsi_common *common) 1044 { 1045 struct rsi_mac_frame *cmd_frame; 1046 struct sk_buff *skb = NULL; 1047 1048 rsi_dbg(MGMT_TX_ZONE, 1049 "%s: Sending Radio Params update frame\n", __func__); 1050 1051 skb = dev_alloc_skb(FRAME_DESC_SZ); 1052 if (!skb) { 1053 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 1054 __func__); 1055 return -ENOMEM; 1056 } 1057 1058 memset(skb->data, 0, FRAME_DESC_SZ); 1059 cmd_frame = (struct rsi_mac_frame *)skb->data; 1060 1061 cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12); 1062 cmd_frame->desc_word[1] = cpu_to_le16(RADIO_PARAMS_UPDATE); 1063 cmd_frame->desc_word[3] = cpu_to_le16(BIT(0)); 1064 1065 cmd_frame->desc_word[3] |= cpu_to_le16(common->tx_power << 8); 1066 1067 skb_put(skb, FRAME_DESC_SZ); 1068 1069 return rsi_send_internal_mgmt_frame(common, skb); 1070 } 1071 1072 /* This function programs the threshold. */ 1073 int rsi_send_vap_dynamic_update(struct rsi_common *common) 1074 { 1075 struct sk_buff *skb; 1076 struct rsi_dynamic_s *dynamic_frame; 1077 1078 rsi_dbg(MGMT_TX_ZONE, 1079 "%s: Sending vap update indication frame\n", __func__); 1080 1081 skb = dev_alloc_skb(sizeof(struct rsi_dynamic_s)); 1082 if (!skb) 1083 return -ENOMEM; 1084 1085 memset(skb->data, 0, sizeof(struct rsi_dynamic_s)); 1086 dynamic_frame = (struct rsi_dynamic_s *)skb->data; 1087 rsi_set_len_qno(&dynamic_frame->desc_dword0.len_qno, 1088 sizeof(dynamic_frame->frame_body), RSI_WIFI_MGMT_Q); 1089 1090 dynamic_frame->desc_dword0.frame_type = VAP_DYNAMIC_UPDATE; 1091 dynamic_frame->desc_dword2.pkt_info = 1092 cpu_to_le32(common->rts_threshold); 1093 1094 if (common->wow_flags & RSI_WOW_ENABLED) { 1095 /* Beacon miss threshold */ 1096 dynamic_frame->desc_dword3.token = 1097 cpu_to_le16(RSI_BCN_MISS_THRESHOLD); 1098 dynamic_frame->frame_body.keep_alive_period = 1099 cpu_to_le16(RSI_WOW_KEEPALIVE); 1100 } else { 1101 dynamic_frame->frame_body.keep_alive_period = 1102 cpu_to_le16(RSI_DEF_KEEPALIVE); 1103 } 1104 1105 dynamic_frame->desc_dword3.sta_id = 0; /* vap id */ 1106 1107 skb_put(skb, sizeof(struct rsi_dynamic_s)); 1108 1109 return rsi_send_internal_mgmt_frame(common, skb); 1110 } 1111 1112 /** 1113 * rsi_compare() - This function is used to compare two integers 1114 * @a: pointer to the first integer 1115 * @b: pointer to the second integer 1116 * 1117 * Return: 0 if both are equal, -1 if the first is smaller, else 1 1118 */ 1119 static int rsi_compare(const void *a, const void *b) 1120 { 1121 u16 _a = *(const u16 *)(a); 1122 u16 _b = *(const u16 *)(b); 1123 1124 if (_a > _b) 1125 return -1; 1126 1127 if (_a < _b) 1128 return 1; 1129 1130 return 0; 1131 } 1132 1133 /** 1134 * rsi_map_rates() - This function is used to map selected rates to hw rates. 1135 * @rate: The standard rate to be mapped. 1136 * @offset: Offset that will be returned. 1137 * 1138 * Return: 0 if it is a mcs rate, else 1 1139 */ 1140 static bool rsi_map_rates(u16 rate, int *offset) 1141 { 1142 int kk; 1143 for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) { 1144 if (rate == mcs[kk]) { 1145 *offset = kk; 1146 return false; 1147 } 1148 } 1149 1150 for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) { 1151 if (rate == rsi_rates[kk].bitrate / 5) { 1152 *offset = kk; 1153 break; 1154 } 1155 } 1156 return true; 1157 } 1158 1159 /** 1160 * rsi_send_auto_rate_request() - This function is to set rates for connection 1161 * and send autorate request to firmware. 1162 * @common: Pointer to the driver private structure. 1163 * 1164 * Return: 0 on success, corresponding error code on failure. 1165 */ 1166 static int rsi_send_auto_rate_request(struct rsi_common *common, 1167 struct ieee80211_sta *sta, 1168 u16 sta_id, 1169 struct ieee80211_vif *vif) 1170 { 1171 struct sk_buff *skb; 1172 struct rsi_auto_rate *auto_rate; 1173 int ii = 0, jj = 0, kk = 0; 1174 struct ieee80211_hw *hw = common->priv->hw; 1175 u8 band = hw->conf.chandef.chan->band; 1176 u8 num_supported_rates = 0; 1177 u8 rate_table_offset, rate_offset = 0; 1178 u32 rate_bitmap; 1179 u16 *selected_rates, min_rate; 1180 bool is_ht = false, is_sgi = false; 1181 u16 frame_len = sizeof(struct rsi_auto_rate); 1182 1183 rsi_dbg(MGMT_TX_ZONE, 1184 "%s: Sending auto rate request frame\n", __func__); 1185 1186 skb = dev_alloc_skb(frame_len); 1187 if (!skb) { 1188 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 1189 __func__); 1190 return -ENOMEM; 1191 } 1192 1193 memset(skb->data, 0, frame_len); 1194 selected_rates = kzalloc(2 * RSI_TBL_SZ, GFP_KERNEL); 1195 if (!selected_rates) { 1196 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n", 1197 __func__); 1198 dev_kfree_skb(skb); 1199 return -ENOMEM; 1200 } 1201 1202 auto_rate = (struct rsi_auto_rate *)skb->data; 1203 1204 auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f)); 1205 auto_rate->collision_tolerance = cpu_to_le16(3); 1206 auto_rate->failure_limit = cpu_to_le16(3); 1207 auto_rate->initial_boundary = cpu_to_le16(3); 1208 auto_rate->max_threshold_limt = cpu_to_le16(27); 1209 1210 auto_rate->desc.desc_dword0.frame_type = AUTO_RATE_IND; 1211 1212 if (common->channel_width == BW_40MHZ) 1213 auto_rate->desc.desc_dword3.qid_tid = BW_40MHZ; 1214 auto_rate->desc.desc_dword3.sta_id = sta_id; 1215 1216 if (vif->type == NL80211_IFTYPE_STATION) { 1217 rate_bitmap = common->bitrate_mask[band]; 1218 is_ht = common->vif_info[0].is_ht; 1219 is_sgi = common->vif_info[0].sgi; 1220 } else { 1221 rate_bitmap = sta->supp_rates[band]; 1222 is_ht = sta->ht_cap.ht_supported; 1223 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) || 1224 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) 1225 is_sgi = true; 1226 } 1227 1228 if (band == NL80211_BAND_2GHZ) { 1229 if ((rate_bitmap == 0) && (is_ht)) 1230 min_rate = RSI_RATE_MCS0; 1231 else 1232 min_rate = RSI_RATE_1; 1233 rate_table_offset = 0; 1234 } else { 1235 if ((rate_bitmap == 0) && (is_ht)) 1236 min_rate = RSI_RATE_MCS0; 1237 else 1238 min_rate = RSI_RATE_6; 1239 rate_table_offset = 4; 1240 } 1241 1242 for (ii = 0, jj = 0; 1243 ii < (ARRAY_SIZE(rsi_rates) - rate_table_offset); ii++) { 1244 if (rate_bitmap & BIT(ii)) { 1245 selected_rates[jj++] = 1246 (rsi_rates[ii + rate_table_offset].bitrate / 5); 1247 rate_offset++; 1248 } 1249 } 1250 num_supported_rates = jj; 1251 1252 if (is_ht) { 1253 for (ii = 0; ii < ARRAY_SIZE(mcs); ii++) 1254 selected_rates[jj++] = mcs[ii]; 1255 num_supported_rates += ARRAY_SIZE(mcs); 1256 rate_offset += ARRAY_SIZE(mcs); 1257 } 1258 1259 sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL); 1260 1261 /* mapping the rates to RSI rates */ 1262 for (ii = 0; ii < jj; ii++) { 1263 if (rsi_map_rates(selected_rates[ii], &kk)) { 1264 auto_rate->supported_rates[ii] = 1265 cpu_to_le16(rsi_rates[kk].hw_value); 1266 } else { 1267 auto_rate->supported_rates[ii] = 1268 cpu_to_le16(rsi_mcsrates[kk]); 1269 } 1270 } 1271 1272 /* loading HT rates in the bottom half of the auto rate table */ 1273 if (is_ht) { 1274 for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1; 1275 ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) { 1276 if (is_sgi || conf_is_ht40(&common->priv->hw->conf)) 1277 auto_rate->supported_rates[ii++] = 1278 cpu_to_le16(rsi_mcsrates[kk] | BIT(9)); 1279 else 1280 auto_rate->supported_rates[ii++] = 1281 cpu_to_le16(rsi_mcsrates[kk]); 1282 auto_rate->supported_rates[ii] = 1283 cpu_to_le16(rsi_mcsrates[kk--]); 1284 } 1285 1286 for (; ii < (RSI_TBL_SZ - 1); ii++) { 1287 auto_rate->supported_rates[ii] = 1288 cpu_to_le16(rsi_mcsrates[0]); 1289 } 1290 } 1291 1292 for (; ii < RSI_TBL_SZ; ii++) 1293 auto_rate->supported_rates[ii] = cpu_to_le16(min_rate); 1294 1295 auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2); 1296 auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2); 1297 num_supported_rates *= 2; 1298 1299 rsi_set_len_qno(&auto_rate->desc.desc_dword0.len_qno, 1300 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q); 1301 1302 skb_put(skb, frame_len); 1303 kfree(selected_rates); 1304 1305 return rsi_send_internal_mgmt_frame(common, skb); 1306 } 1307 1308 /** 1309 * rsi_inform_bss_status() - This function informs about bss status with the 1310 * help of sta notify params by sending an internal 1311 * management frame to firmware. 1312 * @common: Pointer to the driver private structure. 1313 * @status: Bss status type. 1314 * @bssid: Bssid. 1315 * @qos_enable: Qos is enabled. 1316 * @aid: Aid (unique for all STAs). 1317 * 1318 * Return: None. 1319 */ 1320 void rsi_inform_bss_status(struct rsi_common *common, 1321 enum opmode opmode, 1322 u8 status, 1323 const u8 *addr, 1324 u8 qos_enable, 1325 u16 aid, 1326 struct ieee80211_sta *sta, 1327 u16 sta_id, 1328 u16 assoc_cap, 1329 struct ieee80211_vif *vif) 1330 { 1331 if (status) { 1332 if (opmode == RSI_OPMODE_STA) 1333 common->hw_data_qs_blocked = true; 1334 rsi_hal_send_sta_notify_frame(common, 1335 opmode, 1336 STA_CONNECTED, 1337 addr, 1338 qos_enable, 1339 aid, sta_id, 1340 vif); 1341 if (common->min_rate == 0xffff) 1342 rsi_send_auto_rate_request(common, sta, sta_id, vif); 1343 if (opmode == RSI_OPMODE_STA && 1344 !(assoc_cap & WLAN_CAPABILITY_PRIVACY) && 1345 !rsi_send_block_unblock_frame(common, false)) 1346 common->hw_data_qs_blocked = false; 1347 } else { 1348 if (opmode == RSI_OPMODE_STA) 1349 common->hw_data_qs_blocked = true; 1350 1351 if (!(common->wow_flags & RSI_WOW_ENABLED)) 1352 rsi_hal_send_sta_notify_frame(common, opmode, 1353 STA_DISCONNECTED, addr, 1354 qos_enable, aid, sta_id, 1355 vif); 1356 if (opmode == RSI_OPMODE_STA) 1357 rsi_send_block_unblock_frame(common, true); 1358 } 1359 } 1360 1361 /** 1362 * rsi_eeprom_read() - This function sends a frame to read the mac address 1363 * from the eeprom. 1364 * @common: Pointer to the driver private structure. 1365 * 1366 * Return: 0 on success, -1 on failure. 1367 */ 1368 static int rsi_eeprom_read(struct rsi_common *common) 1369 { 1370 struct rsi_eeprom_read_frame *mgmt_frame; 1371 struct rsi_hw *adapter = common->priv; 1372 struct sk_buff *skb; 1373 1374 rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__); 1375 1376 skb = dev_alloc_skb(FRAME_DESC_SZ); 1377 if (!skb) { 1378 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 1379 __func__); 1380 return -ENOMEM; 1381 } 1382 1383 memset(skb->data, 0, FRAME_DESC_SZ); 1384 mgmt_frame = (struct rsi_eeprom_read_frame *)skb->data; 1385 1386 /* FrameType */ 1387 rsi_set_len_qno(&mgmt_frame->len_qno, 0, RSI_WIFI_MGMT_Q); 1388 mgmt_frame->pkt_type = EEPROM_READ; 1389 1390 /* Number of bytes to read */ 1391 mgmt_frame->pkt_info = 1392 cpu_to_le32((adapter->eeprom.length << RSI_EEPROM_LEN_OFFSET) & 1393 RSI_EEPROM_LEN_MASK); 1394 mgmt_frame->pkt_info |= cpu_to_le32((3 << RSI_EEPROM_HDR_SIZE_OFFSET) & 1395 RSI_EEPROM_HDR_SIZE_MASK); 1396 1397 /* Address to read */ 1398 mgmt_frame->eeprom_offset = cpu_to_le32(adapter->eeprom.offset); 1399 1400 skb_put(skb, FRAME_DESC_SZ); 1401 1402 return rsi_send_internal_mgmt_frame(common, skb); 1403 } 1404 1405 /** 1406 * This function sends a frame to block/unblock 1407 * data queues in the firmware 1408 * 1409 * @param common Pointer to the driver private structure. 1410 * @param block event - block if true, unblock if false 1411 * @return 0 on success, -1 on failure. 1412 */ 1413 int rsi_send_block_unblock_frame(struct rsi_common *common, bool block_event) 1414 { 1415 struct rsi_block_unblock_data *mgmt_frame; 1416 struct sk_buff *skb; 1417 1418 rsi_dbg(MGMT_TX_ZONE, "%s: Sending block/unblock frame\n", __func__); 1419 1420 skb = dev_alloc_skb(FRAME_DESC_SZ); 1421 if (!skb) { 1422 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 1423 __func__); 1424 return -ENOMEM; 1425 } 1426 1427 memset(skb->data, 0, FRAME_DESC_SZ); 1428 mgmt_frame = (struct rsi_block_unblock_data *)skb->data; 1429 1430 rsi_set_len_qno(&mgmt_frame->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q); 1431 mgmt_frame->desc_dword0.frame_type = BLOCK_HW_QUEUE; 1432 mgmt_frame->host_quiet_info = QUIET_INFO_VALID; 1433 1434 if (block_event) { 1435 rsi_dbg(INFO_ZONE, "blocking the data qs\n"); 1436 mgmt_frame->block_q_bitmap = cpu_to_le16(0xf); 1437 mgmt_frame->block_q_bitmap |= cpu_to_le16(0xf << 4); 1438 } else { 1439 rsi_dbg(INFO_ZONE, "unblocking the data qs\n"); 1440 mgmt_frame->unblock_q_bitmap = cpu_to_le16(0xf); 1441 mgmt_frame->unblock_q_bitmap |= cpu_to_le16(0xf << 4); 1442 } 1443 1444 skb_put(skb, FRAME_DESC_SZ); 1445 1446 return rsi_send_internal_mgmt_frame(common, skb); 1447 } 1448 1449 /** 1450 * rsi_send_rx_filter_frame() - Sends a frame to filter the RX packets 1451 * 1452 * @common: Pointer to the driver private structure. 1453 * @rx_filter_word: Flags of filter packets 1454 * 1455 * @Return: 0 on success, -1 on failure. 1456 */ 1457 int rsi_send_rx_filter_frame(struct rsi_common *common, u16 rx_filter_word) 1458 { 1459 struct rsi_mac_frame *cmd_frame; 1460 struct sk_buff *skb; 1461 1462 rsi_dbg(MGMT_TX_ZONE, "Sending RX filter frame\n"); 1463 1464 skb = dev_alloc_skb(FRAME_DESC_SZ); 1465 if (!skb) { 1466 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 1467 __func__); 1468 return -ENOMEM; 1469 } 1470 1471 memset(skb->data, 0, FRAME_DESC_SZ); 1472 cmd_frame = (struct rsi_mac_frame *)skb->data; 1473 1474 cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12); 1475 cmd_frame->desc_word[1] = cpu_to_le16(SET_RX_FILTER); 1476 cmd_frame->desc_word[4] = cpu_to_le16(rx_filter_word); 1477 1478 skb_put(skb, FRAME_DESC_SZ); 1479 1480 return rsi_send_internal_mgmt_frame(common, skb); 1481 } 1482 1483 int rsi_send_ps_request(struct rsi_hw *adapter, bool enable, 1484 struct ieee80211_vif *vif) 1485 { 1486 struct rsi_common *common = adapter->priv; 1487 struct ieee80211_bss_conf *bss = &vif->bss_conf; 1488 struct rsi_request_ps *ps; 1489 struct rsi_ps_info *ps_info; 1490 struct sk_buff *skb; 1491 int frame_len = sizeof(*ps); 1492 1493 skb = dev_alloc_skb(frame_len); 1494 if (!skb) 1495 return -ENOMEM; 1496 memset(skb->data, 0, frame_len); 1497 1498 ps = (struct rsi_request_ps *)skb->data; 1499 ps_info = &adapter->ps_info; 1500 1501 rsi_set_len_qno(&ps->desc.desc_dword0.len_qno, 1502 (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q); 1503 ps->desc.desc_dword0.frame_type = WAKEUP_SLEEP_REQUEST; 1504 if (enable) { 1505 ps->ps_sleep.enable = RSI_PS_ENABLE; 1506 ps->desc.desc_dword3.token = cpu_to_le16(RSI_SLEEP_REQUEST); 1507 } else { 1508 ps->ps_sleep.enable = RSI_PS_DISABLE; 1509 ps->desc.desc_dword0.len_qno |= cpu_to_le16(RSI_PS_DISABLE_IND); 1510 ps->desc.desc_dword3.token = cpu_to_le16(RSI_WAKEUP_REQUEST); 1511 } 1512 1513 ps->ps_uapsd_acs = common->uapsd_bitmap; 1514 1515 ps->ps_sleep.sleep_type = ps_info->sleep_type; 1516 ps->ps_sleep.num_bcns_per_lis_int = 1517 cpu_to_le16(ps_info->num_bcns_per_lis_int); 1518 ps->ps_sleep.sleep_duration = 1519 cpu_to_le32(ps_info->deep_sleep_wakeup_period); 1520 1521 if (bss->assoc) 1522 ps->ps_sleep.connected_sleep = RSI_CONNECTED_SLEEP; 1523 else 1524 ps->ps_sleep.connected_sleep = RSI_DEEP_SLEEP; 1525 1526 ps->ps_listen_interval = cpu_to_le32(ps_info->listen_interval); 1527 ps->ps_dtim_interval_duration = 1528 cpu_to_le32(ps_info->dtim_interval_duration); 1529 1530 if (ps_info->listen_interval > ps_info->dtim_interval_duration) 1531 ps->ps_listen_interval = cpu_to_le32(RSI_PS_DISABLE); 1532 1533 ps->ps_num_dtim_intervals = cpu_to_le16(ps_info->num_dtims_per_sleep); 1534 skb_put(skb, frame_len); 1535 1536 return rsi_send_internal_mgmt_frame(common, skb); 1537 } 1538 1539 /** 1540 * rsi_set_antenna() - This fuction send antenna configuration request 1541 * to device 1542 * 1543 * @common: Pointer to the driver private structure. 1544 * @antenna: bitmap for tx antenna selection 1545 * 1546 * Return: 0 on Success, negative error code on failure 1547 */ 1548 int rsi_set_antenna(struct rsi_common *common, u8 antenna) 1549 { 1550 struct rsi_ant_sel_frame *ant_sel_frame; 1551 struct sk_buff *skb; 1552 1553 skb = dev_alloc_skb(FRAME_DESC_SZ); 1554 if (!skb) { 1555 rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n", 1556 __func__); 1557 return -ENOMEM; 1558 } 1559 1560 memset(skb->data, 0, FRAME_DESC_SZ); 1561 1562 ant_sel_frame = (struct rsi_ant_sel_frame *)skb->data; 1563 ant_sel_frame->desc_dword0.frame_type = ANT_SEL_FRAME; 1564 ant_sel_frame->sub_frame_type = ANTENNA_SEL_TYPE; 1565 ant_sel_frame->ant_value = cpu_to_le16(antenna & ANTENNA_MASK_VALUE); 1566 rsi_set_len_qno(&ant_sel_frame->desc_dword0.len_qno, 1567 0, RSI_WIFI_MGMT_Q); 1568 skb_put(skb, FRAME_DESC_SZ); 1569 1570 return rsi_send_internal_mgmt_frame(common, skb); 1571 } 1572 1573 static int rsi_send_beacon(struct rsi_common *common) 1574 { 1575 struct sk_buff *skb = NULL; 1576 u8 dword_align_bytes = 0; 1577 1578 skb = dev_alloc_skb(MAX_MGMT_PKT_SIZE); 1579 if (!skb) 1580 return -ENOMEM; 1581 1582 memset(skb->data, 0, MAX_MGMT_PKT_SIZE); 1583 1584 dword_align_bytes = ((unsigned long)skb->data & 0x3f); 1585 if (dword_align_bytes) 1586 skb_pull(skb, (64 - dword_align_bytes)); 1587 if (rsi_prepare_beacon(common, skb)) { 1588 rsi_dbg(ERR_ZONE, "Failed to prepare beacon\n"); 1589 return -EINVAL; 1590 } 1591 skb_queue_tail(&common->tx_queue[MGMT_BEACON_Q], skb); 1592 rsi_set_event(&common->tx_thread.event); 1593 rsi_dbg(DATA_TX_ZONE, "%s: Added to beacon queue\n", __func__); 1594 1595 return 0; 1596 } 1597 1598 #ifdef CONFIG_PM 1599 int rsi_send_wowlan_request(struct rsi_common *common, u16 flags, 1600 u16 sleep_status) 1601 { 1602 struct rsi_wowlan_req *cmd_frame; 1603 struct sk_buff *skb; 1604 u8 length; 1605 1606 rsi_dbg(ERR_ZONE, "%s: Sending wowlan request frame\n", __func__); 1607 1608 length = sizeof(*cmd_frame); 1609 skb = dev_alloc_skb(length); 1610 if (!skb) 1611 return -ENOMEM; 1612 memset(skb->data, 0, length); 1613 cmd_frame = (struct rsi_wowlan_req *)skb->data; 1614 1615 rsi_set_len_qno(&cmd_frame->desc.desc_dword0.len_qno, 1616 (length - FRAME_DESC_SZ), 1617 RSI_WIFI_MGMT_Q); 1618 cmd_frame->desc.desc_dword0.frame_type = WOWLAN_CONFIG_PARAMS; 1619 cmd_frame->host_sleep_status = sleep_status; 1620 if (common->secinfo.security_enable && 1621 common->secinfo.gtk_cipher) 1622 flags |= RSI_WOW_GTK_REKEY; 1623 if (sleep_status) 1624 cmd_frame->wow_flags = flags; 1625 rsi_dbg(INFO_ZONE, "Host_Sleep_Status : %d Flags : %d\n", 1626 cmd_frame->host_sleep_status, cmd_frame->wow_flags); 1627 1628 skb_put(skb, length); 1629 1630 return rsi_send_internal_mgmt_frame(common, skb); 1631 } 1632 #endif 1633 1634 /** 1635 * rsi_handle_ta_confirm_type() - This function handles the confirm frames. 1636 * @common: Pointer to the driver private structure. 1637 * @msg: Pointer to received packet. 1638 * 1639 * Return: 0 on success, -1 on failure. 1640 */ 1641 static int rsi_handle_ta_confirm_type(struct rsi_common *common, 1642 u8 *msg) 1643 { 1644 struct rsi_hw *adapter = common->priv; 1645 u8 sub_type = (msg[15] & 0xff); 1646 u16 msg_len = ((u16 *)msg)[0] & 0xfff; 1647 u8 offset; 1648 1649 switch (sub_type) { 1650 case BOOTUP_PARAMS_REQUEST: 1651 rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n", 1652 __func__); 1653 if (common->fsm_state == FSM_BOOT_PARAMS_SENT) { 1654 adapter->eeprom.length = (IEEE80211_ADDR_LEN + 1655 WLAN_MAC_MAGIC_WORD_LEN + 1656 WLAN_HOST_MODE_LEN); 1657 adapter->eeprom.offset = WLAN_MAC_EEPROM_ADDR; 1658 if (rsi_eeprom_read(common)) { 1659 common->fsm_state = FSM_CARD_NOT_READY; 1660 goto out; 1661 } 1662 common->fsm_state = FSM_EEPROM_READ_MAC_ADDR; 1663 } else { 1664 rsi_dbg(INFO_ZONE, 1665 "%s: Received bootup params cfm in %d state\n", 1666 __func__, common->fsm_state); 1667 return 0; 1668 } 1669 break; 1670 1671 case EEPROM_READ: 1672 rsi_dbg(FSM_ZONE, "EEPROM READ confirm received\n"); 1673 if (msg_len <= 0) { 1674 rsi_dbg(FSM_ZONE, 1675 "%s: [EEPROM_READ] Invalid len %d\n", 1676 __func__, msg_len); 1677 goto out; 1678 } 1679 if (msg[16] != MAGIC_WORD) { 1680 rsi_dbg(FSM_ZONE, 1681 "%s: [EEPROM_READ] Invalid token\n", __func__); 1682 common->fsm_state = FSM_CARD_NOT_READY; 1683 goto out; 1684 } 1685 if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) { 1686 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN + 1687 WLAN_MAC_MAGIC_WORD_LEN); 1688 memcpy(common->mac_addr, &msg[offset], ETH_ALEN); 1689 adapter->eeprom.length = 1690 ((WLAN_MAC_MAGIC_WORD_LEN + 3) & (~3)); 1691 adapter->eeprom.offset = WLAN_EEPROM_RFTYPE_ADDR; 1692 if (rsi_eeprom_read(common)) { 1693 rsi_dbg(ERR_ZONE, 1694 "%s: Failed reading RF band\n", 1695 __func__); 1696 common->fsm_state = FSM_CARD_NOT_READY; 1697 goto out; 1698 } 1699 common->fsm_state = FSM_EEPROM_READ_RF_TYPE; 1700 } else if (common->fsm_state == FSM_EEPROM_READ_RF_TYPE) { 1701 if ((msg[17] & 0x3) == 0x3) { 1702 rsi_dbg(INIT_ZONE, "Dual band supported\n"); 1703 common->band = NL80211_BAND_5GHZ; 1704 common->num_supp_bands = 2; 1705 } else if ((msg[17] & 0x3) == 0x1) { 1706 rsi_dbg(INIT_ZONE, 1707 "Only 2.4Ghz band supported\n"); 1708 common->band = NL80211_BAND_2GHZ; 1709 common->num_supp_bands = 1; 1710 } 1711 if (rsi_send_reset_mac(common)) 1712 goto out; 1713 common->fsm_state = FSM_RESET_MAC_SENT; 1714 } else { 1715 rsi_dbg(ERR_ZONE, "%s: Invalid EEPROM read type\n", 1716 __func__); 1717 return 0; 1718 } 1719 break; 1720 1721 case RESET_MAC_REQ: 1722 if (common->fsm_state == FSM_RESET_MAC_SENT) { 1723 rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n", 1724 __func__); 1725 1726 if (rsi_load_radio_caps(common)) 1727 goto out; 1728 else 1729 common->fsm_state = FSM_RADIO_CAPS_SENT; 1730 } else { 1731 rsi_dbg(ERR_ZONE, 1732 "%s: Received reset mac cfm in %d state\n", 1733 __func__, common->fsm_state); 1734 return 0; 1735 } 1736 break; 1737 1738 case RADIO_CAPABILITIES: 1739 if (common->fsm_state == FSM_RADIO_CAPS_SENT) { 1740 common->rf_reset = 1; 1741 if (rsi_program_bb_rf(common)) { 1742 goto out; 1743 } else { 1744 common->fsm_state = FSM_BB_RF_PROG_SENT; 1745 rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n", 1746 __func__); 1747 } 1748 } else { 1749 rsi_dbg(INFO_ZONE, 1750 "%s: Received radio caps cfm in %d state\n", 1751 __func__, common->fsm_state); 1752 return 0; 1753 } 1754 break; 1755 1756 case BB_PROG_VALUES_REQUEST: 1757 case RF_PROG_VALUES_REQUEST: 1758 case BBP_PROG_IN_TA: 1759 rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__); 1760 if (common->fsm_state == FSM_BB_RF_PROG_SENT) { 1761 common->bb_rf_prog_count--; 1762 if (!common->bb_rf_prog_count) { 1763 common->fsm_state = FSM_MAC_INIT_DONE; 1764 if (common->reinit_hw) { 1765 complete(&common->wlan_init_completion); 1766 } else { 1767 return rsi_mac80211_attach(common); 1768 } 1769 } 1770 } else { 1771 rsi_dbg(INFO_ZONE, 1772 "%s: Received bbb_rf cfm in %d state\n", 1773 __func__, common->fsm_state); 1774 return 0; 1775 } 1776 break; 1777 case WAKEUP_SLEEP_REQUEST: 1778 rsi_dbg(INFO_ZONE, "Wakeup/Sleep confirmation.\n"); 1779 return rsi_handle_ps_confirm(adapter, msg); 1780 default: 1781 rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n", 1782 __func__); 1783 break; 1784 } 1785 return 0; 1786 out: 1787 rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n", 1788 __func__); 1789 return -EINVAL; 1790 } 1791 1792 int rsi_handle_card_ready(struct rsi_common *common, u8 *msg) 1793 { 1794 switch (common->fsm_state) { 1795 case FSM_CARD_NOT_READY: 1796 rsi_dbg(INIT_ZONE, "Card ready indication from Common HAL\n"); 1797 rsi_set_default_parameters(common); 1798 if (rsi_send_common_dev_params(common) < 0) 1799 return -EINVAL; 1800 common->fsm_state = FSM_COMMON_DEV_PARAMS_SENT; 1801 break; 1802 case FSM_COMMON_DEV_PARAMS_SENT: 1803 rsi_dbg(INIT_ZONE, "Card ready indication from WLAN HAL\n"); 1804 1805 /* Get usb buffer status register address */ 1806 common->priv->usb_buffer_status_reg = *(u32 *)&msg[8]; 1807 rsi_dbg(INFO_ZONE, "USB buffer status register = %x\n", 1808 common->priv->usb_buffer_status_reg); 1809 1810 if (rsi_load_bootup_params(common)) { 1811 common->fsm_state = FSM_CARD_NOT_READY; 1812 return -EINVAL; 1813 } 1814 common->fsm_state = FSM_BOOT_PARAMS_SENT; 1815 break; 1816 default: 1817 rsi_dbg(ERR_ZONE, 1818 "%s: card ready indication in invalid state %d.\n", 1819 __func__, common->fsm_state); 1820 return -EINVAL; 1821 } 1822 1823 return 0; 1824 } 1825 1826 /** 1827 * rsi_mgmt_pkt_recv() - This function processes the management packets 1828 * recieved from the hardware. 1829 * @common: Pointer to the driver private structure. 1830 * @msg: Pointer to the received packet. 1831 * 1832 * Return: 0 on success, -1 on failure. 1833 */ 1834 int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg) 1835 { 1836 s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff); 1837 u16 msg_type = (msg[2]); 1838 1839 rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n", 1840 __func__, msg_len, msg_type); 1841 1842 switch (msg_type) { 1843 case TA_CONFIRM_TYPE: 1844 return rsi_handle_ta_confirm_type(common, msg); 1845 case CARD_READY_IND: 1846 common->hibernate_resume = false; 1847 rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n", 1848 __func__); 1849 return rsi_handle_card_ready(common, msg); 1850 case TX_STATUS_IND: 1851 switch (msg[RSI_TX_STATUS_TYPE]) { 1852 case PROBEREQ_CONFIRM: 1853 common->mgmt_q_block = false; 1854 rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n", 1855 __func__); 1856 break; 1857 case EAPOL4_CONFIRM: 1858 if (msg[RSI_TX_STATUS]) { 1859 common->eapol4_confirm = true; 1860 if (!rsi_send_block_unblock_frame(common, 1861 false)) 1862 common->hw_data_qs_blocked = false; 1863 } 1864 } 1865 break; 1866 case BEACON_EVENT_IND: 1867 rsi_dbg(INFO_ZONE, "Beacon event\n"); 1868 if (common->fsm_state != FSM_MAC_INIT_DONE) 1869 return -1; 1870 if (common->iface_down) 1871 return -1; 1872 if (!common->beacon_enabled) 1873 return -1; 1874 rsi_send_beacon(common); 1875 break; 1876 case RX_DOT11_MGMT: 1877 return rsi_mgmt_pkt_to_core(common, msg, msg_len); 1878 default: 1879 rsi_dbg(INFO_ZONE, "Received packet type: 0x%x\n", msg_type); 1880 } 1881 return 0; 1882 } 1883