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);
493 ista->index = sta_idx;
495 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
499 tsta.sta_index = sta_idx;
500 tsta.vif_index = avp->index;
503 tsta.maxampdu = cpu_to_be16(0xffff);
505 maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
506 sta->ht_cap.ampdu_factor);
507 tsta.maxampdu = cpu_to_be16(maxampdu);
510 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
514 "Unable to add station entry for: %pM\n",
520 ath_dbg(common, CONFIG,
521 "Added a station entry for: %pM (idx: %d)\n",
522 sta->addr, tsta.sta_index);
524 ath_dbg(common, CONFIG,
525 "Added a station entry for VIF %d (idx: %d)\n",
526 avp->index, tsta.sta_index);
529 priv->sta_slot |= (1 << sta_idx);
532 priv->vif_sta_pos[avp->index] = sta_idx;
537 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
538 struct ieee80211_vif *vif,
539 struct ieee80211_sta *sta)
541 struct ath_common *common = ath9k_hw_common(priv->ah);
542 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
543 struct ath9k_htc_sta *ista;
548 ista = (struct ath9k_htc_sta *) sta->drv_priv;
549 sta_idx = ista->index;
551 sta_idx = priv->vif_sta_pos[avp->index];
554 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
558 "Unable to remove station entry for: %pM\n",
564 ath_dbg(common, CONFIG,
565 "Removed a station entry for: %pM (idx: %d)\n",
568 ath_dbg(common, CONFIG,
569 "Removed a station entry for VIF %d (idx: %d)\n",
570 avp->index, sta_idx);
573 priv->sta_slot &= ~(1 << sta_idx);
579 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
582 struct ath9k_htc_cap_target tcap;
586 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
588 tcap.ampdu_limit = cpu_to_be32(0xffff);
589 tcap.ampdu_subframes = 0xff;
590 tcap.enable_coex = enable_coex;
591 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
593 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
598 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
599 struct ieee80211_sta *sta,
600 struct ath9k_htc_target_rate *trate)
602 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
603 struct ieee80211_supported_band *sband;
607 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
609 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
610 if (sta->supp_rates[sband->band] & BIT(i)) {
611 trate->rates.legacy_rates.rs_rates[j]
612 = (sband->bitrates[i].bitrate * 2) / 10;
616 trate->rates.legacy_rates.rs_nrates = j;
618 if (sta->ht_cap.ht_supported) {
619 for (i = 0, j = 0; i < 77; i++) {
620 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
621 trate->rates.ht_rates.rs_rates[j++] = i;
622 if (j == ATH_HTC_RATE_MAX)
625 trate->rates.ht_rates.rs_nrates = j;
627 caps = WLAN_RC_HT_FLAG;
628 if (sta->ht_cap.mcs.rx_mask[1])
629 caps |= WLAN_RC_DS_FLAG;
630 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
631 (conf_is_ht40(&priv->hw->conf)))
632 caps |= WLAN_RC_40_FLAG;
633 if (conf_is_ht40(&priv->hw->conf) &&
634 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
635 caps |= WLAN_RC_SGI_FLAG;
636 else if (conf_is_ht20(&priv->hw->conf) &&
637 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
638 caps |= WLAN_RC_SGI_FLAG;
641 trate->sta_index = ista->index;
643 trate->capflags = cpu_to_be32(caps);
646 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
647 struct ath9k_htc_target_rate *trate)
649 struct ath_common *common = ath9k_hw_common(priv->ah);
653 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
656 "Unable to initialize Rate information on target\n");
662 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
663 struct ieee80211_sta *sta)
665 struct ath_common *common = ath9k_hw_common(priv->ah);
666 struct ath9k_htc_target_rate trate;
669 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
670 ath9k_htc_setup_rate(priv, sta, &trate);
671 ret = ath9k_htc_send_rate_cmd(priv, &trate);
673 ath_dbg(common, CONFIG,
674 "Updated target sta: %pM, rate caps: 0x%X\n",
675 sta->addr, be32_to_cpu(trate.capflags));
678 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
679 struct ieee80211_vif *vif,
680 struct ieee80211_bss_conf *bss_conf)
682 struct ath_common *common = ath9k_hw_common(priv->ah);
683 struct ath9k_htc_target_rate trate;
684 struct ieee80211_sta *sta;
687 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
690 sta = ieee80211_find_sta(vif, bss_conf->bssid);
695 ath9k_htc_setup_rate(priv, sta, &trate);
698 ret = ath9k_htc_send_rate_cmd(priv, &trate);
700 ath_dbg(common, CONFIG,
701 "Updated target sta: %pM, rate caps: 0x%X\n",
702 bss_conf->bssid, be32_to_cpu(trate.capflags));
705 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
706 struct ieee80211_vif *vif,
707 struct ieee80211_sta *sta,
708 enum ieee80211_ampdu_mlme_action action,
711 struct ath_common *common = ath9k_hw_common(priv->ah);
712 struct ath9k_htc_target_aggr aggr;
713 struct ath9k_htc_sta *ista;
717 if (tid >= ATH9K_HTC_MAX_TID)
720 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
721 ista = (struct ath9k_htc_sta *) sta->drv_priv;
723 aggr.sta_index = ista->index;
724 aggr.tidno = tid & 0xf;
725 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
727 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
729 ath_dbg(common, CONFIG,
730 "Unable to %s TX aggregation for (%pM, %d)\n",
731 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
733 ath_dbg(common, CONFIG,
734 "%s TX aggregation for (%pM, %d)\n",
735 (aggr.aggr_enable) ? "Starting" : "Stopping",
738 spin_lock_bh(&priv->tx.tx_lock);
739 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
740 spin_unlock_bh(&priv->tx.tx_lock);
749 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
751 struct ath_common *common = ath9k_hw_common(priv->ah);
752 unsigned long timestamp = jiffies_to_msecs(jiffies);
754 common->ani.longcal_timer = timestamp;
755 common->ani.shortcal_timer = timestamp;
756 common->ani.checkani_timer = timestamp;
758 set_bit(OP_ANI_RUNNING, &priv->op_flags);
760 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
761 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
764 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
766 cancel_delayed_work_sync(&priv->ani_work);
767 clear_bit(OP_ANI_RUNNING, &priv->op_flags);
770 void ath9k_htc_ani_work(struct work_struct *work)
772 struct ath9k_htc_priv *priv =
773 container_of(work, struct ath9k_htc_priv, ani_work.work);
774 struct ath_hw *ah = priv->ah;
775 struct ath_common *common = ath9k_hw_common(ah);
776 bool longcal = false;
777 bool shortcal = false;
778 bool aniflag = false;
779 unsigned int timestamp = jiffies_to_msecs(jiffies);
780 u32 cal_interval, short_cal_interval;
782 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
783 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
785 /* Only calibrate if awake */
786 if (ah->power_mode != ATH9K_PM_AWAKE)
789 /* Long calibration runs independently of short calibration. */
790 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
792 ath_dbg(common, ANI, "longcal @%lu\n", jiffies);
793 common->ani.longcal_timer = timestamp;
796 /* Short calibration applies only while caldone is false */
797 if (!common->ani.caldone) {
798 if ((timestamp - common->ani.shortcal_timer) >=
799 short_cal_interval) {
801 ath_dbg(common, ANI, "shortcal @%lu\n", jiffies);
802 common->ani.shortcal_timer = timestamp;
803 common->ani.resetcal_timer = timestamp;
806 if ((timestamp - common->ani.resetcal_timer) >=
807 ATH_RESTART_CALINTERVAL) {
808 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
809 if (common->ani.caldone)
810 common->ani.resetcal_timer = timestamp;
814 /* Verify whether we must check ANI */
815 if (ah->config.enable_ani &&
816 (timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
818 common->ani.checkani_timer = timestamp;
821 /* Skip all processing if there's nothing to do. */
822 if (longcal || shortcal || aniflag) {
824 ath9k_htc_ps_wakeup(priv);
826 /* Call ANI routine if necessary */
828 ath9k_hw_ani_monitor(ah, ah->curchan);
830 /* Perform calibration if necessary */
831 if (longcal || shortcal)
832 common->ani.caldone =
833 ath9k_hw_calibrate(ah, ah->curchan,
834 ah->rxchainmask, longcal);
836 ath9k_htc_ps_restore(priv);
841 * Set timer interval based on previous results.
842 * The interval must be the shortest necessary to satisfy ANI,
843 * short calibration and long calibration.
845 cal_interval = ATH_LONG_CALINTERVAL;
846 if (ah->config.enable_ani)
847 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
848 if (!common->ani.caldone)
849 cal_interval = min(cal_interval, (u32)short_cal_interval);
851 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
852 msecs_to_jiffies(cal_interval));
855 /**********************/
856 /* mac80211 Callbacks */
857 /**********************/
859 static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
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, 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 if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1042 mutex_unlock(&priv->mutex);
1046 if (priv->num_ibss_vif ||
1047 (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
1048 ath_err(common, "IBSS coexistence with other modes is not allowed\n");
1049 mutex_unlock(&priv->mutex);
1053 if (((vif->type == NL80211_IFTYPE_AP) ||
1054 (vif->type == NL80211_IFTYPE_ADHOC)) &&
1055 ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) {
1056 ath_err(common, "Max. number of beaconing interfaces reached\n");
1057 mutex_unlock(&priv->mutex);
1061 ath9k_htc_ps_wakeup(priv);
1062 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1063 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1065 switch (vif->type) {
1066 case NL80211_IFTYPE_STATION:
1067 hvif.opmode = HTC_M_STA;
1069 case NL80211_IFTYPE_ADHOC:
1070 hvif.opmode = HTC_M_IBSS;
1072 case NL80211_IFTYPE_AP:
1073 hvif.opmode = HTC_M_HOSTAP;
1077 "Interface type %d not yet supported\n", vif->type);
1082 /* Index starts from zero on the target */
1083 avp->index = hvif.index = ffz(priv->vif_slot);
1084 hvif.rtsthreshold = cpu_to_be16(2304);
1085 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1090 * We need a node in target to tx mgmt frames
1091 * before association.
1093 ret = ath9k_htc_add_station(priv, vif, NULL);
1095 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1099 ath9k_htc_set_bssid_mask(priv, vif);
1101 priv->vif_slot |= (1 << avp->index);
1104 INC_VIF(priv, vif->type);
1106 if ((vif->type == NL80211_IFTYPE_AP) ||
1107 (vif->type == NL80211_IFTYPE_ADHOC))
1108 ath9k_htc_assign_bslot(priv, vif);
1110 ath9k_htc_set_opmode(priv);
1112 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1113 !test_bit(OP_ANI_RUNNING, &priv->op_flags)) {
1114 ath9k_hw_set_tsfadjust(priv->ah, true);
1115 ath9k_htc_start_ani(priv);
1118 ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n",
1119 vif->type, avp->index);
1122 ath9k_htc_ps_restore(priv);
1123 mutex_unlock(&priv->mutex);
1128 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1129 struct ieee80211_vif *vif)
1131 struct ath9k_htc_priv *priv = hw->priv;
1132 struct ath_common *common = ath9k_hw_common(priv->ah);
1133 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1134 struct ath9k_htc_target_vif hvif;
1138 mutex_lock(&priv->mutex);
1139 ath9k_htc_ps_wakeup(priv);
1141 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1142 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1143 hvif.index = avp->index;
1144 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1146 ath_err(common, "Unable to remove interface at idx: %d\n",
1150 priv->vif_slot &= ~(1 << avp->index);
1152 ath9k_htc_remove_station(priv, vif, NULL);
1154 DEC_VIF(priv, vif->type);
1156 if ((vif->type == NL80211_IFTYPE_AP) ||
1157 (vif->type == NL80211_IFTYPE_ADHOC))
1158 ath9k_htc_remove_bslot(priv, vif);
1160 ath9k_htc_set_opmode(priv);
1162 ath9k_htc_set_bssid_mask(priv, vif);
1165 * Stop ANI only if there are no associated station interfaces.
1167 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1168 priv->rearm_ani = false;
1169 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1170 ath9k_htc_vif_iter, priv);
1171 if (!priv->rearm_ani)
1172 ath9k_htc_stop_ani(priv);
1175 ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index);
1177 ath9k_htc_ps_restore(priv);
1178 mutex_unlock(&priv->mutex);
1181 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1183 struct ath9k_htc_priv *priv = hw->priv;
1184 struct ath_common *common = ath9k_hw_common(priv->ah);
1185 struct ieee80211_conf *conf = &hw->conf;
1186 bool chip_reset = false;
1189 mutex_lock(&priv->mutex);
1190 ath9k_htc_ps_wakeup(priv);
1192 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1193 mutex_lock(&priv->htc_pm_lock);
1195 priv->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1199 mutex_unlock(&priv->htc_pm_lock);
1203 * Monitor interface should be added before
1204 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1206 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1207 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1208 !priv->ah->is_monitoring)
1209 ath9k_htc_add_monitor_interface(priv);
1210 else if (priv->ah->is_monitoring)
1211 ath9k_htc_remove_monitor_interface(priv);
1214 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
1215 struct ieee80211_channel *curchan = hw->conf.channel;
1216 int pos = curchan->hw_value;
1218 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
1219 curchan->center_freq);
1221 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1223 hw->conf.channel_type);
1225 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1226 ath_err(common, "Unable to set channel\n");
1233 if (changed & IEEE80211_CONF_CHANGE_PS) {
1234 if (conf->flags & IEEE80211_CONF_PS) {
1235 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1236 priv->ps_enabled = true;
1238 priv->ps_enabled = false;
1239 cancel_work_sync(&priv->ps_work);
1240 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1244 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1245 priv->txpowlimit = 2 * conf->power_level;
1246 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1247 priv->txpowlimit, &priv->curtxpow);
1251 ath9k_htc_ps_restore(priv);
1252 mutex_unlock(&priv->mutex);
1256 #define SUPPORTED_FILTERS \
1257 (FIF_PROMISC_IN_BSS | \
1262 FIF_BCN_PRBRESP_PROMISC | \
1266 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1267 unsigned int changed_flags,
1268 unsigned int *total_flags,
1271 struct ath9k_htc_priv *priv = hw->priv;
1274 mutex_lock(&priv->mutex);
1275 changed_flags &= SUPPORTED_FILTERS;
1276 *total_flags &= SUPPORTED_FILTERS;
1278 if (test_bit(OP_INVALID, &priv->op_flags)) {
1279 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1280 "Unable to configure filter on invalid state\n");
1281 mutex_unlock(&priv->mutex);
1284 ath9k_htc_ps_wakeup(priv);
1286 priv->rxfilter = *total_flags;
1287 rfilt = ath9k_htc_calcrxfilter(priv);
1288 ath9k_hw_setrxfilter(priv->ah, rfilt);
1290 ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n",
1293 ath9k_htc_ps_restore(priv);
1294 mutex_unlock(&priv->mutex);
1297 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1298 struct ieee80211_vif *vif,
1299 struct ieee80211_sta *sta)
1301 struct ath9k_htc_priv *priv = hw->priv;
1304 mutex_lock(&priv->mutex);
1305 ath9k_htc_ps_wakeup(priv);
1306 ret = ath9k_htc_add_station(priv, vif, sta);
1308 ath9k_htc_init_rate(priv, sta);
1309 ath9k_htc_ps_restore(priv);
1310 mutex_unlock(&priv->mutex);
1315 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1316 struct ieee80211_vif *vif,
1317 struct ieee80211_sta *sta)
1319 struct ath9k_htc_priv *priv = hw->priv;
1320 struct ath9k_htc_sta *ista;
1323 mutex_lock(&priv->mutex);
1324 ath9k_htc_ps_wakeup(priv);
1325 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1326 htc_sta_drain(priv->htc, ista->index);
1327 ret = ath9k_htc_remove_station(priv, vif, sta);
1328 ath9k_htc_ps_restore(priv);
1329 mutex_unlock(&priv->mutex);
1334 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
1335 struct ieee80211_vif *vif, u16 queue,
1336 const struct ieee80211_tx_queue_params *params)
1338 struct ath9k_htc_priv *priv = hw->priv;
1339 struct ath_common *common = ath9k_hw_common(priv->ah);
1340 struct ath9k_tx_queue_info qi;
1343 if (queue >= WME_NUM_AC)
1346 mutex_lock(&priv->mutex);
1347 ath9k_htc_ps_wakeup(priv);
1349 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1351 qi.tqi_aifs = params->aifs;
1352 qi.tqi_cwmin = params->cw_min;
1353 qi.tqi_cwmax = params->cw_max;
1354 qi.tqi_burstTime = params->txop * 32;
1356 qnum = get_hw_qnum(queue, priv->hwq_map);
1358 ath_dbg(common, CONFIG,
1359 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1360 queue, qnum, params->aifs, params->cw_min,
1361 params->cw_max, params->txop);
1363 ret = ath_htc_txq_update(priv, qnum, &qi);
1365 ath_err(common, "TXQ Update failed\n");
1369 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1370 (qnum == priv->hwq_map[WME_AC_BE]))
1371 ath9k_htc_beaconq_config(priv);
1373 ath9k_htc_ps_restore(priv);
1374 mutex_unlock(&priv->mutex);
1379 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1380 enum set_key_cmd cmd,
1381 struct ieee80211_vif *vif,
1382 struct ieee80211_sta *sta,
1383 struct ieee80211_key_conf *key)
1385 struct ath9k_htc_priv *priv = hw->priv;
1386 struct ath_common *common = ath9k_hw_common(priv->ah);
1389 if (htc_modparam_nohwcrypt)
1392 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1393 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1394 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1395 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1396 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1398 * For now, disable hw crypto for the RSN IBSS group keys. This
1399 * could be optimized in the future to use a modified key cache
1400 * design to support per-STA RX GTK, but until that gets
1401 * implemented, use of software crypto for group addressed
1402 * frames is a acceptable to allow RSN IBSS to be used.
1407 mutex_lock(&priv->mutex);
1408 ath_dbg(common, CONFIG, "Set HW Key\n");
1409 ath9k_htc_ps_wakeup(priv);
1413 ret = ath_key_config(common, vif, sta, key);
1415 key->hw_key_idx = ret;
1416 /* push IV and Michael MIC generation to stack */
1417 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1418 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1419 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1420 if (priv->ah->sw_mgmt_crypto &&
1421 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1422 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1427 ath_key_delete(common, key);
1433 ath9k_htc_ps_restore(priv);
1434 mutex_unlock(&priv->mutex);
1439 static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv)
1441 struct ath_common *common = ath9k_hw_common(priv->ah);
1443 ath9k_hw_write_associd(priv->ah);
1444 ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
1445 common->curbssid, common->curaid);
1448 static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1450 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1451 struct ath_common *common = ath9k_hw_common(priv->ah);
1452 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1454 if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) {
1455 common->curaid = bss_conf->aid;
1456 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1460 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv)
1462 if (priv->num_sta_assoc_vif == 1) {
1463 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1464 ath9k_htc_bss_iter, priv);
1465 ath9k_htc_set_bssid(priv);
1469 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1470 struct ieee80211_vif *vif,
1471 struct ieee80211_bss_conf *bss_conf,
1474 struct ath9k_htc_priv *priv = hw->priv;
1475 struct ath_hw *ah = priv->ah;
1476 struct ath_common *common = ath9k_hw_common(ah);
1478 mutex_lock(&priv->mutex);
1479 ath9k_htc_ps_wakeup(priv);
1481 if (changed & BSS_CHANGED_ASSOC) {
1482 ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n",
1486 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1488 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1489 ath9k_htc_choose_set_bssid(priv);
1490 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
1491 ath9k_htc_start_ani(priv);
1492 else if (priv->num_sta_assoc_vif == 0)
1493 ath9k_htc_stop_ani(priv);
1497 if (changed & BSS_CHANGED_IBSS) {
1498 if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
1499 common->curaid = bss_conf->aid;
1500 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1501 ath9k_htc_set_bssid(priv);
1505 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1506 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1508 ath9k_htc_set_tsfadjust(priv, vif);
1509 set_bit(OP_ENABLE_BEACON, &priv->op_flags);
1510 ath9k_htc_beacon_config(priv, vif);
1513 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1515 * Disable SWBA interrupt only if there are no
1516 * AP/IBSS interfaces.
1518 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1519 ath_dbg(common, CONFIG,
1520 "Beacon disabled for BSS: %pM\n",
1522 clear_bit(OP_ENABLE_BEACON, &priv->op_flags);
1523 ath9k_htc_beacon_config(priv, vif);
1527 if (changed & BSS_CHANGED_BEACON_INT) {
1529 * Reset the HW TSF for the first AP interface.
1531 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1532 (priv->nvifs == 1) &&
1533 (priv->num_ap_vif == 1) &&
1534 (vif->type == NL80211_IFTYPE_AP)) {
1535 set_bit(OP_TSF_RESET, &priv->op_flags);
1537 ath_dbg(common, CONFIG,
1538 "Beacon interval changed for BSS: %pM\n",
1540 ath9k_htc_beacon_config(priv, vif);
1543 if (changed & BSS_CHANGED_ERP_SLOT) {
1544 if (bss_conf->use_short_slot)
1549 ath9k_hw_init_global_settings(ah);
1552 if (changed & BSS_CHANGED_HT)
1553 ath9k_htc_update_rate(priv, vif, bss_conf);
1555 ath9k_htc_ps_restore(priv);
1556 mutex_unlock(&priv->mutex);
1559 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw,
1560 struct ieee80211_vif *vif)
1562 struct ath9k_htc_priv *priv = hw->priv;
1565 mutex_lock(&priv->mutex);
1566 ath9k_htc_ps_wakeup(priv);
1567 tsf = ath9k_hw_gettsf64(priv->ah);
1568 ath9k_htc_ps_restore(priv);
1569 mutex_unlock(&priv->mutex);
1574 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw,
1575 struct ieee80211_vif *vif, u64 tsf)
1577 struct ath9k_htc_priv *priv = hw->priv;
1579 mutex_lock(&priv->mutex);
1580 ath9k_htc_ps_wakeup(priv);
1581 ath9k_hw_settsf64(priv->ah, tsf);
1582 ath9k_htc_ps_restore(priv);
1583 mutex_unlock(&priv->mutex);
1586 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw,
1587 struct ieee80211_vif *vif)
1589 struct ath9k_htc_priv *priv = hw->priv;
1591 mutex_lock(&priv->mutex);
1592 ath9k_htc_ps_wakeup(priv);
1593 ath9k_hw_reset_tsf(priv->ah);
1594 ath9k_htc_ps_restore(priv);
1595 mutex_unlock(&priv->mutex);
1598 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1599 struct ieee80211_vif *vif,
1600 enum ieee80211_ampdu_mlme_action action,
1601 struct ieee80211_sta *sta,
1602 u16 tid, u16 *ssn, u8 buf_size)
1604 struct ath9k_htc_priv *priv = hw->priv;
1605 struct ath9k_htc_sta *ista;
1608 mutex_lock(&priv->mutex);
1609 ath9k_htc_ps_wakeup(priv);
1612 case IEEE80211_AMPDU_RX_START:
1614 case IEEE80211_AMPDU_RX_STOP:
1616 case IEEE80211_AMPDU_TX_START:
1617 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1619 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1621 case IEEE80211_AMPDU_TX_STOP:
1622 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1623 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1625 case IEEE80211_AMPDU_TX_OPERATIONAL:
1626 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1627 spin_lock_bh(&priv->tx.tx_lock);
1628 ista->tid_state[tid] = AGGR_OPERATIONAL;
1629 spin_unlock_bh(&priv->tx.tx_lock);
1632 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1635 ath9k_htc_ps_restore(priv);
1636 mutex_unlock(&priv->mutex);
1641 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1643 struct ath9k_htc_priv *priv = hw->priv;
1645 mutex_lock(&priv->mutex);
1646 spin_lock_bh(&priv->beacon_lock);
1647 set_bit(OP_SCANNING, &priv->op_flags);
1648 spin_unlock_bh(&priv->beacon_lock);
1649 cancel_work_sync(&priv->ps_work);
1650 ath9k_htc_stop_ani(priv);
1651 mutex_unlock(&priv->mutex);
1654 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1656 struct ath9k_htc_priv *priv = hw->priv;
1658 mutex_lock(&priv->mutex);
1659 spin_lock_bh(&priv->beacon_lock);
1660 clear_bit(OP_SCANNING, &priv->op_flags);
1661 spin_unlock_bh(&priv->beacon_lock);
1662 ath9k_htc_ps_wakeup(priv);
1663 ath9k_htc_vif_reconfig(priv);
1664 ath9k_htc_ps_restore(priv);
1665 mutex_unlock(&priv->mutex);
1668 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1673 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1676 struct ath9k_htc_priv *priv = hw->priv;
1678 mutex_lock(&priv->mutex);
1679 ath9k_htc_ps_wakeup(priv);
1680 priv->ah->coverage_class = coverage_class;
1681 ath9k_hw_init_global_settings(priv->ah);
1682 ath9k_htc_ps_restore(priv);
1683 mutex_unlock(&priv->mutex);
1687 * Currently, this is used only for selecting the minimum rate
1688 * for management frames, rate selection for data frames remain
1691 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw,
1692 struct ieee80211_vif *vif,
1693 const struct cfg80211_bitrate_mask *mask)
1695 struct ath9k_htc_priv *priv = hw->priv;
1696 struct ath_common *common = ath9k_hw_common(priv->ah);
1697 struct ath9k_htc_target_rate_mask tmask;
1698 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1702 memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask));
1704 tmask.vif_index = avp->index;
1705 tmask.band = IEEE80211_BAND_2GHZ;
1706 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy);
1708 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1711 "Unable to set 2G rate mask for "
1712 "interface at idx: %d\n", avp->index);
1716 tmask.band = IEEE80211_BAND_5GHZ;
1717 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy);
1719 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1722 "Unable to set 5G rate mask for "
1723 "interface at idx: %d\n", avp->index);
1727 ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n",
1728 mask->control[IEEE80211_BAND_2GHZ].legacy,
1729 mask->control[IEEE80211_BAND_5GHZ].legacy);
1735 static int ath9k_htc_get_stats(struct ieee80211_hw *hw,
1736 struct ieee80211_low_level_stats *stats)
1738 struct ath9k_htc_priv *priv = hw->priv;
1739 struct ath_hw *ah = priv->ah;
1740 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1742 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1743 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1744 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1745 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1750 struct ieee80211_ops ath9k_htc_ops = {
1752 .start = ath9k_htc_start,
1753 .stop = ath9k_htc_stop,
1754 .add_interface = ath9k_htc_add_interface,
1755 .remove_interface = ath9k_htc_remove_interface,
1756 .config = ath9k_htc_config,
1757 .configure_filter = ath9k_htc_configure_filter,
1758 .sta_add = ath9k_htc_sta_add,
1759 .sta_remove = ath9k_htc_sta_remove,
1760 .conf_tx = ath9k_htc_conf_tx,
1761 .bss_info_changed = ath9k_htc_bss_info_changed,
1762 .set_key = ath9k_htc_set_key,
1763 .get_tsf = ath9k_htc_get_tsf,
1764 .set_tsf = ath9k_htc_set_tsf,
1765 .reset_tsf = ath9k_htc_reset_tsf,
1766 .ampdu_action = ath9k_htc_ampdu_action,
1767 .sw_scan_start = ath9k_htc_sw_scan_start,
1768 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1769 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1770 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1771 .set_coverage_class = ath9k_htc_set_coverage_class,
1772 .set_bitrate_mask = ath9k_htc_set_bitrate_mask,
1773 .get_stats = ath9k_htc_get_stats,