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 = 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 = cpu_to_be16(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);
467 ista->index = sta_idx;
469 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
473 tsta.sta_index = sta_idx;
474 tsta.vif_index = avp->index;
475 tsta.maxampdu = cpu_to_be16(0xffff);
476 if (sta && sta->ht_cap.ht_supported)
477 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
479 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
483 "Unable to add station entry for: %pM\n",
489 ath_dbg(common, ATH_DBG_CONFIG,
490 "Added a station entry for: %pM (idx: %d)\n",
491 sta->addr, tsta.sta_index);
493 ath_dbg(common, ATH_DBG_CONFIG,
494 "Added a station entry for VIF %d (idx: %d)\n",
495 avp->index, tsta.sta_index);
498 priv->sta_slot |= (1 << sta_idx);
501 priv->vif_sta_pos[avp->index] = sta_idx;
506 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
507 struct ieee80211_vif *vif,
508 struct ieee80211_sta *sta)
510 struct ath_common *common = ath9k_hw_common(priv->ah);
511 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
512 struct ath9k_htc_sta *ista;
517 ista = (struct ath9k_htc_sta *) sta->drv_priv;
518 sta_idx = ista->index;
520 sta_idx = priv->vif_sta_pos[avp->index];
523 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
527 "Unable to remove station entry for: %pM\n",
533 ath_dbg(common, ATH_DBG_CONFIG,
534 "Removed a station entry for: %pM (idx: %d)\n",
537 ath_dbg(common, ATH_DBG_CONFIG,
538 "Removed a station entry for VIF %d (idx: %d)\n",
539 avp->index, sta_idx);
542 priv->sta_slot &= ~(1 << sta_idx);
548 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
550 struct ath9k_htc_cap_target tcap;
554 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
556 /* FIXME: Values are hardcoded */
557 tcap.flags = 0x240c40;
558 tcap.flags_ext = 0x80601000;
559 tcap.ampdu_limit = 0xffff0000;
560 tcap.ampdu_subframes = 20;
561 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
563 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
565 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
570 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
571 struct ieee80211_sta *sta,
572 struct ath9k_htc_target_rate *trate)
574 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
575 struct ieee80211_supported_band *sband;
579 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
581 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
582 if (sta->supp_rates[sband->band] & BIT(i)) {
583 trate->rates.legacy_rates.rs_rates[j]
584 = (sband->bitrates[i].bitrate * 2) / 10;
588 trate->rates.legacy_rates.rs_nrates = j;
590 if (sta->ht_cap.ht_supported) {
591 for (i = 0, j = 0; i < 77; i++) {
592 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
593 trate->rates.ht_rates.rs_rates[j++] = i;
594 if (j == ATH_HTC_RATE_MAX)
597 trate->rates.ht_rates.rs_nrates = j;
599 caps = WLAN_RC_HT_FLAG;
600 if (sta->ht_cap.mcs.rx_mask[1])
601 caps |= WLAN_RC_DS_FLAG;
602 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
603 (conf_is_ht40(&priv->hw->conf)))
604 caps |= WLAN_RC_40_FLAG;
605 if (conf_is_ht40(&priv->hw->conf) &&
606 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
607 caps |= WLAN_RC_SGI_FLAG;
608 else if (conf_is_ht20(&priv->hw->conf) &&
609 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
610 caps |= WLAN_RC_SGI_FLAG;
613 trate->sta_index = ista->index;
615 trate->capflags = cpu_to_be32(caps);
618 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
619 struct ath9k_htc_target_rate *trate)
621 struct ath_common *common = ath9k_hw_common(priv->ah);
625 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
628 "Unable to initialize Rate information on target\n");
634 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
635 struct ieee80211_sta *sta)
637 struct ath_common *common = ath9k_hw_common(priv->ah);
638 struct ath9k_htc_target_rate trate;
641 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
642 ath9k_htc_setup_rate(priv, sta, &trate);
643 ret = ath9k_htc_send_rate_cmd(priv, &trate);
645 ath_dbg(common, ATH_DBG_CONFIG,
646 "Updated target sta: %pM, rate caps: 0x%X\n",
647 sta->addr, be32_to_cpu(trate.capflags));
650 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
651 struct ieee80211_vif *vif,
652 struct ieee80211_bss_conf *bss_conf)
654 struct ath_common *common = ath9k_hw_common(priv->ah);
655 struct ath9k_htc_target_rate trate;
656 struct ieee80211_sta *sta;
659 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
662 sta = ieee80211_find_sta(vif, bss_conf->bssid);
667 ath9k_htc_setup_rate(priv, sta, &trate);
670 ret = ath9k_htc_send_rate_cmd(priv, &trate);
672 ath_dbg(common, ATH_DBG_CONFIG,
673 "Updated target sta: %pM, rate caps: 0x%X\n",
674 bss_conf->bssid, be32_to_cpu(trate.capflags));
677 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
678 struct ieee80211_vif *vif,
679 struct ieee80211_sta *sta,
680 enum ieee80211_ampdu_mlme_action action,
683 struct ath_common *common = ath9k_hw_common(priv->ah);
684 struct ath9k_htc_target_aggr aggr;
685 struct ath9k_htc_sta *ista;
689 if (tid >= ATH9K_HTC_MAX_TID)
692 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
693 ista = (struct ath9k_htc_sta *) sta->drv_priv;
695 aggr.sta_index = ista->index;
696 aggr.tidno = tid & 0xf;
697 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
699 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
701 ath_dbg(common, ATH_DBG_CONFIG,
702 "Unable to %s TX aggregation for (%pM, %d)\n",
703 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
705 ath_dbg(common, ATH_DBG_CONFIG,
706 "%s TX aggregation for (%pM, %d)\n",
707 (aggr.aggr_enable) ? "Starting" : "Stopping",
710 spin_lock_bh(&priv->tx_lock);
711 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
712 spin_unlock_bh(&priv->tx_lock);
721 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
723 struct ath_common *common = ath9k_hw_common(priv->ah);
724 unsigned long timestamp = jiffies_to_msecs(jiffies);
726 common->ani.longcal_timer = timestamp;
727 common->ani.shortcal_timer = timestamp;
728 common->ani.checkani_timer = timestamp;
730 priv->op_flags |= OP_ANI_RUNNING;
732 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
733 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
736 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
738 cancel_delayed_work_sync(&priv->ani_work);
739 priv->op_flags &= ~OP_ANI_RUNNING;
742 void ath9k_htc_ani_work(struct work_struct *work)
744 struct ath9k_htc_priv *priv =
745 container_of(work, struct ath9k_htc_priv, ani_work.work);
746 struct ath_hw *ah = priv->ah;
747 struct ath_common *common = ath9k_hw_common(ah);
748 bool longcal = false;
749 bool shortcal = false;
750 bool aniflag = false;
751 unsigned int timestamp = jiffies_to_msecs(jiffies);
752 u32 cal_interval, short_cal_interval;
754 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
755 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
757 /* Only calibrate if awake */
758 if (ah->power_mode != ATH9K_PM_AWAKE)
761 /* Long calibration runs independently of short calibration. */
762 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
764 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
765 common->ani.longcal_timer = timestamp;
768 /* Short calibration applies only while caldone is false */
769 if (!common->ani.caldone) {
770 if ((timestamp - common->ani.shortcal_timer) >=
771 short_cal_interval) {
773 ath_dbg(common, ATH_DBG_ANI,
774 "shortcal @%lu\n", jiffies);
775 common->ani.shortcal_timer = timestamp;
776 common->ani.resetcal_timer = timestamp;
779 if ((timestamp - common->ani.resetcal_timer) >=
780 ATH_RESTART_CALINTERVAL) {
781 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
782 if (common->ani.caldone)
783 common->ani.resetcal_timer = timestamp;
787 /* Verify whether we must check ANI */
788 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
790 common->ani.checkani_timer = timestamp;
793 /* Skip all processing if there's nothing to do. */
794 if (longcal || shortcal || aniflag) {
796 ath9k_htc_ps_wakeup(priv);
798 /* Call ANI routine if necessary */
800 ath9k_hw_ani_monitor(ah, ah->curchan);
802 /* Perform calibration if necessary */
803 if (longcal || shortcal)
804 common->ani.caldone =
805 ath9k_hw_calibrate(ah, ah->curchan,
806 common->rx_chainmask,
809 ath9k_htc_ps_restore(priv);
814 * Set timer interval based on previous results.
815 * The interval must be the shortest necessary to satisfy ANI,
816 * short calibration and long calibration.
818 cal_interval = ATH_LONG_CALINTERVAL;
819 if (priv->ah->config.enable_ani)
820 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
821 if (!common->ani.caldone)
822 cal_interval = min(cal_interval, (u32)short_cal_interval);
824 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
825 msecs_to_jiffies(cal_interval));
828 /**********************/
829 /* mac80211 Callbacks */
830 /**********************/
832 static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
834 struct ieee80211_hdr *hdr;
835 struct ath9k_htc_priv *priv = hw->priv;
836 int padpos, padsize, ret;
838 hdr = (struct ieee80211_hdr *) skb->data;
840 /* Add the padding after the header if this is not already done */
841 padpos = ath9k_cmn_padpos(hdr->frame_control);
842 padsize = padpos & 3;
843 if (padsize && skb->len > padpos) {
844 if (skb_headroom(skb) < padsize)
846 skb_push(skb, padsize);
847 memmove(skb->data, skb->data + padsize, padpos);
850 ret = ath9k_htc_tx_start(priv, skb, false);
852 if (ret == -ENOMEM) {
853 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
854 "Stopping TX queues\n");
855 ieee80211_stop_queues(hw);
856 spin_lock_bh(&priv->tx_lock);
857 priv->tx_queues_stop = true;
858 spin_unlock_bh(&priv->tx_lock);
860 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
869 dev_kfree_skb_any(skb);
872 static int ath9k_htc_start(struct ieee80211_hw *hw)
874 struct ath9k_htc_priv *priv = hw->priv;
875 struct ath_hw *ah = priv->ah;
876 struct ath_common *common = ath9k_hw_common(ah);
877 struct ieee80211_channel *curchan = hw->conf.channel;
878 struct ath9k_channel *init_channel;
880 enum htc_phymode mode;
884 mutex_lock(&priv->mutex);
886 ath_dbg(common, ATH_DBG_CONFIG,
887 "Starting driver with initial channel: %d MHz\n",
888 curchan->center_freq);
890 /* Ensure that HW is awake before flushing RX */
891 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
892 WMI_CMD(WMI_FLUSH_RECV_CMDID);
894 /* setup initial channel */
895 init_channel = ath9k_cmn_get_curchannel(hw, ah);
897 ath9k_hw_htc_resetinit(ah);
898 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
901 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
902 ret, curchan->center_freq);
903 mutex_unlock(&priv->mutex);
907 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
910 mode = ath9k_htc_get_curmode(priv, init_channel);
911 htc_mode = cpu_to_be16(mode);
912 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
913 WMI_CMD(WMI_ATH_INIT_CMDID);
914 WMI_CMD(WMI_START_RECV_CMDID);
916 ath9k_host_rx_init(priv);
918 ret = ath9k_htc_update_cap_target(priv);
920 ath_dbg(common, ATH_DBG_CONFIG,
921 "Failed to update capability in target\n");
923 priv->op_flags &= ~OP_INVALID;
924 htc_start(priv->htc);
926 spin_lock_bh(&priv->tx_lock);
927 priv->tx_queues_stop = false;
928 spin_unlock_bh(&priv->tx_lock);
930 ieee80211_wake_queues(hw);
932 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
933 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
934 AR_STOMP_LOW_WLAN_WGHT);
935 ath9k_hw_btcoex_enable(ah);
936 ath_htc_resume_btcoex_work(priv);
938 mutex_unlock(&priv->mutex);
943 static void ath9k_htc_stop(struct ieee80211_hw *hw)
945 struct ath9k_htc_priv *priv = hw->priv;
946 struct ath_hw *ah = priv->ah;
947 struct ath_common *common = ath9k_hw_common(ah);
951 mutex_lock(&priv->mutex);
953 if (priv->op_flags & OP_INVALID) {
954 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
955 mutex_unlock(&priv->mutex);
959 ath9k_htc_ps_wakeup(priv);
961 WMI_CMD(WMI_DISABLE_INTR_CMDID);
962 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
963 WMI_CMD(WMI_STOP_RECV_CMDID);
965 tasklet_kill(&priv->rx_tasklet);
966 tasklet_kill(&priv->tx_tasklet);
968 skb_queue_purge(&priv->tx_queue);
970 ath9k_wmi_event_drain(priv);
972 mutex_unlock(&priv->mutex);
974 /* Cancel all the running timers/work .. */
975 cancel_work_sync(&priv->fatal_work);
976 cancel_work_sync(&priv->ps_work);
977 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
978 ath9k_htc_stop_ani(priv);
979 ath9k_led_stop_brightness(priv);
981 mutex_lock(&priv->mutex);
983 if (ah->btcoex_hw.enabled) {
984 ath9k_hw_btcoex_disable(ah);
985 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
986 ath_htc_cancel_btcoex_work(priv);
989 /* Remove a monitor interface if it's present. */
990 if (priv->ah->is_monitoring)
991 ath9k_htc_remove_monitor_interface(priv);
993 ath9k_hw_phy_disable(ah);
994 ath9k_hw_disable(ah);
995 ath9k_htc_ps_restore(priv);
996 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
998 priv->op_flags |= OP_INVALID;
1000 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1001 mutex_unlock(&priv->mutex);
1004 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1005 struct ieee80211_vif *vif)
1007 struct ath9k_htc_priv *priv = hw->priv;
1008 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1009 struct ath_common *common = ath9k_hw_common(priv->ah);
1010 struct ath9k_htc_target_vif hvif;
1014 mutex_lock(&priv->mutex);
1016 if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1017 mutex_unlock(&priv->mutex);
1021 if (priv->num_ibss_vif ||
1022 (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
1023 ath_err(common, "IBSS coexistence with other modes is not allowed\n");
1024 mutex_unlock(&priv->mutex);
1028 if (((vif->type == NL80211_IFTYPE_AP) ||
1029 (vif->type == NL80211_IFTYPE_ADHOC)) &&
1030 ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) {
1031 ath_err(common, "Max. number of beaconing interfaces reached\n");
1032 mutex_unlock(&priv->mutex);
1036 ath9k_htc_ps_wakeup(priv);
1037 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1038 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1040 switch (vif->type) {
1041 case NL80211_IFTYPE_STATION:
1042 hvif.opmode = HTC_M_STA;
1044 case NL80211_IFTYPE_ADHOC:
1045 hvif.opmode = HTC_M_IBSS;
1047 case NL80211_IFTYPE_AP:
1048 hvif.opmode = HTC_M_HOSTAP;
1052 "Interface type %d not yet supported\n", vif->type);
1057 /* Index starts from zero on the target */
1058 avp->index = hvif.index = ffz(priv->vif_slot);
1059 hvif.rtsthreshold = cpu_to_be16(2304);
1060 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1065 * We need a node in target to tx mgmt frames
1066 * before association.
1068 ret = ath9k_htc_add_station(priv, vif, NULL);
1070 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1074 ath9k_htc_set_bssid_mask(priv, vif);
1076 priv->vif_slot |= (1 << avp->index);
1079 INC_VIF(priv, vif->type);
1081 if ((vif->type == NL80211_IFTYPE_AP) ||
1082 (vif->type == NL80211_IFTYPE_ADHOC))
1083 ath9k_htc_assign_bslot(priv, vif);
1085 ath9k_htc_set_opmode(priv);
1087 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1088 !(priv->op_flags & OP_ANI_RUNNING)) {
1089 ath9k_hw_set_tsfadjust(priv->ah, 1);
1090 ath9k_htc_start_ani(priv);
1093 ath_dbg(common, ATH_DBG_CONFIG,
1094 "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index);
1097 ath9k_htc_ps_restore(priv);
1098 mutex_unlock(&priv->mutex);
1103 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1104 struct ieee80211_vif *vif)
1106 struct ath9k_htc_priv *priv = hw->priv;
1107 struct ath_common *common = ath9k_hw_common(priv->ah);
1108 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1109 struct ath9k_htc_target_vif hvif;
1113 mutex_lock(&priv->mutex);
1114 ath9k_htc_ps_wakeup(priv);
1116 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1117 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1118 hvif.index = avp->index;
1119 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1121 priv->vif_slot &= ~(1 << avp->index);
1123 ath9k_htc_remove_station(priv, vif, NULL);
1125 DEC_VIF(priv, vif->type);
1127 if ((vif->type == NL80211_IFTYPE_AP) ||
1128 (vif->type == NL80211_IFTYPE_ADHOC))
1129 ath9k_htc_remove_bslot(priv, vif);
1131 ath9k_htc_set_opmode(priv);
1134 * Stop ANI only if there are no associated station interfaces.
1136 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1137 priv->rearm_ani = false;
1138 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1139 ath9k_htc_vif_iter, priv);
1140 if (!priv->rearm_ani)
1141 ath9k_htc_stop_ani(priv);
1144 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index);
1146 ath9k_htc_ps_restore(priv);
1147 mutex_unlock(&priv->mutex);
1150 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1152 struct ath9k_htc_priv *priv = hw->priv;
1153 struct ath_common *common = ath9k_hw_common(priv->ah);
1154 struct ieee80211_conf *conf = &hw->conf;
1156 mutex_lock(&priv->mutex);
1158 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1159 bool enable_radio = false;
1160 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1162 mutex_lock(&priv->htc_pm_lock);
1163 if (!idle && priv->ps_idle)
1164 enable_radio = true;
1165 priv->ps_idle = idle;
1166 mutex_unlock(&priv->htc_pm_lock);
1169 ath_dbg(common, ATH_DBG_CONFIG,
1170 "not-idle: enabling radio\n");
1171 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1172 ath9k_htc_radio_enable(hw);
1177 * Monitor interface should be added before
1178 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1180 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1181 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1182 !priv->ah->is_monitoring)
1183 ath9k_htc_add_monitor_interface(priv);
1184 else if (priv->ah->is_monitoring)
1185 ath9k_htc_remove_monitor_interface(priv);
1188 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1189 struct ieee80211_channel *curchan = hw->conf.channel;
1190 int pos = curchan->hw_value;
1192 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1193 curchan->center_freq);
1195 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1197 hw->conf.channel_type);
1199 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1200 ath_err(common, "Unable to set channel\n");
1201 mutex_unlock(&priv->mutex);
1207 if (changed & IEEE80211_CONF_CHANGE_PS) {
1208 if (conf->flags & IEEE80211_CONF_PS) {
1209 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1210 priv->ps_enabled = true;
1212 priv->ps_enabled = false;
1213 cancel_work_sync(&priv->ps_work);
1214 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1218 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1219 priv->txpowlimit = 2 * conf->power_level;
1220 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1221 priv->txpowlimit, &priv->curtxpow);
1224 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1225 mutex_lock(&priv->htc_pm_lock);
1226 if (!priv->ps_idle) {
1227 mutex_unlock(&priv->htc_pm_lock);
1230 mutex_unlock(&priv->htc_pm_lock);
1232 ath_dbg(common, ATH_DBG_CONFIG,
1233 "idle: disabling radio\n");
1234 ath9k_htc_radio_disable(hw);
1238 mutex_unlock(&priv->mutex);
1242 #define SUPPORTED_FILTERS \
1243 (FIF_PROMISC_IN_BSS | \
1248 FIF_BCN_PRBRESP_PROMISC | \
1252 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1253 unsigned int changed_flags,
1254 unsigned int *total_flags,
1257 struct ath9k_htc_priv *priv = hw->priv;
1260 mutex_lock(&priv->mutex);
1261 ath9k_htc_ps_wakeup(priv);
1263 changed_flags &= SUPPORTED_FILTERS;
1264 *total_flags &= SUPPORTED_FILTERS;
1266 priv->rxfilter = *total_flags;
1267 rfilt = ath9k_htc_calcrxfilter(priv);
1268 ath9k_hw_setrxfilter(priv->ah, rfilt);
1270 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1271 "Set HW RX filter: 0x%x\n", rfilt);
1273 ath9k_htc_ps_restore(priv);
1274 mutex_unlock(&priv->mutex);
1277 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1278 struct ieee80211_vif *vif,
1279 struct ieee80211_sta *sta)
1281 struct ath9k_htc_priv *priv = hw->priv;
1284 mutex_lock(&priv->mutex);
1285 ath9k_htc_ps_wakeup(priv);
1286 ret = ath9k_htc_add_station(priv, vif, sta);
1288 ath9k_htc_init_rate(priv, sta);
1289 ath9k_htc_ps_restore(priv);
1290 mutex_unlock(&priv->mutex);
1295 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1296 struct ieee80211_vif *vif,
1297 struct ieee80211_sta *sta)
1299 struct ath9k_htc_priv *priv = hw->priv;
1302 mutex_lock(&priv->mutex);
1303 ath9k_htc_ps_wakeup(priv);
1304 ret = ath9k_htc_remove_station(priv, vif, sta);
1305 ath9k_htc_ps_restore(priv);
1306 mutex_unlock(&priv->mutex);
1311 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1312 const struct ieee80211_tx_queue_params *params)
1314 struct ath9k_htc_priv *priv = hw->priv;
1315 struct ath_common *common = ath9k_hw_common(priv->ah);
1316 struct ath9k_tx_queue_info qi;
1319 if (queue >= WME_NUM_AC)
1322 mutex_lock(&priv->mutex);
1323 ath9k_htc_ps_wakeup(priv);
1325 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1327 qi.tqi_aifs = params->aifs;
1328 qi.tqi_cwmin = params->cw_min;
1329 qi.tqi_cwmax = params->cw_max;
1330 qi.tqi_burstTime = params->txop;
1332 qnum = get_hw_qnum(queue, priv->hwq_map);
1334 ath_dbg(common, ATH_DBG_CONFIG,
1335 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1336 queue, qnum, params->aifs, params->cw_min,
1337 params->cw_max, params->txop);
1339 ret = ath_htc_txq_update(priv, qnum, &qi);
1341 ath_err(common, "TXQ Update failed\n");
1345 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1346 (qnum == priv->hwq_map[WME_AC_BE]))
1347 ath9k_htc_beaconq_config(priv);
1349 ath9k_htc_ps_restore(priv);
1350 mutex_unlock(&priv->mutex);
1355 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1356 enum set_key_cmd cmd,
1357 struct ieee80211_vif *vif,
1358 struct ieee80211_sta *sta,
1359 struct ieee80211_key_conf *key)
1361 struct ath9k_htc_priv *priv = hw->priv;
1362 struct ath_common *common = ath9k_hw_common(priv->ah);
1365 if (htc_modparam_nohwcrypt)
1368 mutex_lock(&priv->mutex);
1369 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1370 ath9k_htc_ps_wakeup(priv);
1374 ret = ath_key_config(common, vif, sta, key);
1376 key->hw_key_idx = ret;
1377 /* push IV and Michael MIC generation to stack */
1378 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1379 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1380 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1381 if (priv->ah->sw_mgmt_crypto &&
1382 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1383 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1388 ath_key_delete(common, key);
1394 ath9k_htc_ps_restore(priv);
1395 mutex_unlock(&priv->mutex);
1400 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1401 struct ieee80211_vif *vif,
1402 struct ieee80211_bss_conf *bss_conf,
1405 struct ath9k_htc_priv *priv = hw->priv;
1406 struct ath_hw *ah = priv->ah;
1407 struct ath_common *common = ath9k_hw_common(ah);
1410 mutex_lock(&priv->mutex);
1411 ath9k_htc_ps_wakeup(priv);
1414 * Set the HW AID/BSSID only for the first station interface
1417 set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) ||
1418 ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
1419 (priv->num_sta_vif == 1)));
1422 if (changed & BSS_CHANGED_ASSOC) {
1424 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1427 common->curaid = bss_conf->assoc ?
1430 if (bss_conf->assoc)
1431 ath9k_htc_start_ani(priv);
1433 ath9k_htc_stop_ani(priv);
1437 if (changed & BSS_CHANGED_BSSID) {
1439 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1440 ath9k_hw_write_associd(ah);
1442 ath_dbg(common, ATH_DBG_CONFIG,
1443 "BSSID: %pM aid: 0x%x\n",
1444 common->curbssid, common->curaid);
1448 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1449 ath_dbg(common, ATH_DBG_CONFIG,
1450 "Beacon enabled for BSS: %pM\n", bss_conf->bssid);
1451 ath9k_htc_set_tsfadjust(priv, vif);
1452 priv->op_flags |= OP_ENABLE_BEACON;
1453 ath9k_htc_beacon_config(priv, vif);
1456 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1458 * Disable SWBA interrupt only if there are no
1459 * AP/IBSS interfaces.
1461 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1462 ath_dbg(common, ATH_DBG_CONFIG,
1463 "Beacon disabled for BSS: %pM\n",
1465 priv->op_flags &= ~OP_ENABLE_BEACON;
1466 ath9k_htc_beacon_config(priv, vif);
1470 if (changed & BSS_CHANGED_BEACON_INT) {
1472 * Reset the HW TSF for the first AP interface.
1474 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1475 (priv->nvifs == 1) &&
1476 (priv->num_ap_vif == 1) &&
1477 (vif->type == NL80211_IFTYPE_AP)) {
1478 priv->op_flags |= OP_TSF_RESET;
1480 ath_dbg(common, ATH_DBG_CONFIG,
1481 "Beacon interval changed for BSS: %pM\n",
1483 ath9k_htc_beacon_config(priv, vif);
1486 if (changed & BSS_CHANGED_ERP_SLOT) {
1487 if (bss_conf->use_short_slot)
1492 ath9k_hw_init_global_settings(ah);
1495 if (changed & BSS_CHANGED_HT)
1496 ath9k_htc_update_rate(priv, vif, bss_conf);
1498 ath9k_htc_ps_restore(priv);
1499 mutex_unlock(&priv->mutex);
1502 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1504 struct ath9k_htc_priv *priv = hw->priv;
1507 mutex_lock(&priv->mutex);
1508 ath9k_htc_ps_wakeup(priv);
1509 tsf = ath9k_hw_gettsf64(priv->ah);
1510 ath9k_htc_ps_restore(priv);
1511 mutex_unlock(&priv->mutex);
1516 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1518 struct ath9k_htc_priv *priv = hw->priv;
1520 mutex_lock(&priv->mutex);
1521 ath9k_htc_ps_wakeup(priv);
1522 ath9k_hw_settsf64(priv->ah, tsf);
1523 ath9k_htc_ps_restore(priv);
1524 mutex_unlock(&priv->mutex);
1527 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1529 struct ath9k_htc_priv *priv = hw->priv;
1531 mutex_lock(&priv->mutex);
1532 ath9k_htc_ps_wakeup(priv);
1533 ath9k_hw_reset_tsf(priv->ah);
1534 ath9k_htc_ps_restore(priv);
1535 mutex_unlock(&priv->mutex);
1538 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1539 struct ieee80211_vif *vif,
1540 enum ieee80211_ampdu_mlme_action action,
1541 struct ieee80211_sta *sta,
1542 u16 tid, u16 *ssn, u8 buf_size)
1544 struct ath9k_htc_priv *priv = hw->priv;
1545 struct ath9k_htc_sta *ista;
1548 mutex_lock(&priv->mutex);
1551 case IEEE80211_AMPDU_RX_START:
1553 case IEEE80211_AMPDU_RX_STOP:
1555 case IEEE80211_AMPDU_TX_START:
1556 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1558 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1560 case IEEE80211_AMPDU_TX_STOP:
1561 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1562 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1564 case IEEE80211_AMPDU_TX_OPERATIONAL:
1565 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1566 spin_lock_bh(&priv->tx_lock);
1567 ista->tid_state[tid] = AGGR_OPERATIONAL;
1568 spin_unlock_bh(&priv->tx_lock);
1571 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1574 mutex_unlock(&priv->mutex);
1579 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1581 struct ath9k_htc_priv *priv = hw->priv;
1583 mutex_lock(&priv->mutex);
1584 spin_lock_bh(&priv->beacon_lock);
1585 priv->op_flags |= OP_SCANNING;
1586 spin_unlock_bh(&priv->beacon_lock);
1587 cancel_work_sync(&priv->ps_work);
1588 ath9k_htc_stop_ani(priv);
1589 mutex_unlock(&priv->mutex);
1592 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1594 struct ath9k_htc_priv *priv = hw->priv;
1596 mutex_lock(&priv->mutex);
1597 spin_lock_bh(&priv->beacon_lock);
1598 priv->op_flags &= ~OP_SCANNING;
1599 spin_unlock_bh(&priv->beacon_lock);
1600 ath9k_htc_ps_wakeup(priv);
1601 ath9k_htc_vif_reconfig(priv);
1602 ath9k_htc_ps_restore(priv);
1603 mutex_unlock(&priv->mutex);
1606 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1611 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1614 struct ath9k_htc_priv *priv = hw->priv;
1616 mutex_lock(&priv->mutex);
1617 ath9k_htc_ps_wakeup(priv);
1618 priv->ah->coverage_class = coverage_class;
1619 ath9k_hw_init_global_settings(priv->ah);
1620 ath9k_htc_ps_restore(priv);
1621 mutex_unlock(&priv->mutex);
1624 struct ieee80211_ops ath9k_htc_ops = {
1626 .start = ath9k_htc_start,
1627 .stop = ath9k_htc_stop,
1628 .add_interface = ath9k_htc_add_interface,
1629 .remove_interface = ath9k_htc_remove_interface,
1630 .config = ath9k_htc_config,
1631 .configure_filter = ath9k_htc_configure_filter,
1632 .sta_add = ath9k_htc_sta_add,
1633 .sta_remove = ath9k_htc_sta_remove,
1634 .conf_tx = ath9k_htc_conf_tx,
1635 .bss_info_changed = ath9k_htc_bss_info_changed,
1636 .set_key = ath9k_htc_set_key,
1637 .get_tsf = ath9k_htc_get_tsf,
1638 .set_tsf = ath9k_htc_set_tsf,
1639 .reset_tsf = ath9k_htc_reset_tsf,
1640 .ampdu_action = ath9k_htc_ampdu_action,
1641 .sw_scan_start = ath9k_htc_sw_scan_start,
1642 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1643 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1644 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1645 .set_coverage_class = ath9k_htc_set_coverage_class,