power.c 19.1 KB
Newer Older
J
Johannes Berg 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/******************************************************************************
 *
 * This file is provided under a dual BSD/GPLv2 license.  When using or
 * redistributing this file, you may do so under either license.
 *
 * GPL LICENSE SUMMARY
 *
 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
 * USA
 *
 * The full GNU General Public License is included in this distribution
25
 * in the file called COPYING.
J
Johannes Berg 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
 *
 * Contact Information:
 *  Intel Linux Wireless <ilw@linux.intel.com>
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *
 * BSD LICENSE
 *
 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name Intel Corporation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>

#include <net/mac80211.h>

#include "iwl-debug.h"
#include "mvm.h"
#include "iwl-modparams.h"
#include "fw-api-power.h"

#define POWER_KEEP_ALIVE_PERIOD_SEC    25

78 79
int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
				   struct iwl_beacon_filter_cmd *cmd)
80 81 82 83 84 85 86 87
{
	int ret;

	ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, CMD_SYNC,
				   sizeof(struct iwl_beacon_filter_cmd), cmd);

	if (!ret) {
		IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
88
				le32_to_cpu(cmd->ba_enable_beacon_abort));
89
		IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
90
				le32_to_cpu(cmd->ba_escape_timer));
91
		IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
92
				le32_to_cpu(cmd->bf_debug_flag));
93
		IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
94
				le32_to_cpu(cmd->bf_enable_beacon_filter));
95
		IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
96
				le32_to_cpu(cmd->bf_energy_delta));
97
		IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
98
				le32_to_cpu(cmd->bf_escape_timer));
99
		IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
100
				le32_to_cpu(cmd->bf_roaming_energy_delta));
101
		IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
102 103 104 105 106 107 108
				le32_to_cpu(cmd->bf_roaming_state));
		IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
				le32_to_cpu(cmd->bf_temp_threshold));
		IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
				le32_to_cpu(cmd->bf_temp_fast_filter));
		IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
				le32_to_cpu(cmd->bf_temp_slow_filter));
109 110 111 112
	}
	return ret;
}

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
static
void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
					  struct ieee80211_vif *vif,
					  struct iwl_beacon_filter_cmd *cmd)
{
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);

	if (vif->bss_conf.cqm_rssi_thold) {
		cmd->bf_energy_delta =
			cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
		/* fw uses an absolute value for this */
		cmd->bf_roaming_state =
			cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
	}
	cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
}

130 131
int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
				struct ieee80211_vif *vif, bool enable)
132 133 134 135
{
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
	struct iwl_beacon_filter_cmd cmd = {
		IWL_BF_CMD_CONFIG_DEFAULTS,
136 137
		.bf_enable_beacon_filter = cpu_to_le32(1),
		.ba_enable_beacon_abort = cpu_to_le32(enable),
138 139
	};

140
	if (!mvmvif->bf_data.bf_enabled)
141 142
		return 0;

143 144 145
	if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
		cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);

146 147
	mvmvif->bf_data.ba_enabled = enable;
	iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
148
	iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
149 150 151
	return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
}

152
static void iwl_mvm_power_log(struct iwl_mvm *mvm,
153
			      struct iwl_mac_power_cmd *cmd)
154 155
{
	IWL_DEBUG_POWER(mvm,
156 157
			"Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
			cmd->id_and_color, iwlmvm_mod_params.power_scheme,
158
			le16_to_cpu(cmd->flags));
159 160
	IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
			le16_to_cpu(cmd->keep_alive_seconds));
161

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
	if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
		IWL_DEBUG_POWER(mvm, "Disable power management\n");
		return;
	}

	IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
			le32_to_cpu(cmd->rx_data_timeout));
	IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
			le32_to_cpu(cmd->tx_data_timeout));
	if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
		IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
				cmd->skip_dtim_periods);
	if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
		IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
				cmd->lprx_rssi_threshold);
	if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
		IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
		IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
				le32_to_cpu(cmd->rx_data_timeout_uapsd));
		IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
				le32_to_cpu(cmd->tx_data_timeout_uapsd));
		IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
		IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
		IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
186 187 188
	}
}

189 190 191
static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
				    struct ieee80211_vif *vif,
				    struct iwl_mac_power_cmd *cmd)
J
Johannes Berg 已提交
192 193 194 195 196 197 198
{
	struct ieee80211_hw *hw = mvm->hw;
	struct ieee80211_chanctx_conf *chanctx_conf;
	struct ieee80211_channel *chan;
	int dtimper, dtimper_msec;
	int keep_alive;
	bool radar_detect = false;
199 200
	struct iwl_mvm_vif *mvmvif __maybe_unused =
		iwl_mvm_vif_from_mac80211(vif);
201 202
	enum ieee80211_ac_numbers ac;
	bool tid_found = false;
J
Johannes Berg 已提交
203

204 205 206 207
	cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
							    mvmvif->color));
	dtimper = hw->conf.ps_dtim_period ?: 1;

208 209 210
	/*
	 * Regardless of power management state the driver must set
	 * keep alive period. FW will use it for sending keep alive NDPs
211 212
	 * immediately after association. Check that keep alive period
	 * is at least 3 * DTIM
213
	 */
214 215 216 217 218
	dtimper_msec = dtimper * vif->bss_conf.beacon_int;
	keep_alive = max_t(int, 3 * dtimper_msec,
			   MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
	keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
	cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
219

220
	if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
J
Johannes Berg 已提交
221 222
		return;

223 224
	cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);

225 226 227 228 229
#ifdef CONFIG_IWLWIFI_DEBUGFS
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
	    mvmvif->dbgfs_pm.disable_power_off)
		cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
#endif
230 231 232 233
	if (!vif->bss_conf.ps)
		return;

	cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
J
Johannes Berg 已提交
234

235 236 237 238
	if (vif->bss_conf.beacon_rate &&
	    (vif->bss_conf.beacon_rate->bitrate == 10 ||
	     vif->bss_conf.beacon_rate->bitrate == 60)) {
		cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
239
		cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
240 241
	}

J
Johannes Berg 已提交
242 243 244 245 246 247 248 249 250 251 252 253
	/* Check if radar detection is required on current channel */
	rcu_read_lock();
	chanctx_conf = rcu_dereference(vif->chanctx_conf);
	WARN_ON(!chanctx_conf);
	if (chanctx_conf) {
		chan = chanctx_conf->def.chan;
		radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
	}
	rcu_read_unlock();

	/* Check skip over DTIM conditions */
	if (!radar_detect && (dtimper <= 10) &&
254 255
	    (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
	     mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
256
		cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
257
		cmd->skip_dtim_periods = 3;
258
	}
J
Johannes Berg 已提交
259

260
	if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
261 262 263 264
		cmd->rx_data_timeout =
			cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
		cmd->tx_data_timeout =
			cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
265
	} else {
266 267 268 269
		cmd->rx_data_timeout =
			cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
		cmd->tx_data_timeout =
			cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
270
	}
271

272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
	for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
		if (!mvmvif->queue_params[ac].uapsd)
			continue;

		cmd->flags |= cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
		cmd->uapsd_ac_flags |= BIT(ac);

		/* QNDP TID - the highest TID with no admission control */
		if (!tid_found && !mvmvif->queue_params[ac].acm) {
			tid_found = true;
			switch (ac) {
			case IEEE80211_AC_VO:
				cmd->qndp_tid = 6;
				break;
			case IEEE80211_AC_VI:
				cmd->qndp_tid = 5;
				break;
			case IEEE80211_AC_BE:
				cmd->qndp_tid = 0;
				break;
			case IEEE80211_AC_BK:
				cmd->qndp_tid = 1;
				break;
			}
		}
	}

	if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
		cmd->rx_data_timeout_uapsd =
			cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
		cmd->tx_data_timeout_uapsd =
			cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
		cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
		cmd->heavy_tx_thld_packets =
			IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
		cmd->heavy_rx_thld_packets =
			IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
		cmd->heavy_tx_thld_percentage =
			IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
		cmd->heavy_rx_thld_percentage =
			IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
	}

315 316
#ifdef CONFIG_IWLWIFI_DEBUGFS
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
317 318
		cmd->keep_alive_seconds =
			cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
		if (mvmvif->dbgfs_pm.skip_over_dtim)
			cmd->flags |=
				cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
		else
			cmd->flags &=
				cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
	}
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
		cmd->rx_data_timeout =
			cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
		cmd->tx_data_timeout =
			cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
334
		cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
335 336 337 338 339 340 341
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
		if (mvmvif->dbgfs_pm.lprx_ena)
			cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
		else
			cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
	}
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
342
		cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
343
#endif /* CONFIG_IWLWIFI_DEBUGFS */
J
Johannes Berg 已提交
344 345
}

346 347
static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
					 struct ieee80211_vif *vif)
J
Johannes Berg 已提交
348
{
349 350
	int ret;
	bool ba_enable;
351
	struct iwl_mac_power_cmd cmd = {};
J
Johannes Berg 已提交
352 353 354 355

	if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
		return 0;

356 357 358 359 360 361 362 363 364 365 366
	/*
	 * TODO: The following vif_count verification is temporary condition.
	 * Avoid power mode update if more than one interface is currently
	 * active. Remove this condition when FW will support power management
	 * on multiple MACs.
	 */
	IWL_DEBUG_POWER(mvm, "Currently %d interfaces active\n",
			mvm->vif_count);
	if (mvm->vif_count > 1)
		return 0;

367
	iwl_mvm_power_build_cmd(mvm, vif, &cmd);
368
	iwl_mvm_power_log(mvm, &cmd);
J
Johannes Berg 已提交
369

370
	ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
371 372 373 374 375 376 377 378
				   sizeof(cmd), &cmd);
	if (ret)
		return ret;

	ba_enable = !!(cmd.flags &
		       cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK));

	return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable);
J
Johannes Berg 已提交
379 380
}

381 382
static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm,
				     struct ieee80211_vif *vif)
J
Johannes Berg 已提交
383
{
384
	struct iwl_mac_power_cmd cmd = {};
385 386
	struct iwl_mvm_vif *mvmvif __maybe_unused =
		iwl_mvm_vif_from_mac80211(vif);
J
Johannes Berg 已提交
387 388 389 390

	if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
		return 0;

391 392 393
	cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
							   mvmvif->color));

394
	if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
395 396
		cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);

397 398 399 400 401
#ifdef CONFIG_IWLWIFI_DEBUGFS
	if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
	    mvmvif->dbgfs_pm.disable_power_off)
		cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
#endif
402
	iwl_mvm_power_log(mvm, &cmd);
J
Johannes Berg 已提交
403

404
	return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC,
J
Johannes Berg 已提交
405 406
				    sizeof(cmd), &cmd);
}
407

408
#ifdef CONFIG_IWLWIFI_DEBUGFS
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
					struct ieee80211_vif *vif, char *buf,
					int bufsz)
{
	struct iwl_mac_power_cmd cmd = {};
	int pos = 0;

	iwl_mvm_power_build_cmd(mvm, vif, &cmd);

	pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
			 (cmd.flags &
			 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
			 0 : 1);
	pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
			 iwlmvm_mod_params.power_scheme);
	pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
			 le16_to_cpu(cmd.flags));
	pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
			 le16_to_cpu(cmd.keep_alive_seconds));

	if (cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) {
		pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
				 (cmd.flags &
				 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ?
				 1 : 0);
434 435 436 437 438 439 440 441 442 443 444
		pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
				 cmd.skip_dtim_periods);
		if (!(cmd.flags &
		      cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
			pos += scnprintf(buf+pos, bufsz-pos,
					 "rx_data_timeout = %d\n",
					 le32_to_cpu(cmd.rx_data_timeout));
			pos += scnprintf(buf+pos, bufsz-pos,
					 "tx_data_timeout = %d\n",
					 le32_to_cpu(cmd.tx_data_timeout));
		}
445 446 447 448
		if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
			pos += scnprintf(buf+pos, bufsz-pos,
					 "lprx_rssi_threshold = %d\n",
					 cmd.lprx_rssi_threshold);
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
		if (cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
			pos +=
			scnprintf(buf+pos, bufsz-pos,
				  "rx_data_timeout_uapsd = %d\n",
				  le32_to_cpu(cmd.rx_data_timeout_uapsd));
			pos +=
			scnprintf(buf+pos, bufsz-pos,
				  "tx_data_timeout_uapsd = %d\n",
				  le32_to_cpu(cmd.tx_data_timeout_uapsd));
			pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n",
					 cmd.qndp_tid);
			pos += scnprintf(buf+pos, bufsz-pos,
					 "uapsd_ac_flags = 0x%x\n",
					 cmd.uapsd_ac_flags);
			pos += scnprintf(buf+pos, bufsz-pos,
					 "uapsd_max_sp = %d\n",
					 cmd.uapsd_max_sp);
			pos += scnprintf(buf+pos, bufsz-pos,
					 "heavy_tx_thld_packets = %d\n",
					 cmd.heavy_tx_thld_packets);
			pos += scnprintf(buf+pos, bufsz-pos,
					 "heavy_rx_thld_packets = %d\n",
					 cmd.heavy_rx_thld_packets);
			pos += scnprintf(buf+pos, bufsz-pos,
					 "heavy_tx_thld_percentage = %d\n",
					 cmd.heavy_tx_thld_percentage);
			pos += scnprintf(buf+pos, bufsz-pos,
					 "heavy_rx_thld_percentage = %d\n",
					 cmd.heavy_rx_thld_percentage);
		}
479 480 481 482
	}
	return pos;
}

483 484 485 486 487 488 489 490
void
iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
					 struct iwl_beacon_filter_cmd *cmd)
{
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
	struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;

	if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
491
		cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
492 493
	if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
		cmd->bf_roaming_energy_delta =
494
				cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
495
	if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
496 497 498 499 500 501 502 503 504 505
		cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
	if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
		cmd->bf_temp_threshold =
				cpu_to_le32(dbgfs_bf->bf_temp_threshold);
	if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
		cmd->bf_temp_fast_filter =
				cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
	if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
		cmd->bf_temp_slow_filter =
				cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
506
	if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
507
		cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
508 509 510 511 512
	if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
		cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
	if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
		cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
	if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
513 514
		cmd->ba_enable_beacon_abort =
				cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
515 516 517
}
#endif

518 519 520 521 522
int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
				 struct ieee80211_vif *vif)
{
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
	struct iwl_beacon_filter_cmd cmd = {
523
		IWL_BF_CMD_CONFIG_DEFAULTS,
524
		.bf_enable_beacon_filter = cpu_to_le32(1),
525
	};
526
	int ret;
527 528 529 530 531

	if (mvmvif != mvm->bf_allowed_vif ||
	    vif->type != NL80211_IFTYPE_STATION || vif->p2p)
		return 0;

532
	iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
533
	iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
534 535 536
	ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);

	if (!ret)
537
		mvmvif->bf_data.bf_enabled = true;
538 539

	return ret;
540 541 542 543 544
}

int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
				  struct ieee80211_vif *vif)
{
545 546 547
	struct iwl_beacon_filter_cmd cmd = {};
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
	int ret;
548

549 550
	if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
	    vif->type != NL80211_IFTYPE_STATION || vif->p2p)
551 552
		return 0;

553 554 555
	ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);

	if (!ret)
556
		mvmvif->bf_data.bf_enabled = false;
557 558

	return ret;
559
}
560

561 562 563 564 565 566 567 568 569 570 571
int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm,
				 struct ieee80211_vif *vif)
{
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);

	if (!mvmvif->bf_data.bf_enabled)
		return 0;

	return iwl_mvm_enable_beacon_filter(mvm, vif);
}

572 573 574 575 576 577 578
const struct iwl_mvm_power_ops pm_mac_ops = {
	.power_update_mode = iwl_mvm_power_mac_update_mode,
	.power_disable = iwl_mvm_power_mac_disable,
#ifdef CONFIG_IWLWIFI_DEBUGFS
	.power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read,
#endif
};