Linux Audio

Check our new training course

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