PageRenderTime 76ms CodeModel.GetById 11ms app.highlight 48ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/net/wireless/wl12xx/main.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 4095 lines | 3042 code | 698 blank | 355 comment | 458 complexity | f019852059d6ce130b8d50f428d81163 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

   1/*
   2 * This file is part of wl1271
   3 *
   4 * Copyright (C) 2008-2010 Nokia Corporation
   5 *
   6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
   7 *
   8 * This program is free software; you can redistribute it and/or
   9 * modify it under the terms of the GNU General Public License
  10 * version 2 as published by the Free Software Foundation.
  11 *
  12 * This program is distributed in the hope that it will be useful, but
  13 * WITHOUT ANY WARRANTY; without even the implied warranty of
  14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15 * General Public License for more details.
  16 *
  17 * You should have received a copy of the GNU General Public License
  18 * along with this program; if not, write to the Free Software
  19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20 * 02110-1301 USA
  21 *
  22 */
  23
  24#include <linux/module.h>
  25#include <linux/firmware.h>
  26#include <linux/delay.h>
  27#include <linux/spi/spi.h>
  28#include <linux/crc32.h>
  29#include <linux/etherdevice.h>
  30#include <linux/vmalloc.h>
  31#include <linux/platform_device.h>
  32#include <linux/slab.h>
  33#include <linux/wl12xx.h>
  34
  35#include "wl12xx.h"
  36#include "wl12xx_80211.h"
  37#include "reg.h"
  38#include "io.h"
  39#include "event.h"
  40#include "tx.h"
  41#include "rx.h"
  42#include "ps.h"
  43#include "init.h"
  44#include "debugfs.h"
  45#include "cmd.h"
  46#include "boot.h"
  47#include "testmode.h"
  48#include "scan.h"
  49
  50#define WL1271_BOOT_RETRIES 3
  51
  52static struct conf_drv_settings default_conf = {
  53	.sg = {
  54		.sta_params = {
  55			[CONF_SG_BT_PER_THRESHOLD]                  = 7500,
  56			[CONF_SG_HV3_MAX_OVERRIDE]                  = 0,
  57			[CONF_SG_BT_NFS_SAMPLE_INTERVAL]            = 400,
  58			[CONF_SG_BT_LOAD_RATIO]                     = 200,
  59			[CONF_SG_AUTO_PS_MODE]                      = 1,
  60			[CONF_SG_AUTO_SCAN_PROBE_REQ]               = 170,
  61			[CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3]   = 50,
  62			[CONF_SG_ANTENNA_CONFIGURATION]             = 0,
  63			[CONF_SG_BEACON_MISS_PERCENT]               = 60,
  64			[CONF_SG_RATE_ADAPT_THRESH]                 = 12,
  65			[CONF_SG_RATE_ADAPT_SNR]                    = 0,
  66			[CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR]      = 10,
  67			[CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR]      = 30,
  68			[CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR]      = 8,
  69			[CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR]       = 20,
  70			[CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR]       = 50,
  71			/* Note: with UPSD, this should be 4 */
  72			[CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR]       = 8,
  73			[CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR]     = 7,
  74			[CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR]     = 25,
  75			[CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR]     = 20,
  76			/* Note: with UPDS, this should be 15 */
  77			[CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR]      = 8,
  78			/* Note: with UPDS, this should be 50 */
  79			[CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR]      = 40,
  80			/* Note: with UPDS, this should be 10 */
  81			[CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR]      = 20,
  82			[CONF_SG_RXT]                               = 1200,
  83			[CONF_SG_TXT]                               = 1000,
  84			[CONF_SG_ADAPTIVE_RXT_TXT]                  = 1,
  85			[CONF_SG_PS_POLL_TIMEOUT]                   = 10,
  86			[CONF_SG_UPSD_TIMEOUT]                      = 10,
  87			[CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7,
  88			[CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15,
  89			[CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15,
  90			[CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR]  = 8,
  91			[CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR]  = 20,
  92			[CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR]  = 15,
  93			[CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR]         = 20,
  94			[CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR]         = 50,
  95			[CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR]         = 10,
  96			[CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3]  = 200,
  97			[CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800,
  98			[CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME]         = 75,
  99			[CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME]       = 15,
 100			[CONF_SG_HV3_MAX_SERVED]                    = 6,
 101			[CONF_SG_DHCP_TIME]                         = 5000,
 102			[CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP]  = 100,
 103		},
 104		.ap_params = {
 105			[CONF_SG_BT_PER_THRESHOLD]                  = 7500,
 106			[CONF_SG_HV3_MAX_OVERRIDE]                  = 0,
 107			[CONF_SG_BT_NFS_SAMPLE_INTERVAL]            = 400,
 108			[CONF_SG_BT_LOAD_RATIO]                     = 50,
 109			[CONF_SG_AUTO_PS_MODE]                      = 1,
 110			[CONF_SG_AUTO_SCAN_PROBE_REQ]               = 170,
 111			[CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3]   = 50,
 112			[CONF_SG_ANTENNA_CONFIGURATION]             = 0,
 113			[CONF_SG_BEACON_MISS_PERCENT]               = 60,
 114			[CONF_SG_RATE_ADAPT_THRESH]                 = 64,
 115			[CONF_SG_RATE_ADAPT_SNR]                    = 1,
 116			[CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR]      = 10,
 117			[CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR]      = 25,
 118			[CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR]      = 25,
 119			[CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR]       = 20,
 120			[CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR]       = 25,
 121			[CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR]       = 25,
 122			[CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR]     = 7,
 123			[CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR]     = 25,
 124			[CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR]     = 25,
 125			[CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR]      = 8,
 126			[CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR]      = 25,
 127			[CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR]      = 25,
 128			[CONF_SG_RXT]                               = 1200,
 129			[CONF_SG_TXT]                               = 1000,
 130			[CONF_SG_ADAPTIVE_RXT_TXT]                  = 1,
 131			[CONF_SG_PS_POLL_TIMEOUT]                   = 10,
 132			[CONF_SG_UPSD_TIMEOUT]                      = 10,
 133			[CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7,
 134			[CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15,
 135			[CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15,
 136			[CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR]  = 8,
 137			[CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR]  = 20,
 138			[CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR]  = 15,
 139			[CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR]         = 20,
 140			[CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR]         = 50,
 141			[CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR]         = 10,
 142			[CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3]  = 200,
 143			[CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800,
 144			[CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME]         = 75,
 145			[CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME]       = 15,
 146			[CONF_SG_HV3_MAX_SERVED]                    = 6,
 147			[CONF_SG_DHCP_TIME]                         = 5000,
 148			[CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP]  = 100,
 149			[CONF_SG_TEMP_PARAM_1]                      = 0,
 150			[CONF_SG_TEMP_PARAM_2]                      = 0,
 151			[CONF_SG_TEMP_PARAM_3]                      = 0,
 152			[CONF_SG_TEMP_PARAM_4]                      = 0,
 153			[CONF_SG_TEMP_PARAM_5]                      = 0,
 154			[CONF_SG_AP_BEACON_MISS_TX]                 = 3,
 155			[CONF_SG_RX_WINDOW_LENGTH]                  = 6,
 156			[CONF_SG_AP_CONNECTION_PROTECTION_TIME]     = 50,
 157			[CONF_SG_TEMP_PARAM_6]                      = 1,
 158		},
 159		.state = CONF_SG_PROTECTIVE,
 160	},
 161	.rx = {
 162		.rx_msdu_life_time           = 512000,
 163		.packet_detection_threshold  = 0,
 164		.ps_poll_timeout             = 15,
 165		.upsd_timeout                = 15,
 166		.rts_threshold               = IEEE80211_MAX_RTS_THRESHOLD,
 167		.rx_cca_threshold            = 0,
 168		.irq_blk_threshold           = 0xFFFF,
 169		.irq_pkt_threshold           = 0,
 170		.irq_timeout                 = 600,
 171		.queue_type                  = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
 172	},
 173	.tx = {
 174		.tx_energy_detection         = 0,
 175		.sta_rc_conf                 = {
 176			.enabled_rates       = 0,
 177			.short_retry_limit   = 10,
 178			.long_retry_limit    = 10,
 179			.aflags              = 0,
 180		},
 181		.ac_conf_count               = 4,
 182		.ac_conf                     = {
 183			[CONF_TX_AC_BE] = {
 184				.ac          = CONF_TX_AC_BE,
 185				.cw_min      = 15,
 186				.cw_max      = 63,
 187				.aifsn       = 3,
 188				.tx_op_limit = 0,
 189			},
 190			[CONF_TX_AC_BK] = {
 191				.ac          = CONF_TX_AC_BK,
 192				.cw_min      = 15,
 193				.cw_max      = 63,
 194				.aifsn       = 7,
 195				.tx_op_limit = 0,
 196			},
 197			[CONF_TX_AC_VI] = {
 198				.ac          = CONF_TX_AC_VI,
 199				.cw_min      = 15,
 200				.cw_max      = 63,
 201				.aifsn       = CONF_TX_AIFS_PIFS,
 202				.tx_op_limit = 3008,
 203			},
 204			[CONF_TX_AC_VO] = {
 205				.ac          = CONF_TX_AC_VO,
 206				.cw_min      = 15,
 207				.cw_max      = 63,
 208				.aifsn       = CONF_TX_AIFS_PIFS,
 209				.tx_op_limit = 1504,
 210			},
 211		},
 212		.ap_max_tx_retries = 100,
 213		.tid_conf_count = 4,
 214		.tid_conf = {
 215			[CONF_TX_AC_BE] = {
 216				.queue_id    = CONF_TX_AC_BE,
 217				.channel_type = CONF_CHANNEL_TYPE_EDCF,
 218				.tsid        = CONF_TX_AC_BE,
 219				.ps_scheme   = CONF_PS_SCHEME_LEGACY,
 220				.ack_policy  = CONF_ACK_POLICY_LEGACY,
 221				.apsd_conf   = {0, 0},
 222			},
 223			[CONF_TX_AC_BK] = {
 224				.queue_id    = CONF_TX_AC_BK,
 225				.channel_type = CONF_CHANNEL_TYPE_EDCF,
 226				.tsid        = CONF_TX_AC_BK,
 227				.ps_scheme   = CONF_PS_SCHEME_LEGACY,
 228				.ack_policy  = CONF_ACK_POLICY_LEGACY,
 229				.apsd_conf   = {0, 0},
 230			},
 231			[CONF_TX_AC_VI] = {
 232				.queue_id    = CONF_TX_AC_VI,
 233				.channel_type = CONF_CHANNEL_TYPE_EDCF,
 234				.tsid        = CONF_TX_AC_VI,
 235				.ps_scheme   = CONF_PS_SCHEME_LEGACY,
 236				.ack_policy  = CONF_ACK_POLICY_LEGACY,
 237				.apsd_conf   = {0, 0},
 238			},
 239			[CONF_TX_AC_VO] = {
 240				.queue_id    = CONF_TX_AC_VO,
 241				.channel_type = CONF_CHANNEL_TYPE_EDCF,
 242				.tsid        = CONF_TX_AC_VO,
 243				.ps_scheme   = CONF_PS_SCHEME_LEGACY,
 244				.ack_policy  = CONF_ACK_POLICY_LEGACY,
 245				.apsd_conf   = {0, 0},
 246			},
 247		},
 248		.frag_threshold              = IEEE80211_MAX_FRAG_THRESHOLD,
 249		.tx_compl_timeout            = 700,
 250		.tx_compl_threshold          = 4,
 251		.basic_rate                  = CONF_HW_BIT_RATE_1MBPS,
 252		.basic_rate_5                = CONF_HW_BIT_RATE_6MBPS,
 253		.tmpl_short_retry_limit      = 10,
 254		.tmpl_long_retry_limit       = 10,
 255	},
 256	.conn = {
 257		.wake_up_event               = CONF_WAKE_UP_EVENT_DTIM,
 258		.listen_interval             = 1,
 259		.bcn_filt_mode               = CONF_BCN_FILT_MODE_ENABLED,
 260		.bcn_filt_ie_count           = 2,
 261		.bcn_filt_ie = {
 262			[0] = {
 263				.ie          = WLAN_EID_CHANNEL_SWITCH,
 264				.rule        = CONF_BCN_RULE_PASS_ON_APPEARANCE,
 265			},
 266			[1] = {
 267				.ie          = WLAN_EID_HT_INFORMATION,
 268				.rule        = CONF_BCN_RULE_PASS_ON_CHANGE,
 269			},
 270		},
 271		.synch_fail_thold            = 10,
 272		.bss_lose_timeout            = 100,
 273		.beacon_rx_timeout           = 10000,
 274		.broadcast_timeout           = 20000,
 275		.rx_broadcast_in_ps          = 1,
 276		.ps_poll_threshold           = 10,
 277		.ps_poll_recovery_period     = 700,
 278		.bet_enable                  = CONF_BET_MODE_ENABLE,
 279		.bet_max_consecutive         = 50,
 280		.psm_entry_retries           = 5,
 281		.psm_exit_retries            = 16,
 282		.psm_entry_nullfunc_retries  = 3,
 283		.psm_entry_hangover_period   = 1,
 284		.keep_alive_interval         = 55000,
 285		.max_listen_interval         = 20,
 286	},
 287	.itrim = {
 288		.enable = false,
 289		.timeout = 50000,
 290	},
 291	.pm_config = {
 292		.host_clk_settling_time = 5000,
 293		.host_fast_wakeup_support = false
 294	},
 295	.roam_trigger = {
 296		.trigger_pacing               = 1,
 297		.avg_weight_rssi_beacon       = 20,
 298		.avg_weight_rssi_data         = 10,
 299		.avg_weight_snr_beacon        = 20,
 300		.avg_weight_snr_data          = 10,
 301	},
 302	.scan = {
 303		.min_dwell_time_active        = 7500,
 304		.max_dwell_time_active        = 30000,
 305		.min_dwell_time_passive       = 100000,
 306		.max_dwell_time_passive       = 100000,
 307		.num_probe_reqs               = 2,
 308	},
 309	.sched_scan = {
 310		/* sched_scan requires dwell times in TU instead of TU/1000 */
 311		.min_dwell_time_active = 8,
 312		.max_dwell_time_active = 30,
 313		.dwell_time_passive    = 100,
 314		.dwell_time_dfs        = 150,
 315		.num_probe_reqs        = 2,
 316		.rssi_threshold        = -90,
 317		.snr_threshold         = 0,
 318	},
 319	.rf = {
 320		.tx_per_channel_power_compensation_2 = {
 321			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 322		},
 323		.tx_per_channel_power_compensation_5 = {
 324			0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 325			0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 326			0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 327		},
 328	},
 329	.ht = {
 330		.tx_ba_win_size = 64,
 331		.inactivity_timeout = 10000,
 332	},
 333	.mem_wl127x = {
 334		.num_stations                 = 1,
 335		.ssid_profiles                = 1,
 336		.rx_block_num                 = 70,
 337		.tx_min_block_num             = 40,
 338		.dynamic_memory               = 1,
 339		.min_req_tx_blocks            = 100,
 340		.min_req_rx_blocks            = 22,
 341		.tx_min                       = 27,
 342	},
 343	.mem_wl128x = {
 344		.num_stations                 = 1,
 345		.ssid_profiles                = 1,
 346		.rx_block_num                 = 40,
 347		.tx_min_block_num             = 40,
 348		.dynamic_memory               = 1,
 349		.min_req_tx_blocks            = 45,
 350		.min_req_rx_blocks            = 22,
 351		.tx_min                       = 27,
 352	},
 353	.fm_coex = {
 354		.enable                       = true,
 355		.swallow_period               = 5,
 356		.n_divider_fref_set_1         = 0xff,       /* default */
 357		.n_divider_fref_set_2         = 12,
 358		.m_divider_fref_set_1         = 148,
 359		.m_divider_fref_set_2         = 0xffff,     /* default */
 360		.coex_pll_stabilization_time  = 0xffffffff, /* default */
 361		.ldo_stabilization_time       = 0xffff,     /* default */
 362		.fm_disturbed_band_margin     = 0xff,       /* default */
 363		.swallow_clk_diff             = 0xff,       /* default */
 364	},
 365	.hci_io_ds = HCI_IO_DS_6MA,
 366};
 367
 368static void __wl1271_op_remove_interface(struct wl1271 *wl,
 369					 bool reset_tx_queues);
 370static void wl1271_free_ap_keys(struct wl1271 *wl);
 371
 372
 373static void wl1271_device_release(struct device *dev)
 374{
 375
 376}
 377
 378static struct platform_device wl1271_device = {
 379	.name           = "wl1271",
 380	.id             = -1,
 381
 382	/* device model insists to have a release function */
 383	.dev            = {
 384		.release = wl1271_device_release,
 385	},
 386};
 387
 388static DEFINE_MUTEX(wl_list_mutex);
 389static LIST_HEAD(wl_list);
 390
 391static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
 392			     void *arg)
 393{
 394	struct net_device *dev = arg;
 395	struct wireless_dev *wdev;
 396	struct wiphy *wiphy;
 397	struct ieee80211_hw *hw;
 398	struct wl1271 *wl;
 399	struct wl1271 *wl_temp;
 400	int ret = 0;
 401
 402	/* Check that this notification is for us. */
 403	if (what != NETDEV_CHANGE)
 404		return NOTIFY_DONE;
 405
 406	wdev = dev->ieee80211_ptr;
 407	if (wdev == NULL)
 408		return NOTIFY_DONE;
 409
 410	wiphy = wdev->wiphy;
 411	if (wiphy == NULL)
 412		return NOTIFY_DONE;
 413
 414	hw = wiphy_priv(wiphy);
 415	if (hw == NULL)
 416		return NOTIFY_DONE;
 417
 418	wl_temp = hw->priv;
 419	mutex_lock(&wl_list_mutex);
 420	list_for_each_entry(wl, &wl_list, list) {
 421		if (wl == wl_temp)
 422			break;
 423	}
 424	mutex_unlock(&wl_list_mutex);
 425	if (wl != wl_temp)
 426		return NOTIFY_DONE;
 427
 428	mutex_lock(&wl->mutex);
 429
 430	if (wl->state == WL1271_STATE_OFF)
 431		goto out;
 432
 433	if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
 434		goto out;
 435
 436	ret = wl1271_ps_elp_wakeup(wl);
 437	if (ret < 0)
 438		goto out;
 439
 440	if ((dev->operstate == IF_OPER_UP) &&
 441	    !test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags)) {
 442		wl1271_cmd_set_sta_state(wl);
 443		wl1271_info("Association completed.");
 444	}
 445
 446	wl1271_ps_elp_sleep(wl);
 447
 448out:
 449	mutex_unlock(&wl->mutex);
 450
 451	return NOTIFY_OK;
 452}
 453
 454static int wl1271_reg_notify(struct wiphy *wiphy,
 455			     struct regulatory_request *request)
 456{
 457	struct ieee80211_supported_band *band;
 458	struct ieee80211_channel *ch;
 459	int i;
 460
 461	band = wiphy->bands[IEEE80211_BAND_5GHZ];
 462	for (i = 0; i < band->n_channels; i++) {
 463		ch = &band->channels[i];
 464		if (ch->flags & IEEE80211_CHAN_DISABLED)
 465			continue;
 466
 467		if (ch->flags & IEEE80211_CHAN_RADAR)
 468			ch->flags |= IEEE80211_CHAN_NO_IBSS |
 469				     IEEE80211_CHAN_PASSIVE_SCAN;
 470
 471	}
 472
 473	return 0;
 474}
 475
 476static void wl1271_conf_init(struct wl1271 *wl)
 477{
 478
 479	/*
 480	 * This function applies the default configuration to the driver. This
 481	 * function is invoked upon driver load (spi probe.)
 482	 *
 483	 * The configuration is stored in a run-time structure in order to
 484	 * facilitate for run-time adjustment of any of the parameters. Making
 485	 * changes to the configuration structure will apply the new values on
 486	 * the next interface up (wl1271_op_start.)
 487	 */
 488
 489	/* apply driver default configuration */
 490	memcpy(&wl->conf, &default_conf, sizeof(default_conf));
 491}
 492
 493
 494static int wl1271_plt_init(struct wl1271 *wl)
 495{
 496	struct conf_tx_ac_category *conf_ac;
 497	struct conf_tx_tid *conf_tid;
 498	int ret, i;
 499
 500	if (wl->chip.id == CHIP_ID_1283_PG20)
 501		ret = wl128x_cmd_general_parms(wl);
 502	else
 503		ret = wl1271_cmd_general_parms(wl);
 504	if (ret < 0)
 505		return ret;
 506
 507	if (wl->chip.id == CHIP_ID_1283_PG20)
 508		ret = wl128x_cmd_radio_parms(wl);
 509	else
 510		ret = wl1271_cmd_radio_parms(wl);
 511	if (ret < 0)
 512		return ret;
 513
 514	if (wl->chip.id != CHIP_ID_1283_PG20) {
 515		ret = wl1271_cmd_ext_radio_parms(wl);
 516		if (ret < 0)
 517			return ret;
 518	}
 519	if (ret < 0)
 520		return ret;
 521
 522	/* Chip-specific initializations */
 523	ret = wl1271_chip_specific_init(wl);
 524	if (ret < 0)
 525		return ret;
 526
 527	ret = wl1271_sta_init_templates_config(wl);
 528	if (ret < 0)
 529		return ret;
 530
 531	ret = wl1271_acx_init_mem_config(wl);
 532	if (ret < 0)
 533		return ret;
 534
 535	/* PHY layer config */
 536	ret = wl1271_init_phy_config(wl);
 537	if (ret < 0)
 538		goto out_free_memmap;
 539
 540	ret = wl1271_acx_dco_itrim_params(wl);
 541	if (ret < 0)
 542		goto out_free_memmap;
 543
 544	/* Initialize connection monitoring thresholds */
 545	ret = wl1271_acx_conn_monit_params(wl, false);
 546	if (ret < 0)
 547		goto out_free_memmap;
 548
 549	/* Bluetooth WLAN coexistence */
 550	ret = wl1271_init_pta(wl);
 551	if (ret < 0)
 552		goto out_free_memmap;
 553
 554	/* FM WLAN coexistence */
 555	ret = wl1271_acx_fm_coex(wl);
 556	if (ret < 0)
 557		goto out_free_memmap;
 558
 559	/* Energy detection */
 560	ret = wl1271_init_energy_detection(wl);
 561	if (ret < 0)
 562		goto out_free_memmap;
 563
 564	ret = wl1271_acx_sta_mem_cfg(wl);
 565	if (ret < 0)
 566		goto out_free_memmap;
 567
 568	/* Default fragmentation threshold */
 569	ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
 570	if (ret < 0)
 571		goto out_free_memmap;
 572
 573	/* Default TID/AC configuration */
 574	BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
 575	for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
 576		conf_ac = &wl->conf.tx.ac_conf[i];
 577		ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
 578					conf_ac->cw_max, conf_ac->aifsn,
 579					conf_ac->tx_op_limit);
 580		if (ret < 0)
 581			goto out_free_memmap;
 582
 583		conf_tid = &wl->conf.tx.tid_conf[i];
 584		ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
 585					 conf_tid->channel_type,
 586					 conf_tid->tsid,
 587					 conf_tid->ps_scheme,
 588					 conf_tid->ack_policy,
 589					 conf_tid->apsd_conf[0],
 590					 conf_tid->apsd_conf[1]);
 591		if (ret < 0)
 592			goto out_free_memmap;
 593	}
 594
 595	/* Enable data path */
 596	ret = wl1271_cmd_data_path(wl, 1);
 597	if (ret < 0)
 598		goto out_free_memmap;
 599
 600	/* Configure for CAM power saving (ie. always active) */
 601	ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
 602	if (ret < 0)
 603		goto out_free_memmap;
 604
 605	/* configure PM */
 606	ret = wl1271_acx_pm_config(wl);
 607	if (ret < 0)
 608		goto out_free_memmap;
 609
 610	return 0;
 611
 612 out_free_memmap:
 613	kfree(wl->target_mem_map);
 614	wl->target_mem_map = NULL;
 615
 616	return ret;
 617}
 618
 619static void wl1271_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_blks)
 620{
 621	bool fw_ps;
 622
 623	/* only regulate station links */
 624	if (hlid < WL1271_AP_STA_HLID_START)
 625		return;
 626
 627	fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
 628
 629	/*
 630	 * Wake up from high level PS if the STA is asleep with too little
 631	 * blocks in FW or if the STA is awake.
 632	 */
 633	if (!fw_ps || tx_blks < WL1271_PS_STA_MAX_BLOCKS)
 634		wl1271_ps_link_end(wl, hlid);
 635
 636	/* Start high-level PS if the STA is asleep with enough blocks in FW */
 637	else if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
 638		wl1271_ps_link_start(wl, hlid, true);
 639}
 640
 641static void wl1271_irq_update_links_status(struct wl1271 *wl,
 642				       struct wl1271_fw_ap_status *status)
 643{
 644	u32 cur_fw_ps_map;
 645	u8 hlid;
 646
 647	cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
 648	if (wl->ap_fw_ps_map != cur_fw_ps_map) {
 649		wl1271_debug(DEBUG_PSM,
 650			     "link ps prev 0x%x cur 0x%x changed 0x%x",
 651			     wl->ap_fw_ps_map, cur_fw_ps_map,
 652			     wl->ap_fw_ps_map ^ cur_fw_ps_map);
 653
 654		wl->ap_fw_ps_map = cur_fw_ps_map;
 655	}
 656
 657	for (hlid = WL1271_AP_STA_HLID_START; hlid < AP_MAX_LINKS; hlid++) {
 658		u8 cnt = status->tx_lnk_free_blks[hlid] -
 659			wl->links[hlid].prev_freed_blks;
 660
 661		wl->links[hlid].prev_freed_blks =
 662			status->tx_lnk_free_blks[hlid];
 663		wl->links[hlid].allocated_blks -= cnt;
 664
 665		wl1271_irq_ps_regulate_link(wl, hlid,
 666					    wl->links[hlid].allocated_blks);
 667	}
 668}
 669
 670static void wl1271_fw_status(struct wl1271 *wl,
 671			     struct wl1271_fw_full_status *full_status)
 672{
 673	struct wl1271_fw_common_status *status = &full_status->common;
 674	struct timespec ts;
 675	u32 old_tx_blk_count = wl->tx_blocks_available;
 676	u32 freed_blocks = 0;
 677	int i;
 678
 679	if (wl->bss_type == BSS_TYPE_AP_BSS) {
 680		wl1271_raw_read(wl, FW_STATUS_ADDR, status,
 681				sizeof(struct wl1271_fw_ap_status), false);
 682	} else {
 683		wl1271_raw_read(wl, FW_STATUS_ADDR, status,
 684				sizeof(struct wl1271_fw_sta_status), false);
 685	}
 686
 687	wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
 688		     "drv_rx_counter = %d, tx_results_counter = %d)",
 689		     status->intr,
 690		     status->fw_rx_counter,
 691		     status->drv_rx_counter,
 692		     status->tx_results_counter);
 693
 694	/* update number of available TX blocks */
 695	for (i = 0; i < NUM_TX_QUEUES; i++) {
 696		freed_blocks += le32_to_cpu(status->tx_released_blks[i]) -
 697				wl->tx_blocks_freed[i];
 698
 699		wl->tx_blocks_freed[i] =
 700			le32_to_cpu(status->tx_released_blks[i]);
 701	}
 702
 703	wl->tx_allocated_blocks -= freed_blocks;
 704
 705	if (wl->bss_type == BSS_TYPE_AP_BSS) {
 706		/* Update num of allocated TX blocks per link and ps status */
 707		wl1271_irq_update_links_status(wl, &full_status->ap);
 708		wl->tx_blocks_available += freed_blocks;
 709	} else {
 710		int avail = full_status->sta.tx_total - wl->tx_allocated_blocks;
 711
 712		/*
 713		 * The FW might change the total number of TX memblocks before
 714		 * we get a notification about blocks being released. Thus, the
 715		 * available blocks calculation might yield a temporary result
 716		 * which is lower than the actual available blocks. Keeping in
 717		 * mind that only blocks that were allocated can be moved from
 718		 * TX to RX, tx_blocks_available should never decrease here.
 719		 */
 720		wl->tx_blocks_available = max((int)wl->tx_blocks_available,
 721					      avail);
 722	}
 723
 724	/* if more blocks are available now, tx work can be scheduled */
 725	if (wl->tx_blocks_available > old_tx_blk_count)
 726		clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
 727
 728	/* update the host-chipset time offset */
 729	getnstimeofday(&ts);
 730	wl->time_offset = (timespec_to_ns(&ts) >> 10) -
 731		(s64)le32_to_cpu(status->fw_localtime);
 732}
 733
 734static void wl1271_flush_deferred_work(struct wl1271 *wl)
 735{
 736	struct sk_buff *skb;
 737
 738	/* Pass all received frames to the network stack */
 739	while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
 740		ieee80211_rx_ni(wl->hw, skb);
 741
 742	/* Return sent skbs to the network stack */
 743	while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
 744		ieee80211_tx_status(wl->hw, skb);
 745}
 746
 747static void wl1271_netstack_work(struct work_struct *work)
 748{
 749	struct wl1271 *wl =
 750		container_of(work, struct wl1271, netstack_work);
 751
 752	do {
 753		wl1271_flush_deferred_work(wl);
 754	} while (skb_queue_len(&wl->deferred_rx_queue));
 755}
 756
 757#define WL1271_IRQ_MAX_LOOPS 256
 758
 759irqreturn_t wl1271_irq(int irq, void *cookie)
 760{
 761	int ret;
 762	u32 intr;
 763	int loopcount = WL1271_IRQ_MAX_LOOPS;
 764	struct wl1271 *wl = (struct wl1271 *)cookie;
 765	bool done = false;
 766	unsigned int defer_count;
 767	unsigned long flags;
 768
 769	/* TX might be handled here, avoid redundant work */
 770	set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
 771	cancel_work_sync(&wl->tx_work);
 772
 773	/*
 774	 * In case edge triggered interrupt must be used, we cannot iterate
 775	 * more than once without introducing race conditions with the hardirq.
 776	 */
 777	if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
 778		loopcount = 1;
 779
 780	mutex_lock(&wl->mutex);
 781
 782	wl1271_debug(DEBUG_IRQ, "IRQ work");
 783
 784	if (unlikely(wl->state == WL1271_STATE_OFF))
 785		goto out;
 786
 787	ret = wl1271_ps_elp_wakeup(wl);
 788	if (ret < 0)
 789		goto out;
 790
 791	while (!done && loopcount--) {
 792		/*
 793		 * In order to avoid a race with the hardirq, clear the flag
 794		 * before acknowledging the chip. Since the mutex is held,
 795		 * wl1271_ps_elp_wakeup cannot be called concurrently.
 796		 */
 797		clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
 798		smp_mb__after_clear_bit();
 799
 800		wl1271_fw_status(wl, wl->fw_status);
 801		intr = le32_to_cpu(wl->fw_status->common.intr);
 802		intr &= WL1271_INTR_MASK;
 803		if (!intr) {
 804			done = true;
 805			continue;
 806		}
 807
 808		if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
 809			wl1271_error("watchdog interrupt received! "
 810				     "starting recovery.");
 811			ieee80211_queue_work(wl->hw, &wl->recovery_work);
 812
 813			/* restarting the chip. ignore any other interrupt. */
 814			goto out;
 815		}
 816
 817		if (likely(intr & WL1271_ACX_INTR_DATA)) {
 818			wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
 819
 820			wl1271_rx(wl, &wl->fw_status->common);
 821
 822			/* Check if any tx blocks were freed */
 823			spin_lock_irqsave(&wl->wl_lock, flags);
 824			if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
 825			    wl->tx_queue_count) {
 826				spin_unlock_irqrestore(&wl->wl_lock, flags);
 827				/*
 828				 * In order to avoid starvation of the TX path,
 829				 * call the work function directly.
 830				 */
 831				wl1271_tx_work_locked(wl);
 832			} else {
 833				spin_unlock_irqrestore(&wl->wl_lock, flags);
 834			}
 835
 836			/* check for tx results */
 837			if (wl->fw_status->common.tx_results_counter !=
 838			    (wl->tx_results_count & 0xff))
 839				wl1271_tx_complete(wl);
 840
 841			/* Make sure the deferred queues don't get too long */
 842			defer_count = skb_queue_len(&wl->deferred_tx_queue) +
 843				      skb_queue_len(&wl->deferred_rx_queue);
 844			if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
 845				wl1271_flush_deferred_work(wl);
 846		}
 847
 848		if (intr & WL1271_ACX_INTR_EVENT_A) {
 849			wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
 850			wl1271_event_handle(wl, 0);
 851		}
 852
 853		if (intr & WL1271_ACX_INTR_EVENT_B) {
 854			wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
 855			wl1271_event_handle(wl, 1);
 856		}
 857
 858		if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
 859			wl1271_debug(DEBUG_IRQ,
 860				     "WL1271_ACX_INTR_INIT_COMPLETE");
 861
 862		if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
 863			wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
 864	}
 865
 866	wl1271_ps_elp_sleep(wl);
 867
 868out:
 869	spin_lock_irqsave(&wl->wl_lock, flags);
 870	/* In case TX was not handled here, queue TX work */
 871	clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
 872	if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
 873	    wl->tx_queue_count)
 874		ieee80211_queue_work(wl->hw, &wl->tx_work);
 875	spin_unlock_irqrestore(&wl->wl_lock, flags);
 876
 877	mutex_unlock(&wl->mutex);
 878
 879	return IRQ_HANDLED;
 880}
 881EXPORT_SYMBOL_GPL(wl1271_irq);
 882
 883static int wl1271_fetch_firmware(struct wl1271 *wl)
 884{
 885	const struct firmware *fw;
 886	const char *fw_name;
 887	int ret;
 888
 889	switch (wl->bss_type) {
 890	case BSS_TYPE_AP_BSS:
 891		if (wl->chip.id == CHIP_ID_1283_PG20)
 892			fw_name = WL128X_AP_FW_NAME;
 893		else
 894			fw_name = WL127X_AP_FW_NAME;
 895		break;
 896	case BSS_TYPE_IBSS:
 897	case BSS_TYPE_STA_BSS:
 898		if (wl->chip.id == CHIP_ID_1283_PG20)
 899			fw_name = WL128X_FW_NAME;
 900		else
 901			fw_name	= WL1271_FW_NAME;
 902		break;
 903	default:
 904		wl1271_error("no compatible firmware for bss_type %d",
 905			     wl->bss_type);
 906		return -EINVAL;
 907	}
 908
 909	wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
 910
 911	ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl));
 912
 913	if (ret < 0) {
 914		wl1271_error("could not get firmware: %d", ret);
 915		return ret;
 916	}
 917
 918	if (fw->size % 4) {
 919		wl1271_error("firmware size is not multiple of 32 bits: %zu",
 920			     fw->size);
 921		ret = -EILSEQ;
 922		goto out;
 923	}
 924
 925	vfree(wl->fw);
 926	wl->fw_len = fw->size;
 927	wl->fw = vmalloc(wl->fw_len);
 928
 929	if (!wl->fw) {
 930		wl1271_error("could not allocate memory for the firmware");
 931		ret = -ENOMEM;
 932		goto out;
 933	}
 934
 935	memcpy(wl->fw, fw->data, wl->fw_len);
 936	wl->fw_bss_type = wl->bss_type;
 937	ret = 0;
 938
 939out:
 940	release_firmware(fw);
 941
 942	return ret;
 943}
 944
 945static int wl1271_fetch_nvs(struct wl1271 *wl)
 946{
 947	const struct firmware *fw;
 948	int ret;
 949
 950	ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl));
 951
 952	if (ret < 0) {
 953		wl1271_error("could not get nvs file: %d", ret);
 954		return ret;
 955	}
 956
 957	wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
 958
 959	if (!wl->nvs) {
 960		wl1271_error("could not allocate memory for the nvs file");
 961		ret = -ENOMEM;
 962		goto out;
 963	}
 964
 965	wl->nvs_len = fw->size;
 966
 967out:
 968	release_firmware(fw);
 969
 970	return ret;
 971}
 972
 973static void wl1271_recovery_work(struct work_struct *work)
 974{
 975	struct wl1271 *wl =
 976		container_of(work, struct wl1271, recovery_work);
 977
 978	mutex_lock(&wl->mutex);
 979
 980	if (wl->state != WL1271_STATE_ON)
 981		goto out;
 982
 983	wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
 984		    wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
 985
 986	if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
 987		ieee80211_connection_loss(wl->vif);
 988
 989	/* Prevent spurious TX during FW restart */
 990	ieee80211_stop_queues(wl->hw);
 991
 992	if (wl->sched_scanning) {
 993		ieee80211_sched_scan_stopped(wl->hw);
 994		wl->sched_scanning = false;
 995	}
 996
 997	/* reboot the chipset */
 998	__wl1271_op_remove_interface(wl, false);
 999	ieee80211_restart_hw(wl->hw);
1000
1001	/*
1002	 * Its safe to enable TX now - the queues are stopped after a request
1003	 * to restart the HW.
1004	 */
1005	ieee80211_wake_queues(wl->hw);
1006
1007out:
1008	mutex_unlock(&wl->mutex);
1009}
1010
1011static void wl1271_fw_wakeup(struct wl1271 *wl)
1012{
1013	u32 elp_reg;
1014
1015	elp_reg = ELPCTRL_WAKE_UP;
1016	wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
1017}
1018
1019static int wl1271_setup(struct wl1271 *wl)
1020{
1021	wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1022	if (!wl->fw_status)
1023		return -ENOMEM;
1024
1025	wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1026	if (!wl->tx_res_if) {
1027		kfree(wl->fw_status);
1028		return -ENOMEM;
1029	}
1030
1031	return 0;
1032}
1033
1034static int wl1271_chip_wakeup(struct wl1271 *wl)
1035{
1036	struct wl1271_partition_set partition;
1037	int ret = 0;
1038
1039	msleep(WL1271_PRE_POWER_ON_SLEEP);
1040	ret = wl1271_power_on(wl);
1041	if (ret < 0)
1042		goto out;
1043	msleep(WL1271_POWER_ON_SLEEP);
1044	wl1271_io_reset(wl);
1045	wl1271_io_init(wl);
1046
1047	/* We don't need a real memory partition here, because we only want
1048	 * to use the registers at this point. */
1049	memset(&partition, 0, sizeof(partition));
1050	partition.reg.start = REGISTERS_BASE;
1051	partition.reg.size = REGISTERS_DOWN_SIZE;
1052	wl1271_set_partition(wl, &partition);
1053
1054	/* ELP module wake up */
1055	wl1271_fw_wakeup(wl);
1056
1057	/* whal_FwCtrl_BootSm() */
1058
1059	/* 0. read chip id from CHIP_ID */
1060	wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
1061
1062	/* 1. check if chip id is valid */
1063
1064	switch (wl->chip.id) {
1065	case CHIP_ID_1271_PG10:
1066		wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
1067			       wl->chip.id);
1068
1069		ret = wl1271_setup(wl);
1070		if (ret < 0)
1071			goto out;
1072		break;
1073	case CHIP_ID_1271_PG20:
1074		wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1075			     wl->chip.id);
1076
1077		/* end-of-transaction flag should be set in wl127x AP mode */
1078		if (wl->bss_type == BSS_TYPE_AP_BSS)
1079			wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION;
1080
1081		ret = wl1271_setup(wl);
1082		if (ret < 0)
1083			goto out;
1084		break;
1085	case CHIP_ID_1283_PG20:
1086		wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1087			     wl->chip.id);
1088
1089		ret = wl1271_setup(wl);
1090		if (ret < 0)
1091			goto out;
1092		if (wl1271_set_block_size(wl))
1093			wl->quirks |= WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT;
1094		break;
1095	case CHIP_ID_1283_PG10:
1096	default:
1097		wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
1098		ret = -ENODEV;
1099		goto out;
1100	}
1101
1102	/* Make sure the firmware type matches the BSS type */
1103	if (wl->fw == NULL || wl->fw_bss_type != wl->bss_type) {
1104		ret = wl1271_fetch_firmware(wl);
1105		if (ret < 0)
1106			goto out;
1107	}
1108
1109	/* No NVS from netlink, try to get it from the filesystem */
1110	if (wl->nvs == NULL) {
1111		ret = wl1271_fetch_nvs(wl);
1112		if (ret < 0)
1113			goto out;
1114	}
1115
1116out:
1117	return ret;
1118}
1119
1120static unsigned int wl1271_get_fw_ver_quirks(struct wl1271 *wl)
1121{
1122	unsigned int quirks = 0;
1123	unsigned int *fw_ver = wl->chip.fw_ver;
1124
1125	/* Only for wl127x */
1126	if ((fw_ver[FW_VER_CHIP] == FW_VER_CHIP_WL127X) &&
1127	    /* Check STA version */
1128	    (((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) &&
1129	      (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_STA_MIN)) ||
1130	     /* Check AP version */
1131	     ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP) &&
1132	      (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_AP_MIN))))
1133		quirks |= WL12XX_QUIRK_USE_2_SPARE_BLOCKS;
1134
1135	return quirks;
1136}
1137
1138int wl1271_plt_start(struct wl1271 *wl)
1139{
1140	int retries = WL1271_BOOT_RETRIES;
1141	int ret;
1142
1143	mutex_lock(&wl->mutex);
1144
1145	wl1271_notice("power up");
1146
1147	if (wl->state != WL1271_STATE_OFF) {
1148		wl1271_error("cannot go into PLT state because not "
1149			     "in off state: %d", wl->state);
1150		ret = -EBUSY;
1151		goto out;
1152	}
1153
1154	wl->bss_type = BSS_TYPE_STA_BSS;
1155
1156	while (retries) {
1157		retries--;
1158		ret = wl1271_chip_wakeup(wl);
1159		if (ret < 0)
1160			goto power_off;
1161
1162		ret = wl1271_boot(wl);
1163		if (ret < 0)
1164			goto power_off;
1165
1166		ret = wl1271_plt_init(wl);
1167		if (ret < 0)
1168			goto irq_disable;
1169
1170		wl->state = WL1271_STATE_PLT;
1171		wl1271_notice("firmware booted in PLT mode (%s)",
1172			      wl->chip.fw_ver_str);
1173
1174		/* Check if any quirks are needed with older fw versions */
1175		wl->quirks |= wl1271_get_fw_ver_quirks(wl);
1176		goto out;
1177
1178irq_disable:
1179		mutex_unlock(&wl->mutex);
1180		/* Unlocking the mutex in the middle of handling is
1181		   inherently unsafe. In this case we deem it safe to do,
1182		   because we need to let any possibly pending IRQ out of
1183		   the system (and while we are WL1271_STATE_OFF the IRQ
1184		   work function will not do anything.) Also, any other
1185		   possible concurrent operations will fail due to the
1186		   current state, hence the wl1271 struct should be safe. */
1187		wl1271_disable_interrupts(wl);
1188		wl1271_flush_deferred_work(wl);
1189		cancel_work_sync(&wl->netstack_work);
1190		mutex_lock(&wl->mutex);
1191power_off:
1192		wl1271_power_off(wl);
1193	}
1194
1195	wl1271_error("firmware boot in PLT mode failed despite %d retries",
1196		     WL1271_BOOT_RETRIES);
1197out:
1198	mutex_unlock(&wl->mutex);
1199
1200	return ret;
1201}
1202
1203static int __wl1271_plt_stop(struct wl1271 *wl)
1204{
1205	int ret = 0;
1206
1207	wl1271_notice("power down");
1208
1209	if (wl->state != WL1271_STATE_PLT) {
1210		wl1271_error("cannot power down because not in PLT "
1211			     "state: %d", wl->state);
1212		ret = -EBUSY;
1213		goto out;
1214	}
1215
1216	wl1271_power_off(wl);
1217
1218	wl->state = WL1271_STATE_OFF;
1219	wl->rx_counter = 0;
1220
1221	mutex_unlock(&wl->mutex);
1222	wl1271_disable_interrupts(wl);
1223	wl1271_flush_deferred_work(wl);
1224	cancel_work_sync(&wl->netstack_work);
1225	cancel_work_sync(&wl->recovery_work);
1226	mutex_lock(&wl->mutex);
1227out:
1228	return ret;
1229}
1230
1231int wl1271_plt_stop(struct wl1271 *wl)
1232{
1233	int ret;
1234
1235	mutex_lock(&wl->mutex);
1236	ret = __wl1271_plt_stop(wl);
1237	mutex_unlock(&wl->mutex);
1238	return ret;
1239}
1240
1241static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1242{
1243	struct wl1271 *wl = hw->priv;
1244	unsigned long flags;
1245	int q;
1246	u8 hlid = 0;
1247
1248	q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
1249
1250	if (wl->bss_type == BSS_TYPE_AP_BSS)
1251		hlid = wl1271_tx_get_hlid(skb);
1252
1253	spin_lock_irqsave(&wl->wl_lock, flags);
1254
1255	wl->tx_queue_count++;
1256
1257	/*
1258	 * The workqueue is slow to process the tx_queue and we need stop
1259	 * the queue here, otherwise the queue will get too long.
1260	 */
1261	if (wl->tx_queue_count >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1262		wl1271_debug(DEBUG_TX, "op_tx: stopping queues");
1263		ieee80211_stop_queues(wl->hw);
1264		set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
1265	}
1266
1267	/* queue the packet */
1268	if (wl->bss_type == BSS_TYPE_AP_BSS) {
1269		wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1270		skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1271	} else {
1272		skb_queue_tail(&wl->tx_queue[q], skb);
1273	}
1274
1275	/*
1276	 * The chip specific setup must run before the first TX packet -
1277	 * before that, the tx_work will not be initialized!
1278	 */
1279
1280	if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1281	    !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
1282		ieee80211_queue_work(wl->hw, &wl->tx_work);
1283
1284	spin_unlock_irqrestore(&wl->wl_lock, flags);
1285}
1286
1287int wl1271_tx_dummy_packet(struct wl1271 *wl)
1288{
1289	unsigned long flags;
1290
1291	spin_lock_irqsave(&wl->wl_lock, flags);
1292	set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
1293	wl->tx_queue_count++;
1294	spin_unlock_irqrestore(&wl->wl_lock, flags);
1295
1296	/* The FW is low on RX memory blocks, so send the dummy packet asap */
1297	if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
1298		wl1271_tx_work_locked(wl);
1299
1300	/*
1301	 * If the FW TX is busy, TX work will be scheduled by the threaded
1302	 * interrupt handler function
1303	 */
1304	return 0;
1305}
1306
1307/*
1308 * The size of the dummy packet should be at least 1400 bytes. However, in
1309 * order to minimize the number of bus transactions, aligning it to 512 bytes
1310 * boundaries could be beneficial, performance wise
1311 */
1312#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1313
1314static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
1315{
1316	struct sk_buff *skb;
1317	struct ieee80211_hdr_3addr *hdr;
1318	unsigned int dummy_packet_size;
1319
1320	dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1321			    sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1322
1323	skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
1324	if (!skb) {
1325		wl1271_warning("Failed to allocate a dummy packet skb");
1326		return NULL;
1327	}
1328
1329	skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1330
1331	hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1332	memset(hdr, 0, sizeof(*hdr));
1333	hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1334					 IEEE80211_STYPE_NULLFUNC |
1335					 IEEE80211_FCTL_TODS);
1336
1337	memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
1338
1339	/* Dummy packets require the TID to be management */
1340	skb->priority = WL1271_TID_MGMT;
1341
1342	/* Initialize all fields that might be used */
1343	skb_set_queue_mapping(skb, 0);
1344	memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
1345
1346	return skb;
1347}
1348
1349
1350static struct notifier_block wl1271_dev_notifier = {
1351	.notifier_call = wl1271_dev_notify,
1352};
1353
1354#ifdef CONFIG_PM
1355static int wl1271_configure_suspend(struct wl1271 *wl)
1356{
1357	int ret;
1358
1359	if (wl->bss_type != BSS_TYPE_STA_BSS)
1360		return 0;
1361
1362	mutex_lock(&wl->mutex);
1363
1364	ret = wl1271_ps_elp_wakeup(wl);
1365	if (ret < 0)
1366		goto out_unlock;
1367
1368	/* enter psm if needed*/
1369	if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
1370		DECLARE_COMPLETION_ONSTACK(compl);
1371
1372		wl->ps_compl = &compl;
1373		ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
1374				   wl->basic_rate, true);
1375		if (ret < 0)
1376			goto out_sleep;
1377
1378		/* we must unlock here so we will be able to get events */
1379		wl1271_ps_elp_sleep(wl);
1380		mutex_unlock(&wl->mutex);
1381
1382		ret = wait_for_completion_timeout(
1383			&compl, msecs_to_jiffies(WL1271_PS_COMPLETE_TIMEOUT));
1384		if (ret <= 0) {
1385			wl1271_warning("couldn't enter ps mode!");
1386			ret = -EBUSY;
1387			goto out;
1388		}
1389
1390		/* take mutex again, and wakeup */
1391		mutex_lock(&wl->mutex);
1392
1393		ret = wl1271_ps_elp_wakeup(wl);
1394		if (ret < 0)
1395			goto out_unlock;
1396	}
1397out_sleep:
1398	wl1271_ps_elp_sleep(wl);
1399out_unlock:
1400	mutex_unlock(&wl->mutex);
1401out:
1402	return ret;
1403
1404}
1405
1406static void wl1271_configure_resume(struct wl1271 *wl)
1407{
1408	int ret;
1409
1410	if (wl->bss_type != BSS_TYPE_STA_BSS)
1411		return;
1412
1413	mutex_lock(&wl->mutex);
1414	ret = wl1271_ps_elp_wakeup(wl);
1415	if (ret < 0)
1416		goto out;
1417
1418	/* exit psm if it wasn't configured */
1419	if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags))
1420		wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
1421				   wl->basic_rate, true);
1422
1423	wl1271_ps_elp_sleep(wl);
1424out:
1425	mutex_unlock(&wl->mutex);
1426}
1427
1428static int wl1271_op_suspend(struct ieee80211_hw *hw,
1429			    struct cfg80211_wowlan *wow)
1430{
1431	struct wl1271 *wl = hw->priv;
1432	wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
1433	wl->wow_enabled = !!wow;
1434	if (wl->wow_enabled) {
1435		int ret;
1436		ret = wl1271_configure_suspend(wl);
1437		if (ret < 0) {
1438			wl1271_warning("couldn't prepare device to suspend");
1439			return ret;
1440		}
1441		/* flush any remaining work */
1442		wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
1443		flush_delayed_work(&wl->scan_complete_work);
1444
1445		/*
1446		 * disable and re-enable interrupts in order to flush
1447		 * the threaded_irq
1448		 */
1449		wl1271_disable_interrupts(wl);
1450
1451		/*
1452		 * set suspended flag to avoid triggering a new threaded_irq
1453		 * work. no need for spinlock as interrupts are disabled.
1454		 */
1455		set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1456
1457		wl1271_enable_interrupts(wl);
1458		flush_work(&wl->tx_work);
1459		flush_delayed_work(&wl->pspoll_work);
1460		flush_delayed_work(&wl->elp_work);
1461	}
1462	return 0;
1463}
1464
1465static int wl1271_op_resume(struct ieee80211_hw *hw)
1466{
1467	struct wl1271 *wl = hw->priv;
1468	wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1469		     wl->wow_enabled);
1470
1471	/*
1472	 * re-enable irq_work enqueuing, and call irq_work directly if
1473	 * there is a pending work.
1474	 */
1475	if (wl->wow_enabled) {
1476		struct wl1271 *wl = hw->priv;
1477		unsigned long flags;
1478		bool run_irq_work = false;
1479
1480		spin_lock_irqsave(&wl->wl_lock, flags);
1481		clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1482		if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1483			run_irq_work = true;
1484		spin_unlock_irqrestore(&wl->wl_lock, flags);
1485
1486		if (run_irq_work) {
1487			wl1271_debug(DEBUG_MAC80211,
1488				     "run postponed irq_work directly");
1489			wl1271_irq(0, wl);
1490			wl1271_enable_interrupts(wl);
1491		}
1492
1493		wl1271_configure_resume(wl);
1494	}
1495
1496	return 0;
1497}
1498#endif
1499
1500static int wl1271_op_start(struct ieee80211_hw *hw)
1501{
1502	wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1503
1504	/*
1505	 * We have to delay the booting of the hardware because
1506	 * we need to know the local MAC address before downloading and
1507	 * initializing the firmware. The MAC address cannot be changed
1508	 * after boot, and without the proper MAC address, the firmware
1509	 * will not function properly.
1510	 *
1511	 * The MAC address is first known when the corresponding interface
1512	 * is added. That is where we will initialize the hardware.
1513	 *
1514	 * In addition, we currently have different firmwares for AP and managed
1515	 * operation. We will know which to boot according to interface type.
1516	 */
1517
1518	return 0;
1519}
1520
1521static void wl1271_op_stop(struct ieee80211_hw *hw)
1522{
1523	wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
1524}
1525
1526static int wl1271_op_add_interface(struct ieee80211_hw *hw,
1527				   struct ieee80211_vif *vif)
1528{
1529	struct wl1271 *wl = hw->priv;
1530	struct wiphy *wiphy = hw->wiphy;
1531	int retries = WL1271_BOOT_RETRIES;
1532	int ret = 0;
1533	bool booted = false;
1534
1535	wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
1536		     vif->type, vif->addr);
1537
1538	mutex_lock(&wl->mutex);
1539	if (wl->vif) {
1540		wl1271_debug(DEBUG_MAC80211,
1541			     "multiple vifs are not supported yet");
1542		ret = -EBUSY;
1543		goto out;
1544	}
1545
1546	/*
1547	 * in some very corner case HW recovery scenarios its possible to
1548	 * get here before __wl1271_op_remove_interface is complete, so
1549	 * opt out if that is the case.
1550	 */
1551	if (test_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags)) {
1552		ret = -EBUSY;
1553		goto out;
1554	}
1555
1556	switch (vif->type) {
1557	case NL80211_IFTYPE_STATION:
1558		wl->bss_type = BSS_TYPE_STA_BSS;
1559		wl->set_bss_type = BSS_TYPE_STA_BSS;
1560		break;
1561	case NL80211_IFTYPE_ADHOC:
1562		wl->bss_type = BSS_TYPE_IBSS;
1563		wl->set_bss_type = BSS_TYPE_STA_BSS;
1564		break;
1565	case NL80211_IFTYPE_AP:
1566		wl->bss_type = BSS_TYPE_AP_BSS;
1567		break;
1568	default:
1569		ret = -EOPNOTSUPP;
1570		goto out;
1571	}
1572
1573	memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
1574
1575	if (wl->state != WL1271_STATE_OFF) {
1576		wl1271_error("cannot start because not in off state: %d",
1577			     wl->state);
1578		ret = -EBUSY;
1579		goto out;
1580	}
1581
1582	while (retries) {
1583		retries--;
1584		ret = wl1271_chip_wakeup(wl);
1585		if (ret < 0)
1586			goto power_off;
1587
1588		ret = wl1271_boot(wl);
1589		if (ret < 0)
1590			goto power_off;
1591
1592		ret = wl1271_hw_init(wl);
1593		if (ret < 0)
1594			goto irq_disable;
1595
1596		booted = true;
1597		break;
1598
1599irq_disable:
1600		mutex_unlock(&wl->mutex);
1601		/* Unlocking the mutex in the middle of handling is
1602		   inherently unsafe. In this case we deem it safe to do,
1603		   because we need to let any possibly pending IRQ out of
1604		   the system (and while we are WL1271_STATE_OFF the IRQ
1605		   work function will not do anything.) Also, any other
1606		   possible concurrent operations will fail due to the
1607		   current state, hence the wl1271 struct should be safe. */
1608		wl1271_disable_interrupts(wl);
1609		wl1271_flush_deferred_work(wl);
1610		cancel_work_sync(&wl->netstack_work);
1611		mutex_lock(&wl->mutex);
1612power_off:
1613		wl1271_power_off(wl);
1614	}
1615
1616	if (!booted) {
1617		wl1271_error("firmware boot failed despite %d retries",
1618			     WL1271_BOOT_RETRIES);
1619		goto out;
1620	}
1621
1622	wl->vif = vif;
1623	wl->state = WL1271_STATE_ON;
1624	set_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags);
1625	wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1626
1627	/* update hw/fw version info in wiphy struct */
1628	wiphy->hw_version = wl->chip.id;
1629	strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1630		sizeof(wiphy->fw_version));
1631
1632	/* Check if any quirks are needed with older fw versions */
1633	wl->quirks |= wl1271_get_fw_ver_quirks(wl);
1634
1635	/*
1636	 * Now we know if 11a is supported (info from the NVS), so disable
1637	 * 11a channels if not supported
1638	 */
1639	if (!wl->enable_11a)
1640		wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
1641
1642	wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
1643		     wl->enable_11a ? "" : "not ");
1644
1645out:
1646	mutex_unlock(&wl->mutex);
1647
1648	mutex_lock(&wl_list_mutex);
1649	if (!ret)
1650		list_add(&wl->list, &wl_list);
1651	mutex_unlock(&wl_list_mutex);
1652
1653	return ret;
1654}
1655
1656static void __wl1271_op_remove_interface(struct wl1271 *wl,
1657					 bool reset_tx_queues)
1658{
1659	int i;
1660
1661	wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
1662
1663	/* because of hardware recovery, we may get here twice */
1664	if (wl->state != WL1271_STATE_ON)
1665		return;
1666
1667	wl1271_info("down");
1668
1669	mutex_lock(&wl_list_mutex);
1670	list_del(&wl->list);
1671	mutex_unlock(&wl_list_mutex);
1672
1673	/* enable dyn ps just in case (if left on due to fw crash etc) */
1674	if (wl->bss_type == BSS_TYPE_STA_BSS)
1675		ieee80211_enable_dyn_ps(wl->vif);
1676
1677	if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
1678		wl->scan.state = WL1271_SCAN_STATE_IDLE;
1679		memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
1680		wl->scan.req = NULL;
1681		ieee80211_scan_completed(wl->hw, true);
1682	}
1683
1684	/*
1685	 * this must be before the cancel_work calls below, so that the work
1686	 * functions don't perform further work.
1687	 */
1688	wl->state = WL1271_STATE_OFF;
1689
1690	mutex_unlock(&wl->mutex);
1691
1692	wl1271_disable_interrupts(wl);
1693	wl1271_flush_deferred_work(wl);
1694	cancel_delayed_work_sync(&wl->scan_complete_work);
1695	cancel_work_sync(&wl->netstack_work);
1696	cancel_work_sync(&wl->tx_work);
1697	cancel_delayed_work_sync(&wl->pspoll_work);
1698	cancel_delayed_work_sync(&wl->elp_work);
1699
1700	mutex_lock(&wl->mutex);
1701
1702	/* let's notify MAC80211 about the remaining pending TX frames */
1703	wl1271_tx_reset(wl, reset_tx_queues);
1704	wl1271_power_off(wl);
1705
1706	memset(wl->bssid, 0, ETH_ALEN);
1707	memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
1708	wl->ssid_len = 0;
1709	wl->bss_type = MAX_BSS_TYPE;
1710	wl->set_bss_type = MAX_BSS_TYPE;
1711	wl->band = IEEE80211_BAND_2GHZ;
1712
1713	wl->rx_counter = 0;
1714	wl->psm_entry_retry = 0;
1715	wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1716	wl->tx_blocks_available = 0;
1717	wl->tx_allocated_blocks = 0;
1718	wl->tx_results_count = 0;
1719	wl->tx_packets_count = 0;
1720	wl->tx_security_last_seq = 0;
1721	wl->tx_security_seq = 0;
1722	wl->time_offset = 0;
1723	wl->session_counter = 0;
1724	wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1725	wl->vif = NULL;
1726	wl->filters = 0;
1727	wl1271_free_ap_keys(wl);
1728	memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map));
1729	wl->ap_fw_ps_map = 0;
1730	wl->ap_ps_map = 0;
1731	wl->sched_scanning = false;
1732
1733	/*
1734	 * this is performed after the cancel_work calls and the associated
1735	 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1736	 * get executed before all these vars have been reset.
1737	 */
1738	wl->flags = 0;
1739
1740	for (i = 0; i < NUM_TX_QUEUES; i++)
1741		wl->tx_blocks_freed[i] = 0;
1742
1743	wl1271_debugfs_reset(wl);
1744
1745	kfree(wl->fw_status);
1746	wl->fw_status = NULL;
1747	kfree(wl->tx_res_if);
1748	wl->tx_res_if = NULL;
1749	kfree(wl->target_mem_map);
1750	wl->target_mem_map = NULL;
1751}
1752
1753static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
1754				       struct ieee80211_vif *vif)
1755{
1756	struct wl1271 *wl = hw->priv;
1757
1758	mutex_lock(&wl->mutex);
1759	/*
1760	 * wl->vif can be null here if someone shuts down the interface
1761	 * just when hardware recovery has been started.
1762	 */
1763	if (wl->vif) {
1764		WARN_ON(wl->vif != vif);
1765		__wl1271_op_remove_interface(wl, true);
1766	}
1767
1768	mutex_unlock(&wl->mutex);
1769	cancel_work_sync(&wl->recovery_work);
1770}
1771
1772void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters)
1773{
1774	wl1271_set_default_filters(wl);
1775
1776	/* combine requested filters with current filter config */
1777	filters = wl->filters | filters;
1778
1779	wl1271_debug(DEBUG_FILTERS, "RX filters set: ");
1780
1781	if (filters & FIF_PROMISC_IN_BSS) {
1782		wl1271_debug(DEBUG_FILTERS, " - FIF_PROMISC_IN_BSS");
1783		wl->rx_config &= ~CFG_UNI_FILTER_EN;
1784		wl->rx_config |= CFG_BSSID_FILTER_EN;
1785	}
1786	if (filters & FIF_BCN_PRBRESP_PROMISC) {
1787		wl1271_debug(DEBUG_FILTERS, " - FIF_BCN_PRBRESP_PROMISC");
1788		wl->rx_config &= ~CFG_BSSID_FILTER_EN;
1789		wl->rx_config &= ~CFG_SSID_FILTER_EN;
1790	}
1791	if (filters & FIF_OTHER_BSS) {
1792		wl1271_debug(DEBUG_FILTERS, " - FIF_OTHER_BSS");
1793		wl->rx_config &= ~CFG_BSSID_FILTER_EN;
1794	}
1795	if (filters & FIF_CONTROL) {
1796		wl1271_debug(DEBUG_FILTERS, " - FIF_CONTROL");
1797		wl->rx_filter |= CFG_RX_CTL_EN;
1798	}
1799	if (filters & FIF_FCSFAIL) {
1800		wl1271_debug(DEBUG_FILTERS, " - FIF_FCSFAIL");
1801		wl->rx_filter |= CFG_RX_FCS_ERROR;
1802	}
1803}
1804
1805static int wl1271_dummy_join(struct wl1271 *wl)
1806{
1807	int ret = 0;
1808	/* we need to use a dummy BSSID for now */
1809	static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde,
1810						  0xad, 0xbe, 0xef };
1811
1812	memcpy(wl->bssid, dummy_bssid, ETH_ALEN);
1813
1814	/* pass through frames from all BSS */
1815	wl1271_configure_filters(wl, FIF_OTHER_BSS);
1816
1817	ret = wl1271_cmd_join(wl, wl->set_bss_type);
1818	if (ret < 0)
1819		goto out;
1820
1821	set_bit(WL1271_FLAG_JOINED, &wl->flags);
1822
1823out:
1824	return ret;
1825}
1826
1827static int wl1271_join(struct wl1271 *wl, bool set_assoc)
1828{
1829	int ret;
1830
1831	/*
1832	 * One of the side effects of the JOIN command is that is clears
1833	 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
1834	 * to a WPA/WPA2 access point will therefore kill the data-path.
1835	 * Currently the only valid scenario for JOIN during association
1836	 * is on roaming, in which case we will also be given new keys.
1837	 * Keep the below message for now, unless it starts bothering
1838	 * users who really like to roam a lot :)
1839	 */
1840	if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1841		wl1271_info("JOIN while associated.");
1842
1843	if (set_assoc)
1844		set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
1845
1846	ret = wl1271_cmd_join(wl, wl->set_bss_type);
1847	if (ret < 0)
1848		goto out;
1849
1850	set_bit(WL1271_FLAG_JOINED, &wl->flags);
1851
1852	if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1853		goto out;
1854
1855	/*
1856	 * The join command disable the keep-alive mode, shut down its process,
1857	 * and also clear the template config, so we need to reset it all after
1858	 * the join. The acx_aid starts the keep-alive process, and the order
1859	 * of the commands below is relevant.
1860	 */
1861	ret = wl1271_acx_keep_alive_mode(wl, true);
1862	if (ret < 0)
1863		goto out;
1864
1865	ret = wl1271_acx_aid(wl, wl->a

Large files files are truncated, but you can click here to view the full file