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.channel;
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.channel;
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.channel->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 = ath9k_cmn_padpos(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.channel;
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.channel;
1197 int pos = curchan->hw_value;
1199 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
1200 curchan->center_freq);
1202 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1204 hw->conf.channel_type);
1206 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1207 ath_err(common, "Unable to set channel\n");
1214 if (changed & IEEE80211_CONF_CHANGE_PS) {
1215 if (conf->flags & IEEE80211_CONF_PS) {
1216 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1217 priv->ps_enabled = true;
1219 priv->ps_enabled = false;
1220 cancel_work_sync(&priv->ps_work);
1221 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1225 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1226 priv->txpowlimit = 2 * conf->power_level;
1227 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1228 priv->txpowlimit, &priv->curtxpow);
1232 ath9k_htc_ps_restore(priv);
1233 mutex_unlock(&priv->mutex);
1237 #define SUPPORTED_FILTERS \
1238 (FIF_PROMISC_IN_BSS | \
1243 FIF_BCN_PRBRESP_PROMISC | \
1247 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1248 unsigned int changed_flags,
1249 unsigned int *total_flags,
1252 struct ath9k_htc_priv *priv = hw->priv;
1255 mutex_lock(&priv->mutex);
1256 changed_flags &= SUPPORTED_FILTERS;
1257 *total_flags &= SUPPORTED_FILTERS;
1259 if (test_bit(OP_INVALID, &priv->op_flags)) {
1260 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1261 "Unable to configure filter on invalid state\n");
1262 mutex_unlock(&priv->mutex);
1265 ath9k_htc_ps_wakeup(priv);
1267 priv->rxfilter = *total_flags;
1268 rfilt = ath9k_htc_calcrxfilter(priv);
1269 ath9k_hw_setrxfilter(priv->ah, rfilt);
1271 ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n",
1274 ath9k_htc_ps_restore(priv);
1275 mutex_unlock(&priv->mutex);
1278 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1279 struct ieee80211_vif *vif,
1280 struct ieee80211_sta *sta)
1282 struct ath9k_htc_priv *priv = hw->priv;
1285 mutex_lock(&priv->mutex);
1286 ath9k_htc_ps_wakeup(priv);
1287 ret = ath9k_htc_add_station(priv, vif, sta);
1289 ath9k_htc_init_rate(priv, sta);
1290 ath9k_htc_ps_restore(priv);
1291 mutex_unlock(&priv->mutex);
1296 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1297 struct ieee80211_vif *vif,
1298 struct ieee80211_sta *sta)
1300 struct ath9k_htc_priv *priv = hw->priv;
1301 struct ath9k_htc_sta *ista;
1304 mutex_lock(&priv->mutex);
1305 ath9k_htc_ps_wakeup(priv);
1306 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1307 htc_sta_drain(priv->htc, ista->index);
1308 ret = ath9k_htc_remove_station(priv, vif, sta);
1309 ath9k_htc_ps_restore(priv);
1310 mutex_unlock(&priv->mutex);
1315 static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
1316 struct ieee80211_vif *vif,
1317 struct ieee80211_sta *sta, u32 changed)
1319 struct ath9k_htc_priv *priv = hw->priv;
1320 struct ath_common *common = ath9k_hw_common(priv->ah);
1321 struct ath9k_htc_target_rate trate;
1323 mutex_lock(&priv->mutex);
1324 ath9k_htc_ps_wakeup(priv);
1326 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
1327 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
1328 ath9k_htc_setup_rate(priv, sta, &trate);
1329 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1330 ath_dbg(common, CONFIG,
1331 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1332 sta->addr, be32_to_cpu(trate.capflags));
1334 ath_dbg(common, CONFIG,
1335 "Unable to update supported rates for sta: %pM\n",
1339 ath9k_htc_ps_restore(priv);
1340 mutex_unlock(&priv->mutex);
1343 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
1344 struct ieee80211_vif *vif, u16 queue,
1345 const struct ieee80211_tx_queue_params *params)
1347 struct ath9k_htc_priv *priv = hw->priv;
1348 struct ath_common *common = ath9k_hw_common(priv->ah);
1349 struct ath9k_tx_queue_info qi;
1352 if (queue >= IEEE80211_NUM_ACS)
1355 mutex_lock(&priv->mutex);
1356 ath9k_htc_ps_wakeup(priv);
1358 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1360 qi.tqi_aifs = params->aifs;
1361 qi.tqi_cwmin = params->cw_min;
1362 qi.tqi_cwmax = params->cw_max;
1363 qi.tqi_burstTime = params->txop * 32;
1365 qnum = get_hw_qnum(queue, priv->hwq_map);
1367 ath_dbg(common, CONFIG,
1368 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1369 queue, qnum, params->aifs, params->cw_min,
1370 params->cw_max, params->txop);
1372 ret = ath_htc_txq_update(priv, qnum, &qi);
1374 ath_err(common, "TXQ Update failed\n");
1378 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1379 (qnum == priv->hwq_map[IEEE80211_AC_BE]))
1380 ath9k_htc_beaconq_config(priv);
1382 ath9k_htc_ps_restore(priv);
1383 mutex_unlock(&priv->mutex);
1388 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1389 enum set_key_cmd cmd,
1390 struct ieee80211_vif *vif,
1391 struct ieee80211_sta *sta,
1392 struct ieee80211_key_conf *key)
1394 struct ath9k_htc_priv *priv = hw->priv;
1395 struct ath_common *common = ath9k_hw_common(priv->ah);
1398 if (htc_modparam_nohwcrypt)
1401 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1402 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1403 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1404 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1405 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1407 * For now, disable hw crypto for the RSN IBSS group keys. This
1408 * could be optimized in the future to use a modified key cache
1409 * design to support per-STA RX GTK, but until that gets
1410 * implemented, use of software crypto for group addressed
1411 * frames is a acceptable to allow RSN IBSS to be used.
1416 mutex_lock(&priv->mutex);
1417 ath_dbg(common, CONFIG, "Set HW Key\n");
1418 ath9k_htc_ps_wakeup(priv);
1422 ret = ath_key_config(common, vif, sta, key);
1424 key->hw_key_idx = ret;
1425 /* push IV and Michael MIC generation to stack */
1426 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1427 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1428 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1429 if (priv->ah->sw_mgmt_crypto &&
1430 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1431 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1436 ath_key_delete(common, key);
1442 ath9k_htc_ps_restore(priv);
1443 mutex_unlock(&priv->mutex);
1448 static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv)
1450 struct ath_common *common = ath9k_hw_common(priv->ah);
1452 ath9k_hw_write_associd(priv->ah);
1453 ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
1454 common->curbssid, common->curaid);
1457 static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1459 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1460 struct ath_common *common = ath9k_hw_common(priv->ah);
1461 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1463 if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) {
1464 common->curaid = bss_conf->aid;
1465 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1469 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv)
1471 if (priv->num_sta_assoc_vif == 1) {
1472 ieee80211_iterate_active_interfaces_atomic(
1473 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1474 ath9k_htc_bss_iter, priv);
1475 ath9k_htc_set_bssid(priv);
1479 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1480 struct ieee80211_vif *vif,
1481 struct ieee80211_bss_conf *bss_conf,
1484 struct ath9k_htc_priv *priv = hw->priv;
1485 struct ath_hw *ah = priv->ah;
1486 struct ath_common *common = ath9k_hw_common(ah);
1488 mutex_lock(&priv->mutex);
1489 ath9k_htc_ps_wakeup(priv);
1491 if (changed & BSS_CHANGED_ASSOC) {
1492 ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n",
1496 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1498 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1499 ath9k_htc_choose_set_bssid(priv);
1500 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
1501 ath9k_htc_start_ani(priv);
1502 else if (priv->num_sta_assoc_vif == 0)
1503 ath9k_htc_stop_ani(priv);
1507 if (changed & BSS_CHANGED_IBSS) {
1508 if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
1509 common->curaid = bss_conf->aid;
1510 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1511 ath9k_htc_set_bssid(priv);
1515 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1516 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1518 ath9k_htc_set_tsfadjust(priv, vif);
1519 set_bit(OP_ENABLE_BEACON, &priv->op_flags);
1520 ath9k_htc_beacon_config(priv, vif);
1523 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1525 * Disable SWBA interrupt only if there are no
1526 * AP/IBSS interfaces.
1528 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1529 ath_dbg(common, CONFIG,
1530 "Beacon disabled for BSS: %pM\n",
1532 clear_bit(OP_ENABLE_BEACON, &priv->op_flags);
1533 ath9k_htc_beacon_config(priv, vif);
1537 if (changed & BSS_CHANGED_BEACON_INT) {
1539 * Reset the HW TSF for the first AP interface.
1541 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1542 (priv->nvifs == 1) &&
1543 (priv->num_ap_vif == 1) &&
1544 (vif->type == NL80211_IFTYPE_AP)) {
1545 set_bit(OP_TSF_RESET, &priv->op_flags);
1547 ath_dbg(common, CONFIG,
1548 "Beacon interval changed for BSS: %pM\n",
1550 ath9k_htc_beacon_config(priv, vif);
1553 if (changed & BSS_CHANGED_ERP_SLOT) {
1554 if (bss_conf->use_short_slot)
1559 ath9k_hw_init_global_settings(ah);
1562 if (changed & BSS_CHANGED_HT)
1563 ath9k_htc_update_rate(priv, vif, bss_conf);
1565 ath9k_htc_ps_restore(priv);
1566 mutex_unlock(&priv->mutex);
1569 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw,
1570 struct ieee80211_vif *vif)
1572 struct ath9k_htc_priv *priv = hw->priv;
1575 mutex_lock(&priv->mutex);
1576 ath9k_htc_ps_wakeup(priv);
1577 tsf = ath9k_hw_gettsf64(priv->ah);
1578 ath9k_htc_ps_restore(priv);
1579 mutex_unlock(&priv->mutex);
1584 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw,
1585 struct ieee80211_vif *vif, u64 tsf)
1587 struct ath9k_htc_priv *priv = hw->priv;
1589 mutex_lock(&priv->mutex);
1590 ath9k_htc_ps_wakeup(priv);
1591 ath9k_hw_settsf64(priv->ah, tsf);
1592 ath9k_htc_ps_restore(priv);
1593 mutex_unlock(&priv->mutex);
1596 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw,
1597 struct ieee80211_vif *vif)
1599 struct ath9k_htc_priv *priv = hw->priv;
1601 mutex_lock(&priv->mutex);
1602 ath9k_htc_ps_wakeup(priv);
1603 ath9k_hw_reset_tsf(priv->ah);
1604 ath9k_htc_ps_restore(priv);
1605 mutex_unlock(&priv->mutex);
1608 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1609 struct ieee80211_vif *vif,
1610 enum ieee80211_ampdu_mlme_action action,
1611 struct ieee80211_sta *sta,
1612 u16 tid, u16 *ssn, u8 buf_size)
1614 struct ath9k_htc_priv *priv = hw->priv;
1615 struct ath9k_htc_sta *ista;
1618 mutex_lock(&priv->mutex);
1619 ath9k_htc_ps_wakeup(priv);
1622 case IEEE80211_AMPDU_RX_START:
1624 case IEEE80211_AMPDU_RX_STOP:
1626 case IEEE80211_AMPDU_TX_START:
1627 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1629 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1631 case IEEE80211_AMPDU_TX_STOP:
1632 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1633 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1635 case IEEE80211_AMPDU_TX_OPERATIONAL:
1636 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1637 spin_lock_bh(&priv->tx.tx_lock);
1638 ista->tid_state[tid] = AGGR_OPERATIONAL;
1639 spin_unlock_bh(&priv->tx.tx_lock);
1642 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1645 ath9k_htc_ps_restore(priv);
1646 mutex_unlock(&priv->mutex);
1651 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1653 struct ath9k_htc_priv *priv = hw->priv;
1655 mutex_lock(&priv->mutex);
1656 spin_lock_bh(&priv->beacon_lock);
1657 set_bit(OP_SCANNING, &priv->op_flags);
1658 spin_unlock_bh(&priv->beacon_lock);
1659 cancel_work_sync(&priv->ps_work);
1660 ath9k_htc_stop_ani(priv);
1661 mutex_unlock(&priv->mutex);
1664 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1666 struct ath9k_htc_priv *priv = hw->priv;
1668 mutex_lock(&priv->mutex);
1669 spin_lock_bh(&priv->beacon_lock);
1670 clear_bit(OP_SCANNING, &priv->op_flags);
1671 spin_unlock_bh(&priv->beacon_lock);
1672 ath9k_htc_ps_wakeup(priv);
1673 ath9k_htc_vif_reconfig(priv);
1674 ath9k_htc_ps_restore(priv);
1675 mutex_unlock(&priv->mutex);
1678 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1683 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1686 struct ath9k_htc_priv *priv = hw->priv;
1688 mutex_lock(&priv->mutex);
1689 ath9k_htc_ps_wakeup(priv);
1690 priv->ah->coverage_class = coverage_class;
1691 ath9k_hw_init_global_settings(priv->ah);
1692 ath9k_htc_ps_restore(priv);
1693 mutex_unlock(&priv->mutex);
1697 * Currently, this is used only for selecting the minimum rate
1698 * for management frames, rate selection for data frames remain
1701 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw,
1702 struct ieee80211_vif *vif,
1703 const struct cfg80211_bitrate_mask *mask)
1705 struct ath9k_htc_priv *priv = hw->priv;
1706 struct ath_common *common = ath9k_hw_common(priv->ah);
1707 struct ath9k_htc_target_rate_mask tmask;
1708 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1712 memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask));
1714 tmask.vif_index = avp->index;
1715 tmask.band = IEEE80211_BAND_2GHZ;
1716 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy);
1718 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1721 "Unable to set 2G rate mask for "
1722 "interface at idx: %d\n", avp->index);
1726 tmask.band = IEEE80211_BAND_5GHZ;
1727 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy);
1729 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1732 "Unable to set 5G rate mask for "
1733 "interface at idx: %d\n", avp->index);
1737 ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n",
1738 mask->control[IEEE80211_BAND_2GHZ].legacy,
1739 mask->control[IEEE80211_BAND_5GHZ].legacy);
1745 static int ath9k_htc_get_stats(struct ieee80211_hw *hw,
1746 struct ieee80211_low_level_stats *stats)
1748 struct ath9k_htc_priv *priv = hw->priv;
1749 struct ath_hw *ah = priv->ah;
1750 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1752 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1753 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1754 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1755 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1760 struct ieee80211_ops ath9k_htc_ops = {
1762 .start = ath9k_htc_start,
1763 .stop = ath9k_htc_stop,
1764 .add_interface = ath9k_htc_add_interface,
1765 .remove_interface = ath9k_htc_remove_interface,
1766 .config = ath9k_htc_config,
1767 .configure_filter = ath9k_htc_configure_filter,
1768 .sta_add = ath9k_htc_sta_add,
1769 .sta_remove = ath9k_htc_sta_remove,
1770 .conf_tx = ath9k_htc_conf_tx,
1771 .sta_rc_update = ath9k_htc_sta_rc_update,
1772 .bss_info_changed = ath9k_htc_bss_info_changed,
1773 .set_key = ath9k_htc_set_key,
1774 .get_tsf = ath9k_htc_get_tsf,
1775 .set_tsf = ath9k_htc_set_tsf,
1776 .reset_tsf = ath9k_htc_reset_tsf,
1777 .ampdu_action = ath9k_htc_ampdu_action,
1778 .sw_scan_start = ath9k_htc_sw_scan_start,
1779 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1780 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1781 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1782 .set_coverage_class = ath9k_htc_set_coverage_class,
1783 .set_bitrate_mask = ath9k_htc_set_bitrate_mask,
1784 .get_stats = ath9k_htc_get_stats,