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,
569 struct ath9k_htc_cap_target tcap;
573 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
575 tcap.ampdu_limit = cpu_to_be32(0xffff);
576 tcap.ampdu_subframes = priv->hw->max_tx_aggregation_subframes;
577 tcap.enable_coex = enable_coex;
578 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
580 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
585 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
586 struct ieee80211_sta *sta,
587 struct ath9k_htc_target_rate *trate)
589 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
590 struct ieee80211_supported_band *sband;
594 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
596 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
597 if (sta->supp_rates[sband->band] & BIT(i)) {
598 trate->rates.legacy_rates.rs_rates[j]
599 = (sband->bitrates[i].bitrate * 2) / 10;
603 trate->rates.legacy_rates.rs_nrates = j;
605 if (sta->ht_cap.ht_supported) {
606 for (i = 0, j = 0; i < 77; i++) {
607 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
608 trate->rates.ht_rates.rs_rates[j++] = i;
609 if (j == ATH_HTC_RATE_MAX)
612 trate->rates.ht_rates.rs_nrates = j;
614 caps = WLAN_RC_HT_FLAG;
615 if (sta->ht_cap.mcs.rx_mask[1])
616 caps |= WLAN_RC_DS_FLAG;
617 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
618 (conf_is_ht40(&priv->hw->conf)))
619 caps |= WLAN_RC_40_FLAG;
620 if (conf_is_ht40(&priv->hw->conf) &&
621 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
622 caps |= WLAN_RC_SGI_FLAG;
623 else if (conf_is_ht20(&priv->hw->conf) &&
624 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
625 caps |= WLAN_RC_SGI_FLAG;
628 trate->sta_index = ista->index;
630 trate->capflags = cpu_to_be32(caps);
633 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
634 struct ath9k_htc_target_rate *trate)
636 struct ath_common *common = ath9k_hw_common(priv->ah);
640 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
643 "Unable to initialize Rate information on target\n");
649 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
650 struct ieee80211_sta *sta)
652 struct ath_common *common = ath9k_hw_common(priv->ah);
653 struct ath9k_htc_target_rate trate;
656 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
657 ath9k_htc_setup_rate(priv, sta, &trate);
658 ret = ath9k_htc_send_rate_cmd(priv, &trate);
660 ath_dbg(common, ATH_DBG_CONFIG,
661 "Updated target sta: %pM, rate caps: 0x%X\n",
662 sta->addr, be32_to_cpu(trate.capflags));
665 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
666 struct ieee80211_vif *vif,
667 struct ieee80211_bss_conf *bss_conf)
669 struct ath_common *common = ath9k_hw_common(priv->ah);
670 struct ath9k_htc_target_rate trate;
671 struct ieee80211_sta *sta;
674 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
677 sta = ieee80211_find_sta(vif, bss_conf->bssid);
682 ath9k_htc_setup_rate(priv, sta, &trate);
685 ret = ath9k_htc_send_rate_cmd(priv, &trate);
687 ath_dbg(common, ATH_DBG_CONFIG,
688 "Updated target sta: %pM, rate caps: 0x%X\n",
689 bss_conf->bssid, be32_to_cpu(trate.capflags));
692 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
693 struct ieee80211_vif *vif,
694 struct ieee80211_sta *sta,
695 enum ieee80211_ampdu_mlme_action action,
698 struct ath_common *common = ath9k_hw_common(priv->ah);
699 struct ath9k_htc_target_aggr aggr;
700 struct ath9k_htc_sta *ista;
704 if (tid >= ATH9K_HTC_MAX_TID)
707 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
708 ista = (struct ath9k_htc_sta *) sta->drv_priv;
710 aggr.sta_index = ista->index;
711 aggr.tidno = tid & 0xf;
712 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
714 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
716 ath_dbg(common, ATH_DBG_CONFIG,
717 "Unable to %s TX aggregation for (%pM, %d)\n",
718 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
720 ath_dbg(common, ATH_DBG_CONFIG,
721 "%s TX aggregation for (%pM, %d)\n",
722 (aggr.aggr_enable) ? "Starting" : "Stopping",
725 spin_lock_bh(&priv->tx.tx_lock);
726 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
727 spin_unlock_bh(&priv->tx.tx_lock);
736 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
738 struct ath_common *common = ath9k_hw_common(priv->ah);
739 unsigned long timestamp = jiffies_to_msecs(jiffies);
741 common->ani.longcal_timer = timestamp;
742 common->ani.shortcal_timer = timestamp;
743 common->ani.checkani_timer = timestamp;
745 priv->op_flags |= OP_ANI_RUNNING;
747 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
748 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
751 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
753 cancel_delayed_work_sync(&priv->ani_work);
754 priv->op_flags &= ~OP_ANI_RUNNING;
757 void ath9k_htc_ani_work(struct work_struct *work)
759 struct ath9k_htc_priv *priv =
760 container_of(work, struct ath9k_htc_priv, ani_work.work);
761 struct ath_hw *ah = priv->ah;
762 struct ath_common *common = ath9k_hw_common(ah);
763 bool longcal = false;
764 bool shortcal = false;
765 bool aniflag = false;
766 unsigned int timestamp = jiffies_to_msecs(jiffies);
767 u32 cal_interval, short_cal_interval;
769 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
770 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
772 /* Only calibrate if awake */
773 if (ah->power_mode != ATH9K_PM_AWAKE)
776 /* Long calibration runs independently of short calibration. */
777 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
779 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
780 common->ani.longcal_timer = timestamp;
783 /* Short calibration applies only while caldone is false */
784 if (!common->ani.caldone) {
785 if ((timestamp - common->ani.shortcal_timer) >=
786 short_cal_interval) {
788 ath_dbg(common, ATH_DBG_ANI,
789 "shortcal @%lu\n", jiffies);
790 common->ani.shortcal_timer = timestamp;
791 common->ani.resetcal_timer = timestamp;
794 if ((timestamp - common->ani.resetcal_timer) >=
795 ATH_RESTART_CALINTERVAL) {
796 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
797 if (common->ani.caldone)
798 common->ani.resetcal_timer = timestamp;
802 /* Verify whether we must check ANI */
803 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
805 common->ani.checkani_timer = timestamp;
808 /* Skip all processing if there's nothing to do. */
809 if (longcal || shortcal || aniflag) {
811 ath9k_htc_ps_wakeup(priv);
813 /* Call ANI routine if necessary */
815 ath9k_hw_ani_monitor(ah, ah->curchan);
817 /* Perform calibration if necessary */
818 if (longcal || shortcal)
819 common->ani.caldone =
820 ath9k_hw_calibrate(ah, ah->curchan,
821 common->rx_chainmask,
824 ath9k_htc_ps_restore(priv);
829 * Set timer interval based on previous results.
830 * The interval must be the shortest necessary to satisfy ANI,
831 * short calibration and long calibration.
833 cal_interval = ATH_LONG_CALINTERVAL;
834 if (priv->ah->config.enable_ani)
835 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
836 if (!common->ani.caldone)
837 cal_interval = min(cal_interval, (u32)short_cal_interval);
839 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
840 msecs_to_jiffies(cal_interval));
843 /**********************/
844 /* mac80211 Callbacks */
845 /**********************/
847 static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
849 struct ieee80211_hdr *hdr;
850 struct ath9k_htc_priv *priv = hw->priv;
851 struct ath_common *common = ath9k_hw_common(priv->ah);
852 int padpos, padsize, ret, slot;
854 hdr = (struct ieee80211_hdr *) skb->data;
856 /* Add the padding after the header if this is not already done */
857 padpos = ath9k_cmn_padpos(hdr->frame_control);
858 padsize = padpos & 3;
859 if (padsize && skb->len > padpos) {
860 if (skb_headroom(skb) < padsize) {
861 ath_dbg(common, ATH_DBG_XMIT, "No room for padding\n");
864 skb_push(skb, padsize);
865 memmove(skb->data, skb->data + padsize, padpos);
868 slot = ath9k_htc_tx_get_slot(priv);
870 ath_dbg(common, ATH_DBG_XMIT, "No free TX slot\n");
874 ret = ath9k_htc_tx_start(priv, skb, slot, false);
876 ath_dbg(common, ATH_DBG_XMIT, "Tx failed\n");
880 ath9k_htc_check_stop_queues(priv);
885 ath9k_htc_tx_clear_slot(priv, slot);
887 dev_kfree_skb_any(skb);
890 static int ath9k_htc_start(struct ieee80211_hw *hw)
892 struct ath9k_htc_priv *priv = hw->priv;
893 struct ath_hw *ah = priv->ah;
894 struct ath_common *common = ath9k_hw_common(ah);
895 struct ieee80211_channel *curchan = hw->conf.channel;
896 struct ath9k_channel *init_channel;
898 enum htc_phymode mode;
902 mutex_lock(&priv->mutex);
904 ath_dbg(common, ATH_DBG_CONFIG,
905 "Starting driver with initial channel: %d MHz\n",
906 curchan->center_freq);
908 /* Ensure that HW is awake before flushing RX */
909 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
910 WMI_CMD(WMI_FLUSH_RECV_CMDID);
912 /* setup initial channel */
913 init_channel = ath9k_cmn_get_curchannel(hw, ah);
915 ath9k_hw_htc_resetinit(ah);
916 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
919 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
920 ret, curchan->center_freq);
921 mutex_unlock(&priv->mutex);
925 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
928 mode = ath9k_htc_get_curmode(priv, init_channel);
929 htc_mode = cpu_to_be16(mode);
930 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
931 WMI_CMD(WMI_ATH_INIT_CMDID);
932 WMI_CMD(WMI_START_RECV_CMDID);
934 ath9k_host_rx_init(priv);
936 ret = ath9k_htc_update_cap_target(priv, 0);
938 ath_dbg(common, ATH_DBG_CONFIG,
939 "Failed to update capability in target\n");
941 priv->op_flags &= ~OP_INVALID;
942 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);
948 ieee80211_wake_queues(hw);
950 mod_timer(&priv->tx.cleanup_timer,
951 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
953 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
954 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
955 AR_STOMP_LOW_WLAN_WGHT);
956 ath9k_hw_btcoex_enable(ah);
957 ath_htc_resume_btcoex_work(priv);
959 mutex_unlock(&priv->mutex);
964 static void ath9k_htc_stop(struct ieee80211_hw *hw)
966 struct ath9k_htc_priv *priv = hw->priv;
967 struct ath_hw *ah = priv->ah;
968 struct ath_common *common = ath9k_hw_common(ah);
969 int ret __attribute__ ((unused));
972 mutex_lock(&priv->mutex);
974 if (priv->op_flags & OP_INVALID) {
975 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
976 mutex_unlock(&priv->mutex);
980 ath9k_htc_ps_wakeup(priv);
982 WMI_CMD(WMI_DISABLE_INTR_CMDID);
983 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
984 WMI_CMD(WMI_STOP_RECV_CMDID);
986 tasklet_kill(&priv->rx_tasklet);
988 del_timer_sync(&priv->tx.cleanup_timer);
989 ath9k_htc_tx_drain(priv);
990 ath9k_wmi_event_drain(priv);
992 mutex_unlock(&priv->mutex);
994 /* Cancel all the running timers/work .. */
995 cancel_work_sync(&priv->fatal_work);
996 cancel_work_sync(&priv->ps_work);
997 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
998 ath9k_htc_stop_ani(priv);
999 ath9k_led_stop_brightness(priv);
1001 mutex_lock(&priv->mutex);
1003 if (ah->btcoex_hw.enabled) {
1004 ath9k_hw_btcoex_disable(ah);
1005 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
1006 ath_htc_cancel_btcoex_work(priv);
1009 /* Remove a monitor interface if it's present. */
1010 if (priv->ah->is_monitoring)
1011 ath9k_htc_remove_monitor_interface(priv);
1013 ath9k_hw_phy_disable(ah);
1014 ath9k_hw_disable(ah);
1015 ath9k_htc_ps_restore(priv);
1016 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1018 priv->op_flags |= OP_INVALID;
1020 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1021 mutex_unlock(&priv->mutex);
1024 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1025 struct ieee80211_vif *vif)
1027 struct ath9k_htc_priv *priv = hw->priv;
1028 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1029 struct ath_common *common = ath9k_hw_common(priv->ah);
1030 struct ath9k_htc_target_vif hvif;
1034 mutex_lock(&priv->mutex);
1036 if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1037 mutex_unlock(&priv->mutex);
1041 if (priv->num_ibss_vif ||
1042 (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
1043 ath_err(common, "IBSS coexistence with other modes is not allowed\n");
1044 mutex_unlock(&priv->mutex);
1048 if (((vif->type == NL80211_IFTYPE_AP) ||
1049 (vif->type == NL80211_IFTYPE_ADHOC)) &&
1050 ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) {
1051 ath_err(common, "Max. number of beaconing interfaces reached\n");
1052 mutex_unlock(&priv->mutex);
1056 ath9k_htc_ps_wakeup(priv);
1057 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1058 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1060 switch (vif->type) {
1061 case NL80211_IFTYPE_STATION:
1062 hvif.opmode = HTC_M_STA;
1064 case NL80211_IFTYPE_ADHOC:
1065 hvif.opmode = HTC_M_IBSS;
1067 case NL80211_IFTYPE_AP:
1068 hvif.opmode = HTC_M_HOSTAP;
1072 "Interface type %d not yet supported\n", vif->type);
1077 /* Index starts from zero on the target */
1078 avp->index = hvif.index = ffz(priv->vif_slot);
1079 hvif.rtsthreshold = cpu_to_be16(2304);
1080 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1085 * We need a node in target to tx mgmt frames
1086 * before association.
1088 ret = ath9k_htc_add_station(priv, vif, NULL);
1090 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1094 ath9k_htc_set_bssid_mask(priv, vif);
1096 priv->vif_slot |= (1 << avp->index);
1099 INC_VIF(priv, vif->type);
1101 if ((vif->type == NL80211_IFTYPE_AP) ||
1102 (vif->type == NL80211_IFTYPE_ADHOC))
1103 ath9k_htc_assign_bslot(priv, vif);
1105 ath9k_htc_set_opmode(priv);
1107 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1108 !(priv->op_flags & OP_ANI_RUNNING)) {
1109 ath9k_hw_set_tsfadjust(priv->ah, 1);
1110 ath9k_htc_start_ani(priv);
1113 ath_dbg(common, ATH_DBG_CONFIG,
1114 "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index);
1117 ath9k_htc_ps_restore(priv);
1118 mutex_unlock(&priv->mutex);
1123 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1124 struct ieee80211_vif *vif)
1126 struct ath9k_htc_priv *priv = hw->priv;
1127 struct ath_common *common = ath9k_hw_common(priv->ah);
1128 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1129 struct ath9k_htc_target_vif hvif;
1133 mutex_lock(&priv->mutex);
1134 ath9k_htc_ps_wakeup(priv);
1136 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1137 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1138 hvif.index = avp->index;
1139 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1141 ath_err(common, "Unable to remove interface at idx: %d\n",
1145 priv->vif_slot &= ~(1 << avp->index);
1147 ath9k_htc_remove_station(priv, vif, NULL);
1149 DEC_VIF(priv, vif->type);
1151 if ((vif->type == NL80211_IFTYPE_AP) ||
1152 (vif->type == NL80211_IFTYPE_ADHOC))
1153 ath9k_htc_remove_bslot(priv, vif);
1155 ath9k_htc_set_opmode(priv);
1158 * Stop ANI only if there are no associated station interfaces.
1160 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1161 priv->rearm_ani = false;
1162 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1163 ath9k_htc_vif_iter, priv);
1164 if (!priv->rearm_ani)
1165 ath9k_htc_stop_ani(priv);
1168 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index);
1170 ath9k_htc_ps_restore(priv);
1171 mutex_unlock(&priv->mutex);
1174 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1176 struct ath9k_htc_priv *priv = hw->priv;
1177 struct ath_common *common = ath9k_hw_common(priv->ah);
1178 struct ieee80211_conf *conf = &hw->conf;
1180 mutex_lock(&priv->mutex);
1182 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1183 bool enable_radio = false;
1184 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1186 mutex_lock(&priv->htc_pm_lock);
1187 if (!idle && priv->ps_idle)
1188 enable_radio = true;
1189 priv->ps_idle = idle;
1190 mutex_unlock(&priv->htc_pm_lock);
1193 ath_dbg(common, ATH_DBG_CONFIG,
1194 "not-idle: enabling radio\n");
1195 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1196 ath9k_htc_radio_enable(hw);
1201 * Monitor interface should be added before
1202 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1204 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1205 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1206 !priv->ah->is_monitoring)
1207 ath9k_htc_add_monitor_interface(priv);
1208 else if (priv->ah->is_monitoring)
1209 ath9k_htc_remove_monitor_interface(priv);
1212 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1213 struct ieee80211_channel *curchan = hw->conf.channel;
1214 int pos = curchan->hw_value;
1216 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1217 curchan->center_freq);
1219 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1221 hw->conf.channel_type);
1223 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1224 ath_err(common, "Unable to set channel\n");
1225 mutex_unlock(&priv->mutex);
1231 if (changed & IEEE80211_CONF_CHANGE_PS) {
1232 if (conf->flags & IEEE80211_CONF_PS) {
1233 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1234 priv->ps_enabled = true;
1236 priv->ps_enabled = false;
1237 cancel_work_sync(&priv->ps_work);
1238 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1242 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1243 priv->txpowlimit = 2 * conf->power_level;
1244 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1245 priv->txpowlimit, &priv->curtxpow);
1248 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1249 mutex_lock(&priv->htc_pm_lock);
1250 if (!priv->ps_idle) {
1251 mutex_unlock(&priv->htc_pm_lock);
1254 mutex_unlock(&priv->htc_pm_lock);
1256 ath_dbg(common, ATH_DBG_CONFIG,
1257 "idle: disabling radio\n");
1258 ath9k_htc_radio_disable(hw);
1262 mutex_unlock(&priv->mutex);
1266 #define SUPPORTED_FILTERS \
1267 (FIF_PROMISC_IN_BSS | \
1272 FIF_BCN_PRBRESP_PROMISC | \
1276 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1277 unsigned int changed_flags,
1278 unsigned int *total_flags,
1281 struct ath9k_htc_priv *priv = hw->priv;
1284 mutex_lock(&priv->mutex);
1285 ath9k_htc_ps_wakeup(priv);
1287 changed_flags &= SUPPORTED_FILTERS;
1288 *total_flags &= SUPPORTED_FILTERS;
1290 priv->rxfilter = *total_flags;
1291 rfilt = ath9k_htc_calcrxfilter(priv);
1292 ath9k_hw_setrxfilter(priv->ah, rfilt);
1294 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1295 "Set HW RX filter: 0x%x\n", rfilt);
1297 ath9k_htc_ps_restore(priv);
1298 mutex_unlock(&priv->mutex);
1301 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1302 struct ieee80211_vif *vif,
1303 struct ieee80211_sta *sta)
1305 struct ath9k_htc_priv *priv = hw->priv;
1308 mutex_lock(&priv->mutex);
1309 ath9k_htc_ps_wakeup(priv);
1310 ret = ath9k_htc_add_station(priv, vif, sta);
1312 ath9k_htc_init_rate(priv, sta);
1313 ath9k_htc_ps_restore(priv);
1314 mutex_unlock(&priv->mutex);
1319 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1320 struct ieee80211_vif *vif,
1321 struct ieee80211_sta *sta)
1323 struct ath9k_htc_priv *priv = hw->priv;
1324 struct ath9k_htc_sta *ista;
1327 mutex_lock(&priv->mutex);
1328 ath9k_htc_ps_wakeup(priv);
1329 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1330 htc_sta_drain(priv->htc, ista->index);
1331 ret = ath9k_htc_remove_station(priv, vif, sta);
1332 ath9k_htc_ps_restore(priv);
1333 mutex_unlock(&priv->mutex);
1338 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1339 const struct ieee80211_tx_queue_params *params)
1341 struct ath9k_htc_priv *priv = hw->priv;
1342 struct ath_common *common = ath9k_hw_common(priv->ah);
1343 struct ath9k_tx_queue_info qi;
1346 if (queue >= WME_NUM_AC)
1349 mutex_lock(&priv->mutex);
1350 ath9k_htc_ps_wakeup(priv);
1352 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1354 qi.tqi_aifs = params->aifs;
1355 qi.tqi_cwmin = params->cw_min;
1356 qi.tqi_cwmax = params->cw_max;
1357 qi.tqi_burstTime = params->txop;
1359 qnum = get_hw_qnum(queue, priv->hwq_map);
1361 ath_dbg(common, ATH_DBG_CONFIG,
1362 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1363 queue, qnum, params->aifs, params->cw_min,
1364 params->cw_max, params->txop);
1366 ret = ath_htc_txq_update(priv, qnum, &qi);
1368 ath_err(common, "TXQ Update failed\n");
1372 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1373 (qnum == priv->hwq_map[WME_AC_BE]))
1374 ath9k_htc_beaconq_config(priv);
1376 ath9k_htc_ps_restore(priv);
1377 mutex_unlock(&priv->mutex);
1382 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1383 enum set_key_cmd cmd,
1384 struct ieee80211_vif *vif,
1385 struct ieee80211_sta *sta,
1386 struct ieee80211_key_conf *key)
1388 struct ath9k_htc_priv *priv = hw->priv;
1389 struct ath_common *common = ath9k_hw_common(priv->ah);
1392 if (htc_modparam_nohwcrypt)
1395 mutex_lock(&priv->mutex);
1396 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1397 ath9k_htc_ps_wakeup(priv);
1401 ret = ath_key_config(common, vif, sta, key);
1403 key->hw_key_idx = ret;
1404 /* push IV and Michael MIC generation to stack */
1405 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1406 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1407 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1408 if (priv->ah->sw_mgmt_crypto &&
1409 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1410 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1415 ath_key_delete(common, key);
1421 ath9k_htc_ps_restore(priv);
1422 mutex_unlock(&priv->mutex);
1427 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1428 struct ieee80211_vif *vif,
1429 struct ieee80211_bss_conf *bss_conf,
1432 struct ath9k_htc_priv *priv = hw->priv;
1433 struct ath_hw *ah = priv->ah;
1434 struct ath_common *common = ath9k_hw_common(ah);
1437 mutex_lock(&priv->mutex);
1438 ath9k_htc_ps_wakeup(priv);
1441 * Set the HW AID/BSSID only for the first station interface
1444 set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) ||
1445 ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
1446 (priv->num_sta_vif == 1)));
1449 if (changed & BSS_CHANGED_ASSOC) {
1451 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1454 common->curaid = bss_conf->assoc ?
1457 if (bss_conf->assoc)
1458 ath9k_htc_start_ani(priv);
1460 ath9k_htc_stop_ani(priv);
1464 if (changed & BSS_CHANGED_BSSID) {
1466 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1467 ath9k_hw_write_associd(ah);
1469 ath_dbg(common, ATH_DBG_CONFIG,
1470 "BSSID: %pM aid: 0x%x\n",
1471 common->curbssid, common->curaid);
1475 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1476 ath_dbg(common, ATH_DBG_CONFIG,
1477 "Beacon enabled for BSS: %pM\n", bss_conf->bssid);
1478 ath9k_htc_set_tsfadjust(priv, vif);
1479 priv->op_flags |= OP_ENABLE_BEACON;
1480 ath9k_htc_beacon_config(priv, vif);
1483 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1485 * Disable SWBA interrupt only if there are no
1486 * AP/IBSS interfaces.
1488 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1489 ath_dbg(common, ATH_DBG_CONFIG,
1490 "Beacon disabled for BSS: %pM\n",
1492 priv->op_flags &= ~OP_ENABLE_BEACON;
1493 ath9k_htc_beacon_config(priv, vif);
1497 if (changed & BSS_CHANGED_BEACON_INT) {
1499 * Reset the HW TSF for the first AP interface.
1501 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1502 (priv->nvifs == 1) &&
1503 (priv->num_ap_vif == 1) &&
1504 (vif->type == NL80211_IFTYPE_AP)) {
1505 priv->op_flags |= OP_TSF_RESET;
1507 ath_dbg(common, ATH_DBG_CONFIG,
1508 "Beacon interval changed for BSS: %pM\n",
1510 ath9k_htc_beacon_config(priv, vif);
1513 if (changed & BSS_CHANGED_ERP_SLOT) {
1514 if (bss_conf->use_short_slot)
1519 ath9k_hw_init_global_settings(ah);
1522 if (changed & BSS_CHANGED_HT)
1523 ath9k_htc_update_rate(priv, vif, bss_conf);
1525 ath9k_htc_ps_restore(priv);
1526 mutex_unlock(&priv->mutex);
1529 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1531 struct ath9k_htc_priv *priv = hw->priv;
1534 mutex_lock(&priv->mutex);
1535 ath9k_htc_ps_wakeup(priv);
1536 tsf = ath9k_hw_gettsf64(priv->ah);
1537 ath9k_htc_ps_restore(priv);
1538 mutex_unlock(&priv->mutex);
1543 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1545 struct ath9k_htc_priv *priv = hw->priv;
1547 mutex_lock(&priv->mutex);
1548 ath9k_htc_ps_wakeup(priv);
1549 ath9k_hw_settsf64(priv->ah, tsf);
1550 ath9k_htc_ps_restore(priv);
1551 mutex_unlock(&priv->mutex);
1554 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1556 struct ath9k_htc_priv *priv = hw->priv;
1558 mutex_lock(&priv->mutex);
1559 ath9k_htc_ps_wakeup(priv);
1560 ath9k_hw_reset_tsf(priv->ah);
1561 ath9k_htc_ps_restore(priv);
1562 mutex_unlock(&priv->mutex);
1565 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1566 struct ieee80211_vif *vif,
1567 enum ieee80211_ampdu_mlme_action action,
1568 struct ieee80211_sta *sta,
1569 u16 tid, u16 *ssn, u8 buf_size)
1571 struct ath9k_htc_priv *priv = hw->priv;
1572 struct ath9k_htc_sta *ista;
1575 mutex_lock(&priv->mutex);
1578 case IEEE80211_AMPDU_RX_START:
1580 case IEEE80211_AMPDU_RX_STOP:
1582 case IEEE80211_AMPDU_TX_START:
1583 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1585 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1587 case IEEE80211_AMPDU_TX_STOP:
1588 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1589 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1591 case IEEE80211_AMPDU_TX_OPERATIONAL:
1592 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1593 spin_lock_bh(&priv->tx.tx_lock);
1594 ista->tid_state[tid] = AGGR_OPERATIONAL;
1595 spin_unlock_bh(&priv->tx.tx_lock);
1598 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1601 mutex_unlock(&priv->mutex);
1606 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1608 struct ath9k_htc_priv *priv = hw->priv;
1610 mutex_lock(&priv->mutex);
1611 spin_lock_bh(&priv->beacon_lock);
1612 priv->op_flags |= OP_SCANNING;
1613 spin_unlock_bh(&priv->beacon_lock);
1614 cancel_work_sync(&priv->ps_work);
1615 ath9k_htc_stop_ani(priv);
1616 mutex_unlock(&priv->mutex);
1619 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1621 struct ath9k_htc_priv *priv = hw->priv;
1623 mutex_lock(&priv->mutex);
1624 spin_lock_bh(&priv->beacon_lock);
1625 priv->op_flags &= ~OP_SCANNING;
1626 spin_unlock_bh(&priv->beacon_lock);
1627 ath9k_htc_ps_wakeup(priv);
1628 ath9k_htc_vif_reconfig(priv);
1629 ath9k_htc_ps_restore(priv);
1630 mutex_unlock(&priv->mutex);
1633 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1638 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1641 struct ath9k_htc_priv *priv = hw->priv;
1643 mutex_lock(&priv->mutex);
1644 ath9k_htc_ps_wakeup(priv);
1645 priv->ah->coverage_class = coverage_class;
1646 ath9k_hw_init_global_settings(priv->ah);
1647 ath9k_htc_ps_restore(priv);
1648 mutex_unlock(&priv->mutex);
1651 struct ieee80211_ops ath9k_htc_ops = {
1653 .start = ath9k_htc_start,
1654 .stop = ath9k_htc_stop,
1655 .add_interface = ath9k_htc_add_interface,
1656 .remove_interface = ath9k_htc_remove_interface,
1657 .config = ath9k_htc_config,
1658 .configure_filter = ath9k_htc_configure_filter,
1659 .sta_add = ath9k_htc_sta_add,
1660 .sta_remove = ath9k_htc_sta_remove,
1661 .conf_tx = ath9k_htc_conf_tx,
1662 .bss_info_changed = ath9k_htc_bss_info_changed,
1663 .set_key = ath9k_htc_set_key,
1664 .get_tsf = ath9k_htc_get_tsf,
1665 .set_tsf = ath9k_htc_set_tsf,
1666 .reset_tsf = ath9k_htc_reset_tsf,
1667 .ampdu_action = ath9k_htc_ampdu_action,
1668 .sw_scan_start = ath9k_htc_sw_scan_start,
1669 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1670 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1671 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1672 .set_coverage_class = ath9k_htc_set_coverage_class,