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(priv->hw,
131 ath9k_htc_vif_iter, priv);
133 ath9k_htc_start_ani(priv);
135 if (priv->reconfig_beacon) {
136 ath9k_htc_ps_wakeup(priv);
137 ath9k_htc_beacon_reconfig(priv);
138 ath9k_htc_ps_restore(priv);
142 static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
144 struct ath9k_vif_iter_data *iter_data = data;
147 for (i = 0; i < ETH_ALEN; i++)
148 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
151 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
152 struct ieee80211_vif *vif)
154 struct ath_common *common = ath9k_hw_common(priv->ah);
155 struct ath9k_vif_iter_data iter_data;
158 * Use the hardware MAC address as reference, the hardware uses it
159 * together with the BSSID mask when matching addresses.
161 iter_data.hw_macaddr = common->macaddr;
162 memset(&iter_data.mask, 0xff, ETH_ALEN);
165 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
167 /* Get list of all active MAC addresses */
168 ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter,
171 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
172 ath_hw_setbssidmask(common);
175 static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv)
177 if (priv->num_ibss_vif)
178 priv->ah->opmode = NL80211_IFTYPE_ADHOC;
179 else if (priv->num_ap_vif)
180 priv->ah->opmode = NL80211_IFTYPE_AP;
182 priv->ah->opmode = NL80211_IFTYPE_STATION;
184 ath9k_hw_setopmode(priv->ah);
187 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
189 struct ath_hw *ah = priv->ah;
190 struct ath_common *common = ath9k_hw_common(ah);
191 struct ieee80211_channel *channel = priv->hw->conf.channel;
192 struct ath9k_hw_cal_data *caldata = NULL;
193 enum htc_phymode mode;
198 mutex_lock(&priv->mutex);
199 ath9k_htc_ps_wakeup(priv);
201 ath9k_htc_stop_ani(priv);
202 ieee80211_stop_queues(priv->hw);
204 del_timer_sync(&priv->tx.cleanup_timer);
205 ath9k_htc_tx_drain(priv);
207 WMI_CMD(WMI_DISABLE_INTR_CMDID);
208 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
209 WMI_CMD(WMI_STOP_RECV_CMDID);
211 ath9k_wmi_event_drain(priv);
213 caldata = &priv->caldata;
214 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
217 "Unable to reset device (%u Mhz) reset status %d\n",
218 channel->center_freq, ret);
221 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
224 WMI_CMD(WMI_START_RECV_CMDID);
225 ath9k_host_rx_init(priv);
227 mode = ath9k_htc_get_curmode(priv, ah->curchan);
228 htc_mode = cpu_to_be16(mode);
229 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
231 WMI_CMD(WMI_ENABLE_INTR_CMDID);
232 htc_start(priv->htc);
233 ath9k_htc_vif_reconfig(priv);
234 ieee80211_wake_queues(priv->hw);
236 mod_timer(&priv->tx.cleanup_timer,
237 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
239 ath9k_htc_ps_restore(priv);
240 mutex_unlock(&priv->mutex);
243 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
244 struct ieee80211_hw *hw,
245 struct ath9k_channel *hchan)
247 struct ath_hw *ah = priv->ah;
248 struct ath_common *common = ath9k_hw_common(ah);
249 struct ieee80211_conf *conf = &common->hw->conf;
251 struct ieee80211_channel *channel = hw->conf.channel;
252 struct ath9k_hw_cal_data *caldata = NULL;
253 enum htc_phymode mode;
258 if (test_bit(OP_INVALID, &priv->op_flags))
261 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
263 ath9k_htc_ps_wakeup(priv);
265 del_timer_sync(&priv->tx.cleanup_timer);
266 ath9k_htc_tx_drain(priv);
268 WMI_CMD(WMI_DISABLE_INTR_CMDID);
269 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
270 WMI_CMD(WMI_STOP_RECV_CMDID);
272 ath9k_wmi_event_drain(priv);
274 ath_dbg(common, CONFIG,
275 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
276 priv->ah->curchan->channel,
277 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
281 caldata = &priv->caldata;
283 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
286 "Unable to reset channel (%u Mhz) reset status %d\n",
287 channel->center_freq, ret);
291 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
294 WMI_CMD(WMI_START_RECV_CMDID);
298 ath9k_host_rx_init(priv);
300 mode = ath9k_htc_get_curmode(priv, hchan);
301 htc_mode = cpu_to_be16(mode);
302 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
306 WMI_CMD(WMI_ENABLE_INTR_CMDID);
310 htc_start(priv->htc);
312 if (!test_bit(OP_SCANNING, &priv->op_flags) &&
313 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
314 ath9k_htc_vif_reconfig(priv);
316 mod_timer(&priv->tx.cleanup_timer,
317 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
320 ath9k_htc_ps_restore(priv);
325 * Monitor mode handling is a tad complicated because the firmware requires
326 * an interface to be created exclusively, while mac80211 doesn't associate
327 * an interface with the mode.
329 * So, for now, only one monitor interface can be configured.
331 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
333 struct ath_common *common = ath9k_hw_common(priv->ah);
334 struct ath9k_htc_target_vif hvif;
338 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
339 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
340 hvif.index = priv->mon_vif_idx;
341 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
343 ath_err(common, "Unable to remove monitor interface at idx: %d\n",
348 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
351 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
353 struct ath_common *common = ath9k_hw_common(priv->ah);
354 struct ath9k_htc_target_vif hvif;
355 struct ath9k_htc_target_sta tsta;
356 int ret = 0, sta_idx;
359 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
360 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
365 sta_idx = ffz(priv->sta_slot);
366 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
374 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
375 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
377 hvif.opmode = HTC_M_MONITOR;
378 hvif.index = ffz(priv->vif_slot);
380 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
385 * Assign the monitor interface index as a special case here.
386 * This is needed when the interface is brought down.
388 priv->mon_vif_idx = hvif.index;
389 priv->vif_slot |= (1 << hvif.index);
392 * Set the hardware mode to monitor only if there are no
396 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
401 * Associate a station with the interface for packet injection.
403 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
405 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
408 tsta.sta_index = sta_idx;
409 tsta.vif_index = hvif.index;
410 tsta.maxampdu = cpu_to_be16(0xffff);
412 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
414 ath_err(common, "Unable to add station entry for monitor mode\n");
418 priv->sta_slot |= (1 << sta_idx);
420 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
421 priv->ah->is_monitoring = true;
423 ath_dbg(common, CONFIG,
424 "Attached a monitor interface at idx: %d, sta idx: %d\n",
425 priv->mon_vif_idx, sta_idx);
431 * Remove the interface from the target.
433 __ath9k_htc_remove_monitor_interface(priv);
435 ath_dbg(common, FATAL, "Unable to attach a monitor interface\n");
440 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
442 struct ath_common *common = ath9k_hw_common(priv->ah);
446 __ath9k_htc_remove_monitor_interface(priv);
448 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
450 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
452 ath_err(common, "Unable to remove station entry for monitor mode\n");
456 priv->sta_slot &= ~(1 << sta_idx);
458 priv->ah->is_monitoring = false;
460 ath_dbg(common, CONFIG,
461 "Removed a monitor interface at idx: %d, sta idx: %d\n",
462 priv->mon_vif_idx, sta_idx);
467 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
468 struct ieee80211_vif *vif,
469 struct ieee80211_sta *sta)
471 struct ath_common *common = ath9k_hw_common(priv->ah);
472 struct ath9k_htc_target_sta tsta;
473 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
474 struct ath9k_htc_sta *ista;
479 if (priv->nstations >= ATH9K_HTC_MAX_STA)
482 sta_idx = ffz(priv->sta_slot);
483 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
486 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
489 ista = (struct ath9k_htc_sta *) sta->drv_priv;
490 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
491 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
492 ista->index = sta_idx;
494 maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
495 sta->ht_cap.ampdu_factor);
496 tsta.maxampdu = cpu_to_be16(maxampdu);
498 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
500 tsta.maxampdu = cpu_to_be16(0xffff);
503 tsta.sta_index = sta_idx;
504 tsta.vif_index = avp->index;
506 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
510 "Unable to add station entry for: %pM\n",
516 ath_dbg(common, CONFIG,
517 "Added a station entry for: %pM (idx: %d)\n",
518 sta->addr, tsta.sta_index);
520 ath_dbg(common, CONFIG,
521 "Added a station entry for VIF %d (idx: %d)\n",
522 avp->index, tsta.sta_index);
525 priv->sta_slot |= (1 << sta_idx);
528 priv->vif_sta_pos[avp->index] = sta_idx;
533 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
534 struct ieee80211_vif *vif,
535 struct ieee80211_sta *sta)
537 struct ath_common *common = ath9k_hw_common(priv->ah);
538 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
539 struct ath9k_htc_sta *ista;
544 ista = (struct ath9k_htc_sta *) sta->drv_priv;
545 sta_idx = ista->index;
547 sta_idx = priv->vif_sta_pos[avp->index];
550 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
554 "Unable to remove station entry for: %pM\n",
560 ath_dbg(common, CONFIG,
561 "Removed a station entry for: %pM (idx: %d)\n",
564 ath_dbg(common, CONFIG,
565 "Removed a station entry for VIF %d (idx: %d)\n",
566 avp->index, sta_idx);
569 priv->sta_slot &= ~(1 << sta_idx);
575 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
578 struct ath9k_htc_cap_target tcap;
582 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
584 tcap.ampdu_limit = cpu_to_be32(0xffff);
585 tcap.ampdu_subframes = 0xff;
586 tcap.enable_coex = enable_coex;
587 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
589 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
594 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
595 struct ieee80211_sta *sta,
596 struct ath9k_htc_target_rate *trate)
598 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
599 struct ieee80211_supported_band *sband;
603 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
605 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
606 if (sta->supp_rates[sband->band] & BIT(i)) {
607 trate->rates.legacy_rates.rs_rates[j]
608 = (sband->bitrates[i].bitrate * 2) / 10;
612 trate->rates.legacy_rates.rs_nrates = j;
614 if (sta->ht_cap.ht_supported) {
615 for (i = 0, j = 0; i < 77; i++) {
616 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
617 trate->rates.ht_rates.rs_rates[j++] = i;
618 if (j == ATH_HTC_RATE_MAX)
621 trate->rates.ht_rates.rs_nrates = j;
623 caps = WLAN_RC_HT_FLAG;
624 if (sta->ht_cap.mcs.rx_mask[1])
625 caps |= WLAN_RC_DS_FLAG;
626 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
627 (conf_is_ht40(&priv->hw->conf)))
628 caps |= WLAN_RC_40_FLAG;
629 if (conf_is_ht40(&priv->hw->conf) &&
630 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
631 caps |= WLAN_RC_SGI_FLAG;
632 else if (conf_is_ht20(&priv->hw->conf) &&
633 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
634 caps |= WLAN_RC_SGI_FLAG;
637 trate->sta_index = ista->index;
639 trate->capflags = cpu_to_be32(caps);
642 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
643 struct ath9k_htc_target_rate *trate)
645 struct ath_common *common = ath9k_hw_common(priv->ah);
649 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
652 "Unable to initialize Rate information on target\n");
658 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
659 struct ieee80211_sta *sta)
661 struct ath_common *common = ath9k_hw_common(priv->ah);
662 struct ath9k_htc_target_rate trate;
665 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
666 ath9k_htc_setup_rate(priv, sta, &trate);
667 ret = ath9k_htc_send_rate_cmd(priv, &trate);
669 ath_dbg(common, CONFIG,
670 "Updated target sta: %pM, rate caps: 0x%X\n",
671 sta->addr, be32_to_cpu(trate.capflags));
674 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
675 struct ieee80211_vif *vif,
676 struct ieee80211_bss_conf *bss_conf)
678 struct ath_common *common = ath9k_hw_common(priv->ah);
679 struct ath9k_htc_target_rate trate;
680 struct ieee80211_sta *sta;
683 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
686 sta = ieee80211_find_sta(vif, bss_conf->bssid);
691 ath9k_htc_setup_rate(priv, sta, &trate);
694 ret = ath9k_htc_send_rate_cmd(priv, &trate);
696 ath_dbg(common, CONFIG,
697 "Updated target sta: %pM, rate caps: 0x%X\n",
698 bss_conf->bssid, be32_to_cpu(trate.capflags));
701 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
702 struct ieee80211_vif *vif,
703 struct ieee80211_sta *sta,
704 enum ieee80211_ampdu_mlme_action action,
707 struct ath_common *common = ath9k_hw_common(priv->ah);
708 struct ath9k_htc_target_aggr aggr;
709 struct ath9k_htc_sta *ista;
713 if (tid >= ATH9K_HTC_MAX_TID)
716 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
717 ista = (struct ath9k_htc_sta *) sta->drv_priv;
719 aggr.sta_index = ista->index;
720 aggr.tidno = tid & 0xf;
721 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
723 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
725 ath_dbg(common, CONFIG,
726 "Unable to %s TX aggregation for (%pM, %d)\n",
727 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
729 ath_dbg(common, CONFIG,
730 "%s TX aggregation for (%pM, %d)\n",
731 (aggr.aggr_enable) ? "Starting" : "Stopping",
734 spin_lock_bh(&priv->tx.tx_lock);
735 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
736 spin_unlock_bh(&priv->tx.tx_lock);
745 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
747 struct ath_common *common = ath9k_hw_common(priv->ah);
748 unsigned long timestamp = jiffies_to_msecs(jiffies);
750 common->ani.longcal_timer = timestamp;
751 common->ani.shortcal_timer = timestamp;
752 common->ani.checkani_timer = timestamp;
754 set_bit(OP_ANI_RUNNING, &priv->op_flags);
756 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
757 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
760 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
762 cancel_delayed_work_sync(&priv->ani_work);
763 clear_bit(OP_ANI_RUNNING, &priv->op_flags);
766 void ath9k_htc_ani_work(struct work_struct *work)
768 struct ath9k_htc_priv *priv =
769 container_of(work, struct ath9k_htc_priv, ani_work.work);
770 struct ath_hw *ah = priv->ah;
771 struct ath_common *common = ath9k_hw_common(ah);
772 bool longcal = false;
773 bool shortcal = false;
774 bool aniflag = false;
775 unsigned int timestamp = jiffies_to_msecs(jiffies);
776 u32 cal_interval, short_cal_interval;
778 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
779 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
781 /* Only calibrate if awake */
782 if (ah->power_mode != ATH9K_PM_AWAKE)
785 /* Long calibration runs independently of short calibration. */
786 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
788 ath_dbg(common, ANI, "longcal @%lu\n", jiffies);
789 common->ani.longcal_timer = timestamp;
792 /* Short calibration applies only while caldone is false */
793 if (!common->ani.caldone) {
794 if ((timestamp - common->ani.shortcal_timer) >=
795 short_cal_interval) {
797 ath_dbg(common, ANI, "shortcal @%lu\n", jiffies);
798 common->ani.shortcal_timer = timestamp;
799 common->ani.resetcal_timer = timestamp;
802 if ((timestamp - common->ani.resetcal_timer) >=
803 ATH_RESTART_CALINTERVAL) {
804 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
805 if (common->ani.caldone)
806 common->ani.resetcal_timer = timestamp;
810 /* Verify whether we must check ANI */
811 if (ah->config.enable_ani &&
812 (timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
814 common->ani.checkani_timer = timestamp;
817 /* Skip all processing if there's nothing to do. */
818 if (longcal || shortcal || aniflag) {
820 ath9k_htc_ps_wakeup(priv);
822 /* Call ANI routine if necessary */
824 ath9k_hw_ani_monitor(ah, ah->curchan);
826 /* Perform calibration if necessary */
827 if (longcal || shortcal)
828 common->ani.caldone =
829 ath9k_hw_calibrate(ah, ah->curchan,
830 ah->rxchainmask, longcal);
832 ath9k_htc_ps_restore(priv);
837 * Set timer interval based on previous results.
838 * The interval must be the shortest necessary to satisfy ANI,
839 * short calibration and long calibration.
841 cal_interval = ATH_LONG_CALINTERVAL;
842 if (ah->config.enable_ani)
843 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
844 if (!common->ani.caldone)
845 cal_interval = min(cal_interval, (u32)short_cal_interval);
847 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
848 msecs_to_jiffies(cal_interval));
851 /**********************/
852 /* mac80211 Callbacks */
853 /**********************/
855 static void ath9k_htc_tx(struct ieee80211_hw *hw,
856 struct ieee80211_tx_control *control,
859 struct ieee80211_hdr *hdr;
860 struct ath9k_htc_priv *priv = hw->priv;
861 struct ath_common *common = ath9k_hw_common(priv->ah);
862 int padpos, padsize, ret, slot;
864 hdr = (struct ieee80211_hdr *) skb->data;
866 /* Add the padding after the header if this is not already done */
867 padpos = ath9k_cmn_padpos(hdr->frame_control);
868 padsize = padpos & 3;
869 if (padsize && skb->len > padpos) {
870 if (skb_headroom(skb) < padsize) {
871 ath_dbg(common, XMIT, "No room for padding\n");
874 skb_push(skb, padsize);
875 memmove(skb->data, skb->data + padsize, padpos);
878 slot = ath9k_htc_tx_get_slot(priv);
880 ath_dbg(common, XMIT, "No free TX slot\n");
884 ret = ath9k_htc_tx_start(priv, control->sta, skb, slot, false);
886 ath_dbg(common, XMIT, "Tx failed\n");
890 ath9k_htc_check_stop_queues(priv);
895 ath9k_htc_tx_clear_slot(priv, slot);
897 dev_kfree_skb_any(skb);
900 static int ath9k_htc_start(struct ieee80211_hw *hw)
902 struct ath9k_htc_priv *priv = hw->priv;
903 struct ath_hw *ah = priv->ah;
904 struct ath_common *common = ath9k_hw_common(ah);
905 struct ieee80211_channel *curchan = hw->conf.channel;
906 struct ath9k_channel *init_channel;
908 enum htc_phymode mode;
912 mutex_lock(&priv->mutex);
914 ath_dbg(common, CONFIG,
915 "Starting driver with initial channel: %d MHz\n",
916 curchan->center_freq);
918 /* Ensure that HW is awake before flushing RX */
919 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
920 WMI_CMD(WMI_FLUSH_RECV_CMDID);
922 /* setup initial channel */
923 init_channel = ath9k_cmn_get_curchannel(hw, ah);
925 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
928 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
929 ret, curchan->center_freq);
930 mutex_unlock(&priv->mutex);
934 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
937 mode = ath9k_htc_get_curmode(priv, init_channel);
938 htc_mode = cpu_to_be16(mode);
939 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
940 WMI_CMD(WMI_ATH_INIT_CMDID);
941 WMI_CMD(WMI_START_RECV_CMDID);
943 ath9k_host_rx_init(priv);
945 ret = ath9k_htc_update_cap_target(priv, 0);
947 ath_dbg(common, CONFIG,
948 "Failed to update capability in target\n");
950 clear_bit(OP_INVALID, &priv->op_flags);
951 htc_start(priv->htc);
953 spin_lock_bh(&priv->tx.tx_lock);
954 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
955 spin_unlock_bh(&priv->tx.tx_lock);
957 ieee80211_wake_queues(hw);
959 mod_timer(&priv->tx.cleanup_timer,
960 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
962 ath9k_htc_start_btcoex(priv);
964 mutex_unlock(&priv->mutex);
969 static void ath9k_htc_stop(struct ieee80211_hw *hw)
971 struct ath9k_htc_priv *priv = hw->priv;
972 struct ath_hw *ah = priv->ah;
973 struct ath_common *common = ath9k_hw_common(ah);
974 int ret __attribute__ ((unused));
977 mutex_lock(&priv->mutex);
979 if (test_bit(OP_INVALID, &priv->op_flags)) {
980 ath_dbg(common, ANY, "Device not present\n");
981 mutex_unlock(&priv->mutex);
985 ath9k_htc_ps_wakeup(priv);
987 WMI_CMD(WMI_DISABLE_INTR_CMDID);
988 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
989 WMI_CMD(WMI_STOP_RECV_CMDID);
991 tasklet_kill(&priv->rx_tasklet);
993 del_timer_sync(&priv->tx.cleanup_timer);
994 ath9k_htc_tx_drain(priv);
995 ath9k_wmi_event_drain(priv);
997 mutex_unlock(&priv->mutex);
999 /* Cancel all the running timers/work .. */
1000 cancel_work_sync(&priv->fatal_work);
1001 cancel_work_sync(&priv->ps_work);
1003 #ifdef CONFIG_MAC80211_LEDS
1004 cancel_work_sync(&priv->led_work);
1006 ath9k_htc_stop_ani(priv);
1008 mutex_lock(&priv->mutex);
1010 ath9k_htc_stop_btcoex(priv);
1012 /* Remove a monitor interface if it's present. */
1013 if (priv->ah->is_monitoring)
1014 ath9k_htc_remove_monitor_interface(priv);
1016 ath9k_hw_phy_disable(ah);
1017 ath9k_hw_disable(ah);
1018 ath9k_htc_ps_restore(priv);
1019 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1021 set_bit(OP_INVALID, &priv->op_flags);
1023 ath_dbg(common, CONFIG, "Driver halt\n");
1024 mutex_unlock(&priv->mutex);
1027 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1028 struct ieee80211_vif *vif)
1030 struct ath9k_htc_priv *priv = hw->priv;
1031 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1032 struct ath_common *common = ath9k_hw_common(priv->ah);
1033 struct ath9k_htc_target_vif hvif;
1037 mutex_lock(&priv->mutex);
1039 if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1040 mutex_unlock(&priv->mutex);
1044 if (priv->num_ibss_vif ||
1045 (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
1046 ath_err(common, "IBSS coexistence with other modes is not allowed\n");
1047 mutex_unlock(&priv->mutex);
1051 if (((vif->type == NL80211_IFTYPE_AP) ||
1052 (vif->type == NL80211_IFTYPE_ADHOC)) &&
1053 ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) {
1054 ath_err(common, "Max. number of beaconing interfaces reached\n");
1055 mutex_unlock(&priv->mutex);
1059 ath9k_htc_ps_wakeup(priv);
1060 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1061 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1063 switch (vif->type) {
1064 case NL80211_IFTYPE_STATION:
1065 hvif.opmode = HTC_M_STA;
1067 case NL80211_IFTYPE_ADHOC:
1068 hvif.opmode = HTC_M_IBSS;
1070 case NL80211_IFTYPE_AP:
1071 hvif.opmode = HTC_M_HOSTAP;
1075 "Interface type %d not yet supported\n", vif->type);
1080 /* Index starts from zero on the target */
1081 avp->index = hvif.index = ffz(priv->vif_slot);
1082 hvif.rtsthreshold = cpu_to_be16(2304);
1083 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1088 * We need a node in target to tx mgmt frames
1089 * before association.
1091 ret = ath9k_htc_add_station(priv, vif, NULL);
1093 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1097 ath9k_htc_set_bssid_mask(priv, vif);
1099 priv->vif_slot |= (1 << avp->index);
1102 INC_VIF(priv, vif->type);
1104 if ((vif->type == NL80211_IFTYPE_AP) ||
1105 (vif->type == NL80211_IFTYPE_ADHOC))
1106 ath9k_htc_assign_bslot(priv, vif);
1108 ath9k_htc_set_opmode(priv);
1110 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1111 !test_bit(OP_ANI_RUNNING, &priv->op_flags)) {
1112 ath9k_hw_set_tsfadjust(priv->ah, true);
1113 ath9k_htc_start_ani(priv);
1116 ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n",
1117 vif->type, avp->index);
1120 ath9k_htc_ps_restore(priv);
1121 mutex_unlock(&priv->mutex);
1126 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1127 struct ieee80211_vif *vif)
1129 struct ath9k_htc_priv *priv = hw->priv;
1130 struct ath_common *common = ath9k_hw_common(priv->ah);
1131 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1132 struct ath9k_htc_target_vif hvif;
1136 mutex_lock(&priv->mutex);
1137 ath9k_htc_ps_wakeup(priv);
1139 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1140 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1141 hvif.index = avp->index;
1142 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1144 ath_err(common, "Unable to remove interface at idx: %d\n",
1148 priv->vif_slot &= ~(1 << avp->index);
1150 ath9k_htc_remove_station(priv, vif, NULL);
1152 DEC_VIF(priv, vif->type);
1154 if ((vif->type == NL80211_IFTYPE_AP) ||
1155 (vif->type == NL80211_IFTYPE_ADHOC))
1156 ath9k_htc_remove_bslot(priv, vif);
1158 ath9k_htc_set_opmode(priv);
1160 ath9k_htc_set_bssid_mask(priv, vif);
1163 * Stop ANI only if there are no associated station interfaces.
1165 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1166 priv->rearm_ani = false;
1167 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1168 ath9k_htc_vif_iter, priv);
1169 if (!priv->rearm_ani)
1170 ath9k_htc_stop_ani(priv);
1173 ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index);
1175 ath9k_htc_ps_restore(priv);
1176 mutex_unlock(&priv->mutex);
1179 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1181 struct ath9k_htc_priv *priv = hw->priv;
1182 struct ath_common *common = ath9k_hw_common(priv->ah);
1183 struct ieee80211_conf *conf = &hw->conf;
1184 bool chip_reset = false;
1187 mutex_lock(&priv->mutex);
1188 ath9k_htc_ps_wakeup(priv);
1190 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1191 mutex_lock(&priv->htc_pm_lock);
1193 priv->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1197 mutex_unlock(&priv->htc_pm_lock);
1201 * Monitor interface should be added before
1202 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1204 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1205 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1206 !priv->ah->is_monitoring)
1207 ath9k_htc_add_monitor_interface(priv);
1208 else if (priv->ah->is_monitoring)
1209 ath9k_htc_remove_monitor_interface(priv);
1212 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
1213 struct ieee80211_channel *curchan = hw->conf.channel;
1214 int pos = curchan->hw_value;
1216 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
1217 curchan->center_freq);
1219 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1221 hw->conf.channel_type);
1223 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1224 ath_err(common, "Unable to set channel\n");
1231 if (changed & IEEE80211_CONF_CHANGE_PS) {
1232 if (conf->flags & IEEE80211_CONF_PS) {
1233 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1234 priv->ps_enabled = true;
1236 priv->ps_enabled = false;
1237 cancel_work_sync(&priv->ps_work);
1238 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1242 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1243 priv->txpowlimit = 2 * conf->power_level;
1244 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1245 priv->txpowlimit, &priv->curtxpow);
1249 ath9k_htc_ps_restore(priv);
1250 mutex_unlock(&priv->mutex);
1254 #define SUPPORTED_FILTERS \
1255 (FIF_PROMISC_IN_BSS | \
1260 FIF_BCN_PRBRESP_PROMISC | \
1264 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1265 unsigned int changed_flags,
1266 unsigned int *total_flags,
1269 struct ath9k_htc_priv *priv = hw->priv;
1272 mutex_lock(&priv->mutex);
1273 changed_flags &= SUPPORTED_FILTERS;
1274 *total_flags &= SUPPORTED_FILTERS;
1276 if (test_bit(OP_INVALID, &priv->op_flags)) {
1277 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1278 "Unable to configure filter on invalid state\n");
1279 mutex_unlock(&priv->mutex);
1282 ath9k_htc_ps_wakeup(priv);
1284 priv->rxfilter = *total_flags;
1285 rfilt = ath9k_htc_calcrxfilter(priv);
1286 ath9k_hw_setrxfilter(priv->ah, rfilt);
1288 ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n",
1291 ath9k_htc_ps_restore(priv);
1292 mutex_unlock(&priv->mutex);
1295 static int ath9k_htc_sta_add(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_add_station(priv, vif, sta);
1306 ath9k_htc_init_rate(priv, sta);
1307 ath9k_htc_ps_restore(priv);
1308 mutex_unlock(&priv->mutex);
1313 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1314 struct ieee80211_vif *vif,
1315 struct ieee80211_sta *sta)
1317 struct ath9k_htc_priv *priv = hw->priv;
1318 struct ath9k_htc_sta *ista;
1321 mutex_lock(&priv->mutex);
1322 ath9k_htc_ps_wakeup(priv);
1323 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1324 htc_sta_drain(priv->htc, ista->index);
1325 ret = ath9k_htc_remove_station(priv, vif, sta);
1326 ath9k_htc_ps_restore(priv);
1327 mutex_unlock(&priv->mutex);
1332 static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
1333 struct ieee80211_vif *vif,
1334 struct ieee80211_sta *sta, u32 changed)
1336 struct ath9k_htc_priv *priv = hw->priv;
1337 struct ath_common *common = ath9k_hw_common(priv->ah);
1338 struct ath9k_htc_target_rate trate;
1340 mutex_lock(&priv->mutex);
1341 ath9k_htc_ps_wakeup(priv);
1343 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
1344 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
1345 ath9k_htc_setup_rate(priv, sta, &trate);
1346 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1347 ath_dbg(common, CONFIG,
1348 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1349 sta->addr, be32_to_cpu(trate.capflags));
1351 ath_dbg(common, CONFIG,
1352 "Unable to update supported rates for sta: %pM\n",
1356 ath9k_htc_ps_restore(priv);
1357 mutex_unlock(&priv->mutex);
1360 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
1361 struct ieee80211_vif *vif, u16 queue,
1362 const struct ieee80211_tx_queue_params *params)
1364 struct ath9k_htc_priv *priv = hw->priv;
1365 struct ath_common *common = ath9k_hw_common(priv->ah);
1366 struct ath9k_tx_queue_info qi;
1369 if (queue >= WME_NUM_AC)
1372 mutex_lock(&priv->mutex);
1373 ath9k_htc_ps_wakeup(priv);
1375 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1377 qi.tqi_aifs = params->aifs;
1378 qi.tqi_cwmin = params->cw_min;
1379 qi.tqi_cwmax = params->cw_max;
1380 qi.tqi_burstTime = params->txop * 32;
1382 qnum = get_hw_qnum(queue, priv->hwq_map);
1384 ath_dbg(common, CONFIG,
1385 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1386 queue, qnum, params->aifs, params->cw_min,
1387 params->cw_max, params->txop);
1389 ret = ath_htc_txq_update(priv, qnum, &qi);
1391 ath_err(common, "TXQ Update failed\n");
1395 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1396 (qnum == priv->hwq_map[WME_AC_BE]))
1397 ath9k_htc_beaconq_config(priv);
1399 ath9k_htc_ps_restore(priv);
1400 mutex_unlock(&priv->mutex);
1405 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1406 enum set_key_cmd cmd,
1407 struct ieee80211_vif *vif,
1408 struct ieee80211_sta *sta,
1409 struct ieee80211_key_conf *key)
1411 struct ath9k_htc_priv *priv = hw->priv;
1412 struct ath_common *common = ath9k_hw_common(priv->ah);
1415 if (htc_modparam_nohwcrypt)
1418 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1419 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1420 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1421 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1422 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1424 * For now, disable hw crypto for the RSN IBSS group keys. This
1425 * could be optimized in the future to use a modified key cache
1426 * design to support per-STA RX GTK, but until that gets
1427 * implemented, use of software crypto for group addressed
1428 * frames is a acceptable to allow RSN IBSS to be used.
1433 mutex_lock(&priv->mutex);
1434 ath_dbg(common, CONFIG, "Set HW Key\n");
1435 ath9k_htc_ps_wakeup(priv);
1439 ret = ath_key_config(common, vif, sta, key);
1441 key->hw_key_idx = ret;
1442 /* push IV and Michael MIC generation to stack */
1443 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1444 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1445 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1446 if (priv->ah->sw_mgmt_crypto &&
1447 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1448 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1453 ath_key_delete(common, key);
1459 ath9k_htc_ps_restore(priv);
1460 mutex_unlock(&priv->mutex);
1465 static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv)
1467 struct ath_common *common = ath9k_hw_common(priv->ah);
1469 ath9k_hw_write_associd(priv->ah);
1470 ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
1471 common->curbssid, common->curaid);
1474 static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1476 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1477 struct ath_common *common = ath9k_hw_common(priv->ah);
1478 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1480 if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) {
1481 common->curaid = bss_conf->aid;
1482 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1486 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv)
1488 if (priv->num_sta_assoc_vif == 1) {
1489 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1490 ath9k_htc_bss_iter, priv);
1491 ath9k_htc_set_bssid(priv);
1495 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1496 struct ieee80211_vif *vif,
1497 struct ieee80211_bss_conf *bss_conf,
1500 struct ath9k_htc_priv *priv = hw->priv;
1501 struct ath_hw *ah = priv->ah;
1502 struct ath_common *common = ath9k_hw_common(ah);
1504 mutex_lock(&priv->mutex);
1505 ath9k_htc_ps_wakeup(priv);
1507 if (changed & BSS_CHANGED_ASSOC) {
1508 ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n",
1512 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1514 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1515 ath9k_htc_choose_set_bssid(priv);
1516 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
1517 ath9k_htc_start_ani(priv);
1518 else if (priv->num_sta_assoc_vif == 0)
1519 ath9k_htc_stop_ani(priv);
1523 if (changed & BSS_CHANGED_IBSS) {
1524 if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
1525 common->curaid = bss_conf->aid;
1526 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1527 ath9k_htc_set_bssid(priv);
1531 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1532 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1534 ath9k_htc_set_tsfadjust(priv, vif);
1535 set_bit(OP_ENABLE_BEACON, &priv->op_flags);
1536 ath9k_htc_beacon_config(priv, vif);
1539 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1541 * Disable SWBA interrupt only if there are no
1542 * AP/IBSS interfaces.
1544 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1545 ath_dbg(common, CONFIG,
1546 "Beacon disabled for BSS: %pM\n",
1548 clear_bit(OP_ENABLE_BEACON, &priv->op_flags);
1549 ath9k_htc_beacon_config(priv, vif);
1553 if (changed & BSS_CHANGED_BEACON_INT) {
1555 * Reset the HW TSF for the first AP interface.
1557 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1558 (priv->nvifs == 1) &&
1559 (priv->num_ap_vif == 1) &&
1560 (vif->type == NL80211_IFTYPE_AP)) {
1561 set_bit(OP_TSF_RESET, &priv->op_flags);
1563 ath_dbg(common, CONFIG,
1564 "Beacon interval changed for BSS: %pM\n",
1566 ath9k_htc_beacon_config(priv, vif);
1569 if (changed & BSS_CHANGED_ERP_SLOT) {
1570 if (bss_conf->use_short_slot)
1575 ath9k_hw_init_global_settings(ah);
1578 if (changed & BSS_CHANGED_HT)
1579 ath9k_htc_update_rate(priv, vif, bss_conf);
1581 ath9k_htc_ps_restore(priv);
1582 mutex_unlock(&priv->mutex);
1585 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw,
1586 struct ieee80211_vif *vif)
1588 struct ath9k_htc_priv *priv = hw->priv;
1591 mutex_lock(&priv->mutex);
1592 ath9k_htc_ps_wakeup(priv);
1593 tsf = ath9k_hw_gettsf64(priv->ah);
1594 ath9k_htc_ps_restore(priv);
1595 mutex_unlock(&priv->mutex);
1600 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw,
1601 struct ieee80211_vif *vif, u64 tsf)
1603 struct ath9k_htc_priv *priv = hw->priv;
1605 mutex_lock(&priv->mutex);
1606 ath9k_htc_ps_wakeup(priv);
1607 ath9k_hw_settsf64(priv->ah, tsf);
1608 ath9k_htc_ps_restore(priv);
1609 mutex_unlock(&priv->mutex);
1612 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw,
1613 struct ieee80211_vif *vif)
1615 struct ath9k_htc_priv *priv = hw->priv;
1617 mutex_lock(&priv->mutex);
1618 ath9k_htc_ps_wakeup(priv);
1619 ath9k_hw_reset_tsf(priv->ah);
1620 ath9k_htc_ps_restore(priv);
1621 mutex_unlock(&priv->mutex);
1624 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1625 struct ieee80211_vif *vif,
1626 enum ieee80211_ampdu_mlme_action action,
1627 struct ieee80211_sta *sta,
1628 u16 tid, u16 *ssn, u8 buf_size)
1630 struct ath9k_htc_priv *priv = hw->priv;
1631 struct ath9k_htc_sta *ista;
1634 mutex_lock(&priv->mutex);
1635 ath9k_htc_ps_wakeup(priv);
1638 case IEEE80211_AMPDU_RX_START:
1640 case IEEE80211_AMPDU_RX_STOP:
1642 case IEEE80211_AMPDU_TX_START:
1643 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1645 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1647 case IEEE80211_AMPDU_TX_STOP:
1648 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1649 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1651 case IEEE80211_AMPDU_TX_OPERATIONAL:
1652 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1653 spin_lock_bh(&priv->tx.tx_lock);
1654 ista->tid_state[tid] = AGGR_OPERATIONAL;
1655 spin_unlock_bh(&priv->tx.tx_lock);
1658 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1661 ath9k_htc_ps_restore(priv);
1662 mutex_unlock(&priv->mutex);
1667 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1669 struct ath9k_htc_priv *priv = hw->priv;
1671 mutex_lock(&priv->mutex);
1672 spin_lock_bh(&priv->beacon_lock);
1673 set_bit(OP_SCANNING, &priv->op_flags);
1674 spin_unlock_bh(&priv->beacon_lock);
1675 cancel_work_sync(&priv->ps_work);
1676 ath9k_htc_stop_ani(priv);
1677 mutex_unlock(&priv->mutex);
1680 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1682 struct ath9k_htc_priv *priv = hw->priv;
1684 mutex_lock(&priv->mutex);
1685 spin_lock_bh(&priv->beacon_lock);
1686 clear_bit(OP_SCANNING, &priv->op_flags);
1687 spin_unlock_bh(&priv->beacon_lock);
1688 ath9k_htc_ps_wakeup(priv);
1689 ath9k_htc_vif_reconfig(priv);
1690 ath9k_htc_ps_restore(priv);
1691 mutex_unlock(&priv->mutex);
1694 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1699 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1702 struct ath9k_htc_priv *priv = hw->priv;
1704 mutex_lock(&priv->mutex);
1705 ath9k_htc_ps_wakeup(priv);
1706 priv->ah->coverage_class = coverage_class;
1707 ath9k_hw_init_global_settings(priv->ah);
1708 ath9k_htc_ps_restore(priv);
1709 mutex_unlock(&priv->mutex);
1713 * Currently, this is used only for selecting the minimum rate
1714 * for management frames, rate selection for data frames remain
1717 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw,
1718 struct ieee80211_vif *vif,
1719 const struct cfg80211_bitrate_mask *mask)
1721 struct ath9k_htc_priv *priv = hw->priv;
1722 struct ath_common *common = ath9k_hw_common(priv->ah);
1723 struct ath9k_htc_target_rate_mask tmask;
1724 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1728 memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask));
1730 tmask.vif_index = avp->index;
1731 tmask.band = IEEE80211_BAND_2GHZ;
1732 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy);
1734 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1737 "Unable to set 2G rate mask for "
1738 "interface at idx: %d\n", avp->index);
1742 tmask.band = IEEE80211_BAND_5GHZ;
1743 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy);
1745 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1748 "Unable to set 5G rate mask for "
1749 "interface at idx: %d\n", avp->index);
1753 ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n",
1754 mask->control[IEEE80211_BAND_2GHZ].legacy,
1755 mask->control[IEEE80211_BAND_5GHZ].legacy);
1761 static int ath9k_htc_get_stats(struct ieee80211_hw *hw,
1762 struct ieee80211_low_level_stats *stats)
1764 struct ath9k_htc_priv *priv = hw->priv;
1765 struct ath_hw *ah = priv->ah;
1766 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1768 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1769 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1770 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1771 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1776 struct ieee80211_ops ath9k_htc_ops = {
1778 .start = ath9k_htc_start,
1779 .stop = ath9k_htc_stop,
1780 .add_interface = ath9k_htc_add_interface,
1781 .remove_interface = ath9k_htc_remove_interface,
1782 .config = ath9k_htc_config,
1783 .configure_filter = ath9k_htc_configure_filter,
1784 .sta_add = ath9k_htc_sta_add,
1785 .sta_remove = ath9k_htc_sta_remove,
1786 .conf_tx = ath9k_htc_conf_tx,
1787 .sta_rc_update = ath9k_htc_sta_rc_update,
1788 .bss_info_changed = ath9k_htc_bss_info_changed,
1789 .set_key = ath9k_htc_set_key,
1790 .get_tsf = ath9k_htc_get_tsf,
1791 .set_tsf = ath9k_htc_set_tsf,
1792 .reset_tsf = ath9k_htc_reset_tsf,
1793 .ampdu_action = ath9k_htc_ampdu_action,
1794 .sw_scan_start = ath9k_htc_sw_scan_start,
1795 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1796 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1797 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1798 .set_coverage_class = ath9k_htc_set_coverage_class,
1799 .set_bitrate_mask = ath9k_htc_set_bitrate_mask,
1800 .get_stats = ath9k_htc_get_stats,