“98ba073c606fba7a48a8e0d36e3b02105d31c768”上不存在“git@gitcode.net:openanolis/cloud-kernel.git”
htc_drv_main.c 41.8 KB
Newer Older
S
Sujith 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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
/*
 * Copyright (c) 2010 Atheros Communications Inc.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "htc.h"

/*************/
/* Utilities */
/*************/

/* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
					      struct ath9k_channel *ichan)
{
	enum htc_phymode mode;

	mode = HTC_MODE_AUTO;

	switch (ichan->chanmode) {
	case CHANNEL_G:
	case CHANNEL_G_HT20:
	case CHANNEL_G_HT40PLUS:
	case CHANNEL_G_HT40MINUS:
		mode = HTC_MODE_11NG;
		break;
	case CHANNEL_A:
	case CHANNEL_A_HT20:
	case CHANNEL_A_HT40PLUS:
	case CHANNEL_A_HT40MINUS:
		mode = HTC_MODE_11NA;
		break;
	default:
		break;
	}

	return mode;
}

S
Sujith Manoharan 已提交
51 52
bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
			enum ath9k_power_mode mode)
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 78 79
{
	bool ret;

	mutex_lock(&priv->htc_pm_lock);
	ret = ath9k_hw_setpower(priv->ah, mode);
	mutex_unlock(&priv->htc_pm_lock);

	return ret;
}

void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
{
	mutex_lock(&priv->htc_pm_lock);
	if (++priv->ps_usecount != 1)
		goto unlock;
	ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);

unlock:
	mutex_unlock(&priv->htc_pm_lock);
}

void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
{
	mutex_lock(&priv->htc_pm_lock);
	if (--priv->ps_usecount != 0)
		goto unlock;

80 81 82
	if (priv->ps_idle)
		ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
	else if (priv->ps_enabled)
83
		ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
84

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
unlock:
	mutex_unlock(&priv->htc_pm_lock);
}

void ath9k_ps_work(struct work_struct *work)
{
	struct ath9k_htc_priv *priv =
		container_of(work, struct ath9k_htc_priv,
			     ps_work);
	ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);

	/* The chip wakes up after receiving the first beacon
	   while network sleep is enabled. For the driver to
	   be in sync with the hw, set the chip to awake and
	   only then set it to sleep.
	 */
	ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
}

104 105 106 107 108
static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
{
	struct ath9k_htc_priv *priv = data;
	struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;

109 110 111
	if ((vif->type == NL80211_IFTYPE_AP) && bss_conf->enable_beacon)
		priv->reconfig_beacon = true;

112 113 114 115 116 117 118 119 120 121 122 123 124 125
	if (bss_conf->assoc) {
		priv->rearm_ani = true;
		priv->reconfig_beacon = true;
	}
}

static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv)
{
	priv->rearm_ani = false;
	priv->reconfig_beacon = false;

	ieee80211_iterate_active_interfaces_atomic(priv->hw,
						   ath9k_htc_vif_iter, priv);
	if (priv->rearm_ani)
126
		ath9k_htc_start_ani(priv);
127 128 129 130 131 132 133 134

	if (priv->reconfig_beacon) {
		ath9k_htc_ps_wakeup(priv);
		ath9k_htc_beacon_reconfig(priv);
		ath9k_htc_ps_restore(priv);
	}
}

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
{
	struct ath9k_vif_iter_data *iter_data = data;
	int i;

	for (i = 0; i < ETH_ALEN; i++)
		iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
}

static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
				     struct ieee80211_vif *vif)
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_vif_iter_data iter_data;

	/*
	 * Use the hardware MAC address as reference, the hardware uses it
	 * together with the BSSID mask when matching addresses.
	 */
	iter_data.hw_macaddr = common->macaddr;
	memset(&iter_data.mask, 0xff, ETH_ALEN);

	if (vif)
		ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);

	/* Get list of all active MAC addresses */
	ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter,
						   &iter_data);

	memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
	ath_hw_setbssidmask(common);
}

168 169 170 171 172 173 174 175 176 177 178 179
static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv)
{
	if (priv->num_ibss_vif)
		priv->ah->opmode = NL80211_IFTYPE_ADHOC;
	else if (priv->num_ap_vif)
		priv->ah->opmode = NL80211_IFTYPE_AP;
	else
		priv->ah->opmode = NL80211_IFTYPE_STATION;

	ath9k_hw_setopmode(priv->ah);
}

180 181 182 183 184
void ath9k_htc_reset(struct ath9k_htc_priv *priv)
{
	struct ath_hw *ah = priv->ah;
	struct ath_common *common = ath9k_hw_common(ah);
	struct ieee80211_channel *channel = priv->hw->conf.channel;
185
	struct ath9k_hw_cal_data *caldata = NULL;
186 187 188 189 190 191 192 193
	enum htc_phymode mode;
	__be16 htc_mode;
	u8 cmd_rsp;
	int ret;

	mutex_lock(&priv->mutex);
	ath9k_htc_ps_wakeup(priv);

194
	ath9k_htc_stop_ani(priv);
195
	ieee80211_stop_queues(priv->hw);
196

197
	del_timer_sync(&priv->tx.cleanup_timer);
198 199
	ath9k_htc_tx_drain(priv);

200 201 202 203
	WMI_CMD(WMI_DISABLE_INTR_CMDID);
	WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
	WMI_CMD(WMI_STOP_RECV_CMDID);

S
Sujith Manoharan 已提交
204 205
	ath9k_wmi_event_drain(priv);

206
	caldata = &priv->caldata;
207 208 209 210 211 212 213
	ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
	if (ret) {
		ath_err(common,
			"Unable to reset device (%u Mhz) reset status %d\n",
			channel->center_freq, ret);
	}

214 215
	ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
			       &priv->curtxpow);
216 217 218 219 220 221 222 223 224 225

	WMI_CMD(WMI_START_RECV_CMDID);
	ath9k_host_rx_init(priv);

	mode = ath9k_htc_get_curmode(priv, ah->curchan);
	htc_mode = cpu_to_be16(mode);
	WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);

	WMI_CMD(WMI_ENABLE_INTR_CMDID);
	htc_start(priv->htc);
226
	ath9k_htc_vif_reconfig(priv);
227 228
	ieee80211_wake_queues(priv->hw);

229 230 231
	mod_timer(&priv->tx.cleanup_timer,
		  jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));

232 233 234 235
	ath9k_htc_ps_restore(priv);
	mutex_unlock(&priv->mutex);
}

S
Sujith 已提交
236 237 238 239 240 241 242
static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
				 struct ieee80211_hw *hw,
				 struct ath9k_channel *hchan)
{
	struct ath_hw *ah = priv->ah;
	struct ath_common *common = ath9k_hw_common(ah);
	struct ieee80211_conf *conf = &common->hw->conf;
243
	bool fastcc;
S
Sujith 已提交
244
	struct ieee80211_channel *channel = hw->conf.channel;
245
	struct ath9k_hw_cal_data *caldata = NULL;
S
Sujith 已提交
246
	enum htc_phymode mode;
S
Sujith 已提交
247
	__be16 htc_mode;
S
Sujith 已提交
248 249 250 251 252 253
	u8 cmd_rsp;
	int ret;

	if (priv->op_flags & OP_INVALID)
		return -EIO;

254
	fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
S
Sujith 已提交
255

256
	ath9k_htc_ps_wakeup(priv);
257

258
	del_timer_sync(&priv->tx.cleanup_timer);
259 260
	ath9k_htc_tx_drain(priv);

S
Sujith 已提交
261 262 263 264
	WMI_CMD(WMI_DISABLE_INTR_CMDID);
	WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
	WMI_CMD(WMI_STOP_RECV_CMDID);

S
Sujith Manoharan 已提交
265 266
	ath9k_wmi_event_drain(priv);

J
Joe Perches 已提交
267 268 269 270 271
	ath_dbg(common, ATH_DBG_CONFIG,
		"(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
		priv->ah->curchan->channel,
		channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
		fastcc);
S
Sujith 已提交
272

273 274
	if (!fastcc)
		caldata = &priv->caldata;
275

276
	ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
S
Sujith 已提交
277
	if (ret) {
278 279 280
		ath_err(common,
			"Unable to reset channel (%u Mhz) reset status %d\n",
			channel->center_freq, ret);
S
Sujith 已提交
281 282 283
		goto err;
	}

284 285
	ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
			       &priv->curtxpow);
S
Sujith 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303

	WMI_CMD(WMI_START_RECV_CMDID);
	if (ret)
		goto err;

	ath9k_host_rx_init(priv);

	mode = ath9k_htc_get_curmode(priv, hchan);
	htc_mode = cpu_to_be16(mode);
	WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
	if (ret)
		goto err;

	WMI_CMD(WMI_ENABLE_INTR_CMDID);
	if (ret)
		goto err;

	htc_start(priv->htc);
304 305 306 307 308

	if (!(priv->op_flags & OP_SCANNING) &&
	    !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
		ath9k_htc_vif_reconfig(priv);

309 310 311
	mod_timer(&priv->tx.cleanup_timer,
		  jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));

S
Sujith 已提交
312
err:
313
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
314 315 316
	return ret;
}

317 318 319 320 321 322 323
/*
 * Monitor mode handling is a tad complicated because the firmware requires
 * an interface to be created exclusively, while mac80211 doesn't associate
 * an interface with the mode.
 *
 * So, for now, only one monitor interface can be configured.
 */
324 325 326 327 328 329 330 331 332
static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_htc_target_vif hvif;
	int ret = 0;
	u8 cmd_rsp;

	memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
	memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
333
	hvif.index = priv->mon_vif_idx;
334
	WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
335 336 337 338 339
	if (ret) {
		ath_err(common, "Unable to remove monitor interface at idx: %d\n",
			priv->mon_vif_idx);
	}

340
	priv->nvifs--;
341
	priv->vif_slot &= ~(1 << priv->mon_vif_idx);
342 343
}

344 345 346 347
static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_htc_target_vif hvif;
348
	struct ath9k_htc_target_sta tsta;
349
	int ret = 0, sta_idx;
350 351
	u8 cmd_rsp;

352 353 354 355 356
	if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
	    (priv->nstations >= ATH9K_HTC_MAX_STA)) {
		ret = -ENOBUFS;
		goto err_vif;
	}
357

358 359 360 361 362
	sta_idx = ffz(priv->sta_slot);
	if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
		ret = -ENOBUFS;
		goto err_vif;
	}
363 364 365 366

	/*
	 * Add an interface.
	 */
367 368 369
	memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
	memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);

370
	hvif.opmode = HTC_M_MONITOR;
371
	hvif.index = ffz(priv->vif_slot);
372 373 374

	WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
	if (ret)
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
		goto err_vif;

	/*
	 * Assign the monitor interface index as a special case here.
	 * This is needed when the interface is brought down.
	 */
	priv->mon_vif_idx = hvif.index;
	priv->vif_slot |= (1 << hvif.index);

	/*
	 * Set the hardware mode to monitor only if there are no
	 * other interfaces.
	 */
	if (!priv->nvifs)
		priv->ah->opmode = NL80211_IFTYPE_MONITOR;
390 391

	priv->nvifs++;
392 393 394 395 396 397 398 399 400

	/*
	 * Associate a station with the interface for packet injection.
	 */
	memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));

	memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);

	tsta.is_vif_sta = 1;
401
	tsta.sta_index = sta_idx;
402
	tsta.vif_index = hvif.index;
403
	tsta.maxampdu = cpu_to_be16(0xffff);
404 405 406 407

	WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
	if (ret) {
		ath_err(common, "Unable to add station entry for monitor mode\n");
408
		goto err_sta;
409 410
	}

411
	priv->sta_slot |= (1 << sta_idx);
412
	priv->nstations++;
413
	priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
414 415
	priv->ah->is_monitoring = true;

416 417 418 419
	ath_dbg(common, ATH_DBG_CONFIG,
		"Attached a monitor interface at idx: %d, sta idx: %d\n",
		priv->mon_vif_idx, sta_idx);

420
	return 0;
421

422
err_sta:
423 424 425 426
	/*
	 * Remove the interface from the target.
	 */
	__ath9k_htc_remove_monitor_interface(priv);
427 428 429
err_vif:
	ath_dbg(common, ATH_DBG_FATAL, "Unable to attach a monitor interface\n");

430
	return ret;
431 432 433 434 435 436
}

static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	int ret = 0;
437
	u8 cmd_rsp, sta_idx;
438

439
	__ath9k_htc_remove_monitor_interface(priv);
440

441
	sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
442 443 444 445 446 447 448

	WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
	if (ret) {
		ath_err(common, "Unable to remove station entry for monitor mode\n");
		return ret;
	}

449
	priv->sta_slot &= ~(1 << sta_idx);
450
	priv->nstations--;
451
	priv->ah->is_monitoring = false;
452

453 454 455 456
	ath_dbg(common, ATH_DBG_CONFIG,
		"Removed a monitor interface at idx: %d, sta idx: %d\n",
		priv->mon_vif_idx, sta_idx);

457
	return 0;
458 459
}

S
Sujith 已提交
460 461 462 463 464 465 466 467
static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
				 struct ieee80211_vif *vif,
				 struct ieee80211_sta *sta)
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_htc_target_sta tsta;
	struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
	struct ath9k_htc_sta *ista;
468
	int ret, sta_idx;
S
Sujith 已提交
469 470 471 472 473
	u8 cmd_rsp;

	if (priv->nstations >= ATH9K_HTC_MAX_STA)
		return -ENOBUFS;

474 475 476 477
	sta_idx = ffz(priv->sta_slot);
	if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
		return -ENOBUFS;

S
Sujith 已提交
478 479 480 481 482 483 484
	memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));

	if (sta) {
		ista = (struct ath9k_htc_sta *) sta->drv_priv;
		memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
		memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
		tsta.is_vif_sta = 0;
485
		ista->index = sta_idx;
S
Sujith 已提交
486 487 488 489 490
	} else {
		memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
		tsta.is_vif_sta = 1;
	}

491
	tsta.sta_index = sta_idx;
S
Sujith 已提交
492
	tsta.vif_index = avp->index;
493
	tsta.maxampdu = cpu_to_be16(0xffff);
S
Sujith 已提交
494 495 496 497 498 499
	if (sta && sta->ht_cap.ht_supported)
		tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);

	WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
	if (ret) {
		if (sta)
500 501 502
			ath_err(common,
				"Unable to add station entry for: %pM\n",
				sta->addr);
S
Sujith 已提交
503 504 505
		return ret;
	}

506
	if (sta) {
J
Joe Perches 已提交
507 508 509
		ath_dbg(common, ATH_DBG_CONFIG,
			"Added a station entry for: %pM (idx: %d)\n",
			sta->addr, tsta.sta_index);
510 511 512 513 514
	} else {
		ath_dbg(common, ATH_DBG_CONFIG,
			"Added a station entry for VIF %d (idx: %d)\n",
			avp->index, tsta.sta_index);
	}
S
Sujith 已提交
515

516
	priv->sta_slot |= (1 << sta_idx);
S
Sujith 已提交
517
	priv->nstations++;
518 519 520
	if (!sta)
		priv->vif_sta_pos[avp->index] = sta_idx;

S
Sujith 已提交
521 522 523 524 525 526 527 528
	return 0;
}

static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
				    struct ieee80211_vif *vif,
				    struct ieee80211_sta *sta)
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
529
	struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
S
Sujith 已提交
530 531 532 533 534 535 536 537
	struct ath9k_htc_sta *ista;
	int ret;
	u8 cmd_rsp, sta_idx;

	if (sta) {
		ista = (struct ath9k_htc_sta *) sta->drv_priv;
		sta_idx = ista->index;
	} else {
538
		sta_idx = priv->vif_sta_pos[avp->index];
S
Sujith 已提交
539 540 541 542 543
	}

	WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
	if (ret) {
		if (sta)
544 545 546
			ath_err(common,
				"Unable to remove station entry for: %pM\n",
				sta->addr);
S
Sujith 已提交
547 548 549
		return ret;
	}

550
	if (sta) {
J
Joe Perches 已提交
551 552 553
		ath_dbg(common, ATH_DBG_CONFIG,
			"Removed a station entry for: %pM (idx: %d)\n",
			sta->addr, sta_idx);
554 555 556 557 558
	} else {
		ath_dbg(common, ATH_DBG_CONFIG,
			"Removed a station entry for VIF %d (idx: %d)\n",
			avp->index, sta_idx);
	}
S
Sujith 已提交
559

560
	priv->sta_slot &= ~(1 << sta_idx);
S
Sujith 已提交
561
	priv->nstations--;
562

S
Sujith 已提交
563 564 565
	return 0;
}

566 567
int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
				u8 enable_coex)
S
Sujith 已提交
568 569 570 571 572 573 574
{
	struct ath9k_htc_cap_target tcap;
	int ret;
	u8 cmd_rsp;

	memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));

575 576 577
	tcap.ampdu_limit = cpu_to_be32(0xffff);
	tcap.ampdu_subframes = priv->hw->max_tx_aggregation_subframes;
	tcap.enable_coex = enable_coex;
S
Sujith 已提交
578
	tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
S
Sujith 已提交
579 580 581 582 583 584

	WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);

	return ret;
}

S
Sujith 已提交
585 586 587
static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
				 struct ieee80211_sta *sta,
				 struct ath9k_htc_target_rate *trate)
S
Sujith 已提交
588 589 590 591
{
	struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
	struct ieee80211_supported_band *sband;
	u32 caps = 0;
S
Sujith 已提交
592
	int i, j;
S
Sujith 已提交
593

S
Sujith 已提交
594
	sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
S
Sujith 已提交
595 596 597

	for (i = 0, j = 0; i < sband->n_bitrates; i++) {
		if (sta->supp_rates[sband->band] & BIT(i)) {
S
Sujith 已提交
598
			trate->rates.legacy_rates.rs_rates[j]
S
Sujith 已提交
599 600 601 602
				= (sband->bitrates[i].bitrate * 2) / 10;
			j++;
		}
	}
S
Sujith 已提交
603
	trate->rates.legacy_rates.rs_nrates = j;
S
Sujith 已提交
604 605 606 607

	if (sta->ht_cap.ht_supported) {
		for (i = 0, j = 0; i < 77; i++) {
			if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
S
Sujith 已提交
608
				trate->rates.ht_rates.rs_rates[j++] = i;
S
Sujith 已提交
609 610 611
			if (j == ATH_HTC_RATE_MAX)
				break;
		}
S
Sujith 已提交
612
		trate->rates.ht_rates.rs_nrates = j;
S
Sujith 已提交
613 614

		caps = WLAN_RC_HT_FLAG;
615 616
		if (sta->ht_cap.mcs.rx_mask[1])
			caps |= WLAN_RC_DS_FLAG;
617 618
		if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
		     (conf_is_ht40(&priv->hw->conf)))
S
Sujith 已提交
619
			caps |= WLAN_RC_40_FLAG;
620 621 622 623 624
		if (conf_is_ht40(&priv->hw->conf) &&
		    (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
			caps |= WLAN_RC_SGI_FLAG;
		else if (conf_is_ht20(&priv->hw->conf) &&
			 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
S
Sujith 已提交
625 626 627
			caps |= WLAN_RC_SGI_FLAG;
	}

S
Sujith 已提交
628 629 630 631 632 633 634 635 636 637 638
	trate->sta_index = ista->index;
	trate->isnew = 1;
	trate->capflags = cpu_to_be32(caps);
}

static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
				    struct ath9k_htc_target_rate *trate)
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	int ret;
	u8 cmd_rsp;
S
Sujith 已提交
639

S
Sujith 已提交
640
	WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
S
Sujith 已提交
641
	if (ret) {
642 643
		ath_err(common,
			"Unable to initialize Rate information on target\n");
S
Sujith 已提交
644 645
	}

S
Sujith 已提交
646
	return ret;
S
Sujith 已提交
647 648
}

S
Sujith 已提交
649 650
static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
				struct ieee80211_sta *sta)
S
Sujith 已提交
651 652
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
S
Sujith 已提交
653
	struct ath9k_htc_target_rate trate;
S
Sujith 已提交
654 655
	int ret;

S
Sujith 已提交
656 657 658 659
	memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
	ath9k_htc_setup_rate(priv, sta, &trate);
	ret = ath9k_htc_send_rate_cmd(priv, &trate);
	if (!ret)
J
Joe Perches 已提交
660 661 662
		ath_dbg(common, ATH_DBG_CONFIG,
			"Updated target sta: %pM, rate caps: 0x%X\n",
			sta->addr, be32_to_cpu(trate.capflags));
S
Sujith 已提交
663 664
}

665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
				  struct ieee80211_vif *vif,
				  struct ieee80211_bss_conf *bss_conf)
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_htc_target_rate trate;
	struct ieee80211_sta *sta;
	int ret;

	memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));

	rcu_read_lock();
	sta = ieee80211_find_sta(vif, bss_conf->bssid);
	if (!sta) {
		rcu_read_unlock();
		return;
	}
	ath9k_htc_setup_rate(priv, sta, &trate);
	rcu_read_unlock();

	ret = ath9k_htc_send_rate_cmd(priv, &trate);
	if (!ret)
J
Joe Perches 已提交
687 688 689
		ath_dbg(common, ATH_DBG_CONFIG,
			"Updated target sta: %pM, rate caps: 0x%X\n",
			bss_conf->bssid, be32_to_cpu(trate.capflags));
690 691
}

692 693 694 695 696
static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
				  struct ieee80211_vif *vif,
				  struct ieee80211_sta *sta,
				  enum ieee80211_ampdu_mlme_action action,
				  u16 tid)
S
Sujith 已提交
697 698 699
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_htc_target_aggr aggr;
700
	struct ath9k_htc_sta *ista;
S
Sujith 已提交
701 702 703
	int ret = 0;
	u8 cmd_rsp;

704
	if (tid >= ATH9K_HTC_MAX_TID)
S
Sujith 已提交
705 706
		return -EINVAL;

707 708
	memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
	ista = (struct ath9k_htc_sta *) sta->drv_priv;
S
Sujith 已提交
709 710

	aggr.sta_index = ista->index;
S
Sujith 已提交
711 712
	aggr.tidno = tid & 0xf;
	aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
S
Sujith 已提交
713 714 715

	WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
	if (ret)
J
Joe Perches 已提交
716 717 718
		ath_dbg(common, ATH_DBG_CONFIG,
			"Unable to %s TX aggregation for (%pM, %d)\n",
			(aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
S
Sujith 已提交
719
	else
J
Joe Perches 已提交
720 721 722 723
		ath_dbg(common, ATH_DBG_CONFIG,
			"%s TX aggregation for (%pM, %d)\n",
			(aggr.aggr_enable) ? "Starting" : "Stopping",
			sta->addr, tid);
S
Sujith 已提交
724

725
	spin_lock_bh(&priv->tx.tx_lock);
S
Sujith 已提交
726
	ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
727
	spin_unlock_bh(&priv->tx.tx_lock);
S
Sujith 已提交
728

S
Sujith 已提交
729
	return ret;
S
Sujith 已提交
730 731 732 733 734 735
}

/*******/
/* ANI */
/*******/

736
void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
S
Sujith 已提交
737 738 739 740 741 742 743 744
{
	struct ath_common *common = ath9k_hw_common(priv->ah);
	unsigned long timestamp = jiffies_to_msecs(jiffies);

	common->ani.longcal_timer = timestamp;
	common->ani.shortcal_timer = timestamp;
	common->ani.checkani_timer = timestamp;

745 746 747
	priv->op_flags |= OP_ANI_RUNNING;

	ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
S
Sujith 已提交
748 749 750
				     msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
}

751 752 753 754 755 756 757
void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
{
	cancel_delayed_work_sync(&priv->ani_work);
	priv->op_flags &= ~OP_ANI_RUNNING;
}

void ath9k_htc_ani_work(struct work_struct *work)
S
Sujith 已提交
758 759
{
	struct ath9k_htc_priv *priv =
760
		container_of(work, struct ath9k_htc_priv, ani_work.work);
S
Sujith 已提交
761 762 763 764 765 766 767 768
	struct ath_hw *ah = priv->ah;
	struct ath_common *common = ath9k_hw_common(ah);
	bool longcal = false;
	bool shortcal = false;
	bool aniflag = false;
	unsigned int timestamp = jiffies_to_msecs(jiffies);
	u32 cal_interval, short_cal_interval;

769 770
	short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
		ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
S
Sujith 已提交
771

772 773 774 775
	/* Only calibrate if awake */
	if (ah->power_mode != ATH9K_PM_AWAKE)
		goto set_timer;

S
Sujith 已提交
776 777 778
	/* Long calibration runs independently of short calibration. */
	if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
		longcal = true;
J
Joe Perches 已提交
779
		ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
S
Sujith 已提交
780 781 782 783 784 785 786 787
		common->ani.longcal_timer = timestamp;
	}

	/* Short calibration applies only while caldone is false */
	if (!common->ani.caldone) {
		if ((timestamp - common->ani.shortcal_timer) >=
		    short_cal_interval) {
			shortcal = true;
J
Joe Perches 已提交
788 789
			ath_dbg(common, ATH_DBG_ANI,
				"shortcal @%lu\n", jiffies);
S
Sujith 已提交
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
			common->ani.shortcal_timer = timestamp;
			common->ani.resetcal_timer = timestamp;
		}
	} else {
		if ((timestamp - common->ani.resetcal_timer) >=
		    ATH_RESTART_CALINTERVAL) {
			common->ani.caldone = ath9k_hw_reset_calvalid(ah);
			if (common->ani.caldone)
				common->ani.resetcal_timer = timestamp;
		}
	}

	/* Verify whether we must check ANI */
	if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
		aniflag = true;
		common->ani.checkani_timer = timestamp;
	}

	/* Skip all processing if there's nothing to do. */
	if (longcal || shortcal || aniflag) {
810 811 812

		ath9k_htc_ps_wakeup(priv);

S
Sujith 已提交
813 814 815 816 817
		/* Call ANI routine if necessary */
		if (aniflag)
			ath9k_hw_ani_monitor(ah, ah->curchan);

		/* Perform calibration if necessary */
818
		if (longcal || shortcal)
S
Sujith 已提交
819 820 821 822 823
			common->ani.caldone =
				ath9k_hw_calibrate(ah, ah->curchan,
						   common->rx_chainmask,
						   longcal);

824
		ath9k_htc_ps_restore(priv);
S
Sujith 已提交
825 826
	}

827
set_timer:
S
Sujith 已提交
828 829 830 831 832 833 834 835 836 837 838
	/*
	* Set timer interval based on previous results.
	* The interval must be the shortest necessary to satisfy ANI,
	* short calibration and long calibration.
	*/
	cal_interval = ATH_LONG_CALINTERVAL;
	if (priv->ah->config.enable_ani)
		cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
	if (!common->ani.caldone)
		cal_interval = min(cal_interval, (u32)short_cal_interval);

839
	ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
S
Sujith 已提交
840 841 842 843 844 845 846
				     msecs_to_jiffies(cal_interval));
}

/**********************/
/* mac80211 Callbacks */
/**********************/

847
static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
S
Sujith 已提交
848 849 850
{
	struct ieee80211_hdr *hdr;
	struct ath9k_htc_priv *priv = hw->priv;
851
	struct ath_common *common = ath9k_hw_common(priv->ah);
S
Sujith Manoharan 已提交
852
	int padpos, padsize, ret, slot;
S
Sujith 已提交
853 854 855 856 857 858 859

	hdr = (struct ieee80211_hdr *) skb->data;

	/* Add the padding after the header if this is not already done */
	padpos = ath9k_cmn_padpos(hdr->frame_control);
	padsize = padpos & 3;
	if (padsize && skb->len > padpos) {
860 861
		if (skb_headroom(skb) < padsize) {
			ath_dbg(common, ATH_DBG_XMIT, "No room for padding\n");
862
			goto fail_tx;
863
		}
S
Sujith 已提交
864 865 866 867
		skb_push(skb, padsize);
		memmove(skb->data, skb->data + padsize, padpos);
	}

S
Sujith Manoharan 已提交
868 869 870 871 872 873 874
	slot = ath9k_htc_tx_get_slot(priv);
	if (slot < 0) {
		ath_dbg(common, ATH_DBG_XMIT, "No free TX slot\n");
		goto fail_tx;
	}

	ret = ath9k_htc_tx_start(priv, skb, slot, false);
S
Sujith 已提交
875
	if (ret != 0) {
876
		ath_dbg(common, ATH_DBG_XMIT, "Tx failed\n");
S
Sujith Manoharan 已提交
877
		goto clear_slot;
S
Sujith 已提交
878 879
	}

880 881
	ath9k_htc_check_stop_queues(priv);

882
	return;
S
Sujith 已提交
883

S
Sujith Manoharan 已提交
884 885
clear_slot:
	ath9k_htc_tx_clear_slot(priv, slot);
S
Sujith 已提交
886 887 888 889
fail_tx:
	dev_kfree_skb_any(skb);
}

S
Sujith 已提交
890
static int ath9k_htc_start(struct ieee80211_hw *hw)
S
Sujith 已提交
891 892 893 894 895 896 897 898
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath_hw *ah = priv->ah;
	struct ath_common *common = ath9k_hw_common(ah);
	struct ieee80211_channel *curchan = hw->conf.channel;
	struct ath9k_channel *init_channel;
	int ret = 0;
	enum htc_phymode mode;
S
Sujith 已提交
899
	__be16 htc_mode;
S
Sujith 已提交
900 901
	u8 cmd_rsp;

S
Sujith 已提交
902 903
	mutex_lock(&priv->mutex);

J
Joe Perches 已提交
904 905 906
	ath_dbg(common, ATH_DBG_CONFIG,
		"Starting driver with initial channel: %d MHz\n",
		curchan->center_freq);
S
Sujith 已提交
907

S
Sujith 已提交
908 909 910 911
	/* Ensure that HW is awake before flushing RX */
	ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
	WMI_CMD(WMI_FLUSH_RECV_CMDID);

S
Sujith 已提交
912 913 914 915
	/* setup initial channel */
	init_channel = ath9k_cmn_get_curchannel(hw, ah);

	ath9k_hw_htc_resetinit(ah);
916
	ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
S
Sujith 已提交
917
	if (ret) {
918 919 920
		ath_err(common,
			"Unable to reset hardware; reset status %d (freq %u MHz)\n",
			ret, curchan->center_freq);
S
Sujith 已提交
921
		mutex_unlock(&priv->mutex);
922
		return ret;
S
Sujith 已提交
923 924
	}

925 926
	ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
			       &priv->curtxpow);
S
Sujith 已提交
927 928 929 930 931 932 933 934 935

	mode = ath9k_htc_get_curmode(priv, init_channel);
	htc_mode = cpu_to_be16(mode);
	WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
	WMI_CMD(WMI_ATH_INIT_CMDID);
	WMI_CMD(WMI_START_RECV_CMDID);

	ath9k_host_rx_init(priv);

936
	ret = ath9k_htc_update_cap_target(priv, 0);
937 938 939 940
	if (ret)
		ath_dbg(common, ATH_DBG_CONFIG,
			"Failed to update capability in target\n");

S
Sujith 已提交
941 942 943
	priv->op_flags &= ~OP_INVALID;
	htc_start(priv->htc);

944
	spin_lock_bh(&priv->tx.tx_lock);
945
	priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
946
	spin_unlock_bh(&priv->tx.tx_lock);
S
Sujith 已提交
947 948 949

	ieee80211_wake_queues(hw);

950 951 952
	mod_timer(&priv->tx.cleanup_timer,
		  jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));

953 954 955 956 957 958
	if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
					   AR_STOMP_LOW_WLAN_WGHT);
		ath9k_hw_btcoex_enable(ah);
		ath_htc_resume_btcoex_work(priv);
	}
S
Sujith 已提交
959
	mutex_unlock(&priv->mutex);
960

S
Sujith 已提交
961 962 963
	return ret;
}

S
Sujith 已提交
964
static void ath9k_htc_stop(struct ieee80211_hw *hw)
S
Sujith 已提交
965 966 967 968
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath_hw *ah = priv->ah;
	struct ath_common *common = ath9k_hw_common(ah);
969
	int ret __attribute__ ((unused));
S
Sujith 已提交
970 971
	u8 cmd_rsp;

S
Sujith 已提交
972 973
	mutex_lock(&priv->mutex);

S
Sujith 已提交
974
	if (priv->op_flags & OP_INVALID) {
J
Joe Perches 已提交
975
		ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
S
Sujith 已提交
976
		mutex_unlock(&priv->mutex);
S
Sujith 已提交
977 978 979
		return;
	}

980
	ath9k_htc_ps_wakeup(priv);
981

S
Sujith 已提交
982 983 984
	WMI_CMD(WMI_DISABLE_INTR_CMDID);
	WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
	WMI_CMD(WMI_STOP_RECV_CMDID);
985 986

	tasklet_kill(&priv->rx_tasklet);
S
Sujith 已提交
987

988
	del_timer_sync(&priv->tx.cleanup_timer);
989
	ath9k_htc_tx_drain(priv);
S
Sujith Manoharan 已提交
990 991
	ath9k_wmi_event_drain(priv);

992 993 994 995 996 997
	mutex_unlock(&priv->mutex);

	/* Cancel all the running timers/work .. */
	cancel_work_sync(&priv->fatal_work);
	cancel_work_sync(&priv->ps_work);
	cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
998
	ath9k_htc_stop_ani(priv);
999 1000 1001 1002
	ath9k_led_stop_brightness(priv);

	mutex_lock(&priv->mutex);

1003 1004 1005 1006 1007 1008
	if (ah->btcoex_hw.enabled) {
		ath9k_hw_btcoex_disable(ah);
		if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
			ath_htc_cancel_btcoex_work(priv);
	}

1009 1010 1011 1012
	/* Remove a monitor interface if it's present. */
	if (priv->ah->is_monitoring)
		ath9k_htc_remove_monitor_interface(priv);

1013 1014 1015 1016 1017
	ath9k_hw_phy_disable(ah);
	ath9k_hw_disable(ah);
	ath9k_htc_ps_restore(priv);
	ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);

S
Sujith 已提交
1018 1019
	priv->op_flags |= OP_INVALID;

J
Joe Perches 已提交
1020
	ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1021 1022 1023
	mutex_unlock(&priv->mutex);
}

S
Sujith 已提交
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
				   struct ieee80211_vif *vif)
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_htc_target_vif hvif;
	int ret = 0;
	u8 cmd_rsp;

	mutex_lock(&priv->mutex);

1036
	if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1037
		mutex_unlock(&priv->mutex);
1038 1039 1040 1041 1042 1043 1044 1045
		return -ENOBUFS;
	}

	if (priv->num_ibss_vif ||
	    (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
		ath_err(common, "IBSS coexistence with other modes is not allowed\n");
		mutex_unlock(&priv->mutex);
		return -ENOBUFS;
S
Sujith 已提交
1046 1047
	}

1048 1049 1050 1051 1052 1053 1054 1055
	if (((vif->type == NL80211_IFTYPE_AP) ||
	     (vif->type == NL80211_IFTYPE_ADHOC)) &&
	    ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) {
		ath_err(common, "Max. number of beaconing interfaces reached\n");
		mutex_unlock(&priv->mutex);
		return -ENOBUFS;
	}

1056
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1057 1058 1059 1060 1061
	memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
	memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);

	switch (vif->type) {
	case NL80211_IFTYPE_STATION:
1062
		hvif.opmode = HTC_M_STA;
S
Sujith 已提交
1063 1064
		break;
	case NL80211_IFTYPE_ADHOC:
1065
		hvif.opmode = HTC_M_IBSS;
S
Sujith 已提交
1066
		break;
1067
	case NL80211_IFTYPE_AP:
1068
		hvif.opmode = HTC_M_HOSTAP;
1069
		break;
S
Sujith 已提交
1070
	default:
1071
		ath_err(common,
S
Sujith 已提交
1072 1073 1074 1075 1076 1077
			"Interface type %d not yet supported\n", vif->type);
		ret = -EOPNOTSUPP;
		goto out;
	}

	/* Index starts from zero on the target */
1078
	avp->index = hvif.index = ffz(priv->vif_slot);
S
Sujith 已提交
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
	hvif.rtsthreshold = cpu_to_be16(2304);
	WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
	if (ret)
		goto out;

	/*
	 * We need a node in target to tx mgmt frames
	 * before association.
	 */
	ret = ath9k_htc_add_station(priv, vif, NULL);
1089 1090
	if (ret) {
		WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
S
Sujith 已提交
1091
		goto out;
1092
	}
S
Sujith 已提交
1093

1094 1095
	ath9k_htc_set_bssid_mask(priv, vif);

1096
	priv->vif_slot |= (1 << avp->index);
1097
	priv->nvifs++;
1098

1099
	INC_VIF(priv, vif->type);
S
Sujith Manoharan 已提交
1100 1101 1102 1103 1104

	if ((vif->type == NL80211_IFTYPE_AP) ||
	    (vif->type == NL80211_IFTYPE_ADHOC))
		ath9k_htc_assign_bslot(priv, vif);

1105
	ath9k_htc_set_opmode(priv);
1106

1107
	if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1108 1109
	    !(priv->op_flags & OP_ANI_RUNNING)) {
		ath9k_hw_set_tsfadjust(priv->ah, 1);
1110
		ath9k_htc_start_ani(priv);
1111
	}
1112

1113 1114 1115
	ath_dbg(common, ATH_DBG_CONFIG,
		"Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index);

S
Sujith 已提交
1116
out:
1117
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1118
	mutex_unlock(&priv->mutex);
S
Sujith 已提交
1119

S
Sujith 已提交
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
	return ret;
}

static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
				       struct ieee80211_vif *vif)
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
	struct ath9k_htc_target_vif hvif;
	int ret = 0;
	u8 cmd_rsp;

	mutex_lock(&priv->mutex);
S
Sujith 已提交
1134
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1135 1136 1137 1138 1139

	memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
	memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
	hvif.index = avp->index;
	WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1140 1141 1142 1143
	if (ret) {
		ath_err(common, "Unable to remove interface at idx: %d\n",
			avp->index);
	}
S
Sujith 已提交
1144
	priv->nvifs--;
1145
	priv->vif_slot &= ~(1 << avp->index);
S
Sujith 已提交
1146 1147 1148

	ath9k_htc_remove_station(priv, vif, NULL);

1149
	DEC_VIF(priv, vif->type);
S
Sujith Manoharan 已提交
1150 1151 1152 1153 1154

	if ((vif->type == NL80211_IFTYPE_AP) ||
	    (vif->type == NL80211_IFTYPE_ADHOC))
		ath9k_htc_remove_bslot(priv, vif);

1155
	ath9k_htc_set_opmode(priv);
1156

1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
	/*
	 * Stop ANI only if there are no associated station interfaces.
	 */
	if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
		priv->rearm_ani = false;
		ieee80211_iterate_active_interfaces_atomic(priv->hw,
						   ath9k_htc_vif_iter, priv);
		if (!priv->rearm_ani)
			ath9k_htc_stop_ani(priv);
	}

1168 1169
	ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index);

S
Sujith 已提交
1170
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
	mutex_unlock(&priv->mutex);
}

static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ieee80211_conf *conf = &hw->conf;

	mutex_lock(&priv->mutex);

1182 1183 1184 1185
	if (changed & IEEE80211_CONF_CHANGE_IDLE) {
		bool enable_radio = false;
		bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);

S
Sujith 已提交
1186
		mutex_lock(&priv->htc_pm_lock);
1187 1188 1189
		if (!idle && priv->ps_idle)
			enable_radio = true;
		priv->ps_idle = idle;
S
Sujith 已提交
1190
		mutex_unlock(&priv->htc_pm_lock);
1191 1192

		if (enable_radio) {
J
Joe Perches 已提交
1193 1194
			ath_dbg(common, ATH_DBG_CONFIG,
				"not-idle: enabling radio\n");
S
Sujith 已提交
1195 1196
			ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
			ath9k_htc_radio_enable(hw);
1197 1198 1199
		}
	}

1200 1201 1202 1203 1204
	/*
	 * Monitor interface should be added before
	 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
	 */
	if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1205 1206 1207 1208 1209
		if ((conf->flags & IEEE80211_CONF_MONITOR) &&
		    !priv->ah->is_monitoring)
			ath9k_htc_add_monitor_interface(priv);
		else if (priv->ah->is_monitoring)
			ath9k_htc_remove_monitor_interface(priv);
1210 1211
	}

S
Sujith 已提交
1212 1213 1214 1215
	if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
		struct ieee80211_channel *curchan = hw->conf.channel;
		int pos = curchan->hw_value;

J
Joe Perches 已提交
1216 1217
		ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
			curchan->center_freq);
S
Sujith 已提交
1218

1219 1220 1221
		ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
					  hw->conf.channel,
					  hw->conf.channel_type);
S
Sujith 已提交
1222 1223

		if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1224
			ath_err(common, "Unable to set channel\n");
S
Sujith 已提交
1225 1226 1227 1228 1229
			mutex_unlock(&priv->mutex);
			return -EINVAL;
		}

	}
1230

1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
	if (changed & IEEE80211_CONF_CHANGE_PS) {
		if (conf->flags & IEEE80211_CONF_PS) {
			ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
			priv->ps_enabled = true;
		} else {
			priv->ps_enabled = false;
			cancel_work_sync(&priv->ps_work);
			ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
		}
	}
S
Sujith 已提交
1241

1242 1243
	if (changed & IEEE80211_CONF_CHANGE_POWER) {
		priv->txpowlimit = 2 * conf->power_level;
1244 1245
		ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
				       priv->txpowlimit, &priv->curtxpow);
1246 1247
	}

S
Sujith 已提交
1248 1249 1250 1251 1252 1253 1254 1255
	if (changed & IEEE80211_CONF_CHANGE_IDLE) {
		mutex_lock(&priv->htc_pm_lock);
		if (!priv->ps_idle) {
			mutex_unlock(&priv->htc_pm_lock);
			goto out;
		}
		mutex_unlock(&priv->htc_pm_lock);

J
Joe Perches 已提交
1256 1257
		ath_dbg(common, ATH_DBG_CONFIG,
			"idle: disabling radio\n");
S
Sujith 已提交
1258
		ath9k_htc_radio_disable(hw);
1259 1260
	}

S
Sujith 已提交
1261
out:
S
Sujith 已提交
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
	mutex_unlock(&priv->mutex);
	return 0;
}

#define SUPPORTED_FILTERS			\
	(FIF_PROMISC_IN_BSS |			\
	FIF_ALLMULTI |				\
	FIF_CONTROL |				\
	FIF_PSPOLL |				\
	FIF_OTHER_BSS |				\
	FIF_BCN_PRBRESP_PROMISC |		\
1273
	FIF_PROBE_REQ |				\
S
Sujith 已提交
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
	FIF_FCSFAIL)

static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
				       unsigned int changed_flags,
				       unsigned int *total_flags,
				       u64 multicast)
{
	struct ath9k_htc_priv *priv = hw->priv;
	u32 rfilt;

	mutex_lock(&priv->mutex);
1285
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1286

S
Sujith 已提交
1287 1288 1289 1290
	changed_flags &= SUPPORTED_FILTERS;
	*total_flags &= SUPPORTED_FILTERS;

	priv->rxfilter = *total_flags;
1291
	rfilt = ath9k_htc_calcrxfilter(priv);
S
Sujith 已提交
1292 1293
	ath9k_hw_setrxfilter(priv->ah, rfilt);

J
Joe Perches 已提交
1294 1295
	ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
		"Set HW RX filter: 0x%x\n", rfilt);
S
Sujith 已提交
1296

1297
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1298 1299 1300
	mutex_unlock(&priv->mutex);
}

1301 1302 1303
static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
			     struct ieee80211_vif *vif,
			     struct ieee80211_sta *sta)
S
Sujith 已提交
1304 1305 1306 1307
{
	struct ath9k_htc_priv *priv = hw->priv;
	int ret;

1308
	mutex_lock(&priv->mutex);
S
Sujith 已提交
1309
	ath9k_htc_ps_wakeup(priv);
1310 1311 1312 1313 1314
	ret = ath9k_htc_add_station(priv, vif, sta);
	if (!ret)
		ath9k_htc_init_rate(priv, sta);
	ath9k_htc_ps_restore(priv);
	mutex_unlock(&priv->mutex);
1315

1316 1317 1318 1319 1320 1321 1322 1323
	return ret;
}

static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
				struct ieee80211_vif *vif,
				struct ieee80211_sta *sta)
{
	struct ath9k_htc_priv *priv = hw->priv;
1324
	struct ath9k_htc_sta *ista;
1325
	int ret;
1326

1327 1328
	mutex_lock(&priv->mutex);
	ath9k_htc_ps_wakeup(priv);
1329 1330
	ista = (struct ath9k_htc_sta *) sta->drv_priv;
	htc_sta_drain(priv->htc, ista->index);
1331
	ret = ath9k_htc_remove_station(priv, vif, sta);
S
Sujith 已提交
1332
	ath9k_htc_ps_restore(priv);
1333
	mutex_unlock(&priv->mutex);
1334 1335

	return ret;
S
Sujith 已提交
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
}

static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
			     const struct ieee80211_tx_queue_params *params)
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath_common *common = ath9k_hw_common(priv->ah);
	struct ath9k_tx_queue_info qi;
	int ret = 0, qnum;

	if (queue >= WME_NUM_AC)
		return 0;

	mutex_lock(&priv->mutex);
S
Sujith 已提交
1350
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360

	memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));

	qi.tqi_aifs = params->aifs;
	qi.tqi_cwmin = params->cw_min;
	qi.tqi_cwmax = params->cw_max;
	qi.tqi_burstTime = params->txop;

	qnum = get_hw_qnum(queue, priv->hwq_map);

J
Joe Perches 已提交
1361 1362 1363 1364
	ath_dbg(common, ATH_DBG_CONFIG,
		"Configure tx [queue/hwq] [%d/%d],  aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
		queue, qnum, params->aifs, params->cw_min,
		params->cw_max, params->txop);
S
Sujith 已提交
1365

1366
	ret = ath_htc_txq_update(priv, qnum, &qi);
S
Sujith 已提交
1367
	if (ret) {
1368
		ath_err(common, "TXQ Update failed\n");
S
Sujith 已提交
1369 1370
		goto out;
	}
S
Sujith 已提交
1371

S
Sujith 已提交
1372
	if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1373
	    (qnum == priv->hwq_map[WME_AC_BE]))
S
Sujith 已提交
1374 1375
		    ath9k_htc_beaconq_config(priv);
out:
S
Sujith 已提交
1376
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
	mutex_unlock(&priv->mutex);

	return ret;
}

static int ath9k_htc_set_key(struct ieee80211_hw *hw,
			     enum set_key_cmd cmd,
			     struct ieee80211_vif *vif,
			     struct ieee80211_sta *sta,
			     struct ieee80211_key_conf *key)
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath_common *common = ath9k_hw_common(priv->ah);
	int ret = 0;

1392
	if (htc_modparam_nohwcrypt)
S
Sujith 已提交
1393 1394 1395
		return -ENOSPC;

	mutex_lock(&priv->mutex);
J
Joe Perches 已提交
1396
	ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1397
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1398 1399 1400

	switch (cmd) {
	case SET_KEY:
1401
		ret = ath_key_config(common, vif, sta, key);
S
Sujith 已提交
1402 1403 1404 1405
		if (ret >= 0) {
			key->hw_key_idx = ret;
			/* push IV and Michael MIC generation to stack */
			key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1406
			if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
S
Sujith 已提交
1407
				key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1408 1409
			if (priv->ah->sw_mgmt_crypto &&
			    key->cipher == WLAN_CIPHER_SUITE_CCMP)
S
Sujith 已提交
1410 1411 1412 1413 1414
				key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
			ret = 0;
		}
		break;
	case DISABLE_KEY:
1415
		ath_key_delete(common, key);
S
Sujith 已提交
1416 1417 1418 1419 1420
		break;
	default:
		ret = -EINVAL;
	}

1421
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
	mutex_unlock(&priv->mutex);

	return ret;
}

static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
				       struct ieee80211_vif *vif,
				       struct ieee80211_bss_conf *bss_conf,
				       u32 changed)
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath_hw *ah = priv->ah;
	struct ath_common *common = ath9k_hw_common(ah);
1435
	bool set_assoc;
S
Sujith 已提交
1436 1437

	mutex_lock(&priv->mutex);
1438
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1439

1440 1441 1442 1443 1444 1445 1446 1447 1448
	/*
	 * Set the HW AID/BSSID only for the first station interface
	 * or in IBSS mode.
	 */
	set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) ||
		       ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
			(priv->num_sta_vif == 1)));


S
Sujith 已提交
1449
	if (changed & BSS_CHANGED_ASSOC) {
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
		if (set_assoc) {
			ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
				bss_conf->assoc);

			common->curaid = bss_conf->assoc ?
				bss_conf->aid : 0;

			if (bss_conf->assoc)
				ath9k_htc_start_ani(priv);
			else
				ath9k_htc_stop_ani(priv);
		}
S
Sujith 已提交
1462 1463 1464
	}

	if (changed & BSS_CHANGED_BSSID) {
1465 1466 1467
		if (set_assoc) {
			memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
			ath9k_hw_write_associd(ah);
S
Sujith 已提交
1468

1469 1470 1471 1472
			ath_dbg(common, ATH_DBG_CONFIG,
				"BSSID: %pM aid: 0x%x\n",
				common->curbssid, common->curaid);
		}
S
Sujith 已提交
1473 1474
	}

1475 1476 1477
	if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
		ath_dbg(common, ATH_DBG_CONFIG,
			"Beacon enabled for BSS: %pM\n", bss_conf->bssid);
1478
		ath9k_htc_set_tsfadjust(priv, vif);
S
Sujith 已提交
1479
		priv->op_flags |= OP_ENABLE_BEACON;
1480
		ath9k_htc_beacon_config(priv, vif);
S
Sujith 已提交
1481 1482
	}

1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
	if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
		/*
		 * Disable SWBA interrupt only if there are no
		 * AP/IBSS interfaces.
		 */
		if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
			ath_dbg(common, ATH_DBG_CONFIG,
				"Beacon disabled for BSS: %pM\n",
				bss_conf->bssid);
			priv->op_flags &= ~OP_ENABLE_BEACON;
			ath9k_htc_beacon_config(priv, vif);
		}
	}

	if (changed & BSS_CHANGED_BEACON_INT) {
		/*
		 * Reset the HW TSF for the first AP interface.
		 */
		if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
		    (priv->nvifs == 1) &&
		    (priv->num_ap_vif == 1) &&
		    (vif->type == NL80211_IFTYPE_AP)) {
			priv->op_flags |= OP_TSF_RESET;
		}
		ath_dbg(common, ATH_DBG_CONFIG,
			"Beacon interval changed for BSS: %pM\n",
			bss_conf->bssid);
1510
		ath9k_htc_beacon_config(priv, vif);
S
Sujith 已提交
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
	}

	if (changed & BSS_CHANGED_ERP_SLOT) {
		if (bss_conf->use_short_slot)
			ah->slottime = 9;
		else
			ah->slottime = 20;

		ath9k_hw_init_global_settings(ah);
	}

1522 1523 1524
	if (changed & BSS_CHANGED_HT)
		ath9k_htc_update_rate(priv, vif, bss_conf);

1525
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1526 1527 1528 1529 1530 1531 1532 1533 1534
	mutex_unlock(&priv->mutex);
}

static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
{
	struct ath9k_htc_priv *priv = hw->priv;
	u64 tsf;

	mutex_lock(&priv->mutex);
S
Sujith 已提交
1535
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1536
	tsf = ath9k_hw_gettsf64(priv->ah);
S
Sujith 已提交
1537
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1538 1539 1540 1541 1542 1543 1544 1545 1546 1547
	mutex_unlock(&priv->mutex);

	return tsf;
}

static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
{
	struct ath9k_htc_priv *priv = hw->priv;

	mutex_lock(&priv->mutex);
S
Sujith 已提交
1548
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1549
	ath9k_hw_settsf64(priv->ah, tsf);
S
Sujith 已提交
1550
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1551 1552 1553 1554 1555 1556 1557 1558
	mutex_unlock(&priv->mutex);
}

static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
{
	struct ath9k_htc_priv *priv = hw->priv;

	mutex_lock(&priv->mutex);
S
Sujith 已提交
1559
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1560
	ath9k_hw_reset_tsf(priv->ah);
1561
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1562
	mutex_unlock(&priv->mutex);
S
Sujith 已提交
1563 1564 1565 1566 1567 1568
}

static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
				  struct ieee80211_vif *vif,
				  enum ieee80211_ampdu_mlme_action action,
				  struct ieee80211_sta *sta,
1569
				  u16 tid, u16 *ssn, u8 buf_size)
S
Sujith 已提交
1570 1571 1572
{
	struct ath9k_htc_priv *priv = hw->priv;
	struct ath9k_htc_sta *ista;
S
Sujith 已提交
1573
	int ret = 0;
S
Sujith 已提交
1574

1575 1576
	mutex_lock(&priv->mutex);

S
Sujith 已提交
1577 1578 1579 1580 1581 1582
	switch (action) {
	case IEEE80211_AMPDU_RX_START:
		break;
	case IEEE80211_AMPDU_RX_STOP:
		break;
	case IEEE80211_AMPDU_TX_START:
S
Sujith 已提交
1583 1584 1585 1586
		ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
		if (!ret)
			ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
		break;
S
Sujith 已提交
1587
	case IEEE80211_AMPDU_TX_STOP:
S
Sujith 已提交
1588 1589
		ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
		ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
S
Sujith 已提交
1590 1591 1592
		break;
	case IEEE80211_AMPDU_TX_OPERATIONAL:
		ista = (struct ath9k_htc_sta *) sta->drv_priv;
1593
		spin_lock_bh(&priv->tx.tx_lock);
S
Sujith 已提交
1594
		ista->tid_state[tid] = AGGR_OPERATIONAL;
1595
		spin_unlock_bh(&priv->tx.tx_lock);
S
Sujith 已提交
1596 1597
		break;
	default:
1598
		ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
S
Sujith 已提交
1599 1600
	}

1601 1602
	mutex_unlock(&priv->mutex);

S
Sujith 已提交
1603
	return ret;
S
Sujith 已提交
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613
}

static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
{
	struct ath9k_htc_priv *priv = hw->priv;

	mutex_lock(&priv->mutex);
	spin_lock_bh(&priv->beacon_lock);
	priv->op_flags |= OP_SCANNING;
	spin_unlock_bh(&priv->beacon_lock);
1614
	cancel_work_sync(&priv->ps_work);
1615
	ath9k_htc_stop_ani(priv);
S
Sujith 已提交
1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626
	mutex_unlock(&priv->mutex);
}

static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
{
	struct ath9k_htc_priv *priv = hw->priv;

	mutex_lock(&priv->mutex);
	spin_lock_bh(&priv->beacon_lock);
	priv->op_flags &= ~OP_SCANNING;
	spin_unlock_bh(&priv->beacon_lock);
1627 1628
	ath9k_htc_ps_wakeup(priv);
	ath9k_htc_vif_reconfig(priv);
1629
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1630
	mutex_unlock(&priv->mutex);
S
Sujith 已提交
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
}

static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
{
	return 0;
}

static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
					 u8 coverage_class)
{
	struct ath9k_htc_priv *priv = hw->priv;

	mutex_lock(&priv->mutex);
S
Sujith 已提交
1644
	ath9k_htc_ps_wakeup(priv);
S
Sujith 已提交
1645 1646
	priv->ah->coverage_class = coverage_class;
	ath9k_hw_init_global_settings(priv->ah);
S
Sujith 已提交
1647
	ath9k_htc_ps_restore(priv);
S
Sujith 已提交
1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
	mutex_unlock(&priv->mutex);
}

struct ieee80211_ops ath9k_htc_ops = {
	.tx                 = ath9k_htc_tx,
	.start              = ath9k_htc_start,
	.stop               = ath9k_htc_stop,
	.add_interface      = ath9k_htc_add_interface,
	.remove_interface   = ath9k_htc_remove_interface,
	.config             = ath9k_htc_config,
	.configure_filter   = ath9k_htc_configure_filter,
1659 1660
	.sta_add            = ath9k_htc_sta_add,
	.sta_remove         = ath9k_htc_sta_remove,
S
Sujith 已提交
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
	.conf_tx            = ath9k_htc_conf_tx,
	.bss_info_changed   = ath9k_htc_bss_info_changed,
	.set_key            = ath9k_htc_set_key,
	.get_tsf            = ath9k_htc_get_tsf,
	.set_tsf            = ath9k_htc_set_tsf,
	.reset_tsf          = ath9k_htc_reset_tsf,
	.ampdu_action       = ath9k_htc_ampdu_action,
	.sw_scan_start      = ath9k_htc_sw_scan_start,
	.sw_scan_complete   = ath9k_htc_sw_scan_complete,
	.set_rts_threshold  = ath9k_htc_set_rts_threshold,
	.rfkill_poll        = ath9k_htc_rfkill_poll_state,
	.set_coverage_class = ath9k_htc_set_coverage_class,
};