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