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_debugfs.h" 19#include "rsi_mgmt.h" 20#include "rsi_sdio.h" 21#include "rsi_common.h" 22#include "rsi_ps.h" 23 24static const struct ieee80211_channel rsi_2ghz_channels[] = { 25 { .band = NL80211_BAND_2GHZ, .center_freq = 2412, 26 .hw_value = 1 }, /* Channel 1 */ 27 { .band = NL80211_BAND_2GHZ, .center_freq = 2417, 28 .hw_value = 2 }, /* Channel 2 */ 29 { .band = NL80211_BAND_2GHZ, .center_freq = 2422, 30 .hw_value = 3 }, /* Channel 3 */ 31 { .band = NL80211_BAND_2GHZ, .center_freq = 2427, 32 .hw_value = 4 }, /* Channel 4 */ 33 { .band = NL80211_BAND_2GHZ, .center_freq = 2432, 34 .hw_value = 5 }, /* Channel 5 */ 35 { .band = NL80211_BAND_2GHZ, .center_freq = 2437, 36 .hw_value = 6 }, /* Channel 6 */ 37 { .band = NL80211_BAND_2GHZ, .center_freq = 2442, 38 .hw_value = 7 }, /* Channel 7 */ 39 { .band = NL80211_BAND_2GHZ, .center_freq = 2447, 40 .hw_value = 8 }, /* Channel 8 */ 41 { .band = NL80211_BAND_2GHZ, .center_freq = 2452, 42 .hw_value = 9 }, /* Channel 9 */ 43 { .band = NL80211_BAND_2GHZ, .center_freq = 2457, 44 .hw_value = 10 }, /* Channel 10 */ 45 { .band = NL80211_BAND_2GHZ, .center_freq = 2462, 46 .hw_value = 11 }, /* Channel 11 */ 47 { .band = NL80211_BAND_2GHZ, .center_freq = 2467, 48 .hw_value = 12 }, /* Channel 12 */ 49 { .band = NL80211_BAND_2GHZ, .center_freq = 2472, 50 .hw_value = 13 }, /* Channel 13 */ 51 { .band = NL80211_BAND_2GHZ, .center_freq = 2484, 52 .hw_value = 14 }, /* Channel 14 */ 53}; 54 55static const struct ieee80211_channel rsi_5ghz_channels[] = { 56 { .band = NL80211_BAND_5GHZ, .center_freq = 5180, 57 .hw_value = 36, }, /* Channel 36 */ 58 { .band = NL80211_BAND_5GHZ, .center_freq = 5200, 59 .hw_value = 40, }, /* Channel 40 */ 60 { .band = NL80211_BAND_5GHZ, .center_freq = 5220, 61 .hw_value = 44, }, /* Channel 44 */ 62 { .band = NL80211_BAND_5GHZ, .center_freq = 5240, 63 .hw_value = 48, }, /* Channel 48 */ 64 { .band = NL80211_BAND_5GHZ, .center_freq = 5260, 65 .hw_value = 52, }, /* Channel 52 */ 66 { .band = NL80211_BAND_5GHZ, .center_freq = 5280, 67 .hw_value = 56, }, /* Channel 56 */ 68 { .band = NL80211_BAND_5GHZ, .center_freq = 5300, 69 .hw_value = 60, }, /* Channel 60 */ 70 { .band = NL80211_BAND_5GHZ, .center_freq = 5320, 71 .hw_value = 64, }, /* Channel 64 */ 72 { .band = NL80211_BAND_5GHZ, .center_freq = 5500, 73 .hw_value = 100, }, /* Channel 100 */ 74 { .band = NL80211_BAND_5GHZ, .center_freq = 5520, 75 .hw_value = 104, }, /* Channel 104 */ 76 { .band = NL80211_BAND_5GHZ, .center_freq = 5540, 77 .hw_value = 108, }, /* Channel 108 */ 78 { .band = NL80211_BAND_5GHZ, .center_freq = 5560, 79 .hw_value = 112, }, /* Channel 112 */ 80 { .band = NL80211_BAND_5GHZ, .center_freq = 5580, 81 .hw_value = 116, }, /* Channel 116 */ 82 { .band = NL80211_BAND_5GHZ, .center_freq = 5600, 83 .hw_value = 120, }, /* Channel 120 */ 84 { .band = NL80211_BAND_5GHZ, .center_freq = 5620, 85 .hw_value = 124, }, /* Channel 124 */ 86 { .band = NL80211_BAND_5GHZ, .center_freq = 5640, 87 .hw_value = 128, }, /* Channel 128 */ 88 { .band = NL80211_BAND_5GHZ, .center_freq = 5660, 89 .hw_value = 132, }, /* Channel 132 */ 90 { .band = NL80211_BAND_5GHZ, .center_freq = 5680, 91 .hw_value = 136, }, /* Channel 136 */ 92 { .band = NL80211_BAND_5GHZ, .center_freq = 5700, 93 .hw_value = 140, }, /* Channel 140 */ 94 { .band = NL80211_BAND_5GHZ, .center_freq = 5745, 95 .hw_value = 149, }, /* Channel 149 */ 96 { .band = NL80211_BAND_5GHZ, .center_freq = 5765, 97 .hw_value = 153, }, /* Channel 153 */ 98 { .band = NL80211_BAND_5GHZ, .center_freq = 5785, 99 .hw_value = 157, }, /* Channel 157 */ 100 { .band = NL80211_BAND_5GHZ, .center_freq = 5805, 101 .hw_value = 161, }, /* Channel 161 */ 102 { .band = NL80211_BAND_5GHZ, .center_freq = 5825, 103 .hw_value = 165, }, /* Channel 165 */ 104}; 105 106struct ieee80211_rate rsi_rates[12] = { 107 { .bitrate = STD_RATE_01 * 5, .hw_value = RSI_RATE_1 }, 108 { .bitrate = STD_RATE_02 * 5, .hw_value = RSI_RATE_2 }, 109 { .bitrate = STD_RATE_5_5 * 5, .hw_value = RSI_RATE_5_5 }, 110 { .bitrate = STD_RATE_11 * 5, .hw_value = RSI_RATE_11 }, 111 { .bitrate = STD_RATE_06 * 5, .hw_value = RSI_RATE_6 }, 112 { .bitrate = STD_RATE_09 * 5, .hw_value = RSI_RATE_9 }, 113 { .bitrate = STD_RATE_12 * 5, .hw_value = RSI_RATE_12 }, 114 { .bitrate = STD_RATE_18 * 5, .hw_value = RSI_RATE_18 }, 115 { .bitrate = STD_RATE_24 * 5, .hw_value = RSI_RATE_24 }, 116 { .bitrate = STD_RATE_36 * 5, .hw_value = RSI_RATE_36 }, 117 { .bitrate = STD_RATE_48 * 5, .hw_value = RSI_RATE_48 }, 118 { .bitrate = STD_RATE_54 * 5, .hw_value = RSI_RATE_54 }, 119}; 120 121const u16 rsi_mcsrates[8] = { 122 RSI_RATE_MCS0, RSI_RATE_MCS1, RSI_RATE_MCS2, RSI_RATE_MCS3, 123 RSI_RATE_MCS4, RSI_RATE_MCS5, RSI_RATE_MCS6, RSI_RATE_MCS7 124}; 125 126static const u32 rsi_max_ap_stas[16] = { 127 32, /* 1 - Wi-Fi alone */ 128 0, /* 2 */ 129 0, /* 3 */ 130 0, /* 4 - BT EDR alone */ 131 4, /* 5 - STA + BT EDR */ 132 32, /* 6 - AP + BT EDR */ 133 0, /* 7 */ 134 0, /* 8 - BT LE alone */ 135 4, /* 9 - STA + BE LE */ 136 0, /* 10 */ 137 0, /* 11 */ 138 0, /* 12 */ 139 1, /* 13 - STA + BT Dual */ 140 4, /* 14 - AP + BT Dual */ 141}; 142 143static const struct ieee80211_iface_limit rsi_iface_limits[] = { 144 { 145 .max = 1, 146 .types = BIT(NL80211_IFTYPE_STATION), 147 }, 148 { 149 .max = 1, 150 .types = BIT(NL80211_IFTYPE_AP) | 151 BIT(NL80211_IFTYPE_P2P_CLIENT) | 152 BIT(NL80211_IFTYPE_P2P_GO), 153 }, 154 { 155 .max = 1, 156 .types = BIT(NL80211_IFTYPE_P2P_DEVICE), 157 }, 158}; 159 160static const struct ieee80211_iface_combination rsi_iface_combinations[] = { 161 { 162 .num_different_channels = 1, 163 .max_interfaces = 3, 164 .limits = rsi_iface_limits, 165 .n_limits = ARRAY_SIZE(rsi_iface_limits), 166 }, 167}; 168 169/** 170 * rsi_is_cipher_wep() - This function determines if the cipher is WEP or not. 171 * @common: Pointer to the driver private structure. 172 * 173 * Return: If cipher type is WEP, a value of 1 is returned, else 0. 174 */ 175 176bool rsi_is_cipher_wep(struct rsi_common *common) 177{ 178 if (((common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP104) || 179 (common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP40)) && 180 (!common->secinfo.ptk_cipher)) 181 return true; 182 else 183 return false; 184} 185 186/** 187 * rsi_register_rates_channels() - This function registers channels and rates. 188 * @adapter: Pointer to the adapter structure. 189 * @band: Operating band to be set. 190 * 191 * Return: int - 0 on success, negative error on failure. 192 */ 193static int rsi_register_rates_channels(struct rsi_hw *adapter, int band) 194{ 195 struct ieee80211_supported_band *sbands = &adapter->sbands[band]; 196 void *channels = NULL; 197 198 if (band == NL80211_BAND_2GHZ) { 199 channels = kmemdup(rsi_2ghz_channels, sizeof(rsi_2ghz_channels), 200 GFP_KERNEL); 201 if (!channels) 202 return -ENOMEM; 203 sbands->band = NL80211_BAND_2GHZ; 204 sbands->n_channels = ARRAY_SIZE(rsi_2ghz_channels); 205 sbands->bitrates = rsi_rates; 206 sbands->n_bitrates = ARRAY_SIZE(rsi_rates); 207 } else { 208 channels = kmemdup(rsi_5ghz_channels, sizeof(rsi_5ghz_channels), 209 GFP_KERNEL); 210 if (!channels) 211 return -ENOMEM; 212 sbands->band = NL80211_BAND_5GHZ; 213 sbands->n_channels = ARRAY_SIZE(rsi_5ghz_channels); 214 sbands->bitrates = &rsi_rates[4]; 215 sbands->n_bitrates = ARRAY_SIZE(rsi_rates) - 4; 216 } 217 218 sbands->channels = channels; 219 220 memset(&sbands->ht_cap, 0, sizeof(struct ieee80211_sta_ht_cap)); 221 sbands->ht_cap.ht_supported = true; 222 sbands->ht_cap.cap = (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 223 IEEE80211_HT_CAP_SGI_20 | 224 IEEE80211_HT_CAP_SGI_40); 225 sbands->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K; 226 sbands->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; 227 sbands->ht_cap.mcs.rx_mask[0] = 0xff; 228 sbands->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; 229 /* sbands->ht_cap.mcs.rx_highest = 0x82; */ 230 return 0; 231} 232 233static int rsi_mac80211_hw_scan_start(struct ieee80211_hw *hw, 234 struct ieee80211_vif *vif, 235 struct ieee80211_scan_request *hw_req) 236{ 237 struct cfg80211_scan_request *scan_req = &hw_req->req; 238 struct rsi_hw *adapter = hw->priv; 239 struct rsi_common *common = adapter->priv; 240 struct ieee80211_bss_conf *bss = &vif->bss_conf; 241 242 rsi_dbg(INFO_ZONE, "***** Hardware scan start *****\n"); 243 common->mac_ops_resumed = false; 244 245 if (common->fsm_state != FSM_MAC_INIT_DONE) 246 return -ENODEV; 247 248 if ((common->wow_flags & RSI_WOW_ENABLED) || 249 scan_req->n_channels == 0) 250 return -EINVAL; 251 252 /* Scan already in progress. So return */ 253 if (common->bgscan_en) 254 return -EBUSY; 255 256 /* If STA is not connected, return with special value 1, in order 257 * to start sw_scan in mac80211 258 */ 259 if (!bss->assoc) 260 return 1; 261 262 mutex_lock(&common->mutex); 263 common->hwscan = scan_req; 264 if (!rsi_send_bgscan_params(common, RSI_START_BGSCAN)) { 265 if (!rsi_send_bgscan_probe_req(common, vif)) { 266 rsi_dbg(INFO_ZONE, "Background scan started...\n"); 267 common->bgscan_en = true; 268 } 269 } 270 mutex_unlock(&common->mutex); 271 272 return 0; 273} 274 275static void rsi_mac80211_cancel_hw_scan(struct ieee80211_hw *hw, 276 struct ieee80211_vif *vif) 277{ 278 struct rsi_hw *adapter = hw->priv; 279 struct rsi_common *common = adapter->priv; 280 struct cfg80211_scan_info info; 281 282 rsi_dbg(INFO_ZONE, "***** Hardware scan stop *****\n"); 283 mutex_lock(&common->mutex); 284 285 if (common->bgscan_en) { 286 if (!rsi_send_bgscan_params(common, RSI_STOP_BGSCAN)) 287 common->bgscan_en = false; 288 info.aborted = false; 289 ieee80211_scan_completed(adapter->hw, &info); 290 rsi_dbg(INFO_ZONE, "Back ground scan cancelled\n"); 291 } 292 common->hwscan = NULL; 293 mutex_unlock(&common->mutex); 294} 295 296/** 297 * rsi_mac80211_detach() - This function is used to de-initialize the 298 * Mac80211 stack. 299 * @adapter: Pointer to the adapter structure. 300 * 301 * Return: None. 302 */ 303void rsi_mac80211_detach(struct rsi_hw *adapter) 304{ 305 struct ieee80211_hw *hw = adapter->hw; 306 enum nl80211_band band; 307 308 if (hw) { 309 ieee80211_stop_queues(hw); 310 ieee80211_unregister_hw(hw); 311 ieee80211_free_hw(hw); 312 adapter->hw = NULL; 313 } 314 315 for (band = 0; band < NUM_NL80211_BANDS; band++) { 316 struct ieee80211_supported_band *sband = 317 &adapter->sbands[band]; 318 319 kfree(sband->channels); 320 } 321 322#ifdef CONFIG_RSI_DEBUGFS 323 rsi_remove_dbgfs(adapter); 324 kfree(adapter->dfsentry); 325#endif 326} 327EXPORT_SYMBOL_GPL(rsi_mac80211_detach); 328 329/** 330 * rsi_indicate_tx_status() - This function indicates the transmit status. 331 * @adapter: Pointer to the adapter structure. 332 * @skb: Pointer to the socket buffer structure. 333 * @status: Status 334 * 335 * Return: None. 336 */ 337void rsi_indicate_tx_status(struct rsi_hw *adapter, 338 struct sk_buff *skb, 339 int status) 340{ 341 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 342 struct skb_info *tx_params; 343 344 if (!adapter->hw) { 345 rsi_dbg(ERR_ZONE, "##### No MAC #####\n"); 346 return; 347 } 348 349 if (!status) 350 info->flags |= IEEE80211_TX_STAT_ACK; 351 352 tx_params = (struct skb_info *)info->driver_data; 353 skb_pull(skb, tx_params->internal_hdr_size); 354 memset(info->driver_data, 0, IEEE80211_TX_INFO_DRIVER_DATA_SIZE); 355 356 ieee80211_tx_status_irqsafe(adapter->hw, skb); 357} 358 359/** 360 * rsi_mac80211_tx() - This is the handler that 802.11 module calls for each 361 * transmitted frame.SKB contains the buffer starting 362 * from the IEEE 802.11 header. 363 * @hw: Pointer to the ieee80211_hw structure. 364 * @control: Pointer to the ieee80211_tx_control structure 365 * @skb: Pointer to the socket buffer structure. 366 * 367 * Return: None 368 */ 369static void rsi_mac80211_tx(struct ieee80211_hw *hw, 370 struct ieee80211_tx_control *control, 371 struct sk_buff *skb) 372{ 373 struct rsi_hw *adapter = hw->priv; 374 struct rsi_common *common = adapter->priv; 375 struct ieee80211_hdr *wlh = (struct ieee80211_hdr *)skb->data; 376 377 if (ieee80211_is_auth(wlh->frame_control)) 378 common->mac_ops_resumed = false; 379 380 rsi_core_xmit(common, skb); 381} 382 383/** 384 * rsi_mac80211_start() - This is first handler that 802.11 module calls, since 385 * the driver init is complete by then, just 386 * returns success. 387 * @hw: Pointer to the ieee80211_hw structure. 388 * 389 * Return: 0 as success. 390 */ 391static int rsi_mac80211_start(struct ieee80211_hw *hw) 392{ 393 struct rsi_hw *adapter = hw->priv; 394 struct rsi_common *common = adapter->priv; 395 396 rsi_dbg(ERR_ZONE, "===> Interface UP <===\n"); 397 mutex_lock(&common->mutex); 398 if (common->hibernate_resume) { 399 common->reinit_hw = true; 400 adapter->host_intf_ops->reinit_device(adapter); 401 wait_for_completion(&adapter->priv->wlan_init_completion); 402 } 403 common->iface_down = false; 404 wiphy_rfkill_start_polling(hw->wiphy); 405 rsi_send_rx_filter_frame(common, 0); 406 mutex_unlock(&common->mutex); 407 408 return 0; 409} 410 411/** 412 * rsi_mac80211_stop() - This is the last handler that 802.11 module calls. 413 * @hw: Pointer to the ieee80211_hw structure. 414 * 415 * Return: None. 416 */ 417static void rsi_mac80211_stop(struct ieee80211_hw *hw) 418{ 419 struct rsi_hw *adapter = hw->priv; 420 struct rsi_common *common = adapter->priv; 421 422 rsi_dbg(ERR_ZONE, "===> Interface DOWN <===\n"); 423 mutex_lock(&common->mutex); 424 common->iface_down = true; 425 wiphy_rfkill_stop_polling(hw->wiphy); 426 427 /* Block all rx frames */ 428 rsi_send_rx_filter_frame(common, 0xffff); 429 430 mutex_unlock(&common->mutex); 431} 432 433static int rsi_map_intf_mode(enum nl80211_iftype vif_type) 434{ 435 switch (vif_type) { 436 case NL80211_IFTYPE_STATION: 437 return RSI_OPMODE_STA; 438 case NL80211_IFTYPE_AP: 439 return RSI_OPMODE_AP; 440 case NL80211_IFTYPE_P2P_DEVICE: 441 return RSI_OPMODE_P2P_CLIENT; 442 case NL80211_IFTYPE_P2P_CLIENT: 443 return RSI_OPMODE_P2P_CLIENT; 444 case NL80211_IFTYPE_P2P_GO: 445 return RSI_OPMODE_P2P_GO; 446 default: 447 return RSI_OPMODE_UNSUPPORTED; 448 } 449} 450 451/** 452 * rsi_mac80211_add_interface() - This function is called when a netdevice 453 * attached to the hardware is enabled. 454 * @hw: Pointer to the ieee80211_hw structure. 455 * @vif: Pointer to the ieee80211_vif structure. 456 * 457 * Return: ret: 0 on success, negative error code on failure. 458 */ 459static int rsi_mac80211_add_interface(struct ieee80211_hw *hw, 460 struct ieee80211_vif *vif) 461{ 462 struct rsi_hw *adapter = hw->priv; 463 struct rsi_common *common = adapter->priv; 464 struct vif_priv *vif_info = (struct vif_priv *)vif->drv_priv; 465 enum opmode intf_mode; 466 enum vap_status vap_status; 467 int vap_idx = -1, i; 468 469 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 470 mutex_lock(&common->mutex); 471 472 intf_mode = rsi_map_intf_mode(vif->type); 473 if (intf_mode == RSI_OPMODE_UNSUPPORTED) { 474 rsi_dbg(ERR_ZONE, 475 "%s: Interface type %d not supported\n", __func__, 476 vif->type); 477 mutex_unlock(&common->mutex); 478 return -EOPNOTSUPP; 479 } 480 if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) || 481 (vif->type == NL80211_IFTYPE_P2P_CLIENT) || 482 (vif->type == NL80211_IFTYPE_P2P_GO)) 483 common->p2p_enabled = true; 484 485 /* Get free vap index */ 486 for (i = 0; i < RSI_MAX_VIFS; i++) { 487 if (!adapter->vifs[i] || 488 !memcmp(vif->addr, adapter->vifs[i]->addr, ETH_ALEN)) { 489 vap_idx = i; 490 break; 491 } 492 } 493 if (vap_idx < 0) { 494 rsi_dbg(ERR_ZONE, "Reject: Max VAPs reached\n"); 495 mutex_unlock(&common->mutex); 496 return -EOPNOTSUPP; 497 } 498 vif_info->vap_id = vap_idx; 499 adapter->vifs[vap_idx] = vif; 500 adapter->sc_nvifs++; 501 vap_status = VAP_ADD; 502 503 if (rsi_set_vap_capabilities(common, intf_mode, vif->addr, 504 vif_info->vap_id, vap_status)) { 505 rsi_dbg(ERR_ZONE, "Failed to set VAP capabilities\n"); 506 mutex_unlock(&common->mutex); 507 return -EINVAL; 508 } 509 510 if ((vif->type == NL80211_IFTYPE_AP) || 511 (vif->type == NL80211_IFTYPE_P2P_GO)) { 512 rsi_send_rx_filter_frame(common, DISALLOW_BEACONS); 513 for (i = 0; i < common->max_stations; i++) 514 common->stations[i].sta = NULL; 515 } 516 517 mutex_unlock(&common->mutex); 518 519 return 0; 520} 521 522/** 523 * rsi_mac80211_remove_interface() - This function notifies driver that an 524 * interface is going down. 525 * @hw: Pointer to the ieee80211_hw structure. 526 * @vif: Pointer to the ieee80211_vif structure. 527 * 528 * Return: None. 529 */ 530static void rsi_mac80211_remove_interface(struct ieee80211_hw *hw, 531 struct ieee80211_vif *vif) 532{ 533 struct rsi_hw *adapter = hw->priv; 534 struct rsi_common *common = adapter->priv; 535 enum opmode opmode; 536 int i; 537 538 rsi_dbg(INFO_ZONE, "Remove Interface Called\n"); 539 540 mutex_lock(&common->mutex); 541 542 if (adapter->sc_nvifs <= 0) { 543 mutex_unlock(&common->mutex); 544 return; 545 } 546 547 opmode = rsi_map_intf_mode(vif->type); 548 if (opmode == RSI_OPMODE_UNSUPPORTED) { 549 rsi_dbg(ERR_ZONE, "Opmode error : %d\n", opmode); 550 mutex_unlock(&common->mutex); 551 return; 552 } 553 for (i = 0; i < RSI_MAX_VIFS; i++) { 554 if (!adapter->vifs[i]) 555 continue; 556 if (vif == adapter->vifs[i]) { 557 rsi_set_vap_capabilities(common, opmode, vif->addr, 558 i, VAP_DELETE); 559 adapter->sc_nvifs--; 560 adapter->vifs[i] = NULL; 561 } 562 } 563 mutex_unlock(&common->mutex); 564} 565 566/** 567 * rsi_channel_change() - This function is a performs the checks 568 * required for changing a channel and sets 569 * the channel accordingly. 570 * @hw: Pointer to the ieee80211_hw structure. 571 * 572 * Return: 0 on success, negative error code on failure. 573 */ 574static int rsi_channel_change(struct ieee80211_hw *hw) 575{ 576 struct rsi_hw *adapter = hw->priv; 577 struct rsi_common *common = adapter->priv; 578 int status = -EOPNOTSUPP; 579 struct ieee80211_channel *curchan = hw->conf.chandef.chan; 580 u16 channel = curchan->hw_value; 581 struct ieee80211_vif *vif; 582 struct ieee80211_bss_conf *bss; 583 bool assoc = false; 584 int i; 585 586 rsi_dbg(INFO_ZONE, 587 "%s: Set channel: %d MHz type: %d channel_no %d\n", 588 __func__, curchan->center_freq, 589 curchan->flags, channel); 590 591 for (i = 0; i < RSI_MAX_VIFS; i++) { 592 vif = adapter->vifs[i]; 593 if (!vif) 594 continue; 595 if (vif->type == NL80211_IFTYPE_STATION) { 596 bss = &vif->bss_conf; 597 if (bss->assoc) { 598 assoc = true; 599 break; 600 } 601 } 602 } 603 if (assoc) { 604 if (!common->hw_data_qs_blocked && 605 (rsi_get_connected_channel(vif) != channel)) { 606 rsi_dbg(INFO_ZONE, "blk data q %d\n", channel); 607 if (!rsi_send_block_unblock_frame(common, true)) 608 common->hw_data_qs_blocked = true; 609 } 610 } 611 612 status = rsi_band_check(common, curchan); 613 if (!status) 614 status = rsi_set_channel(adapter->priv, curchan); 615 616 if (assoc) { 617 if (common->hw_data_qs_blocked && 618 (rsi_get_connected_channel(vif) == channel)) { 619 rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel); 620 if (!rsi_send_block_unblock_frame(common, false)) 621 common->hw_data_qs_blocked = false; 622 } 623 } 624 625 return status; 626} 627 628/** 629 * rsi_config_power() - This function configures tx power to device 630 * @hw: Pointer to the ieee80211_hw structure. 631 * 632 * Return: 0 on success, negative error code on failure. 633 */ 634static int rsi_config_power(struct ieee80211_hw *hw) 635{ 636 struct rsi_hw *adapter = hw->priv; 637 struct rsi_common *common = adapter->priv; 638 struct ieee80211_conf *conf = &hw->conf; 639 640 if (adapter->sc_nvifs <= 0) { 641 rsi_dbg(ERR_ZONE, "%s: No virtual interface found\n", __func__); 642 return -EINVAL; 643 } 644 645 rsi_dbg(INFO_ZONE, 646 "%s: Set tx power: %d dBM\n", __func__, conf->power_level); 647 648 if (conf->power_level == common->tx_power) 649 return 0; 650 651 common->tx_power = conf->power_level; 652 653 return rsi_send_radio_params_update(common); 654} 655 656/** 657 * rsi_mac80211_config() - This function is a handler for configuration 658 * requests. The stack calls this function to 659 * change hardware configuration, e.g., channel. 660 * @hw: Pointer to the ieee80211_hw structure. 661 * @changed: Changed flags set. 662 * 663 * Return: 0 on success, negative error code on failure. 664 */ 665static int rsi_mac80211_config(struct ieee80211_hw *hw, 666 u32 changed) 667{ 668 struct rsi_hw *adapter = hw->priv; 669 struct rsi_common *common = adapter->priv; 670 struct ieee80211_conf *conf = &hw->conf; 671 int status = -EOPNOTSUPP; 672 673 mutex_lock(&common->mutex); 674 675 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) 676 status = rsi_channel_change(hw); 677 678 /* tx power */ 679 if (changed & IEEE80211_CONF_CHANGE_POWER) { 680 rsi_dbg(INFO_ZONE, "%s: Configuring Power\n", __func__); 681 status = rsi_config_power(hw); 682 } 683 684 /* Power save parameters */ 685 if ((changed & IEEE80211_CONF_CHANGE_PS) && 686 !common->mac_ops_resumed) { 687 struct ieee80211_vif *vif, *sta_vif = NULL; 688 unsigned long flags; 689 int i, set_ps = 1; 690 691 for (i = 0; i < RSI_MAX_VIFS; i++) { 692 vif = adapter->vifs[i]; 693 if (!vif) 694 continue; 695 /* Don't go to power save if AP vap exists */ 696 if ((vif->type == NL80211_IFTYPE_AP) || 697 (vif->type == NL80211_IFTYPE_P2P_GO)) { 698 set_ps = 0; 699 break; 700 } 701 if ((vif->type == NL80211_IFTYPE_STATION || 702 vif->type == NL80211_IFTYPE_P2P_CLIENT) && 703 (!sta_vif || vif->bss_conf.assoc)) 704 sta_vif = vif; 705 } 706 if (set_ps && sta_vif) { 707 spin_lock_irqsave(&adapter->ps_lock, flags); 708 if (conf->flags & IEEE80211_CONF_PS) 709 rsi_enable_ps(adapter, sta_vif); 710 else 711 rsi_disable_ps(adapter, sta_vif); 712 spin_unlock_irqrestore(&adapter->ps_lock, flags); 713 } 714 } 715 716 /* RTS threshold */ 717 if (changed & WIPHY_PARAM_RTS_THRESHOLD) { 718 rsi_dbg(INFO_ZONE, "RTS threshold\n"); 719 if ((common->rts_threshold) <= IEEE80211_MAX_RTS_THRESHOLD) { 720 rsi_dbg(INFO_ZONE, 721 "%s: Sending vap updates....\n", __func__); 722 status = rsi_send_vap_dynamic_update(common); 723 } 724 } 725 mutex_unlock(&common->mutex); 726 727 return status; 728} 729 730/** 731 * rsi_get_connected_channel() - This function is used to get the current 732 * connected channel number. 733 * @vif: Pointer to the ieee80211_vif structure. 734 * 735 * Return: Current connected AP's channel number is returned. 736 */ 737u16 rsi_get_connected_channel(struct ieee80211_vif *vif) 738{ 739 struct ieee80211_bss_conf *bss; 740 struct ieee80211_channel *channel; 741 742 if (!vif) 743 return 0; 744 745 bss = &vif->bss_conf; 746 channel = bss->chandef.chan; 747 748 if (!channel) 749 return 0; 750 751 return channel->hw_value; 752} 753 754static void rsi_switch_channel(struct rsi_hw *adapter, 755 struct ieee80211_vif *vif) 756{ 757 struct rsi_common *common = adapter->priv; 758 struct ieee80211_channel *channel; 759 760 if (common->iface_down) 761 return; 762 if (!vif) 763 return; 764 765 channel = vif->bss_conf.chandef.chan; 766 767 if (!channel) 768 return; 769 770 rsi_band_check(common, channel); 771 rsi_set_channel(common, channel); 772 rsi_dbg(INFO_ZONE, "Switched to channel - %d\n", channel->hw_value); 773} 774 775/** 776 * rsi_mac80211_bss_info_changed() - This function is a handler for config 777 * requests related to BSS parameters that 778 * may vary during BSS's lifespan. 779 * @hw: Pointer to the ieee80211_hw structure. 780 * @vif: Pointer to the ieee80211_vif structure. 781 * @bss_conf: Pointer to the ieee80211_bss_conf structure. 782 * @changed: Changed flags set. 783 * 784 * Return: None. 785 */ 786static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw, 787 struct ieee80211_vif *vif, 788 struct ieee80211_bss_conf *bss_conf, 789 u32 changed) 790{ 791 struct rsi_hw *adapter = hw->priv; 792 struct rsi_common *common = adapter->priv; 793 struct ieee80211_bss_conf *bss = &vif->bss_conf; 794 struct ieee80211_conf *conf = &hw->conf; 795 u16 rx_filter_word = 0; 796 797 mutex_lock(&common->mutex); 798 if (changed & BSS_CHANGED_ASSOC) { 799 rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n", 800 __func__, bss_conf->assoc); 801 if (bss_conf->assoc) { 802 /* Send the RX filter frame */ 803 rx_filter_word = (ALLOW_DATA_ASSOC_PEER | 804 ALLOW_CTRL_ASSOC_PEER | 805 ALLOW_MGMT_ASSOC_PEER); 806 rsi_send_rx_filter_frame(common, rx_filter_word); 807 } 808 rsi_inform_bss_status(common, 809 RSI_OPMODE_STA, 810 bss_conf->assoc, 811 bss_conf->bssid, 812 bss_conf->qos, 813 bss_conf->aid, 814 NULL, 0, 815 bss_conf->assoc_capability, vif); 816 adapter->ps_info.dtim_interval_duration = bss->dtim_period; 817 adapter->ps_info.listen_interval = conf->listen_interval; 818 819 /* If U-APSD is updated, send ps parameters to firmware */ 820 if (bss->assoc) { 821 if (common->uapsd_bitmap) { 822 rsi_dbg(INFO_ZONE, "Configuring UAPSD\n"); 823 rsi_conf_uapsd(adapter, vif); 824 } 825 } else { 826 common->uapsd_bitmap = 0; 827 } 828 } 829 830 if (changed & BSS_CHANGED_CQM) { 831 common->cqm_info.last_cqm_event_rssi = 0; 832 common->cqm_info.rssi_thold = bss_conf->cqm_rssi_thold; 833 common->cqm_info.rssi_hyst = bss_conf->cqm_rssi_hyst; 834 rsi_dbg(INFO_ZONE, "RSSI threshold & hysteresis are: %d %d\n", 835 common->cqm_info.rssi_thold, 836 common->cqm_info.rssi_hyst); 837 } 838 839 if ((changed & BSS_CHANGED_BEACON_ENABLED) && 840 ((vif->type == NL80211_IFTYPE_AP) || 841 (vif->type == NL80211_IFTYPE_P2P_GO))) { 842 if (bss->enable_beacon) { 843 rsi_dbg(INFO_ZONE, "===> BEACON ENABLED <===\n"); 844 common->beacon_enabled = 1; 845 } else { 846 rsi_dbg(INFO_ZONE, "===> BEACON DISABLED <===\n"); 847 common->beacon_enabled = 0; 848 } 849 } 850 851 mutex_unlock(&common->mutex); 852} 853 854/** 855 * rsi_mac80211_conf_filter() - This function configure the device's RX filter. 856 * @hw: Pointer to the ieee80211_hw structure. 857 * @changed_flags: Changed flags set. 858 * @total_flags: Total initial flags set. 859 * @multicast: Multicast. 860 * 861 * Return: None. 862 */ 863static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw, 864 u32 changed_flags, 865 u32 *total_flags, 866 u64 multicast) 867{ 868 /* Not doing much here as of now */ 869 *total_flags &= RSI_SUPP_FILTERS; 870} 871 872/** 873 * rsi_mac80211_conf_tx() - This function configures TX queue parameters 874 * (EDCF (aifs, cw_min, cw_max), bursting) 875 * for a hardware TX queue. 876 * @hw: Pointer to the ieee80211_hw structure 877 * @vif: Pointer to the ieee80211_vif structure. 878 * @queue: Queue number. 879 * @params: Pointer to ieee80211_tx_queue_params structure. 880 * 881 * Return: 0 on success, negative error code on failure. 882 */ 883static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw, 884 struct ieee80211_vif *vif, u16 queue, 885 const struct ieee80211_tx_queue_params *params) 886{ 887 struct rsi_hw *adapter = hw->priv; 888 struct rsi_common *common = adapter->priv; 889 u8 idx = 0; 890 891 if (queue >= IEEE80211_NUM_ACS) 892 return 0; 893 894 rsi_dbg(INFO_ZONE, 895 "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n", 896 __func__, queue, params->aifs, 897 params->cw_min, params->cw_max, params->txop); 898 899 mutex_lock(&common->mutex); 900 /* Map into the way the f/w expects */ 901 switch (queue) { 902 case IEEE80211_AC_VO: 903 idx = VO_Q; 904 break; 905 case IEEE80211_AC_VI: 906 idx = VI_Q; 907 break; 908 case IEEE80211_AC_BE: 909 idx = BE_Q; 910 break; 911 case IEEE80211_AC_BK: 912 idx = BK_Q; 913 break; 914 default: 915 idx = BE_Q; 916 break; 917 } 918 919 memcpy(&common->edca_params[idx], 920 params, 921 sizeof(struct ieee80211_tx_queue_params)); 922 923 if (params->uapsd) 924 common->uapsd_bitmap |= idx; 925 else 926 common->uapsd_bitmap &= (~idx); 927 928 mutex_unlock(&common->mutex); 929 930 return 0; 931} 932 933/** 934 * rsi_hal_key_config() - This function loads the keys into the firmware. 935 * @hw: Pointer to the ieee80211_hw structure. 936 * @vif: Pointer to the ieee80211_vif structure. 937 * @key: Pointer to the ieee80211_key_conf structure. 938 * @sta: Pointer to the ieee80211_sta structure. 939 * 940 * Return: status: 0 on success, negative error codes on failure. 941 */ 942static int rsi_hal_key_config(struct ieee80211_hw *hw, 943 struct ieee80211_vif *vif, 944 struct ieee80211_key_conf *key, 945 struct ieee80211_sta *sta) 946{ 947 struct rsi_hw *adapter = hw->priv; 948 struct rsi_sta *rsta = NULL; 949 int status; 950 u8 key_type; 951 s16 sta_id = 0; 952 953 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 954 key_type = RSI_PAIRWISE_KEY; 955 else 956 key_type = RSI_GROUP_KEY; 957 958 rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n", 959 __func__, key->cipher, key_type, key->keylen); 960 961 if ((vif->type == NL80211_IFTYPE_AP) || 962 (vif->type == NL80211_IFTYPE_P2P_GO)) { 963 if (sta) { 964 rsta = rsi_find_sta(adapter->priv, sta->addr); 965 if (rsta) 966 sta_id = rsta->sta_id; 967 } 968 adapter->priv->key = key; 969 } else { 970 if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) || 971 (key->cipher == WLAN_CIPHER_SUITE_WEP40)) { 972 status = rsi_hal_load_key(adapter->priv, 973 key->key, 974 key->keylen, 975 RSI_PAIRWISE_KEY, 976 key->keyidx, 977 key->cipher, 978 sta_id, 979 vif); 980 if (status) 981 return status; 982 } 983 } 984 985 status = rsi_hal_load_key(adapter->priv, 986 key->key, 987 key->keylen, 988 key_type, 989 key->keyidx, 990 key->cipher, 991 sta_id, 992 vif); 993 if (status) 994 return status; 995 996 if (vif->type == NL80211_IFTYPE_STATION && 997 (key->cipher == WLAN_CIPHER_SUITE_WEP104 || 998 key->cipher == WLAN_CIPHER_SUITE_WEP40)) { 999 if (!rsi_send_block_unblock_frame(adapter->priv, false)) 1000 adapter->priv->hw_data_qs_blocked = false; 1001 } 1002 1003 return 0; 1004} 1005 1006/** 1007 * rsi_mac80211_set_key() - This function sets type of key to be loaded. 1008 * @hw: Pointer to the ieee80211_hw structure. 1009 * @cmd: enum set_key_cmd. 1010 * @vif: Pointer to the ieee80211_vif structure. 1011 * @sta: Pointer to the ieee80211_sta structure. 1012 * @key: Pointer to the ieee80211_key_conf structure. 1013 * 1014 * Return: status: 0 on success, negative error code on failure. 1015 */ 1016static int rsi_mac80211_set_key(struct ieee80211_hw *hw, 1017 enum set_key_cmd cmd, 1018 struct ieee80211_vif *vif, 1019 struct ieee80211_sta *sta, 1020 struct ieee80211_key_conf *key) 1021{ 1022 struct rsi_hw *adapter = hw->priv; 1023 struct rsi_common *common = adapter->priv; 1024 struct security_info *secinfo = &common->secinfo; 1025 int status; 1026 1027 mutex_lock(&common->mutex); 1028 switch (cmd) { 1029 case SET_KEY: 1030 status = rsi_hal_key_config(hw, vif, key, sta); 1031 if (status) { 1032 mutex_unlock(&common->mutex); 1033 return status; 1034 } 1035 1036 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 1037 secinfo->ptk_cipher = key->cipher; 1038 else 1039 secinfo->gtk_cipher = key->cipher; 1040 1041 key->hw_key_idx = key->keyidx; 1042 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 1043 1044 rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__); 1045 break; 1046 1047 case DISABLE_KEY: 1048 rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__); 1049 memset(key, 0, sizeof(struct ieee80211_key_conf)); 1050 status = rsi_hal_key_config(hw, vif, key, sta); 1051 break; 1052 1053 default: 1054 status = -EOPNOTSUPP; 1055 break; 1056 } 1057 1058 mutex_unlock(&common->mutex); 1059 return status; 1060} 1061 1062/** 1063 * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for 1064 * the corresponding mlme_action flag and 1065 * informs the f/w regarding this. 1066 * @hw: Pointer to the ieee80211_hw structure. 1067 * @vif: Pointer to the ieee80211_vif structure. 1068 * @params: Pointer to A-MPDU action parameters 1069 * 1070 * Return: status: 0 on success, negative error code on failure. 1071 */ 1072static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw, 1073 struct ieee80211_vif *vif, 1074 struct ieee80211_ampdu_params *params) 1075{ 1076 int status = -EOPNOTSUPP; 1077 struct rsi_hw *adapter = hw->priv; 1078 struct rsi_common *common = adapter->priv; 1079 struct rsi_sta *rsta = NULL; 1080 u16 seq_no = 0, seq_start = 0; 1081 u8 ii = 0; 1082 struct ieee80211_sta *sta = params->sta; 1083 u8 sta_id = 0; 1084 enum ieee80211_ampdu_mlme_action action = params->action; 1085 u16 tid = params->tid; 1086 u16 *ssn = ¶ms->ssn; 1087 u8 buf_size = params->buf_size; 1088 1089 for (ii = 0; ii < RSI_MAX_VIFS; ii++) { 1090 if (vif == adapter->vifs[ii]) 1091 break; 1092 } 1093 1094 mutex_lock(&common->mutex); 1095 1096 if (ssn != NULL) 1097 seq_no = *ssn; 1098 1099 if ((vif->type == NL80211_IFTYPE_AP) || 1100 (vif->type == NL80211_IFTYPE_P2P_GO)) { 1101 rsta = rsi_find_sta(common, sta->addr); 1102 if (!rsta) { 1103 rsi_dbg(ERR_ZONE, "No station mapped\n"); 1104 status = 0; 1105 goto unlock; 1106 } 1107 sta_id = rsta->sta_id; 1108 } 1109 1110 rsi_dbg(INFO_ZONE, 1111 "%s: AMPDU action tid=%d ssn=0x%x, buf_size=%d sta_id=%d\n", 1112 __func__, tid, seq_no, buf_size, sta_id); 1113 1114 switch (action) { 1115 case IEEE80211_AMPDU_RX_START: 1116 status = rsi_send_aggregation_params_frame(common, 1117 tid, 1118 seq_no, 1119 buf_size, 1120 STA_RX_ADDBA_DONE, 1121 sta_id); 1122 break; 1123 1124 case IEEE80211_AMPDU_RX_STOP: 1125 status = rsi_send_aggregation_params_frame(common, 1126 tid, 1127 0, 1128 buf_size, 1129 STA_RX_DELBA, 1130 sta_id); 1131 break; 1132 1133 case IEEE80211_AMPDU_TX_START: 1134 if ((vif->type == NL80211_IFTYPE_STATION) || 1135 (vif->type == NL80211_IFTYPE_P2P_CLIENT)) 1136 common->vif_info[ii].seq_start = seq_no; 1137 else if ((vif->type == NL80211_IFTYPE_AP) || 1138 (vif->type == NL80211_IFTYPE_P2P_GO)) 1139 rsta->seq_start[tid] = seq_no; 1140 status = IEEE80211_AMPDU_TX_START_IMMEDIATE; 1141 break; 1142 1143 case IEEE80211_AMPDU_TX_STOP_CONT: 1144 case IEEE80211_AMPDU_TX_STOP_FLUSH: 1145 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 1146 status = rsi_send_aggregation_params_frame(common, 1147 tid, 1148 seq_no, 1149 buf_size, 1150 STA_TX_DELBA, 1151 sta_id); 1152 if (!status) 1153 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 1154 break; 1155 1156 case IEEE80211_AMPDU_TX_OPERATIONAL: 1157 if ((vif->type == NL80211_IFTYPE_STATION) || 1158 (vif->type == NL80211_IFTYPE_P2P_CLIENT)) 1159 seq_start = common->vif_info[ii].seq_start; 1160 else if ((vif->type == NL80211_IFTYPE_AP) || 1161 (vif->type == NL80211_IFTYPE_P2P_GO)) 1162 seq_start = rsta->seq_start[tid]; 1163 status = rsi_send_aggregation_params_frame(common, 1164 tid, 1165 seq_start, 1166 buf_size, 1167 STA_TX_ADDBA_DONE, 1168 sta_id); 1169 break; 1170 1171 default: 1172 rsi_dbg(ERR_ZONE, "%s: Unknown AMPDU action\n", __func__); 1173 break; 1174 } 1175 1176unlock: 1177 mutex_unlock(&common->mutex); 1178 return status; 1179} 1180 1181/** 1182 * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value. 1183 * @hw: Pointer to the ieee80211_hw structure. 1184 * @value: Rts threshold value. 1185 * 1186 * Return: 0 on success. 1187 */ 1188static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw, 1189 u32 value) 1190{ 1191 struct rsi_hw *adapter = hw->priv; 1192 struct rsi_common *common = adapter->priv; 1193 1194 mutex_lock(&common->mutex); 1195 common->rts_threshold = value; 1196 mutex_unlock(&common->mutex); 1197 1198 return 0; 1199} 1200 1201/** 1202 * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used. 1203 * @hw: Pointer to the ieee80211_hw structure 1204 * @vif: Pointer to the ieee80211_vif structure. 1205 * @mask: Pointer to the cfg80211_bitrate_mask structure. 1206 * 1207 * Return: 0 on success. 1208 */ 1209static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw, 1210 struct ieee80211_vif *vif, 1211 const struct cfg80211_bitrate_mask *mask) 1212{ 1213 const unsigned int mcs_offset = ARRAY_SIZE(rsi_rates); 1214 struct rsi_hw *adapter = hw->priv; 1215 struct rsi_common *common = adapter->priv; 1216 int i; 1217 1218 mutex_lock(&common->mutex); 1219 1220 for (i = 0; i < ARRAY_SIZE(common->rate_config); i++) { 1221 struct rsi_rate_config *cfg = &common->rate_config[i]; 1222 u32 bm; 1223 1224 bm = mask->control[i].legacy | (mask->control[i].ht_mcs[0] << mcs_offset); 1225 if (hweight32(bm) == 1) { /* single rate */ 1226 int rate_index = ffs(bm) - 1; 1227 1228 if (rate_index < mcs_offset) 1229 cfg->fixed_hw_rate = rsi_rates[rate_index].hw_value; 1230 else 1231 cfg->fixed_hw_rate = rsi_mcsrates[rate_index - mcs_offset]; 1232 cfg->fixed_enabled = true; 1233 } else { 1234 cfg->configured_mask = bm; 1235 cfg->fixed_enabled = false; 1236 } 1237 } 1238 1239 mutex_unlock(&common->mutex); 1240 1241 return 0; 1242} 1243 1244/** 1245 * rsi_perform_cqm() - This function performs cqm. 1246 * @common: Pointer to the driver private structure. 1247 * @bssid: pointer to the bssid. 1248 * @rssi: RSSI value. 1249 * @vif: Pointer to the ieee80211_vif structure. 1250 */ 1251static void rsi_perform_cqm(struct rsi_common *common, 1252 u8 *bssid, 1253 s8 rssi, 1254 struct ieee80211_vif *vif) 1255{ 1256 s8 last_event = common->cqm_info.last_cqm_event_rssi; 1257 int thold = common->cqm_info.rssi_thold; 1258 u32 hyst = common->cqm_info.rssi_hyst; 1259 enum nl80211_cqm_rssi_threshold_event event; 1260 1261 if (rssi < thold && (last_event == 0 || rssi < (last_event - hyst))) 1262 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; 1263 else if (rssi > thold && 1264 (last_event == 0 || rssi > (last_event + hyst))) 1265 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; 1266 else 1267 return; 1268 1269 common->cqm_info.last_cqm_event_rssi = rssi; 1270 rsi_dbg(INFO_ZONE, "CQM: Notifying event: %d\n", event); 1271 ieee80211_cqm_rssi_notify(vif, event, rssi, GFP_KERNEL); 1272 1273 return; 1274} 1275 1276/** 1277 * rsi_fill_rx_status() - This function fills rx status in 1278 * ieee80211_rx_status structure. 1279 * @hw: Pointer to the ieee80211_hw structure. 1280 * @skb: Pointer to the socket buffer structure. 1281 * @common: Pointer to the driver private structure. 1282 * @rxs: Pointer to the ieee80211_rx_status structure. 1283 * 1284 * Return: None. 1285 */ 1286static void rsi_fill_rx_status(struct ieee80211_hw *hw, 1287 struct sk_buff *skb, 1288 struct rsi_common *common, 1289 struct ieee80211_rx_status *rxs) 1290{ 1291 struct rsi_hw *adapter = common->priv; 1292 struct ieee80211_vif *vif; 1293 struct ieee80211_bss_conf *bss = NULL; 1294 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1295 struct skb_info *rx_params = (struct skb_info *)info->driver_data; 1296 struct ieee80211_hdr *hdr; 1297 char rssi = rx_params->rssi; 1298 u8 hdrlen = 0; 1299 u8 channel = rx_params->channel; 1300 s32 freq; 1301 int i; 1302 1303 hdr = ((struct ieee80211_hdr *)(skb->data)); 1304 hdrlen = ieee80211_hdrlen(hdr->frame_control); 1305 1306 memset(info, 0, sizeof(struct ieee80211_tx_info)); 1307 1308 rxs->signal = -(rssi); 1309 1310 rxs->band = common->band; 1311 1312 freq = ieee80211_channel_to_frequency(channel, rxs->band); 1313 1314 if (freq) 1315 rxs->freq = freq; 1316 1317 if (ieee80211_has_protected(hdr->frame_control)) { 1318 if (rsi_is_cipher_wep(common)) { 1319 memmove(skb->data + 4, skb->data, hdrlen); 1320 skb_pull(skb, 4); 1321 } else { 1322 memmove(skb->data + 8, skb->data, hdrlen); 1323 skb_pull(skb, 8); 1324 rxs->flag |= RX_FLAG_MMIC_STRIPPED; 1325 } 1326 rxs->flag |= RX_FLAG_DECRYPTED; 1327 rxs->flag |= RX_FLAG_IV_STRIPPED; 1328 } 1329 1330 for (i = 0; i < RSI_MAX_VIFS; i++) { 1331 vif = adapter->vifs[i]; 1332 if (!vif) 1333 continue; 1334 if (vif->type == NL80211_IFTYPE_STATION) { 1335 bss = &vif->bss_conf; 1336 break; 1337 } 1338 } 1339 if (!bss) 1340 return; 1341 /* CQM only for connected AP beacons, the RSSI is a weighted avg */ 1342 if (bss->assoc && !(memcmp(bss->bssid, hdr->addr2, ETH_ALEN))) { 1343 if (ieee80211_is_beacon(hdr->frame_control)) 1344 rsi_perform_cqm(common, hdr->addr2, rxs->signal, vif); 1345 } 1346 1347 return; 1348} 1349 1350/** 1351 * rsi_indicate_pkt_to_os() - This function sends received packet to mac80211. 1352 * @common: Pointer to the driver private structure. 1353 * @skb: Pointer to the socket buffer structure. 1354 * 1355 * Return: None. 1356 */ 1357void rsi_indicate_pkt_to_os(struct rsi_common *common, 1358 struct sk_buff *skb) 1359{ 1360 struct rsi_hw *adapter = common->priv; 1361 struct ieee80211_hw *hw = adapter->hw; 1362 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1363 1364 if ((common->iface_down) || (!adapter->sc_nvifs)) { 1365 dev_kfree_skb(skb); 1366 return; 1367 } 1368 1369 /* filling in the ieee80211_rx_status flags */ 1370 rsi_fill_rx_status(hw, skb, common, rx_status); 1371 1372 ieee80211_rx_irqsafe(hw, skb); 1373} 1374 1375/** 1376 * rsi_mac80211_sta_add() - This function notifies driver about a peer getting 1377 * connected. 1378 * @hw: pointer to the ieee80211_hw structure. 1379 * @vif: Pointer to the ieee80211_vif structure. 1380 * @sta: Pointer to the ieee80211_sta structure. 1381 * 1382 * Return: 0 on success, negative error codes on failure. 1383 */ 1384static int rsi_mac80211_sta_add(struct ieee80211_hw *hw, 1385 struct ieee80211_vif *vif, 1386 struct ieee80211_sta *sta) 1387{ 1388 struct rsi_hw *adapter = hw->priv; 1389 struct rsi_common *common = adapter->priv; 1390 bool sta_exist = false; 1391 struct rsi_sta *rsta; 1392 int status = 0; 1393 1394 rsi_dbg(INFO_ZONE, "Station Add: %pM\n", sta->addr); 1395 1396 mutex_lock(&common->mutex); 1397 1398 if ((vif->type == NL80211_IFTYPE_AP) || 1399 (vif->type == NL80211_IFTYPE_P2P_GO)) { 1400 u8 cnt; 1401 int sta_idx = -1; 1402 int free_index = -1; 1403 1404 /* Check if max stations reached */ 1405 if (common->num_stations >= common->max_stations) { 1406 rsi_dbg(ERR_ZONE, "Reject: Max Stations exists\n"); 1407 status = -EOPNOTSUPP; 1408 goto unlock; 1409 } 1410 for (cnt = 0; cnt < common->max_stations; cnt++) { 1411 rsta = &common->stations[cnt]; 1412 1413 if (!rsta->sta) { 1414 if (free_index < 0) 1415 free_index = cnt; 1416 continue; 1417 } 1418 if (!memcmp(rsta->sta->addr, sta->addr, ETH_ALEN)) { 1419 rsi_dbg(INFO_ZONE, "Station exists\n"); 1420 sta_idx = cnt; 1421 sta_exist = true; 1422 break; 1423 } 1424 } 1425 if (!sta_exist) { 1426 if (free_index >= 0) 1427 sta_idx = free_index; 1428 } 1429 if (sta_idx < 0) { 1430 rsi_dbg(ERR_ZONE, 1431 "%s: Some problem reaching here...\n", 1432 __func__); 1433 status = -EINVAL; 1434 goto unlock; 1435 } 1436 rsta = &common->stations[sta_idx]; 1437 rsta->sta = sta; 1438 rsta->sta_id = sta_idx; 1439 for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++) 1440 rsta->start_tx_aggr[cnt] = false; 1441 for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++) 1442 rsta->seq_start[cnt] = 0; 1443 if (!sta_exist) { 1444 rsi_dbg(INFO_ZONE, "New Station\n"); 1445 1446 /* Send peer notify to device */ 1447 rsi_dbg(INFO_ZONE, "Indicate bss status to device\n"); 1448 rsi_inform_bss_status(common, RSI_OPMODE_AP, 1, 1449 sta->addr, sta->wme, sta->aid, 1450 sta, sta_idx, 0, vif); 1451 1452 if (common->key) { 1453 struct ieee80211_key_conf *key = common->key; 1454 1455 if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) || 1456 (key->cipher == WLAN_CIPHER_SUITE_WEP40)) 1457 rsi_hal_load_key(adapter->priv, 1458 key->key, 1459 key->keylen, 1460 RSI_PAIRWISE_KEY, 1461 key->keyidx, 1462 key->cipher, 1463 sta_idx, 1464 vif); 1465 } 1466 1467 common->num_stations++; 1468 } 1469 } 1470 1471 if ((vif->type == NL80211_IFTYPE_STATION) || 1472 (vif->type == NL80211_IFTYPE_P2P_CLIENT)) { 1473 common->bitrate_mask[common->band] = sta->supp_rates[common->band]; 1474 common->vif_info[0].is_ht = sta->ht_cap.ht_supported; 1475 if (sta->ht_cap.ht_supported) { 1476 common->bitrate_mask[NL80211_BAND_2GHZ] = 1477 sta->supp_rates[NL80211_BAND_2GHZ]; 1478 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) || 1479 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) 1480 common->vif_info[0].sgi = true; 1481 ieee80211_start_tx_ba_session(sta, 0, 0); 1482 } 1483 } 1484 1485unlock: 1486 mutex_unlock(&common->mutex); 1487 1488 return status; 1489} 1490 1491/** 1492 * rsi_mac80211_sta_remove() - This function notifies driver about a peer 1493 * getting disconnected. 1494 * @hw: Pointer to the ieee80211_hw structure. 1495 * @vif: Pointer to the ieee80211_vif structure. 1496 * @sta: Pointer to the ieee80211_sta structure. 1497 * 1498 * Return: 0 on success, negative error codes on failure. 1499 */ 1500static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw, 1501 struct ieee80211_vif *vif, 1502 struct ieee80211_sta *sta) 1503{ 1504 struct rsi_hw *adapter = hw->priv; 1505 struct rsi_common *common = adapter->priv; 1506 struct ieee80211_bss_conf *bss = &vif->bss_conf; 1507 struct rsi_sta *rsta; 1508 1509 rsi_dbg(INFO_ZONE, "Station Remove: %pM\n", sta->addr); 1510 1511 mutex_lock(&common->mutex); 1512 1513 if ((vif->type == NL80211_IFTYPE_AP) || 1514 (vif->type == NL80211_IFTYPE_P2P_GO)) { 1515 u8 sta_idx, cnt; 1516 1517 /* Send peer notify to device */ 1518 rsi_dbg(INFO_ZONE, "Indicate bss status to device\n"); 1519 for (sta_idx = 0; sta_idx < common->max_stations; sta_idx++) { 1520 rsta = &common->stations[sta_idx]; 1521 1522 if (!rsta->sta) 1523 continue; 1524 if (!memcmp(rsta->sta->addr, sta->addr, ETH_ALEN)) { 1525 rsi_inform_bss_status(common, RSI_OPMODE_AP, 0, 1526 sta->addr, sta->wme, 1527 sta->aid, sta, sta_idx, 1528 0, vif); 1529 rsta->sta = NULL; 1530 rsta->sta_id = -1; 1531 for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++) 1532 rsta->start_tx_aggr[cnt] = false; 1533 if (common->num_stations > 0) 1534 common->num_stations--; 1535 break; 1536 } 1537 } 1538 if (sta_idx >= common->max_stations) 1539 rsi_dbg(ERR_ZONE, "%s: No station found\n", __func__); 1540 } 1541 1542 if ((vif->type == NL80211_IFTYPE_STATION) || 1543 (vif->type == NL80211_IFTYPE_P2P_CLIENT)) { 1544 /* Resetting all the fields to default values */ 1545 memcpy((u8 *)bss->bssid, (u8 *)sta->addr, ETH_ALEN); 1546 bss->qos = sta->wme; 1547 common->bitrate_mask[NL80211_BAND_2GHZ] = 0; 1548 common->bitrate_mask[NL80211_BAND_5GHZ] = 0; 1549 common->vif_info[0].is_ht = false; 1550 common->vif_info[0].sgi = false; 1551 common->vif_info[0].seq_start = 0; 1552 common->secinfo.ptk_cipher = 0; 1553 common->secinfo.gtk_cipher = 0; 1554 if (!common->iface_down) 1555 rsi_send_rx_filter_frame(common, 0); 1556 } 1557 mutex_unlock(&common->mutex); 1558 1559 return 0; 1560} 1561 1562/** 1563 * rsi_mac80211_set_antenna() - This function is used to configure 1564 * tx and rx antennas. 1565 * @hw: Pointer to the ieee80211_hw structure. 1566 * @tx_ant: Bitmap for tx antenna 1567 * @rx_ant: Bitmap for rx antenna 1568 * 1569 * Return: 0 on success, Negative error code on failure. 1570 */ 1571static int rsi_mac80211_set_antenna(struct ieee80211_hw *hw, 1572 u32 tx_ant, u32 rx_ant) 1573{ 1574 struct rsi_hw *adapter = hw->priv; 1575 struct rsi_common *common = adapter->priv; 1576 u8 antenna = 0; 1577 1578 if (tx_ant > 1 || rx_ant > 1) { 1579 rsi_dbg(ERR_ZONE, 1580 "Invalid antenna selection (tx: %d, rx:%d)\n", 1581 tx_ant, rx_ant); 1582 rsi_dbg(ERR_ZONE, 1583 "Use 0 for int_ant, 1 for ext_ant\n"); 1584 return -EINVAL; 1585 } 1586 1587 rsi_dbg(INFO_ZONE, "%s: Antenna map Tx %x Rx %d\n", 1588 __func__, tx_ant, rx_ant); 1589 1590 mutex_lock(&common->mutex); 1591 1592 antenna = tx_ant ? ANTENNA_SEL_UFL : ANTENNA_SEL_INT; 1593 if (common->ant_in_use != antenna) 1594 if (rsi_set_antenna(common, antenna)) 1595 goto fail_set_antenna; 1596 1597 rsi_dbg(INFO_ZONE, "(%s) Antenna path configured successfully\n", 1598 tx_ant ? "UFL" : "INT"); 1599 1600 common->ant_in_use = antenna; 1601 1602 mutex_unlock(&common->mutex); 1603 1604 return 0; 1605 1606fail_set_antenna: 1607 rsi_dbg(ERR_ZONE, "%s: Failed.\n", __func__); 1608 mutex_unlock(&common->mutex); 1609 return -EINVAL; 1610} 1611 1612/** 1613 * rsi_mac80211_get_antenna() - This function is used to configure 1614 * tx and rx antennas. 1615 * 1616 * @hw: Pointer to the ieee80211_hw structure. 1617 * @tx_ant: Bitmap for tx antenna 1618 * @rx_ant: Bitmap for rx antenna 1619 * 1620 * Return: 0 on success, negative error codes on failure. 1621 */ 1622static int rsi_mac80211_get_antenna(struct ieee80211_hw *hw, 1623 u32 *tx_ant, u32 *rx_ant) 1624{ 1625 struct rsi_hw *adapter = hw->priv; 1626 struct rsi_common *common = adapter->priv; 1627 1628 mutex_lock(&common->mutex); 1629 1630 *tx_ant = (common->ant_in_use == ANTENNA_SEL_UFL) ? 1 : 0; 1631 *rx_ant = 0; 1632 1633 mutex_unlock(&common->mutex); 1634 1635 return 0; 1636} 1637 1638static int rsi_map_region_code(enum nl80211_dfs_regions region_code) 1639{ 1640 switch (region_code) { 1641 case NL80211_DFS_FCC: 1642 return RSI_REGION_FCC; 1643 case NL80211_DFS_ETSI: 1644 return RSI_REGION_ETSI; 1645 case NL80211_DFS_JP: 1646 return RSI_REGION_TELEC; 1647 case NL80211_DFS_UNSET: 1648 return RSI_REGION_WORLD; 1649 } 1650 return RSI_REGION_WORLD; 1651} 1652 1653static void rsi_reg_notify(struct wiphy *wiphy, 1654 struct regulatory_request *request) 1655{ 1656 struct ieee80211_supported_band *sband; 1657 struct ieee80211_channel *ch; 1658 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 1659 struct rsi_hw * adapter = hw->priv; 1660 struct rsi_common *common = adapter->priv; 1661 int i; 1662 1663 mutex_lock(&common->mutex); 1664 1665 rsi_dbg(INFO_ZONE, "country = %s dfs_region = %d\n", 1666 request->alpha2, request->dfs_region); 1667 1668 if (common->num_supp_bands > 1) { 1669 sband = wiphy->bands[NL80211_BAND_5GHZ]; 1670 1671 for (i = 0; i < sband->n_channels; i++) { 1672 ch = &sband->channels[i]; 1673 if (ch->flags & IEEE80211_CHAN_DISABLED) 1674 continue; 1675 1676 if (ch->flags & IEEE80211_CHAN_RADAR) 1677 ch->flags |= IEEE80211_CHAN_NO_IR; 1678 } 1679 } 1680 adapter->dfs_region = rsi_map_region_code(request->dfs_region); 1681 rsi_dbg(INFO_ZONE, "RSI region code = %d\n", adapter->dfs_region); 1682 1683 adapter->country[0] = request->alpha2[0]; 1684 adapter->country[1] = request->alpha2[1]; 1685 1686 mutex_unlock(&common->mutex); 1687} 1688 1689static void rsi_mac80211_rfkill_poll(struct ieee80211_hw *hw) 1690{ 1691 struct rsi_hw *adapter = hw->priv; 1692 struct rsi_common *common = adapter->priv; 1693 1694 mutex_lock(&common->mutex); 1695 if (common->fsm_state != FSM_MAC_INIT_DONE) 1696 wiphy_rfkill_set_hw_state(hw->wiphy, true); 1697 else 1698 wiphy_rfkill_set_hw_state(hw->wiphy, false); 1699 mutex_unlock(&common->mutex); 1700} 1701 1702static void rsi_resume_conn_channel(struct rsi_common *common) 1703{ 1704 struct rsi_hw *adapter = common->priv; 1705 struct ieee80211_vif *vif; 1706 int cnt; 1707 1708 for (cnt = 0; cnt < RSI_MAX_VIFS; cnt++) { 1709 vif = adapter->vifs[cnt]; 1710 if (!vif) 1711 continue; 1712 1713 if ((vif->type == NL80211_IFTYPE_AP) || 1714 (vif->type == NL80211_IFTYPE_P2P_GO)) { 1715 rsi_switch_channel(adapter, vif); 1716 break; 1717 } 1718 if (((vif->type == NL80211_IFTYPE_STATION) || 1719 (vif->type == NL80211_IFTYPE_P2P_CLIENT)) && 1720 vif->bss_conf.assoc) { 1721 rsi_switch_channel(adapter, vif); 1722 break; 1723 } 1724 } 1725} 1726 1727void rsi_roc_timeout(struct timer_list *t) 1728{ 1729 struct rsi_common *common = from_timer(common, t, roc_timer); 1730 1731 rsi_dbg(INFO_ZONE, "Remain on channel expired\n"); 1732 1733 mutex_lock(&common->mutex); 1734 ieee80211_remain_on_channel_expired(common->priv->hw); 1735 1736 if (timer_pending(&common->roc_timer)) 1737 del_timer(&common->roc_timer); 1738 1739 rsi_resume_conn_channel(common); 1740 mutex_unlock(&common->mutex); 1741} 1742 1743static int rsi_mac80211_roc(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1744 struct ieee80211_channel *chan, int duration, 1745 enum ieee80211_roc_type type) 1746{ 1747 struct rsi_hw *adapter = (struct rsi_hw *)hw->priv; 1748 struct rsi_common *common = (struct rsi_common *)adapter->priv; 1749 int status = 0; 1750 1751 rsi_dbg(INFO_ZONE, "***** Remain on channel *****\n"); 1752 1753 mutex_lock(&common->mutex); 1754 rsi_dbg(INFO_ZONE, "%s: channel: %d duration: %dms\n", 1755 __func__, chan->hw_value, duration); 1756 1757 if (timer_pending(&common->roc_timer)) { 1758 rsi_dbg(INFO_ZONE, "Stop on-going ROC\n"); 1759 del_timer(&common->roc_timer); 1760 } 1761 common->roc_timer.expires = msecs_to_jiffies(duration) + jiffies; 1762 add_timer(&common->roc_timer); 1763 1764 /* Configure band */ 1765 if (rsi_band_check(common, chan)) { 1766 rsi_dbg(ERR_ZONE, "Failed to set band\n"); 1767 status = -EINVAL; 1768 goto out; 1769 } 1770 1771 /* Configure channel */ 1772 if (rsi_set_channel(common, chan)) { 1773 rsi_dbg(ERR_ZONE, "Failed to set the channel\n"); 1774 status = -EINVAL; 1775 goto out; 1776 } 1777 1778 common->roc_vif = vif; 1779 ieee80211_ready_on_channel(hw); 1780 rsi_dbg(INFO_ZONE, "%s: Ready on channel :%d\n", 1781 __func__, chan->hw_value); 1782 1783out: 1784 mutex_unlock(&common->mutex); 1785 1786 return status; 1787} 1788 1789static int rsi_mac80211_cancel_roc(struct ieee80211_hw *hw, 1790 struct ieee80211_vif *vif) 1791{ 1792 struct rsi_hw *adapter = hw->priv; 1793 struct rsi_common *common = adapter->priv; 1794 1795 rsi_dbg(INFO_ZONE, "Cancel remain on channel\n"); 1796 1797 mutex_lock(&common->mutex); 1798 if (!timer_pending(&common->roc_timer)) { 1799 mutex_unlock(&common->mutex); 1800 return 0; 1801 } 1802 1803 del_timer(&common->roc_timer); 1804 1805 rsi_resume_conn_channel(common); 1806 mutex_unlock(&common->mutex); 1807 1808 return 0; 1809} 1810 1811#ifdef CONFIG_PM 1812static const struct wiphy_wowlan_support rsi_wowlan_support = { 1813 .flags = WIPHY_WOWLAN_ANY | 1814 WIPHY_WOWLAN_MAGIC_PKT | 1815 WIPHY_WOWLAN_DISCONNECT | 1816 WIPHY_WOWLAN_GTK_REKEY_FAILURE | 1817 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 1818 WIPHY_WOWLAN_EAP_IDENTITY_REQ | 1819 WIPHY_WOWLAN_4WAY_HANDSHAKE, 1820}; 1821 1822static u16 rsi_wow_map_triggers(struct rsi_common *common, 1823 struct cfg80211_wowlan *wowlan) 1824{ 1825 u16 wow_triggers = 0; 1826 1827 rsi_dbg(INFO_ZONE, "Mapping wowlan triggers\n"); 1828 1829 if (wowlan->any) 1830 wow_triggers |= RSI_WOW_ANY; 1831 if (wowlan->magic_pkt) 1832 wow_triggers |= RSI_WOW_MAGIC_PKT; 1833 if (wowlan->disconnect) 1834 wow_triggers |= RSI_WOW_DISCONNECT; 1835 if (wowlan->gtk_rekey_failure || wowlan->eap_identity_req || 1836 wowlan->four_way_handshake) 1837 wow_triggers |= RSI_WOW_GTK_REKEY; 1838 1839 return wow_triggers; 1840} 1841 1842int rsi_config_wowlan(struct rsi_hw *adapter, struct cfg80211_wowlan *wowlan) 1843{ 1844 struct rsi_common *common = adapter->priv; 1845 u16 triggers = 0; 1846 u16 rx_filter_word = 0; 1847 struct ieee80211_bss_conf *bss = NULL; 1848 1849 rsi_dbg(INFO_ZONE, "Config WoWLAN to device\n"); 1850 1851 if (!adapter->vifs[0]) 1852 return -EINVAL; 1853 1854 bss = &adapter->vifs[0]->bss_conf; 1855 1856 if (WARN_ON(!wowlan)) { 1857 rsi_dbg(ERR_ZONE, "WoW triggers not enabled\n"); 1858 return -EINVAL; 1859 } 1860 1861 common->wow_flags |= RSI_WOW_ENABLED; 1862 triggers = rsi_wow_map_triggers(common, wowlan); 1863 if (!triggers) { 1864 rsi_dbg(ERR_ZONE, "%s:No valid WoW triggers\n", __func__); 1865 return -EINVAL; 1866 } 1867 if (!bss->assoc) { 1868 rsi_dbg(ERR_ZONE, 1869 "Cannot configure WoWLAN (Station not connected)\n"); 1870 common->wow_flags |= RSI_WOW_NO_CONNECTION; 1871 return 0; 1872 } 1873 rsi_dbg(INFO_ZONE, "TRIGGERS %x\n", triggers); 1874 1875 if (common->coex_mode > 1) 1876 rsi_disable_ps(adapter, adapter->vifs[0]); 1877 1878 rsi_send_wowlan_request(common, triggers, 1); 1879 1880 /** 1881 * Increase the beacon_miss threshold & keep-alive timers in 1882 * vap_update frame 1883 */ 1884 rsi_send_vap_dynamic_update(common); 1885 1886 rx_filter_word = (ALLOW_DATA_ASSOC_PEER | DISALLOW_BEACONS); 1887 rsi_send_rx_filter_frame(common, rx_filter_word); 1888 1889 return 0; 1890} 1891EXPORT_SYMBOL(rsi_config_wowlan); 1892 1893static int rsi_mac80211_suspend(struct ieee80211_hw *hw, 1894 struct cfg80211_wowlan *wowlan) 1895{ 1896 struct rsi_hw *adapter = hw->priv; 1897 struct rsi_common *common = adapter->priv; 1898 1899 rsi_dbg(INFO_ZONE, "%s: mac80211 suspend\n", __func__); 1900 mutex_lock(&common->mutex); 1901 if (rsi_config_wowlan(adapter, wowlan)) { 1902 rsi_dbg(ERR_ZONE, "Failed to configure WoWLAN\n"); 1903 mutex_unlock(&common->mutex); 1904 return 1; 1905 } 1906 mutex_unlock(&common->mutex); 1907 1908 return 0; 1909} 1910 1911static int rsi_mac80211_resume(struct ieee80211_hw *hw) 1912{ 1913 u16 rx_filter_word = 0; 1914 struct rsi_hw *adapter = hw->priv; 1915 struct rsi_common *common = adapter->priv; 1916 1917 common->wow_flags = 0; 1918 1919 rsi_dbg(INFO_ZONE, "%s: mac80211 resume\n", __func__); 1920 1921 if (common->hibernate_resume) { 1922 common->mac_ops_resumed = true; 1923 /* Device need a complete restart of all MAC operations. 1924 * returning 1 will serve this purpose. 1925 */ 1926 return 1; 1927 } 1928 1929 mutex_lock(&common->mutex); 1930 rsi_send_wowlan_request(common, 0, 0); 1931 1932 rx_filter_word = (ALLOW_DATA_ASSOC_PEER | ALLOW_CTRL_ASSOC_PEER | 1933 ALLOW_MGMT_ASSOC_PEER); 1934 rsi_send_rx_filter_frame(common, rx_filter_word); 1935 mutex_unlock(&common->mutex); 1936 1937 return 0; 1938} 1939 1940#endif 1941 1942static const struct ieee80211_ops mac80211_ops = { 1943 .tx = rsi_mac80211_tx, 1944 .start = rsi_mac80211_start, 1945 .stop = rsi_mac80211_stop, 1946 .add_interface = rsi_mac80211_add_interface, 1947 .remove_interface = rsi_mac80211_remove_interface, 1948 .config = rsi_mac80211_config, 1949 .bss_info_changed = rsi_mac80211_bss_info_changed, 1950 .conf_tx = rsi_mac80211_conf_tx, 1951 .configure_filter = rsi_mac80211_conf_filter, 1952 .set_key = rsi_mac80211_set_key, 1953 .set_rts_threshold = rsi_mac80211_set_rts_threshold, 1954 .set_bitrate_mask = rsi_mac80211_set_rate_mask, 1955 .ampdu_action = rsi_mac80211_ampdu_action, 1956 .sta_add = rsi_mac80211_sta_add, 1957 .sta_remove = rsi_mac80211_sta_remove, 1958 .set_antenna = rsi_mac80211_set_antenna, 1959 .get_antenna = rsi_mac80211_get_antenna, 1960 .rfkill_poll = rsi_mac80211_rfkill_poll, 1961 .remain_on_channel = rsi_mac80211_roc, 1962 .cancel_remain_on_channel = rsi_mac80211_cancel_roc, 1963#ifdef CONFIG_PM 1964 .suspend = rsi_mac80211_suspend, 1965 .resume = rsi_mac80211_resume, 1966#endif 1967 .hw_scan = rsi_mac80211_hw_scan_start, 1968 .cancel_hw_scan = rsi_mac80211_cancel_hw_scan, 1969}; 1970 1971/** 1972 * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack. 1973 * @common: Pointer to the driver private structure. 1974 * 1975 * Return: 0 on success, negative error codes on failure. 1976 */ 1977int rsi_mac80211_attach(struct rsi_common *common) 1978{ 1979 int status = 0; 1980 struct ieee80211_hw *hw = NULL; 1981 struct wiphy *wiphy = NULL; 1982 struct rsi_hw *adapter = common->priv; 1983 u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3}; 1984 1985 rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__); 1986 1987 hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops); 1988 if (!hw) { 1989 rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__); 1990 return -ENOMEM; 1991 } 1992 1993 wiphy = hw->wiphy; 1994 1995 SET_IEEE80211_DEV(hw, adapter->device); 1996 1997 hw->priv = adapter; 1998 adapter->hw = hw; 1999 2000 ieee80211_hw_set(hw, SIGNAL_DBM); 2001 ieee80211_hw_set(hw, HAS_RATE_CONTROL); 2002 ieee80211_hw_set(hw, AMPDU_AGGREGATION); 2003 ieee80211_hw_set(hw, SUPPORTS_PS); 2004 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 2005 2006 hw->queues = MAX_HW_QUEUES; 2007 hw->extra_tx_headroom = RSI_NEEDED_HEADROOM; 2008 2009 hw->max_rates = 1; 2010 hw->max_rate_tries = MAX_RETRIES; 2011 hw->uapsd_queues = RSI_IEEE80211_UAPSD_QUEUES; 2012 hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL; 2013 2014 hw->max_tx_aggregation_subframes = RSI_MAX_TX_AGGR_FRMS; 2015 hw->max_rx_aggregation_subframes = RSI_MAX_RX_AGGR_FRMS; 2016 hw->rate_control_algorithm = "AARF"; 2017 2018 SET_IEEE80211_PERM_ADDR(hw, common->mac_addr); 2019 ether_addr_copy(hw->wiphy->addr_mask, addr_mask); 2020 2021 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 2022 BIT(NL80211_IFTYPE_AP) | 2023 BIT(NL80211_IFTYPE_P2P_DEVICE) | 2024 BIT(NL80211_IFTYPE_P2P_CLIENT) | 2025 BIT(NL80211_IFTYPE_P2P_GO); 2026 2027 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 2028 wiphy->retry_short = RETRY_SHORT; 2029 wiphy->retry_long = RETRY_LONG; 2030 wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD; 2031 wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 2032 wiphy->flags = 0; 2033 2034 wiphy->available_antennas_rx = 1; 2035 wiphy->available_antennas_tx = 1; 2036 2037 status = rsi_register_rates_channels(adapter, NL80211_BAND_2GHZ); 2038 if (status) 2039 return status; 2040 wiphy->bands[NL80211_BAND_2GHZ] = 2041 &adapter->sbands[NL80211_BAND_2GHZ]; 2042 if (common->num_supp_bands > 1) { 2043 status = rsi_register_rates_channels(adapter, 2044 NL80211_BAND_5GHZ); 2045 if (status) 2046 return status; 2047 wiphy->bands[NL80211_BAND_5GHZ] = 2048 &adapter->sbands[NL80211_BAND_5GHZ]; 2049 } 2050 2051 /* AP Parameters */ 2052 wiphy->max_ap_assoc_sta = rsi_max_ap_stas[common->oper_mode - 1]; 2053 common->max_stations = wiphy->max_ap_assoc_sta; 2054 rsi_dbg(ERR_ZONE, "Max Stations Allowed = %d\n", common->max_stations); 2055 hw->sta_data_size = sizeof(struct rsi_sta); 2056 2057 wiphy->max_scan_ssids = RSI_MAX_SCAN_SSIDS; 2058 wiphy->max_scan_ie_len = RSI_MAX_SCAN_IE_LEN; 2059 wiphy->flags = WIPHY_FLAG_REPORTS_OBSS; 2060 wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 2061 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER; 2062 wiphy->reg_notifier = rsi_reg_notify; 2063 2064#ifdef CONFIG_PM 2065 wiphy->wowlan = &rsi_wowlan_support; 2066#endif 2067 2068 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); 2069 2070 /* Wi-Fi direct parameters */ 2071 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 2072 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX; 2073 wiphy->max_remain_on_channel_duration = 10000; 2074 hw->max_listen_interval = 10; 2075 wiphy->iface_combinations = rsi_iface_combinations; 2076 wiphy->n_iface_combinations = ARRAY_SIZE(rsi_iface_combinations); 2077 2078 if (common->coex_mode > 1) 2079 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 2080 2081 status = ieee80211_register_hw(hw); 2082 if (status) 2083 return status; 2084 2085 return rsi_init_dbgfs(adapter); 2086} 2087