2 * Copyright (c) 2010 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
24 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
25 struct ath9k_channel *ichan)
27 enum htc_phymode mode;
31 switch (ichan->chanmode) {
34 case CHANNEL_G_HT40PLUS:
35 case CHANNEL_G_HT40MINUS:
40 case CHANNEL_A_HT40PLUS:
41 case CHANNEL_A_HT40MINUS:
51 bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
52 enum ath9k_power_mode mode)
56 mutex_lock(&priv->htc_pm_lock);
57 ret = ath9k_hw_setpower(priv->ah, mode);
58 mutex_unlock(&priv->htc_pm_lock);
63 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
65 mutex_lock(&priv->htc_pm_lock);
66 if (++priv->ps_usecount != 1)
68 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
71 mutex_unlock(&priv->htc_pm_lock);
74 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
76 mutex_lock(&priv->htc_pm_lock);
77 if (--priv->ps_usecount != 0)
81 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
82 else if (priv->ps_enabled)
83 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
86 mutex_unlock(&priv->htc_pm_lock);
89 void ath9k_ps_work(struct work_struct *work)
91 struct ath9k_htc_priv *priv =
92 container_of(work, struct ath9k_htc_priv,
94 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
96 /* The chip wakes up after receiving the first beacon
97 while network sleep is enabled. For the driver to
98 be in sync with the hw, set the chip to awake and
99 only then set it to sleep.
101 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
104 static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
106 struct ath9k_htc_priv *priv = data;
107 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
109 if ((vif->type == NL80211_IFTYPE_AP) && bss_conf->enable_beacon)
110 priv->reconfig_beacon = true;
112 if (bss_conf->assoc) {
113 priv->rearm_ani = true;
114 priv->reconfig_beacon = true;
118 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv)
120 priv->rearm_ani = false;
121 priv->reconfig_beacon = false;
123 ieee80211_iterate_active_interfaces_atomic(priv->hw,
124 ath9k_htc_vif_iter, priv);
126 ath9k_htc_start_ani(priv);
128 if (priv->reconfig_beacon) {
129 ath9k_htc_ps_wakeup(priv);
130 ath9k_htc_beacon_reconfig(priv);
131 ath9k_htc_ps_restore(priv);
135 static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
137 struct ath9k_vif_iter_data *iter_data = data;
140 for (i = 0; i < ETH_ALEN; i++)
141 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
144 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
145 struct ieee80211_vif *vif)
147 struct ath_common *common = ath9k_hw_common(priv->ah);
148 struct ath9k_vif_iter_data iter_data;
151 * Use the hardware MAC address as reference, the hardware uses it
152 * together with the BSSID mask when matching addresses.
154 iter_data.hw_macaddr = common->macaddr;
155 memset(&iter_data.mask, 0xff, ETH_ALEN);
158 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
160 /* Get list of all active MAC addresses */
161 ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter,
164 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
165 ath_hw_setbssidmask(common);
168 static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv)
170 if (priv->num_ibss_vif)
171 priv->ah->opmode = NL80211_IFTYPE_ADHOC;
172 else if (priv->num_ap_vif)
173 priv->ah->opmode = NL80211_IFTYPE_AP;
175 priv->ah->opmode = NL80211_IFTYPE_STATION;
177 ath9k_hw_setopmode(priv->ah);
180 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
182 struct ath_hw *ah = priv->ah;
183 struct ath_common *common = ath9k_hw_common(ah);
184 struct ieee80211_channel *channel = priv->hw->conf.channel;
185 struct ath9k_hw_cal_data *caldata = NULL;
186 enum htc_phymode mode;
191 mutex_lock(&priv->mutex);
192 ath9k_htc_ps_wakeup(priv);
194 ath9k_htc_stop_ani(priv);
195 ieee80211_stop_queues(priv->hw);
197 WMI_CMD(WMI_DISABLE_INTR_CMDID);
198 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
199 WMI_CMD(WMI_STOP_RECV_CMDID);
201 ath9k_wmi_event_drain(priv);
203 caldata = &priv->caldata;
204 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
207 "Unable to reset device (%u Mhz) reset status %d\n",
208 channel->center_freq, ret);
211 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
214 WMI_CMD(WMI_START_RECV_CMDID);
215 ath9k_host_rx_init(priv);
217 mode = ath9k_htc_get_curmode(priv, ah->curchan);
218 htc_mode = cpu_to_be16(mode);
219 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
221 WMI_CMD(WMI_ENABLE_INTR_CMDID);
222 htc_start(priv->htc);
223 ath9k_htc_vif_reconfig(priv);
224 ieee80211_wake_queues(priv->hw);
226 ath9k_htc_ps_restore(priv);
227 mutex_unlock(&priv->mutex);
230 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
231 struct ieee80211_hw *hw,
232 struct ath9k_channel *hchan)
234 struct ath_hw *ah = priv->ah;
235 struct ath_common *common = ath9k_hw_common(ah);
236 struct ieee80211_conf *conf = &common->hw->conf;
238 struct ieee80211_channel *channel = hw->conf.channel;
239 struct ath9k_hw_cal_data *caldata = NULL;
240 enum htc_phymode mode;
245 if (priv->op_flags & OP_INVALID)
248 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
250 ath9k_htc_ps_wakeup(priv);
252 WMI_CMD(WMI_DISABLE_INTR_CMDID);
253 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
254 WMI_CMD(WMI_STOP_RECV_CMDID);
256 ath9k_wmi_event_drain(priv);
258 ath_dbg(common, ATH_DBG_CONFIG,
259 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
260 priv->ah->curchan->channel,
261 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
265 caldata = &priv->caldata;
266 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
269 "Unable to reset channel (%u Mhz) reset status %d\n",
270 channel->center_freq, ret);
274 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
277 WMI_CMD(WMI_START_RECV_CMDID);
281 ath9k_host_rx_init(priv);
283 mode = ath9k_htc_get_curmode(priv, hchan);
284 htc_mode = cpu_to_be16(mode);
285 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
289 WMI_CMD(WMI_ENABLE_INTR_CMDID);
293 htc_start(priv->htc);
295 if (!(priv->op_flags & OP_SCANNING) &&
296 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
297 ath9k_htc_vif_reconfig(priv);
300 ath9k_htc_ps_restore(priv);
305 * Monitor mode handling is a tad complicated because the firmware requires
306 * an interface to be created exclusively, while mac80211 doesn't associate
307 * an interface with the mode.
309 * So, for now, only one monitor interface can be configured.
311 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
313 struct ath_common *common = ath9k_hw_common(priv->ah);
314 struct ath9k_htc_target_vif hvif;
318 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
319 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
320 hvif.index = priv->mon_vif_idx;
321 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
323 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
326 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
328 struct ath_common *common = ath9k_hw_common(priv->ah);
329 struct ath9k_htc_target_vif hvif;
330 struct ath9k_htc_target_sta tsta;
331 int ret = 0, sta_idx;
334 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
335 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
340 sta_idx = ffz(priv->sta_slot);
341 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
349 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
350 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
352 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
353 hvif.index = ffz(priv->vif_slot);
355 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
360 * Assign the monitor interface index as a special case here.
361 * This is needed when the interface is brought down.
363 priv->mon_vif_idx = hvif.index;
364 priv->vif_slot |= (1 << hvif.index);
367 * Set the hardware mode to monitor only if there are no
371 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
376 * Associate a station with the interface for packet injection.
378 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
380 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
383 tsta.sta_index = sta_idx;
384 tsta.vif_index = hvif.index;
385 tsta.maxampdu = 0xffff;
387 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
389 ath_err(common, "Unable to add station entry for monitor mode\n");
393 priv->sta_slot |= (1 << sta_idx);
395 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
396 priv->ah->is_monitoring = true;
398 ath_dbg(common, ATH_DBG_CONFIG,
399 "Attached a monitor interface at idx: %d, sta idx: %d\n",
400 priv->mon_vif_idx, sta_idx);
406 * Remove the interface from the target.
408 __ath9k_htc_remove_monitor_interface(priv);
410 ath_dbg(common, ATH_DBG_FATAL, "Unable to attach a monitor interface\n");
415 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
417 struct ath_common *common = ath9k_hw_common(priv->ah);
421 __ath9k_htc_remove_monitor_interface(priv);
423 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
425 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
427 ath_err(common, "Unable to remove station entry for monitor mode\n");
431 priv->sta_slot &= ~(1 << sta_idx);
433 priv->ah->is_monitoring = false;
435 ath_dbg(common, ATH_DBG_CONFIG,
436 "Removed a monitor interface at idx: %d, sta idx: %d\n",
437 priv->mon_vif_idx, sta_idx);
442 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
443 struct ieee80211_vif *vif,
444 struct ieee80211_sta *sta)
446 struct ath_common *common = ath9k_hw_common(priv->ah);
447 struct ath9k_htc_target_sta tsta;
448 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
449 struct ath9k_htc_sta *ista;
453 if (priv->nstations >= ATH9K_HTC_MAX_STA)
456 sta_idx = ffz(priv->sta_slot);
457 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
460 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
463 ista = (struct ath9k_htc_sta *) sta->drv_priv;
464 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
465 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
466 tsta.associd = common->curaid;
469 ista->index = sta_idx;
471 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
475 tsta.sta_index = sta_idx;
476 tsta.vif_index = avp->index;
477 tsta.maxampdu = 0xffff;
478 if (sta && sta->ht_cap.ht_supported)
479 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
481 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
485 "Unable to add station entry for: %pM\n",
491 ath_dbg(common, ATH_DBG_CONFIG,
492 "Added a station entry for: %pM (idx: %d)\n",
493 sta->addr, tsta.sta_index);
495 ath_dbg(common, ATH_DBG_CONFIG,
496 "Added a station entry for VIF %d (idx: %d)\n",
497 avp->index, tsta.sta_index);
500 priv->sta_slot |= (1 << sta_idx);
503 priv->vif_sta_pos[avp->index] = sta_idx;
508 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
509 struct ieee80211_vif *vif,
510 struct ieee80211_sta *sta)
512 struct ath_common *common = ath9k_hw_common(priv->ah);
513 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
514 struct ath9k_htc_sta *ista;
519 ista = (struct ath9k_htc_sta *) sta->drv_priv;
520 sta_idx = ista->index;
522 sta_idx = priv->vif_sta_pos[avp->index];
525 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
529 "Unable to remove station entry for: %pM\n",
535 ath_dbg(common, ATH_DBG_CONFIG,
536 "Removed a station entry for: %pM (idx: %d)\n",
539 ath_dbg(common, ATH_DBG_CONFIG,
540 "Removed a station entry for VIF %d (idx: %d)\n",
541 avp->index, sta_idx);
544 priv->sta_slot &= ~(1 << sta_idx);
550 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
552 struct ath9k_htc_cap_target tcap;
556 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
558 /* FIXME: Values are hardcoded */
559 tcap.flags = 0x240c40;
560 tcap.flags_ext = 0x80601000;
561 tcap.ampdu_limit = 0xffff0000;
562 tcap.ampdu_subframes = 20;
563 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
565 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
567 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
572 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
573 struct ieee80211_sta *sta,
574 struct ath9k_htc_target_rate *trate)
576 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
577 struct ieee80211_supported_band *sband;
581 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
583 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
584 if (sta->supp_rates[sband->band] & BIT(i)) {
585 trate->rates.legacy_rates.rs_rates[j]
586 = (sband->bitrates[i].bitrate * 2) / 10;
590 trate->rates.legacy_rates.rs_nrates = j;
592 if (sta->ht_cap.ht_supported) {
593 for (i = 0, j = 0; i < 77; i++) {
594 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
595 trate->rates.ht_rates.rs_rates[j++] = i;
596 if (j == ATH_HTC_RATE_MAX)
599 trate->rates.ht_rates.rs_nrates = j;
601 caps = WLAN_RC_HT_FLAG;
602 if (sta->ht_cap.mcs.rx_mask[1])
603 caps |= WLAN_RC_DS_FLAG;
604 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
605 (conf_is_ht40(&priv->hw->conf)))
606 caps |= WLAN_RC_40_FLAG;
607 if (conf_is_ht40(&priv->hw->conf) &&
608 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
609 caps |= WLAN_RC_SGI_FLAG;
610 else if (conf_is_ht20(&priv->hw->conf) &&
611 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
612 caps |= WLAN_RC_SGI_FLAG;
615 trate->sta_index = ista->index;
617 trate->capflags = cpu_to_be32(caps);
620 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
621 struct ath9k_htc_target_rate *trate)
623 struct ath_common *common = ath9k_hw_common(priv->ah);
627 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
630 "Unable to initialize Rate information on target\n");
636 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
637 struct ieee80211_sta *sta)
639 struct ath_common *common = ath9k_hw_common(priv->ah);
640 struct ath9k_htc_target_rate trate;
643 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
644 ath9k_htc_setup_rate(priv, sta, &trate);
645 ret = ath9k_htc_send_rate_cmd(priv, &trate);
647 ath_dbg(common, ATH_DBG_CONFIG,
648 "Updated target sta: %pM, rate caps: 0x%X\n",
649 sta->addr, be32_to_cpu(trate.capflags));
652 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
653 struct ieee80211_vif *vif,
654 struct ieee80211_bss_conf *bss_conf)
656 struct ath_common *common = ath9k_hw_common(priv->ah);
657 struct ath9k_htc_target_rate trate;
658 struct ieee80211_sta *sta;
661 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
664 sta = ieee80211_find_sta(vif, bss_conf->bssid);
669 ath9k_htc_setup_rate(priv, sta, &trate);
672 ret = ath9k_htc_send_rate_cmd(priv, &trate);
674 ath_dbg(common, ATH_DBG_CONFIG,
675 "Updated target sta: %pM, rate caps: 0x%X\n",
676 bss_conf->bssid, be32_to_cpu(trate.capflags));
679 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
680 struct ieee80211_vif *vif,
681 struct ieee80211_sta *sta,
682 enum ieee80211_ampdu_mlme_action action,
685 struct ath_common *common = ath9k_hw_common(priv->ah);
686 struct ath9k_htc_target_aggr aggr;
687 struct ath9k_htc_sta *ista;
691 if (tid >= ATH9K_HTC_MAX_TID)
694 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
695 ista = (struct ath9k_htc_sta *) sta->drv_priv;
697 aggr.sta_index = ista->index;
698 aggr.tidno = tid & 0xf;
699 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
701 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
703 ath_dbg(common, ATH_DBG_CONFIG,
704 "Unable to %s TX aggregation for (%pM, %d)\n",
705 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
707 ath_dbg(common, ATH_DBG_CONFIG,
708 "%s TX aggregation for (%pM, %d)\n",
709 (aggr.aggr_enable) ? "Starting" : "Stopping",
712 spin_lock_bh(&priv->tx_lock);
713 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
714 spin_unlock_bh(&priv->tx_lock);
723 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
725 struct ath_common *common = ath9k_hw_common(priv->ah);
726 unsigned long timestamp = jiffies_to_msecs(jiffies);
728 common->ani.longcal_timer = timestamp;
729 common->ani.shortcal_timer = timestamp;
730 common->ani.checkani_timer = timestamp;
732 priv->op_flags |= OP_ANI_RUNNING;
734 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
735 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
738 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
740 cancel_delayed_work_sync(&priv->ani_work);
741 priv->op_flags &= ~OP_ANI_RUNNING;
744 void ath9k_htc_ani_work(struct work_struct *work)
746 struct ath9k_htc_priv *priv =
747 container_of(work, struct ath9k_htc_priv, ani_work.work);
748 struct ath_hw *ah = priv->ah;
749 struct ath_common *common = ath9k_hw_common(ah);
750 bool longcal = false;
751 bool shortcal = false;
752 bool aniflag = false;
753 unsigned int timestamp = jiffies_to_msecs(jiffies);
754 u32 cal_interval, short_cal_interval;
756 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
757 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
759 /* Only calibrate if awake */
760 if (ah->power_mode != ATH9K_PM_AWAKE)
763 /* Long calibration runs independently of short calibration. */
764 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
766 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
767 common->ani.longcal_timer = timestamp;
770 /* Short calibration applies only while caldone is false */
771 if (!common->ani.caldone) {
772 if ((timestamp - common->ani.shortcal_timer) >=
773 short_cal_interval) {
775 ath_dbg(common, ATH_DBG_ANI,
776 "shortcal @%lu\n", jiffies);
777 common->ani.shortcal_timer = timestamp;
778 common->ani.resetcal_timer = timestamp;
781 if ((timestamp - common->ani.resetcal_timer) >=
782 ATH_RESTART_CALINTERVAL) {
783 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
784 if (common->ani.caldone)
785 common->ani.resetcal_timer = timestamp;
789 /* Verify whether we must check ANI */
790 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
792 common->ani.checkani_timer = timestamp;
795 /* Skip all processing if there's nothing to do. */
796 if (longcal || shortcal || aniflag) {
798 ath9k_htc_ps_wakeup(priv);
800 /* Call ANI routine if necessary */
802 ath9k_hw_ani_monitor(ah, ah->curchan);
804 /* Perform calibration if necessary */
805 if (longcal || shortcal)
806 common->ani.caldone =
807 ath9k_hw_calibrate(ah, ah->curchan,
808 common->rx_chainmask,
811 ath9k_htc_ps_restore(priv);
816 * Set timer interval based on previous results.
817 * The interval must be the shortest necessary to satisfy ANI,
818 * short calibration and long calibration.
820 cal_interval = ATH_LONG_CALINTERVAL;
821 if (priv->ah->config.enable_ani)
822 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
823 if (!common->ani.caldone)
824 cal_interval = min(cal_interval, (u32)short_cal_interval);
826 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
827 msecs_to_jiffies(cal_interval));
830 /**********************/
831 /* mac80211 Callbacks */
832 /**********************/
834 static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
836 struct ieee80211_hdr *hdr;
837 struct ath9k_htc_priv *priv = hw->priv;
838 int padpos, padsize, ret;
840 hdr = (struct ieee80211_hdr *) skb->data;
842 /* Add the padding after the header if this is not already done */
843 padpos = ath9k_cmn_padpos(hdr->frame_control);
844 padsize = padpos & 3;
845 if (padsize && skb->len > padpos) {
846 if (skb_headroom(skb) < padsize)
848 skb_push(skb, padsize);
849 memmove(skb->data, skb->data + padsize, padpos);
852 ret = ath9k_htc_tx_start(priv, skb, false);
854 if (ret == -ENOMEM) {
855 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
856 "Stopping TX queues\n");
857 ieee80211_stop_queues(hw);
858 spin_lock_bh(&priv->tx_lock);
859 priv->tx_queues_stop = true;
860 spin_unlock_bh(&priv->tx_lock);
862 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
871 dev_kfree_skb_any(skb);
874 static int ath9k_htc_start(struct ieee80211_hw *hw)
876 struct ath9k_htc_priv *priv = hw->priv;
877 struct ath_hw *ah = priv->ah;
878 struct ath_common *common = ath9k_hw_common(ah);
879 struct ieee80211_channel *curchan = hw->conf.channel;
880 struct ath9k_channel *init_channel;
882 enum htc_phymode mode;
886 mutex_lock(&priv->mutex);
888 ath_dbg(common, ATH_DBG_CONFIG,
889 "Starting driver with initial channel: %d MHz\n",
890 curchan->center_freq);
892 /* Ensure that HW is awake before flushing RX */
893 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
894 WMI_CMD(WMI_FLUSH_RECV_CMDID);
896 /* setup initial channel */
897 init_channel = ath9k_cmn_get_curchannel(hw, ah);
899 ath9k_hw_htc_resetinit(ah);
900 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
903 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
904 ret, curchan->center_freq);
905 mutex_unlock(&priv->mutex);
909 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
912 mode = ath9k_htc_get_curmode(priv, init_channel);
913 htc_mode = cpu_to_be16(mode);
914 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
915 WMI_CMD(WMI_ATH_INIT_CMDID);
916 WMI_CMD(WMI_START_RECV_CMDID);
918 ath9k_host_rx_init(priv);
920 ret = ath9k_htc_update_cap_target(priv);
922 ath_dbg(common, ATH_DBG_CONFIG,
923 "Failed to update capability in target\n");
925 priv->op_flags &= ~OP_INVALID;
926 htc_start(priv->htc);
928 spin_lock_bh(&priv->tx_lock);
929 priv->tx_queues_stop = false;
930 spin_unlock_bh(&priv->tx_lock);
932 ieee80211_wake_queues(hw);
934 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
935 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
936 AR_STOMP_LOW_WLAN_WGHT);
937 ath9k_hw_btcoex_enable(ah);
938 ath_htc_resume_btcoex_work(priv);
940 mutex_unlock(&priv->mutex);
945 static void ath9k_htc_stop(struct ieee80211_hw *hw)
947 struct ath9k_htc_priv *priv = hw->priv;
948 struct ath_hw *ah = priv->ah;
949 struct ath_common *common = ath9k_hw_common(ah);
953 mutex_lock(&priv->mutex);
955 if (priv->op_flags & OP_INVALID) {
956 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
957 mutex_unlock(&priv->mutex);
961 ath9k_htc_ps_wakeup(priv);
963 WMI_CMD(WMI_DISABLE_INTR_CMDID);
964 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
965 WMI_CMD(WMI_STOP_RECV_CMDID);
967 tasklet_kill(&priv->rx_tasklet);
968 tasklet_kill(&priv->tx_tasklet);
970 skb_queue_purge(&priv->tx_queue);
972 ath9k_wmi_event_drain(priv);
974 mutex_unlock(&priv->mutex);
976 /* Cancel all the running timers/work .. */
977 cancel_work_sync(&priv->fatal_work);
978 cancel_work_sync(&priv->ps_work);
979 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
980 ath9k_htc_stop_ani(priv);
981 ath9k_led_stop_brightness(priv);
983 mutex_lock(&priv->mutex);
985 if (ah->btcoex_hw.enabled) {
986 ath9k_hw_btcoex_disable(ah);
987 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
988 ath_htc_cancel_btcoex_work(priv);
991 /* Remove a monitor interface if it's present. */
992 if (priv->ah->is_monitoring)
993 ath9k_htc_remove_monitor_interface(priv);
995 ath9k_hw_phy_disable(ah);
996 ath9k_hw_disable(ah);
997 ath9k_htc_ps_restore(priv);
998 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1000 priv->op_flags |= OP_INVALID;
1002 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1003 mutex_unlock(&priv->mutex);
1006 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1007 struct ieee80211_vif *vif)
1009 struct ath9k_htc_priv *priv = hw->priv;
1010 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1011 struct ath_common *common = ath9k_hw_common(priv->ah);
1012 struct ath9k_htc_target_vif hvif;
1016 mutex_lock(&priv->mutex);
1018 if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1019 mutex_unlock(&priv->mutex);
1023 if (priv->num_ibss_vif ||
1024 (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
1025 ath_err(common, "IBSS coexistence with other modes is not allowed\n");
1026 mutex_unlock(&priv->mutex);
1030 if (((vif->type == NL80211_IFTYPE_AP) ||
1031 (vif->type == NL80211_IFTYPE_ADHOC)) &&
1032 ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) {
1033 ath_err(common, "Max. number of beaconing interfaces reached\n");
1034 mutex_unlock(&priv->mutex);
1038 ath9k_htc_ps_wakeup(priv);
1039 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1040 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1042 switch (vif->type) {
1043 case NL80211_IFTYPE_STATION:
1044 hvif.opmode = cpu_to_be32(HTC_M_STA);
1046 case NL80211_IFTYPE_ADHOC:
1047 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1049 case NL80211_IFTYPE_AP:
1050 hvif.opmode = cpu_to_be32(HTC_M_HOSTAP);
1054 "Interface type %d not yet supported\n", vif->type);
1059 /* Index starts from zero on the target */
1060 avp->index = hvif.index = ffz(priv->vif_slot);
1061 hvif.rtsthreshold = cpu_to_be16(2304);
1062 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1067 * We need a node in target to tx mgmt frames
1068 * before association.
1070 ret = ath9k_htc_add_station(priv, vif, NULL);
1072 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1076 ath9k_htc_set_bssid_mask(priv, vif);
1078 priv->vif_slot |= (1 << avp->index);
1081 INC_VIF(priv, vif->type);
1083 if ((vif->type == NL80211_IFTYPE_AP) ||
1084 (vif->type == NL80211_IFTYPE_ADHOC))
1085 ath9k_htc_assign_bslot(priv, vif);
1087 ath9k_htc_set_opmode(priv);
1089 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1090 !(priv->op_flags & OP_ANI_RUNNING)) {
1091 ath9k_hw_set_tsfadjust(priv->ah, 1);
1092 ath9k_htc_start_ani(priv);
1095 ath_dbg(common, ATH_DBG_CONFIG,
1096 "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index);
1099 ath9k_htc_ps_restore(priv);
1100 mutex_unlock(&priv->mutex);
1105 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1106 struct ieee80211_vif *vif)
1108 struct ath9k_htc_priv *priv = hw->priv;
1109 struct ath_common *common = ath9k_hw_common(priv->ah);
1110 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1111 struct ath9k_htc_target_vif hvif;
1115 mutex_lock(&priv->mutex);
1116 ath9k_htc_ps_wakeup(priv);
1118 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1119 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1120 hvif.index = avp->index;
1121 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1123 priv->vif_slot &= ~(1 << avp->index);
1125 ath9k_htc_remove_station(priv, vif, NULL);
1127 DEC_VIF(priv, vif->type);
1129 if ((vif->type == NL80211_IFTYPE_AP) ||
1130 (vif->type == NL80211_IFTYPE_ADHOC))
1131 ath9k_htc_remove_bslot(priv, vif);
1133 ath9k_htc_set_opmode(priv);
1136 * Stop ANI only if there are no associated station interfaces.
1138 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1139 priv->rearm_ani = false;
1140 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1141 ath9k_htc_vif_iter, priv);
1142 if (!priv->rearm_ani)
1143 ath9k_htc_stop_ani(priv);
1146 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index);
1148 ath9k_htc_ps_restore(priv);
1149 mutex_unlock(&priv->mutex);
1152 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1154 struct ath9k_htc_priv *priv = hw->priv;
1155 struct ath_common *common = ath9k_hw_common(priv->ah);
1156 struct ieee80211_conf *conf = &hw->conf;
1158 mutex_lock(&priv->mutex);
1160 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1161 bool enable_radio = false;
1162 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1164 mutex_lock(&priv->htc_pm_lock);
1165 if (!idle && priv->ps_idle)
1166 enable_radio = true;
1167 priv->ps_idle = idle;
1168 mutex_unlock(&priv->htc_pm_lock);
1171 ath_dbg(common, ATH_DBG_CONFIG,
1172 "not-idle: enabling radio\n");
1173 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1174 ath9k_htc_radio_enable(hw);
1179 * Monitor interface should be added before
1180 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1182 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1183 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1184 !priv->ah->is_monitoring)
1185 ath9k_htc_add_monitor_interface(priv);
1186 else if (priv->ah->is_monitoring)
1187 ath9k_htc_remove_monitor_interface(priv);
1190 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1191 struct ieee80211_channel *curchan = hw->conf.channel;
1192 int pos = curchan->hw_value;
1194 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1195 curchan->center_freq);
1197 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1199 hw->conf.channel_type);
1201 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1202 ath_err(common, "Unable to set channel\n");
1203 mutex_unlock(&priv->mutex);
1209 if (changed & IEEE80211_CONF_CHANGE_PS) {
1210 if (conf->flags & IEEE80211_CONF_PS) {
1211 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1212 priv->ps_enabled = true;
1214 priv->ps_enabled = false;
1215 cancel_work_sync(&priv->ps_work);
1216 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1220 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1221 priv->txpowlimit = 2 * conf->power_level;
1222 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1223 priv->txpowlimit, &priv->curtxpow);
1226 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1227 mutex_lock(&priv->htc_pm_lock);
1228 if (!priv->ps_idle) {
1229 mutex_unlock(&priv->htc_pm_lock);
1232 mutex_unlock(&priv->htc_pm_lock);
1234 ath_dbg(common, ATH_DBG_CONFIG,
1235 "idle: disabling radio\n");
1236 ath9k_htc_radio_disable(hw);
1240 mutex_unlock(&priv->mutex);
1244 #define SUPPORTED_FILTERS \
1245 (FIF_PROMISC_IN_BSS | \
1250 FIF_BCN_PRBRESP_PROMISC | \
1254 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1255 unsigned int changed_flags,
1256 unsigned int *total_flags,
1259 struct ath9k_htc_priv *priv = hw->priv;
1262 mutex_lock(&priv->mutex);
1263 ath9k_htc_ps_wakeup(priv);
1265 changed_flags &= SUPPORTED_FILTERS;
1266 *total_flags &= SUPPORTED_FILTERS;
1268 priv->rxfilter = *total_flags;
1269 rfilt = ath9k_htc_calcrxfilter(priv);
1270 ath9k_hw_setrxfilter(priv->ah, rfilt);
1272 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1273 "Set HW RX filter: 0x%x\n", rfilt);
1275 ath9k_htc_ps_restore(priv);
1276 mutex_unlock(&priv->mutex);
1279 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1280 struct ieee80211_vif *vif,
1281 struct ieee80211_sta *sta)
1283 struct ath9k_htc_priv *priv = hw->priv;
1286 mutex_lock(&priv->mutex);
1287 ath9k_htc_ps_wakeup(priv);
1288 ret = ath9k_htc_add_station(priv, vif, sta);
1290 ath9k_htc_init_rate(priv, sta);
1291 ath9k_htc_ps_restore(priv);
1292 mutex_unlock(&priv->mutex);
1297 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1298 struct ieee80211_vif *vif,
1299 struct ieee80211_sta *sta)
1301 struct ath9k_htc_priv *priv = hw->priv;
1304 mutex_lock(&priv->mutex);
1305 ath9k_htc_ps_wakeup(priv);
1306 ret = ath9k_htc_remove_station(priv, vif, sta);
1307 ath9k_htc_ps_restore(priv);
1308 mutex_unlock(&priv->mutex);
1313 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1314 const struct ieee80211_tx_queue_params *params)
1316 struct ath9k_htc_priv *priv = hw->priv;
1317 struct ath_common *common = ath9k_hw_common(priv->ah);
1318 struct ath9k_tx_queue_info qi;
1321 if (queue >= WME_NUM_AC)
1324 mutex_lock(&priv->mutex);
1325 ath9k_htc_ps_wakeup(priv);
1327 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1329 qi.tqi_aifs = params->aifs;
1330 qi.tqi_cwmin = params->cw_min;
1331 qi.tqi_cwmax = params->cw_max;
1332 qi.tqi_burstTime = params->txop;
1334 qnum = get_hw_qnum(queue, priv->hwq_map);
1336 ath_dbg(common, ATH_DBG_CONFIG,
1337 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1338 queue, qnum, params->aifs, params->cw_min,
1339 params->cw_max, params->txop);
1341 ret = ath_htc_txq_update(priv, qnum, &qi);
1343 ath_err(common, "TXQ Update failed\n");
1347 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1348 (qnum == priv->hwq_map[WME_AC_BE]))
1349 ath9k_htc_beaconq_config(priv);
1351 ath9k_htc_ps_restore(priv);
1352 mutex_unlock(&priv->mutex);
1357 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1358 enum set_key_cmd cmd,
1359 struct ieee80211_vif *vif,
1360 struct ieee80211_sta *sta,
1361 struct ieee80211_key_conf *key)
1363 struct ath9k_htc_priv *priv = hw->priv;
1364 struct ath_common *common = ath9k_hw_common(priv->ah);
1367 if (htc_modparam_nohwcrypt)
1370 mutex_lock(&priv->mutex);
1371 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1372 ath9k_htc_ps_wakeup(priv);
1376 ret = ath_key_config(common, vif, sta, key);
1378 key->hw_key_idx = ret;
1379 /* push IV and Michael MIC generation to stack */
1380 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1381 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1382 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1383 if (priv->ah->sw_mgmt_crypto &&
1384 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1385 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1390 ath_key_delete(common, key);
1396 ath9k_htc_ps_restore(priv);
1397 mutex_unlock(&priv->mutex);
1402 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1403 struct ieee80211_vif *vif,
1404 struct ieee80211_bss_conf *bss_conf,
1407 struct ath9k_htc_priv *priv = hw->priv;
1408 struct ath_hw *ah = priv->ah;
1409 struct ath_common *common = ath9k_hw_common(ah);
1412 mutex_lock(&priv->mutex);
1413 ath9k_htc_ps_wakeup(priv);
1416 * Set the HW AID/BSSID only for the first station interface
1419 set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) ||
1420 ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
1421 (priv->num_sta_vif == 1)));
1424 if (changed & BSS_CHANGED_ASSOC) {
1426 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1429 common->curaid = bss_conf->assoc ?
1432 if (bss_conf->assoc)
1433 ath9k_htc_start_ani(priv);
1435 ath9k_htc_stop_ani(priv);
1439 if (changed & BSS_CHANGED_BSSID) {
1441 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1442 ath9k_hw_write_associd(ah);
1444 ath_dbg(common, ATH_DBG_CONFIG,
1445 "BSSID: %pM aid: 0x%x\n",
1446 common->curbssid, common->curaid);
1450 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1451 ath_dbg(common, ATH_DBG_CONFIG,
1452 "Beacon enabled for BSS: %pM\n", bss_conf->bssid);
1453 ath9k_htc_set_tsfadjust(priv, vif);
1454 priv->op_flags |= OP_ENABLE_BEACON;
1455 ath9k_htc_beacon_config(priv, vif);
1458 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1460 * Disable SWBA interrupt only if there are no
1461 * AP/IBSS interfaces.
1463 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1464 ath_dbg(common, ATH_DBG_CONFIG,
1465 "Beacon disabled for BSS: %pM\n",
1467 priv->op_flags &= ~OP_ENABLE_BEACON;
1468 ath9k_htc_beacon_config(priv, vif);
1472 if (changed & BSS_CHANGED_BEACON_INT) {
1474 * Reset the HW TSF for the first AP interface.
1476 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1477 (priv->nvifs == 1) &&
1478 (priv->num_ap_vif == 1) &&
1479 (vif->type == NL80211_IFTYPE_AP)) {
1480 priv->op_flags |= OP_TSF_RESET;
1482 ath_dbg(common, ATH_DBG_CONFIG,
1483 "Beacon interval changed for BSS: %pM\n",
1485 ath9k_htc_beacon_config(priv, vif);
1488 if (changed & BSS_CHANGED_ERP_SLOT) {
1489 if (bss_conf->use_short_slot)
1494 ath9k_hw_init_global_settings(ah);
1497 if (changed & BSS_CHANGED_HT)
1498 ath9k_htc_update_rate(priv, vif, bss_conf);
1500 ath9k_htc_ps_restore(priv);
1501 mutex_unlock(&priv->mutex);
1504 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1506 struct ath9k_htc_priv *priv = hw->priv;
1509 mutex_lock(&priv->mutex);
1510 ath9k_htc_ps_wakeup(priv);
1511 tsf = ath9k_hw_gettsf64(priv->ah);
1512 ath9k_htc_ps_restore(priv);
1513 mutex_unlock(&priv->mutex);
1518 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1520 struct ath9k_htc_priv *priv = hw->priv;
1522 mutex_lock(&priv->mutex);
1523 ath9k_htc_ps_wakeup(priv);
1524 ath9k_hw_settsf64(priv->ah, tsf);
1525 ath9k_htc_ps_restore(priv);
1526 mutex_unlock(&priv->mutex);
1529 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1531 struct ath9k_htc_priv *priv = hw->priv;
1533 mutex_lock(&priv->mutex);
1534 ath9k_htc_ps_wakeup(priv);
1535 ath9k_hw_reset_tsf(priv->ah);
1536 ath9k_htc_ps_restore(priv);
1537 mutex_unlock(&priv->mutex);
1540 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1541 struct ieee80211_vif *vif,
1542 enum ieee80211_ampdu_mlme_action action,
1543 struct ieee80211_sta *sta,
1544 u16 tid, u16 *ssn, u8 buf_size)
1546 struct ath9k_htc_priv *priv = hw->priv;
1547 struct ath9k_htc_sta *ista;
1550 mutex_lock(&priv->mutex);
1553 case IEEE80211_AMPDU_RX_START:
1555 case IEEE80211_AMPDU_RX_STOP:
1557 case IEEE80211_AMPDU_TX_START:
1558 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1560 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1562 case IEEE80211_AMPDU_TX_STOP:
1563 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1564 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1566 case IEEE80211_AMPDU_TX_OPERATIONAL:
1567 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1568 spin_lock_bh(&priv->tx_lock);
1569 ista->tid_state[tid] = AGGR_OPERATIONAL;
1570 spin_unlock_bh(&priv->tx_lock);
1573 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1576 mutex_unlock(&priv->mutex);
1581 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1583 struct ath9k_htc_priv *priv = hw->priv;
1585 mutex_lock(&priv->mutex);
1586 spin_lock_bh(&priv->beacon_lock);
1587 priv->op_flags |= OP_SCANNING;
1588 spin_unlock_bh(&priv->beacon_lock);
1589 cancel_work_sync(&priv->ps_work);
1590 ath9k_htc_stop_ani(priv);
1591 mutex_unlock(&priv->mutex);
1594 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1596 struct ath9k_htc_priv *priv = hw->priv;
1598 mutex_lock(&priv->mutex);
1599 spin_lock_bh(&priv->beacon_lock);
1600 priv->op_flags &= ~OP_SCANNING;
1601 spin_unlock_bh(&priv->beacon_lock);
1602 ath9k_htc_ps_wakeup(priv);
1603 ath9k_htc_vif_reconfig(priv);
1604 ath9k_htc_ps_restore(priv);
1605 mutex_unlock(&priv->mutex);
1608 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1613 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1616 struct ath9k_htc_priv *priv = hw->priv;
1618 mutex_lock(&priv->mutex);
1619 ath9k_htc_ps_wakeup(priv);
1620 priv->ah->coverage_class = coverage_class;
1621 ath9k_hw_init_global_settings(priv->ah);
1622 ath9k_htc_ps_restore(priv);
1623 mutex_unlock(&priv->mutex);
1626 struct ieee80211_ops ath9k_htc_ops = {
1628 .start = ath9k_htc_start,
1629 .stop = ath9k_htc_stop,
1630 .add_interface = ath9k_htc_add_interface,
1631 .remove_interface = ath9k_htc_remove_interface,
1632 .config = ath9k_htc_config,
1633 .configure_filter = ath9k_htc_configure_filter,
1634 .sta_add = ath9k_htc_sta_add,
1635 .sta_remove = ath9k_htc_sta_remove,
1636 .conf_tx = ath9k_htc_conf_tx,
1637 .bss_info_changed = ath9k_htc_bss_info_changed,
1638 .set_key = ath9k_htc_set_key,
1639 .get_tsf = ath9k_htc_get_tsf,
1640 .set_tsf = ath9k_htc_set_tsf,
1641 .reset_tsf = ath9k_htc_reset_tsf,
1642 .ampdu_action = ath9k_htc_ampdu_action,
1643 .sw_scan_start = ath9k_htc_sw_scan_start,
1644 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1645 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1646 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1647 .set_coverage_class = ath9k_htc_set_coverage_class,