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 del_timer_sync(&priv->tx.cleanup_timer);
198 ath9k_htc_tx_drain(priv);
200 WMI_CMD(WMI_DISABLE_INTR_CMDID);
201 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
202 WMI_CMD(WMI_STOP_RECV_CMDID);
204 ath9k_wmi_event_drain(priv);
206 caldata = &priv->caldata;
207 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
210 "Unable to reset device (%u Mhz) reset status %d\n",
211 channel->center_freq, ret);
214 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
217 WMI_CMD(WMI_START_RECV_CMDID);
218 ath9k_host_rx_init(priv);
220 mode = ath9k_htc_get_curmode(priv, ah->curchan);
221 htc_mode = cpu_to_be16(mode);
222 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
224 WMI_CMD(WMI_ENABLE_INTR_CMDID);
225 htc_start(priv->htc);
226 ath9k_htc_vif_reconfig(priv);
227 ieee80211_wake_queues(priv->hw);
229 mod_timer(&priv->tx.cleanup_timer,
230 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
232 ath9k_htc_ps_restore(priv);
233 mutex_unlock(&priv->mutex);
236 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
237 struct ieee80211_hw *hw,
238 struct ath9k_channel *hchan)
240 struct ath_hw *ah = priv->ah;
241 struct ath_common *common = ath9k_hw_common(ah);
242 struct ieee80211_conf *conf = &common->hw->conf;
244 struct ieee80211_channel *channel = hw->conf.channel;
245 struct ath9k_hw_cal_data *caldata = NULL;
246 enum htc_phymode mode;
251 if (priv->op_flags & OP_INVALID)
254 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
256 ath9k_htc_ps_wakeup(priv);
258 del_timer_sync(&priv->tx.cleanup_timer);
259 ath9k_htc_tx_drain(priv);
261 WMI_CMD(WMI_DISABLE_INTR_CMDID);
262 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
263 WMI_CMD(WMI_STOP_RECV_CMDID);
265 ath9k_wmi_event_drain(priv);
267 ath_dbg(common, ATH_DBG_CONFIG,
268 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
269 priv->ah->curchan->channel,
270 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
274 caldata = &priv->caldata;
276 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
279 "Unable to reset channel (%u Mhz) reset status %d\n",
280 channel->center_freq, ret);
284 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
287 WMI_CMD(WMI_START_RECV_CMDID);
291 ath9k_host_rx_init(priv);
293 mode = ath9k_htc_get_curmode(priv, hchan);
294 htc_mode = cpu_to_be16(mode);
295 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
299 WMI_CMD(WMI_ENABLE_INTR_CMDID);
303 htc_start(priv->htc);
305 if (!(priv->op_flags & OP_SCANNING) &&
306 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
307 ath9k_htc_vif_reconfig(priv);
309 mod_timer(&priv->tx.cleanup_timer,
310 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
313 ath9k_htc_ps_restore(priv);
318 * Monitor mode handling is a tad complicated because the firmware requires
319 * an interface to be created exclusively, while mac80211 doesn't associate
320 * an interface with the mode.
322 * So, for now, only one monitor interface can be configured.
324 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
326 struct ath_common *common = ath9k_hw_common(priv->ah);
327 struct ath9k_htc_target_vif hvif;
331 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
332 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
333 hvif.index = priv->mon_vif_idx;
334 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
336 ath_err(common, "Unable to remove monitor interface at idx: %d\n",
341 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
344 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
346 struct ath_common *common = ath9k_hw_common(priv->ah);
347 struct ath9k_htc_target_vif hvif;
348 struct ath9k_htc_target_sta tsta;
349 int ret = 0, sta_idx;
352 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
353 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
358 sta_idx = ffz(priv->sta_slot);
359 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
367 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
368 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
370 hvif.opmode = HTC_M_MONITOR;
371 hvif.index = ffz(priv->vif_slot);
373 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
378 * Assign the monitor interface index as a special case here.
379 * This is needed when the interface is brought down.
381 priv->mon_vif_idx = hvif.index;
382 priv->vif_slot |= (1 << hvif.index);
385 * Set the hardware mode to monitor only if there are no
389 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
394 * Associate a station with the interface for packet injection.
396 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
398 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
401 tsta.sta_index = sta_idx;
402 tsta.vif_index = hvif.index;
403 tsta.maxampdu = cpu_to_be16(0xffff);
405 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
407 ath_err(common, "Unable to add station entry for monitor mode\n");
411 priv->sta_slot |= (1 << sta_idx);
413 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
414 priv->ah->is_monitoring = true;
416 ath_dbg(common, ATH_DBG_CONFIG,
417 "Attached a monitor interface at idx: %d, sta idx: %d\n",
418 priv->mon_vif_idx, sta_idx);
424 * Remove the interface from the target.
426 __ath9k_htc_remove_monitor_interface(priv);
428 ath_dbg(common, ATH_DBG_FATAL, "Unable to attach a monitor interface\n");
433 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
435 struct ath_common *common = ath9k_hw_common(priv->ah);
439 __ath9k_htc_remove_monitor_interface(priv);
441 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
443 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
445 ath_err(common, "Unable to remove station entry for monitor mode\n");
449 priv->sta_slot &= ~(1 << sta_idx);
451 priv->ah->is_monitoring = false;
453 ath_dbg(common, ATH_DBG_CONFIG,
454 "Removed a monitor interface at idx: %d, sta idx: %d\n",
455 priv->mon_vif_idx, sta_idx);
460 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
461 struct ieee80211_vif *vif,
462 struct ieee80211_sta *sta)
464 struct ath_common *common = ath9k_hw_common(priv->ah);
465 struct ath9k_htc_target_sta tsta;
466 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
467 struct ath9k_htc_sta *ista;
471 if (priv->nstations >= ATH9K_HTC_MAX_STA)
474 sta_idx = ffz(priv->sta_slot);
475 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
478 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
481 ista = (struct ath9k_htc_sta *) sta->drv_priv;
482 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
483 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
485 ista->index = sta_idx;
487 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
491 tsta.sta_index = sta_idx;
492 tsta.vif_index = avp->index;
493 tsta.maxampdu = cpu_to_be16(0xffff);
494 if (sta && sta->ht_cap.ht_supported)
495 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
497 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
501 "Unable to add station entry for: %pM\n",
507 ath_dbg(common, ATH_DBG_CONFIG,
508 "Added a station entry for: %pM (idx: %d)\n",
509 sta->addr, tsta.sta_index);
511 ath_dbg(common, ATH_DBG_CONFIG,
512 "Added a station entry for VIF %d (idx: %d)\n",
513 avp->index, tsta.sta_index);
516 priv->sta_slot |= (1 << sta_idx);
519 priv->vif_sta_pos[avp->index] = sta_idx;
524 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
525 struct ieee80211_vif *vif,
526 struct ieee80211_sta *sta)
528 struct ath_common *common = ath9k_hw_common(priv->ah);
529 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
530 struct ath9k_htc_sta *ista;
535 ista = (struct ath9k_htc_sta *) sta->drv_priv;
536 sta_idx = ista->index;
538 sta_idx = priv->vif_sta_pos[avp->index];
541 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
545 "Unable to remove station entry for: %pM\n",
551 ath_dbg(common, ATH_DBG_CONFIG,
552 "Removed a station entry for: %pM (idx: %d)\n",
555 ath_dbg(common, ATH_DBG_CONFIG,
556 "Removed a station entry for VIF %d (idx: %d)\n",
557 avp->index, sta_idx);
560 priv->sta_slot &= ~(1 << sta_idx);
566 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
568 struct ath9k_htc_cap_target tcap;
572 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
574 /* FIXME: Values are hardcoded */
575 tcap.flags = 0x240c40;
576 tcap.flags_ext = 0x80601000;
577 tcap.ampdu_limit = 0xffff0000;
578 tcap.ampdu_subframes = 20;
579 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
581 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
583 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
588 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
589 struct ieee80211_sta *sta,
590 struct ath9k_htc_target_rate *trate)
592 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
593 struct ieee80211_supported_band *sband;
597 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
599 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
600 if (sta->supp_rates[sband->band] & BIT(i)) {
601 trate->rates.legacy_rates.rs_rates[j]
602 = (sband->bitrates[i].bitrate * 2) / 10;
606 trate->rates.legacy_rates.rs_nrates = j;
608 if (sta->ht_cap.ht_supported) {
609 for (i = 0, j = 0; i < 77; i++) {
610 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
611 trate->rates.ht_rates.rs_rates[j++] = i;
612 if (j == ATH_HTC_RATE_MAX)
615 trate->rates.ht_rates.rs_nrates = j;
617 caps = WLAN_RC_HT_FLAG;
618 if (sta->ht_cap.mcs.rx_mask[1])
619 caps |= WLAN_RC_DS_FLAG;
620 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
621 (conf_is_ht40(&priv->hw->conf)))
622 caps |= WLAN_RC_40_FLAG;
623 if (conf_is_ht40(&priv->hw->conf) &&
624 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
625 caps |= WLAN_RC_SGI_FLAG;
626 else if (conf_is_ht20(&priv->hw->conf) &&
627 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
628 caps |= WLAN_RC_SGI_FLAG;
631 trate->sta_index = ista->index;
633 trate->capflags = cpu_to_be32(caps);
636 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
637 struct ath9k_htc_target_rate *trate)
639 struct ath_common *common = ath9k_hw_common(priv->ah);
643 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
646 "Unable to initialize Rate information on target\n");
652 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
653 struct ieee80211_sta *sta)
655 struct ath_common *common = ath9k_hw_common(priv->ah);
656 struct ath9k_htc_target_rate trate;
659 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
660 ath9k_htc_setup_rate(priv, sta, &trate);
661 ret = ath9k_htc_send_rate_cmd(priv, &trate);
663 ath_dbg(common, ATH_DBG_CONFIG,
664 "Updated target sta: %pM, rate caps: 0x%X\n",
665 sta->addr, be32_to_cpu(trate.capflags));
668 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
669 struct ieee80211_vif *vif,
670 struct ieee80211_bss_conf *bss_conf)
672 struct ath_common *common = ath9k_hw_common(priv->ah);
673 struct ath9k_htc_target_rate trate;
674 struct ieee80211_sta *sta;
677 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
680 sta = ieee80211_find_sta(vif, bss_conf->bssid);
685 ath9k_htc_setup_rate(priv, sta, &trate);
688 ret = ath9k_htc_send_rate_cmd(priv, &trate);
690 ath_dbg(common, ATH_DBG_CONFIG,
691 "Updated target sta: %pM, rate caps: 0x%X\n",
692 bss_conf->bssid, be32_to_cpu(trate.capflags));
695 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
696 struct ieee80211_vif *vif,
697 struct ieee80211_sta *sta,
698 enum ieee80211_ampdu_mlme_action action,
701 struct ath_common *common = ath9k_hw_common(priv->ah);
702 struct ath9k_htc_target_aggr aggr;
703 struct ath9k_htc_sta *ista;
707 if (tid >= ATH9K_HTC_MAX_TID)
710 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
711 ista = (struct ath9k_htc_sta *) sta->drv_priv;
713 aggr.sta_index = ista->index;
714 aggr.tidno = tid & 0xf;
715 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
717 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
719 ath_dbg(common, ATH_DBG_CONFIG,
720 "Unable to %s TX aggregation for (%pM, %d)\n",
721 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
723 ath_dbg(common, ATH_DBG_CONFIG,
724 "%s TX aggregation for (%pM, %d)\n",
725 (aggr.aggr_enable) ? "Starting" : "Stopping",
728 spin_lock_bh(&priv->tx.tx_lock);
729 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
730 spin_unlock_bh(&priv->tx.tx_lock);
739 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
741 struct ath_common *common = ath9k_hw_common(priv->ah);
742 unsigned long timestamp = jiffies_to_msecs(jiffies);
744 common->ani.longcal_timer = timestamp;
745 common->ani.shortcal_timer = timestamp;
746 common->ani.checkani_timer = timestamp;
748 priv->op_flags |= OP_ANI_RUNNING;
750 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
751 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
754 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
756 cancel_delayed_work_sync(&priv->ani_work);
757 priv->op_flags &= ~OP_ANI_RUNNING;
760 void ath9k_htc_ani_work(struct work_struct *work)
762 struct ath9k_htc_priv *priv =
763 container_of(work, struct ath9k_htc_priv, ani_work.work);
764 struct ath_hw *ah = priv->ah;
765 struct ath_common *common = ath9k_hw_common(ah);
766 bool longcal = false;
767 bool shortcal = false;
768 bool aniflag = false;
769 unsigned int timestamp = jiffies_to_msecs(jiffies);
770 u32 cal_interval, short_cal_interval;
772 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
773 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
775 /* Only calibrate if awake */
776 if (ah->power_mode != ATH9K_PM_AWAKE)
779 /* Long calibration runs independently of short calibration. */
780 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
782 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
783 common->ani.longcal_timer = timestamp;
786 /* Short calibration applies only while caldone is false */
787 if (!common->ani.caldone) {
788 if ((timestamp - common->ani.shortcal_timer) >=
789 short_cal_interval) {
791 ath_dbg(common, ATH_DBG_ANI,
792 "shortcal @%lu\n", jiffies);
793 common->ani.shortcal_timer = timestamp;
794 common->ani.resetcal_timer = timestamp;
797 if ((timestamp - common->ani.resetcal_timer) >=
798 ATH_RESTART_CALINTERVAL) {
799 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
800 if (common->ani.caldone)
801 common->ani.resetcal_timer = timestamp;
805 /* Verify whether we must check ANI */
806 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
808 common->ani.checkani_timer = timestamp;
811 /* Skip all processing if there's nothing to do. */
812 if (longcal || shortcal || aniflag) {
814 ath9k_htc_ps_wakeup(priv);
816 /* Call ANI routine if necessary */
818 ath9k_hw_ani_monitor(ah, ah->curchan);
820 /* Perform calibration if necessary */
821 if (longcal || shortcal)
822 common->ani.caldone =
823 ath9k_hw_calibrate(ah, ah->curchan,
824 common->rx_chainmask,
827 ath9k_htc_ps_restore(priv);
832 * Set timer interval based on previous results.
833 * The interval must be the shortest necessary to satisfy ANI,
834 * short calibration and long calibration.
836 cal_interval = ATH_LONG_CALINTERVAL;
837 if (priv->ah->config.enable_ani)
838 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
839 if (!common->ani.caldone)
840 cal_interval = min(cal_interval, (u32)short_cal_interval);
842 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
843 msecs_to_jiffies(cal_interval));
846 /**********************/
847 /* mac80211 Callbacks */
848 /**********************/
850 static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
852 struct ieee80211_hdr *hdr;
853 struct ath9k_htc_priv *priv = hw->priv;
854 struct ath_common *common = ath9k_hw_common(priv->ah);
855 int padpos, padsize, ret, slot;
857 hdr = (struct ieee80211_hdr *) skb->data;
859 /* Add the padding after the header if this is not already done */
860 padpos = ath9k_cmn_padpos(hdr->frame_control);
861 padsize = padpos & 3;
862 if (padsize && skb->len > padpos) {
863 if (skb_headroom(skb) < padsize) {
864 ath_dbg(common, ATH_DBG_XMIT, "No room for padding\n");
867 skb_push(skb, padsize);
868 memmove(skb->data, skb->data + padsize, padpos);
871 slot = ath9k_htc_tx_get_slot(priv);
873 ath_dbg(common, ATH_DBG_XMIT, "No free TX slot\n");
877 ret = ath9k_htc_tx_start(priv, skb, slot, false);
879 ath_dbg(common, ATH_DBG_XMIT, "Tx failed\n");
883 ath9k_htc_check_stop_queues(priv);
888 ath9k_htc_tx_clear_slot(priv, slot);
890 dev_kfree_skb_any(skb);
893 static int ath9k_htc_start(struct ieee80211_hw *hw)
895 struct ath9k_htc_priv *priv = hw->priv;
896 struct ath_hw *ah = priv->ah;
897 struct ath_common *common = ath9k_hw_common(ah);
898 struct ieee80211_channel *curchan = hw->conf.channel;
899 struct ath9k_channel *init_channel;
901 enum htc_phymode mode;
905 mutex_lock(&priv->mutex);
907 ath_dbg(common, ATH_DBG_CONFIG,
908 "Starting driver with initial channel: %d MHz\n",
909 curchan->center_freq);
911 /* Ensure that HW is awake before flushing RX */
912 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
913 WMI_CMD(WMI_FLUSH_RECV_CMDID);
915 /* setup initial channel */
916 init_channel = ath9k_cmn_get_curchannel(hw, ah);
918 ath9k_hw_htc_resetinit(ah);
919 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
922 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
923 ret, curchan->center_freq);
924 mutex_unlock(&priv->mutex);
928 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
931 mode = ath9k_htc_get_curmode(priv, init_channel);
932 htc_mode = cpu_to_be16(mode);
933 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
934 WMI_CMD(WMI_ATH_INIT_CMDID);
935 WMI_CMD(WMI_START_RECV_CMDID);
937 ath9k_host_rx_init(priv);
939 ret = ath9k_htc_update_cap_target(priv);
941 ath_dbg(common, ATH_DBG_CONFIG,
942 "Failed to update capability in target\n");
944 priv->op_flags &= ~OP_INVALID;
945 htc_start(priv->htc);
947 spin_lock_bh(&priv->tx.tx_lock);
948 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
949 spin_unlock_bh(&priv->tx.tx_lock);
951 ieee80211_wake_queues(hw);
953 mod_timer(&priv->tx.cleanup_timer,
954 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
956 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
957 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
958 AR_STOMP_LOW_WLAN_WGHT);
959 ath9k_hw_btcoex_enable(ah);
960 ath_htc_resume_btcoex_work(priv);
962 mutex_unlock(&priv->mutex);
967 static void ath9k_htc_stop(struct ieee80211_hw *hw)
969 struct ath9k_htc_priv *priv = hw->priv;
970 struct ath_hw *ah = priv->ah;
971 struct ath_common *common = ath9k_hw_common(ah);
972 int ret __attribute__ ((unused));
975 mutex_lock(&priv->mutex);
977 if (priv->op_flags & OP_INVALID) {
978 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
979 mutex_unlock(&priv->mutex);
983 ath9k_htc_ps_wakeup(priv);
985 WMI_CMD(WMI_DISABLE_INTR_CMDID);
986 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
987 WMI_CMD(WMI_STOP_RECV_CMDID);
989 tasklet_kill(&priv->rx_tasklet);
991 del_timer_sync(&priv->tx.cleanup_timer);
992 ath9k_htc_tx_drain(priv);
993 ath9k_wmi_event_drain(priv);
995 mutex_unlock(&priv->mutex);
997 /* Cancel all the running timers/work .. */
998 cancel_work_sync(&priv->fatal_work);
999 cancel_work_sync(&priv->ps_work);
1000 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1001 ath9k_htc_stop_ani(priv);
1002 ath9k_led_stop_brightness(priv);
1004 mutex_lock(&priv->mutex);
1006 if (ah->btcoex_hw.enabled) {
1007 ath9k_hw_btcoex_disable(ah);
1008 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
1009 ath_htc_cancel_btcoex_work(priv);
1012 /* Remove a monitor interface if it's present. */
1013 if (priv->ah->is_monitoring)
1014 ath9k_htc_remove_monitor_interface(priv);
1016 ath9k_hw_phy_disable(ah);
1017 ath9k_hw_disable(ah);
1018 ath9k_htc_ps_restore(priv);
1019 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1021 priv->op_flags |= OP_INVALID;
1023 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1024 mutex_unlock(&priv->mutex);
1027 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1028 struct ieee80211_vif *vif)
1030 struct ath9k_htc_priv *priv = hw->priv;
1031 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1032 struct ath_common *common = ath9k_hw_common(priv->ah);
1033 struct ath9k_htc_target_vif hvif;
1037 mutex_lock(&priv->mutex);
1039 if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1040 mutex_unlock(&priv->mutex);
1044 if (priv->num_ibss_vif ||
1045 (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
1046 ath_err(common, "IBSS coexistence with other modes is not allowed\n");
1047 mutex_unlock(&priv->mutex);
1051 if (((vif->type == NL80211_IFTYPE_AP) ||
1052 (vif->type == NL80211_IFTYPE_ADHOC)) &&
1053 ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) {
1054 ath_err(common, "Max. number of beaconing interfaces reached\n");
1055 mutex_unlock(&priv->mutex);
1059 ath9k_htc_ps_wakeup(priv);
1060 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1061 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1063 switch (vif->type) {
1064 case NL80211_IFTYPE_STATION:
1065 hvif.opmode = HTC_M_STA;
1067 case NL80211_IFTYPE_ADHOC:
1068 hvif.opmode = HTC_M_IBSS;
1070 case NL80211_IFTYPE_AP:
1071 hvif.opmode = HTC_M_HOSTAP;
1075 "Interface type %d not yet supported\n", vif->type);
1080 /* Index starts from zero on the target */
1081 avp->index = hvif.index = ffz(priv->vif_slot);
1082 hvif.rtsthreshold = cpu_to_be16(2304);
1083 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1088 * We need a node in target to tx mgmt frames
1089 * before association.
1091 ret = ath9k_htc_add_station(priv, vif, NULL);
1093 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1097 ath9k_htc_set_bssid_mask(priv, vif);
1099 priv->vif_slot |= (1 << avp->index);
1102 INC_VIF(priv, vif->type);
1104 if ((vif->type == NL80211_IFTYPE_AP) ||
1105 (vif->type == NL80211_IFTYPE_ADHOC))
1106 ath9k_htc_assign_bslot(priv, vif);
1108 ath9k_htc_set_opmode(priv);
1110 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1111 !(priv->op_flags & OP_ANI_RUNNING)) {
1112 ath9k_hw_set_tsfadjust(priv->ah, 1);
1113 ath9k_htc_start_ani(priv);
1116 ath_dbg(common, ATH_DBG_CONFIG,
1117 "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index);
1120 ath9k_htc_ps_restore(priv);
1121 mutex_unlock(&priv->mutex);
1126 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1127 struct ieee80211_vif *vif)
1129 struct ath9k_htc_priv *priv = hw->priv;
1130 struct ath_common *common = ath9k_hw_common(priv->ah);
1131 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1132 struct ath9k_htc_target_vif hvif;
1136 mutex_lock(&priv->mutex);
1137 ath9k_htc_ps_wakeup(priv);
1139 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1140 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1141 hvif.index = avp->index;
1142 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1144 ath_err(common, "Unable to remove interface at idx: %d\n",
1148 priv->vif_slot &= ~(1 << avp->index);
1150 ath9k_htc_remove_station(priv, vif, NULL);
1152 DEC_VIF(priv, vif->type);
1154 if ((vif->type == NL80211_IFTYPE_AP) ||
1155 (vif->type == NL80211_IFTYPE_ADHOC))
1156 ath9k_htc_remove_bslot(priv, vif);
1158 ath9k_htc_set_opmode(priv);
1161 * Stop ANI only if there are no associated station interfaces.
1163 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1164 priv->rearm_ani = false;
1165 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1166 ath9k_htc_vif_iter, priv);
1167 if (!priv->rearm_ani)
1168 ath9k_htc_stop_ani(priv);
1171 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index);
1173 ath9k_htc_ps_restore(priv);
1174 mutex_unlock(&priv->mutex);
1177 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1179 struct ath9k_htc_priv *priv = hw->priv;
1180 struct ath_common *common = ath9k_hw_common(priv->ah);
1181 struct ieee80211_conf *conf = &hw->conf;
1183 mutex_lock(&priv->mutex);
1185 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1186 bool enable_radio = false;
1187 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1189 mutex_lock(&priv->htc_pm_lock);
1190 if (!idle && priv->ps_idle)
1191 enable_radio = true;
1192 priv->ps_idle = idle;
1193 mutex_unlock(&priv->htc_pm_lock);
1196 ath_dbg(common, ATH_DBG_CONFIG,
1197 "not-idle: enabling radio\n");
1198 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1199 ath9k_htc_radio_enable(hw);
1204 * Monitor interface should be added before
1205 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1207 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1208 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1209 !priv->ah->is_monitoring)
1210 ath9k_htc_add_monitor_interface(priv);
1211 else if (priv->ah->is_monitoring)
1212 ath9k_htc_remove_monitor_interface(priv);
1215 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1216 struct ieee80211_channel *curchan = hw->conf.channel;
1217 int pos = curchan->hw_value;
1219 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1220 curchan->center_freq);
1222 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1224 hw->conf.channel_type);
1226 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1227 ath_err(common, "Unable to set channel\n");
1228 mutex_unlock(&priv->mutex);
1234 if (changed & IEEE80211_CONF_CHANGE_PS) {
1235 if (conf->flags & IEEE80211_CONF_PS) {
1236 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1237 priv->ps_enabled = true;
1239 priv->ps_enabled = false;
1240 cancel_work_sync(&priv->ps_work);
1241 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1245 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1246 priv->txpowlimit = 2 * conf->power_level;
1247 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1248 priv->txpowlimit, &priv->curtxpow);
1251 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1252 mutex_lock(&priv->htc_pm_lock);
1253 if (!priv->ps_idle) {
1254 mutex_unlock(&priv->htc_pm_lock);
1257 mutex_unlock(&priv->htc_pm_lock);
1259 ath_dbg(common, ATH_DBG_CONFIG,
1260 "idle: disabling radio\n");
1261 ath9k_htc_radio_disable(hw);
1265 mutex_unlock(&priv->mutex);
1269 #define SUPPORTED_FILTERS \
1270 (FIF_PROMISC_IN_BSS | \
1275 FIF_BCN_PRBRESP_PROMISC | \
1279 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1280 unsigned int changed_flags,
1281 unsigned int *total_flags,
1284 struct ath9k_htc_priv *priv = hw->priv;
1287 mutex_lock(&priv->mutex);
1288 ath9k_htc_ps_wakeup(priv);
1290 changed_flags &= SUPPORTED_FILTERS;
1291 *total_flags &= SUPPORTED_FILTERS;
1293 priv->rxfilter = *total_flags;
1294 rfilt = ath9k_htc_calcrxfilter(priv);
1295 ath9k_hw_setrxfilter(priv->ah, rfilt);
1297 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1298 "Set HW RX filter: 0x%x\n", rfilt);
1300 ath9k_htc_ps_restore(priv);
1301 mutex_unlock(&priv->mutex);
1304 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1305 struct ieee80211_vif *vif,
1306 struct ieee80211_sta *sta)
1308 struct ath9k_htc_priv *priv = hw->priv;
1311 mutex_lock(&priv->mutex);
1312 ath9k_htc_ps_wakeup(priv);
1313 ret = ath9k_htc_add_station(priv, vif, sta);
1315 ath9k_htc_init_rate(priv, sta);
1316 ath9k_htc_ps_restore(priv);
1317 mutex_unlock(&priv->mutex);
1322 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1323 struct ieee80211_vif *vif,
1324 struct ieee80211_sta *sta)
1326 struct ath9k_htc_priv *priv = hw->priv;
1327 struct ath9k_htc_sta *ista;
1330 mutex_lock(&priv->mutex);
1331 ath9k_htc_ps_wakeup(priv);
1332 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1333 htc_sta_drain(priv->htc, ista->index);
1334 ret = ath9k_htc_remove_station(priv, vif, sta);
1335 ath9k_htc_ps_restore(priv);
1336 mutex_unlock(&priv->mutex);
1341 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1342 const struct ieee80211_tx_queue_params *params)
1344 struct ath9k_htc_priv *priv = hw->priv;
1345 struct ath_common *common = ath9k_hw_common(priv->ah);
1346 struct ath9k_tx_queue_info qi;
1349 if (queue >= WME_NUM_AC)
1352 mutex_lock(&priv->mutex);
1353 ath9k_htc_ps_wakeup(priv);
1355 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1357 qi.tqi_aifs = params->aifs;
1358 qi.tqi_cwmin = params->cw_min;
1359 qi.tqi_cwmax = params->cw_max;
1360 qi.tqi_burstTime = params->txop;
1362 qnum = get_hw_qnum(queue, priv->hwq_map);
1364 ath_dbg(common, ATH_DBG_CONFIG,
1365 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1366 queue, qnum, params->aifs, params->cw_min,
1367 params->cw_max, params->txop);
1369 ret = ath_htc_txq_update(priv, qnum, &qi);
1371 ath_err(common, "TXQ Update failed\n");
1375 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1376 (qnum == priv->hwq_map[WME_AC_BE]))
1377 ath9k_htc_beaconq_config(priv);
1379 ath9k_htc_ps_restore(priv);
1380 mutex_unlock(&priv->mutex);
1385 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1386 enum set_key_cmd cmd,
1387 struct ieee80211_vif *vif,
1388 struct ieee80211_sta *sta,
1389 struct ieee80211_key_conf *key)
1391 struct ath9k_htc_priv *priv = hw->priv;
1392 struct ath_common *common = ath9k_hw_common(priv->ah);
1395 if (htc_modparam_nohwcrypt)
1398 mutex_lock(&priv->mutex);
1399 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1400 ath9k_htc_ps_wakeup(priv);
1404 ret = ath_key_config(common, vif, sta, key);
1406 key->hw_key_idx = ret;
1407 /* push IV and Michael MIC generation to stack */
1408 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1409 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1410 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1411 if (priv->ah->sw_mgmt_crypto &&
1412 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1413 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1418 ath_key_delete(common, key);
1424 ath9k_htc_ps_restore(priv);
1425 mutex_unlock(&priv->mutex);
1430 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1431 struct ieee80211_vif *vif,
1432 struct ieee80211_bss_conf *bss_conf,
1435 struct ath9k_htc_priv *priv = hw->priv;
1436 struct ath_hw *ah = priv->ah;
1437 struct ath_common *common = ath9k_hw_common(ah);
1440 mutex_lock(&priv->mutex);
1441 ath9k_htc_ps_wakeup(priv);
1444 * Set the HW AID/BSSID only for the first station interface
1447 set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) ||
1448 ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
1449 (priv->num_sta_vif == 1)));
1452 if (changed & BSS_CHANGED_ASSOC) {
1454 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1457 common->curaid = bss_conf->assoc ?
1460 if (bss_conf->assoc)
1461 ath9k_htc_start_ani(priv);
1463 ath9k_htc_stop_ani(priv);
1467 if (changed & BSS_CHANGED_BSSID) {
1469 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1470 ath9k_hw_write_associd(ah);
1472 ath_dbg(common, ATH_DBG_CONFIG,
1473 "BSSID: %pM aid: 0x%x\n",
1474 common->curbssid, common->curaid);
1478 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1479 ath_dbg(common, ATH_DBG_CONFIG,
1480 "Beacon enabled for BSS: %pM\n", bss_conf->bssid);
1481 ath9k_htc_set_tsfadjust(priv, vif);
1482 priv->op_flags |= OP_ENABLE_BEACON;
1483 ath9k_htc_beacon_config(priv, vif);
1486 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1488 * Disable SWBA interrupt only if there are no
1489 * AP/IBSS interfaces.
1491 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1492 ath_dbg(common, ATH_DBG_CONFIG,
1493 "Beacon disabled for BSS: %pM\n",
1495 priv->op_flags &= ~OP_ENABLE_BEACON;
1496 ath9k_htc_beacon_config(priv, vif);
1500 if (changed & BSS_CHANGED_BEACON_INT) {
1502 * Reset the HW TSF for the first AP interface.
1504 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1505 (priv->nvifs == 1) &&
1506 (priv->num_ap_vif == 1) &&
1507 (vif->type == NL80211_IFTYPE_AP)) {
1508 priv->op_flags |= OP_TSF_RESET;
1510 ath_dbg(common, ATH_DBG_CONFIG,
1511 "Beacon interval changed for BSS: %pM\n",
1513 ath9k_htc_beacon_config(priv, vif);
1516 if (changed & BSS_CHANGED_ERP_SLOT) {
1517 if (bss_conf->use_short_slot)
1522 ath9k_hw_init_global_settings(ah);
1525 if (changed & BSS_CHANGED_HT)
1526 ath9k_htc_update_rate(priv, vif, bss_conf);
1528 ath9k_htc_ps_restore(priv);
1529 mutex_unlock(&priv->mutex);
1532 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1534 struct ath9k_htc_priv *priv = hw->priv;
1537 mutex_lock(&priv->mutex);
1538 ath9k_htc_ps_wakeup(priv);
1539 tsf = ath9k_hw_gettsf64(priv->ah);
1540 ath9k_htc_ps_restore(priv);
1541 mutex_unlock(&priv->mutex);
1546 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1548 struct ath9k_htc_priv *priv = hw->priv;
1550 mutex_lock(&priv->mutex);
1551 ath9k_htc_ps_wakeup(priv);
1552 ath9k_hw_settsf64(priv->ah, tsf);
1553 ath9k_htc_ps_restore(priv);
1554 mutex_unlock(&priv->mutex);
1557 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1559 struct ath9k_htc_priv *priv = hw->priv;
1561 mutex_lock(&priv->mutex);
1562 ath9k_htc_ps_wakeup(priv);
1563 ath9k_hw_reset_tsf(priv->ah);
1564 ath9k_htc_ps_restore(priv);
1565 mutex_unlock(&priv->mutex);
1568 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1569 struct ieee80211_vif *vif,
1570 enum ieee80211_ampdu_mlme_action action,
1571 struct ieee80211_sta *sta,
1572 u16 tid, u16 *ssn, u8 buf_size)
1574 struct ath9k_htc_priv *priv = hw->priv;
1575 struct ath9k_htc_sta *ista;
1578 mutex_lock(&priv->mutex);
1581 case IEEE80211_AMPDU_RX_START:
1583 case IEEE80211_AMPDU_RX_STOP:
1585 case IEEE80211_AMPDU_TX_START:
1586 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1588 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1590 case IEEE80211_AMPDU_TX_STOP:
1591 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1592 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1594 case IEEE80211_AMPDU_TX_OPERATIONAL:
1595 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1596 spin_lock_bh(&priv->tx.tx_lock);
1597 ista->tid_state[tid] = AGGR_OPERATIONAL;
1598 spin_unlock_bh(&priv->tx.tx_lock);
1601 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1604 mutex_unlock(&priv->mutex);
1609 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1611 struct ath9k_htc_priv *priv = hw->priv;
1613 mutex_lock(&priv->mutex);
1614 spin_lock_bh(&priv->beacon_lock);
1615 priv->op_flags |= OP_SCANNING;
1616 spin_unlock_bh(&priv->beacon_lock);
1617 cancel_work_sync(&priv->ps_work);
1618 ath9k_htc_stop_ani(priv);
1619 mutex_unlock(&priv->mutex);
1622 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1624 struct ath9k_htc_priv *priv = hw->priv;
1626 mutex_lock(&priv->mutex);
1627 spin_lock_bh(&priv->beacon_lock);
1628 priv->op_flags &= ~OP_SCANNING;
1629 spin_unlock_bh(&priv->beacon_lock);
1630 ath9k_htc_ps_wakeup(priv);
1631 ath9k_htc_vif_reconfig(priv);
1632 ath9k_htc_ps_restore(priv);
1633 mutex_unlock(&priv->mutex);
1636 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1641 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1644 struct ath9k_htc_priv *priv = hw->priv;
1646 mutex_lock(&priv->mutex);
1647 ath9k_htc_ps_wakeup(priv);
1648 priv->ah->coverage_class = coverage_class;
1649 ath9k_hw_init_global_settings(priv->ah);
1650 ath9k_htc_ps_restore(priv);
1651 mutex_unlock(&priv->mutex);
1654 struct ieee80211_ops ath9k_htc_ops = {
1656 .start = ath9k_htc_start,
1657 .stop = ath9k_htc_stop,
1658 .add_interface = ath9k_htc_add_interface,
1659 .remove_interface = ath9k_htc_remove_interface,
1660 .config = ath9k_htc_config,
1661 .configure_filter = ath9k_htc_configure_filter,
1662 .sta_add = ath9k_htc_sta_add,
1663 .sta_remove = ath9k_htc_sta_remove,
1664 .conf_tx = ath9k_htc_conf_tx,
1665 .bss_info_changed = ath9k_htc_bss_info_changed,
1666 .set_key = ath9k_htc_set_key,
1667 .get_tsf = ath9k_htc_get_tsf,
1668 .set_tsf = ath9k_htc_set_tsf,
1669 .reset_tsf = ath9k_htc_reset_tsf,
1670 .ampdu_action = ath9k_htc_ampdu_action,
1671 .sw_scan_start = ath9k_htc_sw_scan_start,
1672 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1673 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1674 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1675 .set_coverage_class = ath9k_htc_set_coverage_class,