2 * Copyright (c) 2010-2011 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:
53 bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
54 enum ath9k_power_mode mode)
58 mutex_lock(&priv->htc_pm_lock);
59 ret = ath9k_hw_setpower(priv->ah, mode);
60 mutex_unlock(&priv->htc_pm_lock);
65 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
67 mutex_lock(&priv->htc_pm_lock);
68 if (++priv->ps_usecount != 1)
70 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
73 mutex_unlock(&priv->htc_pm_lock);
76 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
80 mutex_lock(&priv->htc_pm_lock);
81 if (--priv->ps_usecount != 0)
85 ath9k_hw_setrxabort(priv->ah, true);
86 ath9k_hw_stopdmarecv(priv->ah, &reset);
87 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
88 } else if (priv->ps_enabled) {
89 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
93 mutex_unlock(&priv->htc_pm_lock);
96 void ath9k_ps_work(struct work_struct *work)
98 struct ath9k_htc_priv *priv =
99 container_of(work, struct ath9k_htc_priv,
101 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
103 /* The chip wakes up after receiving the first beacon
104 while network sleep is enabled. For the driver to
105 be in sync with the hw, set the chip to awake and
106 only then set it to sleep.
108 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
111 static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
113 struct ath9k_htc_priv *priv = data;
114 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
116 if ((vif->type == NL80211_IFTYPE_AP) && bss_conf->enable_beacon)
117 priv->reconfig_beacon = true;
119 if (bss_conf->assoc) {
120 priv->rearm_ani = true;
121 priv->reconfig_beacon = true;
125 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv)
127 priv->rearm_ani = false;
128 priv->reconfig_beacon = false;
130 ieee80211_iterate_active_interfaces_atomic(
131 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
132 ath9k_htc_vif_iter, priv);
134 ath9k_htc_start_ani(priv);
136 if (priv->reconfig_beacon) {
137 ath9k_htc_ps_wakeup(priv);
138 ath9k_htc_beacon_reconfig(priv);
139 ath9k_htc_ps_restore(priv);
143 static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
145 struct ath9k_vif_iter_data *iter_data = data;
148 for (i = 0; i < ETH_ALEN; i++)
149 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
152 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
153 struct ieee80211_vif *vif)
155 struct ath_common *common = ath9k_hw_common(priv->ah);
156 struct ath9k_vif_iter_data iter_data;
159 * Use the hardware MAC address as reference, the hardware uses it
160 * together with the BSSID mask when matching addresses.
162 iter_data.hw_macaddr = common->macaddr;
163 memset(&iter_data.mask, 0xff, ETH_ALEN);
166 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
168 /* Get list of all active MAC addresses */
169 ieee80211_iterate_active_interfaces_atomic(
170 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
171 ath9k_htc_bssid_iter, &iter_data);
173 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
174 ath_hw_setbssidmask(common);
177 static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv)
179 if (priv->num_ibss_vif)
180 priv->ah->opmode = NL80211_IFTYPE_ADHOC;
181 else if (priv->num_ap_vif)
182 priv->ah->opmode = NL80211_IFTYPE_AP;
184 priv->ah->opmode = NL80211_IFTYPE_STATION;
186 ath9k_hw_setopmode(priv->ah);
189 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
191 struct ath_hw *ah = priv->ah;
192 struct ath_common *common = ath9k_hw_common(ah);
193 struct ieee80211_channel *channel = priv->hw->conf.chandef.chan;
194 struct ath9k_hw_cal_data *caldata = NULL;
195 enum htc_phymode mode;
200 mutex_lock(&priv->mutex);
201 ath9k_htc_ps_wakeup(priv);
203 ath9k_htc_stop_ani(priv);
204 ieee80211_stop_queues(priv->hw);
206 del_timer_sync(&priv->tx.cleanup_timer);
207 ath9k_htc_tx_drain(priv);
209 WMI_CMD(WMI_DISABLE_INTR_CMDID);
210 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
211 WMI_CMD(WMI_STOP_RECV_CMDID);
213 ath9k_wmi_event_drain(priv);
215 caldata = &priv->caldata;
216 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
219 "Unable to reset device (%u Mhz) reset status %d\n",
220 channel->center_freq, ret);
223 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
226 WMI_CMD(WMI_START_RECV_CMDID);
227 ath9k_host_rx_init(priv);
229 mode = ath9k_htc_get_curmode(priv, ah->curchan);
230 htc_mode = cpu_to_be16(mode);
231 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
233 WMI_CMD(WMI_ENABLE_INTR_CMDID);
234 htc_start(priv->htc);
235 ath9k_htc_vif_reconfig(priv);
236 ieee80211_wake_queues(priv->hw);
238 mod_timer(&priv->tx.cleanup_timer,
239 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
241 ath9k_htc_ps_restore(priv);
242 mutex_unlock(&priv->mutex);
245 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
246 struct ieee80211_hw *hw,
247 struct ath9k_channel *hchan)
249 struct ath_hw *ah = priv->ah;
250 struct ath_common *common = ath9k_hw_common(ah);
251 struct ieee80211_conf *conf = &common->hw->conf;
253 struct ieee80211_channel *channel = hw->conf.chandef.chan;
254 struct ath9k_hw_cal_data *caldata = NULL;
255 enum htc_phymode mode;
260 if (test_bit(OP_INVALID, &priv->op_flags))
263 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
265 ath9k_htc_ps_wakeup(priv);
267 del_timer_sync(&priv->tx.cleanup_timer);
268 ath9k_htc_tx_drain(priv);
270 WMI_CMD(WMI_DISABLE_INTR_CMDID);
271 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
272 WMI_CMD(WMI_STOP_RECV_CMDID);
274 ath9k_wmi_event_drain(priv);
276 ath_dbg(common, CONFIG,
277 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
278 priv->ah->curchan->channel,
279 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
283 caldata = &priv->caldata;
285 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
288 "Unable to reset channel (%u Mhz) reset status %d\n",
289 channel->center_freq, ret);
293 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
296 WMI_CMD(WMI_START_RECV_CMDID);
300 ath9k_host_rx_init(priv);
302 mode = ath9k_htc_get_curmode(priv, hchan);
303 htc_mode = cpu_to_be16(mode);
304 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
308 WMI_CMD(WMI_ENABLE_INTR_CMDID);
312 htc_start(priv->htc);
314 if (!test_bit(OP_SCANNING, &priv->op_flags) &&
315 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
316 ath9k_htc_vif_reconfig(priv);
318 mod_timer(&priv->tx.cleanup_timer,
319 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
322 ath9k_htc_ps_restore(priv);
327 * Monitor mode handling is a tad complicated because the firmware requires
328 * an interface to be created exclusively, while mac80211 doesn't associate
329 * an interface with the mode.
331 * So, for now, only one monitor interface can be configured.
333 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
335 struct ath_common *common = ath9k_hw_common(priv->ah);
336 struct ath9k_htc_target_vif hvif;
340 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
341 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
342 hvif.index = priv->mon_vif_idx;
343 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
345 ath_err(common, "Unable to remove monitor interface at idx: %d\n",
350 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
353 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
355 struct ath_common *common = ath9k_hw_common(priv->ah);
356 struct ath9k_htc_target_vif hvif;
357 struct ath9k_htc_target_sta tsta;
358 int ret = 0, sta_idx;
361 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
362 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
367 sta_idx = ffz(priv->sta_slot);
368 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
376 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
377 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
379 hvif.opmode = HTC_M_MONITOR;
380 hvif.index = ffz(priv->vif_slot);
382 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
387 * Assign the monitor interface index as a special case here.
388 * This is needed when the interface is brought down.
390 priv->mon_vif_idx = hvif.index;
391 priv->vif_slot |= (1 << hvif.index);
394 * Set the hardware mode to monitor only if there are no
398 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
403 * Associate a station with the interface for packet injection.
405 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
407 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
410 tsta.sta_index = sta_idx;
411 tsta.vif_index = hvif.index;
412 tsta.maxampdu = cpu_to_be16(0xffff);
414 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
416 ath_err(common, "Unable to add station entry for monitor mode\n");
420 priv->sta_slot |= (1 << sta_idx);
422 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
423 priv->ah->is_monitoring = true;
425 ath_dbg(common, CONFIG,
426 "Attached a monitor interface at idx: %d, sta idx: %d\n",
427 priv->mon_vif_idx, sta_idx);
433 * Remove the interface from the target.
435 __ath9k_htc_remove_monitor_interface(priv);
437 ath_dbg(common, FATAL, "Unable to attach a monitor interface\n");
442 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
444 struct ath_common *common = ath9k_hw_common(priv->ah);
448 __ath9k_htc_remove_monitor_interface(priv);
450 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
452 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
454 ath_err(common, "Unable to remove station entry for monitor mode\n");
458 priv->sta_slot &= ~(1 << sta_idx);
460 priv->ah->is_monitoring = false;
462 ath_dbg(common, CONFIG,
463 "Removed a monitor interface at idx: %d, sta idx: %d\n",
464 priv->mon_vif_idx, sta_idx);
469 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
470 struct ieee80211_vif *vif,
471 struct ieee80211_sta *sta)
473 struct ath_common *common = ath9k_hw_common(priv->ah);
474 struct ath9k_htc_target_sta tsta;
475 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
476 struct ath9k_htc_sta *ista;
481 if (priv->nstations >= ATH9K_HTC_MAX_STA)
484 sta_idx = ffz(priv->sta_slot);
485 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
488 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
491 ista = (struct ath9k_htc_sta *) sta->drv_priv;
492 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
493 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
494 ista->index = sta_idx;
496 maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
497 sta->ht_cap.ampdu_factor);
498 tsta.maxampdu = cpu_to_be16(maxampdu);
500 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
502 tsta.maxampdu = cpu_to_be16(0xffff);
505 tsta.sta_index = sta_idx;
506 tsta.vif_index = avp->index;
508 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
512 "Unable to add station entry for: %pM\n",
518 ath_dbg(common, CONFIG,
519 "Added a station entry for: %pM (idx: %d)\n",
520 sta->addr, tsta.sta_index);
522 ath_dbg(common, CONFIG,
523 "Added a station entry for VIF %d (idx: %d)\n",
524 avp->index, tsta.sta_index);
527 priv->sta_slot |= (1 << sta_idx);
530 priv->vif_sta_pos[avp->index] = sta_idx;
535 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
536 struct ieee80211_vif *vif,
537 struct ieee80211_sta *sta)
539 struct ath_common *common = ath9k_hw_common(priv->ah);
540 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
541 struct ath9k_htc_sta *ista;
546 ista = (struct ath9k_htc_sta *) sta->drv_priv;
547 sta_idx = ista->index;
549 sta_idx = priv->vif_sta_pos[avp->index];
552 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
556 "Unable to remove station entry for: %pM\n",
562 ath_dbg(common, CONFIG,
563 "Removed a station entry for: %pM (idx: %d)\n",
566 ath_dbg(common, CONFIG,
567 "Removed a station entry for VIF %d (idx: %d)\n",
568 avp->index, sta_idx);
571 priv->sta_slot &= ~(1 << sta_idx);
577 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
580 struct ath9k_htc_cap_target tcap;
584 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
586 tcap.ampdu_limit = cpu_to_be32(0xffff);
587 tcap.ampdu_subframes = 0xff;
588 tcap.enable_coex = enable_coex;
589 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
591 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
596 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
597 struct ieee80211_sta *sta,
598 struct ath9k_htc_target_rate *trate)
600 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
601 struct ieee80211_supported_band *sband;
605 sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band];
607 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
608 if (sta->supp_rates[sband->band] & BIT(i)) {
609 trate->rates.legacy_rates.rs_rates[j]
610 = (sband->bitrates[i].bitrate * 2) / 10;
614 trate->rates.legacy_rates.rs_nrates = j;
616 if (sta->ht_cap.ht_supported) {
617 for (i = 0, j = 0; i < 77; i++) {
618 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
619 trate->rates.ht_rates.rs_rates[j++] = i;
620 if (j == ATH_HTC_RATE_MAX)
623 trate->rates.ht_rates.rs_nrates = j;
625 caps = WLAN_RC_HT_FLAG;
626 if (sta->ht_cap.mcs.rx_mask[1])
627 caps |= WLAN_RC_DS_FLAG;
628 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
629 (conf_is_ht40(&priv->hw->conf)))
630 caps |= WLAN_RC_40_FLAG;
631 if (conf_is_ht40(&priv->hw->conf) &&
632 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
633 caps |= WLAN_RC_SGI_FLAG;
634 else if (conf_is_ht20(&priv->hw->conf) &&
635 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
636 caps |= WLAN_RC_SGI_FLAG;
639 trate->sta_index = ista->index;
641 trate->capflags = cpu_to_be32(caps);
644 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
645 struct ath9k_htc_target_rate *trate)
647 struct ath_common *common = ath9k_hw_common(priv->ah);
651 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
654 "Unable to initialize Rate information on target\n");
660 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
661 struct ieee80211_sta *sta)
663 struct ath_common *common = ath9k_hw_common(priv->ah);
664 struct ath9k_htc_target_rate trate;
667 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
668 ath9k_htc_setup_rate(priv, sta, &trate);
669 ret = ath9k_htc_send_rate_cmd(priv, &trate);
671 ath_dbg(common, CONFIG,
672 "Updated target sta: %pM, rate caps: 0x%X\n",
673 sta->addr, be32_to_cpu(trate.capflags));
676 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
677 struct ieee80211_vif *vif,
678 struct ieee80211_bss_conf *bss_conf)
680 struct ath_common *common = ath9k_hw_common(priv->ah);
681 struct ath9k_htc_target_rate trate;
682 struct ieee80211_sta *sta;
685 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
688 sta = ieee80211_find_sta(vif, bss_conf->bssid);
693 ath9k_htc_setup_rate(priv, sta, &trate);
696 ret = ath9k_htc_send_rate_cmd(priv, &trate);
698 ath_dbg(common, CONFIG,
699 "Updated target sta: %pM, rate caps: 0x%X\n",
700 bss_conf->bssid, be32_to_cpu(trate.capflags));
703 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
704 struct ieee80211_vif *vif,
705 struct ieee80211_sta *sta,
706 enum ieee80211_ampdu_mlme_action action,
709 struct ath_common *common = ath9k_hw_common(priv->ah);
710 struct ath9k_htc_target_aggr aggr;
711 struct ath9k_htc_sta *ista;
715 if (tid >= ATH9K_HTC_MAX_TID)
718 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
719 ista = (struct ath9k_htc_sta *) sta->drv_priv;
721 aggr.sta_index = ista->index;
722 aggr.tidno = tid & 0xf;
723 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
725 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
727 ath_dbg(common, CONFIG,
728 "Unable to %s TX aggregation for (%pM, %d)\n",
729 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
731 ath_dbg(common, CONFIG,
732 "%s TX aggregation for (%pM, %d)\n",
733 (aggr.aggr_enable) ? "Starting" : "Stopping",
736 spin_lock_bh(&priv->tx.tx_lock);
737 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
738 spin_unlock_bh(&priv->tx.tx_lock);
747 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
749 struct ath_common *common = ath9k_hw_common(priv->ah);
750 unsigned long timestamp = jiffies_to_msecs(jiffies);
752 common->ani.longcal_timer = timestamp;
753 common->ani.shortcal_timer = timestamp;
754 common->ani.checkani_timer = timestamp;
756 set_bit(OP_ANI_RUNNING, &priv->op_flags);
758 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
759 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
762 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
764 cancel_delayed_work_sync(&priv->ani_work);
765 clear_bit(OP_ANI_RUNNING, &priv->op_flags);
768 void ath9k_htc_ani_work(struct work_struct *work)
770 struct ath9k_htc_priv *priv =
771 container_of(work, struct ath9k_htc_priv, ani_work.work);
772 struct ath_hw *ah = priv->ah;
773 struct ath_common *common = ath9k_hw_common(ah);
774 bool longcal = false;
775 bool shortcal = false;
776 bool aniflag = false;
777 unsigned int timestamp = jiffies_to_msecs(jiffies);
778 u32 cal_interval, short_cal_interval;
780 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
781 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
783 /* Only calibrate if awake */
784 if (ah->power_mode != ATH9K_PM_AWAKE)
787 /* Long calibration runs independently of short calibration. */
788 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
790 ath_dbg(common, ANI, "longcal @%lu\n", jiffies);
791 common->ani.longcal_timer = timestamp;
794 /* Short calibration applies only while caldone is false */
795 if (!common->ani.caldone) {
796 if ((timestamp - common->ani.shortcal_timer) >=
797 short_cal_interval) {
799 ath_dbg(common, ANI, "shortcal @%lu\n", jiffies);
800 common->ani.shortcal_timer = timestamp;
801 common->ani.resetcal_timer = timestamp;
804 if ((timestamp - common->ani.resetcal_timer) >=
805 ATH_RESTART_CALINTERVAL) {
806 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
807 if (common->ani.caldone)
808 common->ani.resetcal_timer = timestamp;
812 /* Verify whether we must check ANI */
813 if (ah->config.enable_ani &&
814 (timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
816 common->ani.checkani_timer = timestamp;
819 /* Skip all processing if there's nothing to do. */
820 if (longcal || shortcal || aniflag) {
822 ath9k_htc_ps_wakeup(priv);
824 /* Call ANI routine if necessary */
826 ath9k_hw_ani_monitor(ah, ah->curchan);
828 /* Perform calibration if necessary */
829 if (longcal || shortcal)
830 common->ani.caldone =
831 ath9k_hw_calibrate(ah, ah->curchan,
832 ah->rxchainmask, longcal);
834 ath9k_htc_ps_restore(priv);
839 * Set timer interval based on previous results.
840 * The interval must be the shortest necessary to satisfy ANI,
841 * short calibration and long calibration.
843 cal_interval = ATH_LONG_CALINTERVAL;
844 if (ah->config.enable_ani)
845 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
846 if (!common->ani.caldone)
847 cal_interval = min(cal_interval, (u32)short_cal_interval);
849 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
850 msecs_to_jiffies(cal_interval));
853 /**********************/
854 /* mac80211 Callbacks */
855 /**********************/
857 static void ath9k_htc_tx(struct ieee80211_hw *hw,
858 struct ieee80211_tx_control *control,
861 struct ieee80211_hdr *hdr;
862 struct ath9k_htc_priv *priv = hw->priv;
863 struct ath_common *common = ath9k_hw_common(priv->ah);
864 int padpos, padsize, ret, slot;
866 hdr = (struct ieee80211_hdr *) skb->data;
868 /* Add the padding after the header if this is not already done */
869 padpos = ieee80211_hdrlen(hdr->frame_control);
870 padsize = padpos & 3;
871 if (padsize && skb->len > padpos) {
872 if (skb_headroom(skb) < padsize) {
873 ath_dbg(common, XMIT, "No room for padding\n");
876 skb_push(skb, padsize);
877 memmove(skb->data, skb->data + padsize, padpos);
880 slot = ath9k_htc_tx_get_slot(priv);
882 ath_dbg(common, XMIT, "No free TX slot\n");
886 ret = ath9k_htc_tx_start(priv, control->sta, skb, slot, false);
888 ath_dbg(common, XMIT, "Tx failed\n");
892 ath9k_htc_check_stop_queues(priv);
897 ath9k_htc_tx_clear_slot(priv, slot);
899 dev_kfree_skb_any(skb);
902 static int ath9k_htc_start(struct ieee80211_hw *hw)
904 struct ath9k_htc_priv *priv = hw->priv;
905 struct ath_hw *ah = priv->ah;
906 struct ath_common *common = ath9k_hw_common(ah);
907 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
908 struct ath9k_channel *init_channel;
910 enum htc_phymode mode;
914 mutex_lock(&priv->mutex);
916 ath_dbg(common, CONFIG,
917 "Starting driver with initial channel: %d MHz\n",
918 curchan->center_freq);
920 /* Ensure that HW is awake before flushing RX */
921 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
922 WMI_CMD(WMI_FLUSH_RECV_CMDID);
924 /* setup initial channel */
925 init_channel = ath9k_cmn_get_curchannel(hw, ah);
927 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
930 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
931 ret, curchan->center_freq);
932 mutex_unlock(&priv->mutex);
936 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
939 mode = ath9k_htc_get_curmode(priv, init_channel);
940 htc_mode = cpu_to_be16(mode);
941 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
942 WMI_CMD(WMI_ATH_INIT_CMDID);
943 WMI_CMD(WMI_START_RECV_CMDID);
945 ath9k_host_rx_init(priv);
947 ret = ath9k_htc_update_cap_target(priv, 0);
949 ath_dbg(common, CONFIG,
950 "Failed to update capability in target\n");
952 clear_bit(OP_INVALID, &priv->op_flags);
953 htc_start(priv->htc);
955 spin_lock_bh(&priv->tx.tx_lock);
956 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
957 spin_unlock_bh(&priv->tx.tx_lock);
959 ieee80211_wake_queues(hw);
961 mod_timer(&priv->tx.cleanup_timer,
962 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
964 ath9k_htc_start_btcoex(priv);
966 mutex_unlock(&priv->mutex);
971 static void ath9k_htc_stop(struct ieee80211_hw *hw)
973 struct ath9k_htc_priv *priv = hw->priv;
974 struct ath_hw *ah = priv->ah;
975 struct ath_common *common = ath9k_hw_common(ah);
976 int ret __attribute__ ((unused));
979 mutex_lock(&priv->mutex);
981 if (test_bit(OP_INVALID, &priv->op_flags)) {
982 ath_dbg(common, ANY, "Device not present\n");
983 mutex_unlock(&priv->mutex);
987 ath9k_htc_ps_wakeup(priv);
989 WMI_CMD(WMI_DISABLE_INTR_CMDID);
990 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
991 WMI_CMD(WMI_STOP_RECV_CMDID);
993 tasklet_kill(&priv->rx_tasklet);
995 del_timer_sync(&priv->tx.cleanup_timer);
996 ath9k_htc_tx_drain(priv);
997 ath9k_wmi_event_drain(priv);
999 mutex_unlock(&priv->mutex);
1001 /* Cancel all the running timers/work .. */
1002 cancel_work_sync(&priv->fatal_work);
1003 cancel_work_sync(&priv->ps_work);
1005 #ifdef CONFIG_MAC80211_LEDS
1006 cancel_work_sync(&priv->led_work);
1008 ath9k_htc_stop_ani(priv);
1010 mutex_lock(&priv->mutex);
1012 ath9k_htc_stop_btcoex(priv);
1014 /* Remove a monitor interface if it's present. */
1015 if (priv->ah->is_monitoring)
1016 ath9k_htc_remove_monitor_interface(priv);
1018 ath9k_hw_phy_disable(ah);
1019 ath9k_hw_disable(ah);
1020 ath9k_htc_ps_restore(priv);
1021 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1023 set_bit(OP_INVALID, &priv->op_flags);
1025 ath_dbg(common, CONFIG, "Driver halt\n");
1026 mutex_unlock(&priv->mutex);
1029 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1030 struct ieee80211_vif *vif)
1032 struct ath9k_htc_priv *priv = hw->priv;
1033 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1034 struct ath_common *common = ath9k_hw_common(priv->ah);
1035 struct ath9k_htc_target_vif hvif;
1039 mutex_lock(&priv->mutex);
1041 ath9k_htc_ps_wakeup(priv);
1042 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1043 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1045 switch (vif->type) {
1046 case NL80211_IFTYPE_STATION:
1047 hvif.opmode = HTC_M_STA;
1049 case NL80211_IFTYPE_ADHOC:
1050 hvif.opmode = HTC_M_IBSS;
1052 case NL80211_IFTYPE_AP:
1053 hvif.opmode = HTC_M_HOSTAP;
1057 "Interface type %d not yet supported\n", vif->type);
1062 /* Index starts from zero on the target */
1063 avp->index = hvif.index = ffz(priv->vif_slot);
1064 hvif.rtsthreshold = cpu_to_be16(2304);
1065 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1070 * We need a node in target to tx mgmt frames
1071 * before association.
1073 ret = ath9k_htc_add_station(priv, vif, NULL);
1075 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1079 ath9k_htc_set_bssid_mask(priv, vif);
1081 priv->vif_slot |= (1 << avp->index);
1084 INC_VIF(priv, vif->type);
1086 if ((vif->type == NL80211_IFTYPE_AP) ||
1087 (vif->type == NL80211_IFTYPE_ADHOC))
1088 ath9k_htc_assign_bslot(priv, vif);
1090 ath9k_htc_set_opmode(priv);
1092 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1093 !test_bit(OP_ANI_RUNNING, &priv->op_flags)) {
1094 ath9k_hw_set_tsfadjust(priv->ah, true);
1095 ath9k_htc_start_ani(priv);
1098 ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n",
1099 vif->type, avp->index);
1102 ath9k_htc_ps_restore(priv);
1103 mutex_unlock(&priv->mutex);
1108 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1109 struct ieee80211_vif *vif)
1111 struct ath9k_htc_priv *priv = hw->priv;
1112 struct ath_common *common = ath9k_hw_common(priv->ah);
1113 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1114 struct ath9k_htc_target_vif hvif;
1118 mutex_lock(&priv->mutex);
1119 ath9k_htc_ps_wakeup(priv);
1121 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1122 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1123 hvif.index = avp->index;
1124 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1126 ath_err(common, "Unable to remove interface at idx: %d\n",
1130 priv->vif_slot &= ~(1 << avp->index);
1132 ath9k_htc_remove_station(priv, vif, NULL);
1134 DEC_VIF(priv, vif->type);
1136 if ((vif->type == NL80211_IFTYPE_AP) ||
1137 (vif->type == NL80211_IFTYPE_ADHOC))
1138 ath9k_htc_remove_bslot(priv, vif);
1140 ath9k_htc_set_opmode(priv);
1142 ath9k_htc_set_bssid_mask(priv, vif);
1145 * Stop ANI only if there are no associated station interfaces.
1147 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1148 priv->rearm_ani = false;
1149 ieee80211_iterate_active_interfaces_atomic(
1150 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1151 ath9k_htc_vif_iter, priv);
1152 if (!priv->rearm_ani)
1153 ath9k_htc_stop_ani(priv);
1156 ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index);
1158 ath9k_htc_ps_restore(priv);
1159 mutex_unlock(&priv->mutex);
1162 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1164 struct ath9k_htc_priv *priv = hw->priv;
1165 struct ath_common *common = ath9k_hw_common(priv->ah);
1166 struct ieee80211_conf *conf = &hw->conf;
1167 bool chip_reset = false;
1170 mutex_lock(&priv->mutex);
1171 ath9k_htc_ps_wakeup(priv);
1173 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1174 mutex_lock(&priv->htc_pm_lock);
1176 priv->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1180 mutex_unlock(&priv->htc_pm_lock);
1184 * Monitor interface should be added before
1185 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1187 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1188 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1189 !priv->ah->is_monitoring)
1190 ath9k_htc_add_monitor_interface(priv);
1191 else if (priv->ah->is_monitoring)
1192 ath9k_htc_remove_monitor_interface(priv);
1195 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
1196 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
1197 enum nl80211_channel_type channel_type =
1198 cfg80211_get_chandef_type(&hw->conf.chandef);
1199 int pos = curchan->hw_value;
1201 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
1202 curchan->center_freq);
1204 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1205 hw->conf.chandef.chan,
1208 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1209 ath_err(common, "Unable to set channel\n");
1216 if (changed & IEEE80211_CONF_CHANGE_PS) {
1217 if (conf->flags & IEEE80211_CONF_PS) {
1218 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1219 priv->ps_enabled = true;
1221 priv->ps_enabled = false;
1222 cancel_work_sync(&priv->ps_work);
1223 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1227 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1228 priv->txpowlimit = 2 * conf->power_level;
1229 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1230 priv->txpowlimit, &priv->curtxpow);
1234 ath9k_htc_ps_restore(priv);
1235 mutex_unlock(&priv->mutex);
1239 #define SUPPORTED_FILTERS \
1240 (FIF_PROMISC_IN_BSS | \
1245 FIF_BCN_PRBRESP_PROMISC | \
1249 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1250 unsigned int changed_flags,
1251 unsigned int *total_flags,
1254 struct ath9k_htc_priv *priv = hw->priv;
1257 mutex_lock(&priv->mutex);
1258 changed_flags &= SUPPORTED_FILTERS;
1259 *total_flags &= SUPPORTED_FILTERS;
1261 if (test_bit(OP_INVALID, &priv->op_flags)) {
1262 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1263 "Unable to configure filter on invalid state\n");
1264 mutex_unlock(&priv->mutex);
1267 ath9k_htc_ps_wakeup(priv);
1269 priv->rxfilter = *total_flags;
1270 rfilt = ath9k_htc_calcrxfilter(priv);
1271 ath9k_hw_setrxfilter(priv->ah, rfilt);
1273 ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n",
1276 ath9k_htc_ps_restore(priv);
1277 mutex_unlock(&priv->mutex);
1280 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1281 struct ieee80211_vif *vif,
1282 struct ieee80211_sta *sta)
1284 struct ath9k_htc_priv *priv = hw->priv;
1287 mutex_lock(&priv->mutex);
1288 ath9k_htc_ps_wakeup(priv);
1289 ret = ath9k_htc_add_station(priv, vif, sta);
1291 ath9k_htc_init_rate(priv, sta);
1292 ath9k_htc_ps_restore(priv);
1293 mutex_unlock(&priv->mutex);
1298 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1299 struct ieee80211_vif *vif,
1300 struct ieee80211_sta *sta)
1302 struct ath9k_htc_priv *priv = hw->priv;
1303 struct ath9k_htc_sta *ista;
1306 mutex_lock(&priv->mutex);
1307 ath9k_htc_ps_wakeup(priv);
1308 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1309 htc_sta_drain(priv->htc, ista->index);
1310 ret = ath9k_htc_remove_station(priv, vif, sta);
1311 ath9k_htc_ps_restore(priv);
1312 mutex_unlock(&priv->mutex);
1317 static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
1318 struct ieee80211_vif *vif,
1319 struct ieee80211_sta *sta, u32 changed)
1321 struct ath9k_htc_priv *priv = hw->priv;
1322 struct ath_common *common = ath9k_hw_common(priv->ah);
1323 struct ath9k_htc_target_rate trate;
1325 mutex_lock(&priv->mutex);
1326 ath9k_htc_ps_wakeup(priv);
1328 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
1329 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
1330 ath9k_htc_setup_rate(priv, sta, &trate);
1331 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1332 ath_dbg(common, CONFIG,
1333 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1334 sta->addr, be32_to_cpu(trate.capflags));
1336 ath_dbg(common, CONFIG,
1337 "Unable to update supported rates for sta: %pM\n",
1341 ath9k_htc_ps_restore(priv);
1342 mutex_unlock(&priv->mutex);
1345 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
1346 struct ieee80211_vif *vif, u16 queue,
1347 const struct ieee80211_tx_queue_params *params)
1349 struct ath9k_htc_priv *priv = hw->priv;
1350 struct ath_common *common = ath9k_hw_common(priv->ah);
1351 struct ath9k_tx_queue_info qi;
1354 if (queue >= IEEE80211_NUM_ACS)
1357 mutex_lock(&priv->mutex);
1358 ath9k_htc_ps_wakeup(priv);
1360 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1362 qi.tqi_aifs = params->aifs;
1363 qi.tqi_cwmin = params->cw_min;
1364 qi.tqi_cwmax = params->cw_max;
1365 qi.tqi_burstTime = params->txop * 32;
1367 qnum = get_hw_qnum(queue, priv->hwq_map);
1369 ath_dbg(common, CONFIG,
1370 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1371 queue, qnum, params->aifs, params->cw_min,
1372 params->cw_max, params->txop);
1374 ret = ath_htc_txq_update(priv, qnum, &qi);
1376 ath_err(common, "TXQ Update failed\n");
1380 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1381 (qnum == priv->hwq_map[IEEE80211_AC_BE]))
1382 ath9k_htc_beaconq_config(priv);
1384 ath9k_htc_ps_restore(priv);
1385 mutex_unlock(&priv->mutex);
1390 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1391 enum set_key_cmd cmd,
1392 struct ieee80211_vif *vif,
1393 struct ieee80211_sta *sta,
1394 struct ieee80211_key_conf *key)
1396 struct ath9k_htc_priv *priv = hw->priv;
1397 struct ath_common *common = ath9k_hw_common(priv->ah);
1400 if (htc_modparam_nohwcrypt)
1403 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1404 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1405 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1406 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1407 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1409 * For now, disable hw crypto for the RSN IBSS group keys. This
1410 * could be optimized in the future to use a modified key cache
1411 * design to support per-STA RX GTK, but until that gets
1412 * implemented, use of software crypto for group addressed
1413 * frames is a acceptable to allow RSN IBSS to be used.
1418 mutex_lock(&priv->mutex);
1419 ath_dbg(common, CONFIG, "Set HW Key\n");
1420 ath9k_htc_ps_wakeup(priv);
1424 ret = ath_key_config(common, vif, sta, key);
1426 key->hw_key_idx = ret;
1427 /* push IV and Michael MIC generation to stack */
1428 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1429 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1430 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1431 if (priv->ah->sw_mgmt_crypto &&
1432 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1433 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1438 ath_key_delete(common, key);
1444 ath9k_htc_ps_restore(priv);
1445 mutex_unlock(&priv->mutex);
1450 static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv)
1452 struct ath_common *common = ath9k_hw_common(priv->ah);
1454 ath9k_hw_write_associd(priv->ah);
1455 ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
1456 common->curbssid, common->curaid);
1459 static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1461 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1462 struct ath_common *common = ath9k_hw_common(priv->ah);
1463 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1465 if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) {
1466 common->curaid = bss_conf->aid;
1467 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1471 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv)
1473 if (priv->num_sta_assoc_vif == 1) {
1474 ieee80211_iterate_active_interfaces_atomic(
1475 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1476 ath9k_htc_bss_iter, priv);
1477 ath9k_htc_set_bssid(priv);
1481 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1482 struct ieee80211_vif *vif,
1483 struct ieee80211_bss_conf *bss_conf,
1486 struct ath9k_htc_priv *priv = hw->priv;
1487 struct ath_hw *ah = priv->ah;
1488 struct ath_common *common = ath9k_hw_common(ah);
1490 mutex_lock(&priv->mutex);
1491 ath9k_htc_ps_wakeup(priv);
1493 if (changed & BSS_CHANGED_ASSOC) {
1494 ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n",
1498 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1500 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1501 ath9k_htc_choose_set_bssid(priv);
1502 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
1503 ath9k_htc_start_ani(priv);
1504 else if (priv->num_sta_assoc_vif == 0)
1505 ath9k_htc_stop_ani(priv);
1509 if (changed & BSS_CHANGED_IBSS) {
1510 if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
1511 common->curaid = bss_conf->aid;
1512 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1513 ath9k_htc_set_bssid(priv);
1517 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1518 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1520 ath9k_htc_set_tsfadjust(priv, vif);
1521 set_bit(OP_ENABLE_BEACON, &priv->op_flags);
1522 ath9k_htc_beacon_config(priv, vif);
1525 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1527 * Disable SWBA interrupt only if there are no
1528 * AP/IBSS interfaces.
1530 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1531 ath_dbg(common, CONFIG,
1532 "Beacon disabled for BSS: %pM\n",
1534 clear_bit(OP_ENABLE_BEACON, &priv->op_flags);
1535 ath9k_htc_beacon_config(priv, vif);
1539 if (changed & BSS_CHANGED_BEACON_INT) {
1541 * Reset the HW TSF for the first AP interface.
1543 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1544 (priv->nvifs == 1) &&
1545 (priv->num_ap_vif == 1) &&
1546 (vif->type == NL80211_IFTYPE_AP)) {
1547 set_bit(OP_TSF_RESET, &priv->op_flags);
1549 ath_dbg(common, CONFIG,
1550 "Beacon interval changed for BSS: %pM\n",
1552 ath9k_htc_beacon_config(priv, vif);
1555 if (changed & BSS_CHANGED_ERP_SLOT) {
1556 if (bss_conf->use_short_slot)
1561 ath9k_hw_init_global_settings(ah);
1564 if (changed & BSS_CHANGED_HT)
1565 ath9k_htc_update_rate(priv, vif, bss_conf);
1567 ath9k_htc_ps_restore(priv);
1568 mutex_unlock(&priv->mutex);
1571 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw,
1572 struct ieee80211_vif *vif)
1574 struct ath9k_htc_priv *priv = hw->priv;
1577 mutex_lock(&priv->mutex);
1578 ath9k_htc_ps_wakeup(priv);
1579 tsf = ath9k_hw_gettsf64(priv->ah);
1580 ath9k_htc_ps_restore(priv);
1581 mutex_unlock(&priv->mutex);
1586 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw,
1587 struct ieee80211_vif *vif, u64 tsf)
1589 struct ath9k_htc_priv *priv = hw->priv;
1591 mutex_lock(&priv->mutex);
1592 ath9k_htc_ps_wakeup(priv);
1593 ath9k_hw_settsf64(priv->ah, tsf);
1594 ath9k_htc_ps_restore(priv);
1595 mutex_unlock(&priv->mutex);
1598 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw,
1599 struct ieee80211_vif *vif)
1601 struct ath9k_htc_priv *priv = hw->priv;
1603 mutex_lock(&priv->mutex);
1604 ath9k_htc_ps_wakeup(priv);
1605 ath9k_hw_reset_tsf(priv->ah);
1606 ath9k_htc_ps_restore(priv);
1607 mutex_unlock(&priv->mutex);
1610 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1611 struct ieee80211_vif *vif,
1612 enum ieee80211_ampdu_mlme_action action,
1613 struct ieee80211_sta *sta,
1614 u16 tid, u16 *ssn, u8 buf_size)
1616 struct ath9k_htc_priv *priv = hw->priv;
1617 struct ath9k_htc_sta *ista;
1620 mutex_lock(&priv->mutex);
1621 ath9k_htc_ps_wakeup(priv);
1624 case IEEE80211_AMPDU_RX_START:
1626 case IEEE80211_AMPDU_RX_STOP:
1628 case IEEE80211_AMPDU_TX_START:
1629 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1631 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1633 case IEEE80211_AMPDU_TX_STOP_CONT:
1634 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1635 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1636 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1637 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1639 case IEEE80211_AMPDU_TX_OPERATIONAL:
1640 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1641 spin_lock_bh(&priv->tx.tx_lock);
1642 ista->tid_state[tid] = AGGR_OPERATIONAL;
1643 spin_unlock_bh(&priv->tx.tx_lock);
1646 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1649 ath9k_htc_ps_restore(priv);
1650 mutex_unlock(&priv->mutex);
1655 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1657 struct ath9k_htc_priv *priv = hw->priv;
1659 mutex_lock(&priv->mutex);
1660 spin_lock_bh(&priv->beacon_lock);
1661 set_bit(OP_SCANNING, &priv->op_flags);
1662 spin_unlock_bh(&priv->beacon_lock);
1663 cancel_work_sync(&priv->ps_work);
1664 ath9k_htc_stop_ani(priv);
1665 mutex_unlock(&priv->mutex);
1668 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1670 struct ath9k_htc_priv *priv = hw->priv;
1672 mutex_lock(&priv->mutex);
1673 spin_lock_bh(&priv->beacon_lock);
1674 clear_bit(OP_SCANNING, &priv->op_flags);
1675 spin_unlock_bh(&priv->beacon_lock);
1676 ath9k_htc_ps_wakeup(priv);
1677 ath9k_htc_vif_reconfig(priv);
1678 ath9k_htc_ps_restore(priv);
1679 mutex_unlock(&priv->mutex);
1682 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1687 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1690 struct ath9k_htc_priv *priv = hw->priv;
1692 mutex_lock(&priv->mutex);
1693 ath9k_htc_ps_wakeup(priv);
1694 priv->ah->coverage_class = coverage_class;
1695 ath9k_hw_init_global_settings(priv->ah);
1696 ath9k_htc_ps_restore(priv);
1697 mutex_unlock(&priv->mutex);
1701 * Currently, this is used only for selecting the minimum rate
1702 * for management frames, rate selection for data frames remain
1705 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw,
1706 struct ieee80211_vif *vif,
1707 const struct cfg80211_bitrate_mask *mask)
1709 struct ath9k_htc_priv *priv = hw->priv;
1710 struct ath_common *common = ath9k_hw_common(priv->ah);
1711 struct ath9k_htc_target_rate_mask tmask;
1712 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1716 memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask));
1718 tmask.vif_index = avp->index;
1719 tmask.band = IEEE80211_BAND_2GHZ;
1720 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy);
1722 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1725 "Unable to set 2G rate mask for "
1726 "interface at idx: %d\n", avp->index);
1730 tmask.band = IEEE80211_BAND_5GHZ;
1731 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy);
1733 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1736 "Unable to set 5G rate mask for "
1737 "interface at idx: %d\n", avp->index);
1741 ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n",
1742 mask->control[IEEE80211_BAND_2GHZ].legacy,
1743 mask->control[IEEE80211_BAND_5GHZ].legacy);
1749 static int ath9k_htc_get_stats(struct ieee80211_hw *hw,
1750 struct ieee80211_low_level_stats *stats)
1752 struct ath9k_htc_priv *priv = hw->priv;
1753 struct ath_hw *ah = priv->ah;
1754 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1756 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1757 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1758 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1759 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1764 struct ieee80211_ops ath9k_htc_ops = {
1766 .start = ath9k_htc_start,
1767 .stop = ath9k_htc_stop,
1768 .add_interface = ath9k_htc_add_interface,
1769 .remove_interface = ath9k_htc_remove_interface,
1770 .config = ath9k_htc_config,
1771 .configure_filter = ath9k_htc_configure_filter,
1772 .sta_add = ath9k_htc_sta_add,
1773 .sta_remove = ath9k_htc_sta_remove,
1774 .conf_tx = ath9k_htc_conf_tx,
1775 .sta_rc_update = ath9k_htc_sta_rc_update,
1776 .bss_info_changed = ath9k_htc_bss_info_changed,
1777 .set_key = ath9k_htc_set_key,
1778 .get_tsf = ath9k_htc_get_tsf,
1779 .set_tsf = ath9k_htc_set_tsf,
1780 .reset_tsf = ath9k_htc_reset_tsf,
1781 .ampdu_action = ath9k_htc_ampdu_action,
1782 .sw_scan_start = ath9k_htc_sw_scan_start,
1783 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1784 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1785 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1786 .set_coverage_class = ath9k_htc_set_coverage_class,
1787 .set_bitrate_mask = ath9k_htc_set_bitrate_mask,
1788 .get_stats = ath9k_htc_get_stats,