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 if (iter_data->hw_macaddr != NULL) {
149 for (i = 0; i < ETH_ALEN; i++)
150 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
152 iter_data->hw_macaddr = mac;
156 static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
157 struct ieee80211_vif *vif)
159 struct ath_common *common = ath9k_hw_common(priv->ah);
160 struct ath9k_vif_iter_data iter_data;
163 * Pick the MAC address of the first interface as the new hardware
164 * MAC address. The hardware will use it together with the BSSID mask
165 * when matching addresses.
167 iter_data.hw_macaddr = NULL;
168 memset(&iter_data.mask, 0xff, ETH_ALEN);
171 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
173 /* Get list of all active MAC addresses */
174 ieee80211_iterate_active_interfaces_atomic(
175 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
176 ath9k_htc_bssid_iter, &iter_data);
178 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
180 if (iter_data.hw_macaddr)
181 memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
183 ath_hw_setbssidmask(common);
186 static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv)
188 if (priv->num_ibss_vif)
189 priv->ah->opmode = NL80211_IFTYPE_ADHOC;
190 else if (priv->num_ap_vif)
191 priv->ah->opmode = NL80211_IFTYPE_AP;
193 priv->ah->opmode = NL80211_IFTYPE_STATION;
195 ath9k_hw_setopmode(priv->ah);
198 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
200 struct ath_hw *ah = priv->ah;
201 struct ath_common *common = ath9k_hw_common(ah);
202 struct ieee80211_channel *channel = priv->hw->conf.chandef.chan;
203 struct ath9k_hw_cal_data *caldata = NULL;
204 enum htc_phymode mode;
209 mutex_lock(&priv->mutex);
210 ath9k_htc_ps_wakeup(priv);
212 ath9k_htc_stop_ani(priv);
213 ieee80211_stop_queues(priv->hw);
215 del_timer_sync(&priv->tx.cleanup_timer);
216 ath9k_htc_tx_drain(priv);
218 WMI_CMD(WMI_DISABLE_INTR_CMDID);
219 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
220 WMI_CMD(WMI_STOP_RECV_CMDID);
222 ath9k_wmi_event_drain(priv);
224 caldata = &priv->caldata;
225 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
228 "Unable to reset device (%u Mhz) reset status %d\n",
229 channel->center_freq, ret);
232 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
235 WMI_CMD(WMI_START_RECV_CMDID);
236 ath9k_host_rx_init(priv);
238 mode = ath9k_htc_get_curmode(priv, ah->curchan);
239 htc_mode = cpu_to_be16(mode);
240 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
242 WMI_CMD(WMI_ENABLE_INTR_CMDID);
243 htc_start(priv->htc);
244 ath9k_htc_vif_reconfig(priv);
245 ieee80211_wake_queues(priv->hw);
247 mod_timer(&priv->tx.cleanup_timer,
248 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
250 ath9k_htc_ps_restore(priv);
251 mutex_unlock(&priv->mutex);
254 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
255 struct ieee80211_hw *hw,
256 struct ath9k_channel *hchan)
258 struct ath_hw *ah = priv->ah;
259 struct ath_common *common = ath9k_hw_common(ah);
260 struct ieee80211_conf *conf = &common->hw->conf;
262 struct ieee80211_channel *channel = hw->conf.chandef.chan;
263 struct ath9k_hw_cal_data *caldata = NULL;
264 enum htc_phymode mode;
269 if (test_bit(OP_INVALID, &priv->op_flags))
272 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
274 ath9k_htc_ps_wakeup(priv);
276 del_timer_sync(&priv->tx.cleanup_timer);
277 ath9k_htc_tx_drain(priv);
279 WMI_CMD(WMI_DISABLE_INTR_CMDID);
280 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
281 WMI_CMD(WMI_STOP_RECV_CMDID);
283 ath9k_wmi_event_drain(priv);
285 ath_dbg(common, CONFIG,
286 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
287 priv->ah->curchan->channel,
288 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
292 caldata = &priv->caldata;
294 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
297 "Unable to reset channel (%u Mhz) reset status %d\n",
298 channel->center_freq, ret);
302 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
305 WMI_CMD(WMI_START_RECV_CMDID);
309 ath9k_host_rx_init(priv);
311 mode = ath9k_htc_get_curmode(priv, hchan);
312 htc_mode = cpu_to_be16(mode);
313 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
317 WMI_CMD(WMI_ENABLE_INTR_CMDID);
321 htc_start(priv->htc);
323 if (!test_bit(OP_SCANNING, &priv->op_flags) &&
324 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
325 ath9k_htc_vif_reconfig(priv);
327 mod_timer(&priv->tx.cleanup_timer,
328 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
331 ath9k_htc_ps_restore(priv);
336 * Monitor mode handling is a tad complicated because the firmware requires
337 * an interface to be created exclusively, while mac80211 doesn't associate
338 * an interface with the mode.
340 * So, for now, only one monitor interface can be configured.
342 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
344 struct ath_common *common = ath9k_hw_common(priv->ah);
345 struct ath9k_htc_target_vif hvif;
349 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
350 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
351 hvif.index = priv->mon_vif_idx;
352 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
354 ath_err(common, "Unable to remove monitor interface at idx: %d\n",
359 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
362 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
364 struct ath_common *common = ath9k_hw_common(priv->ah);
365 struct ath9k_htc_target_vif hvif;
366 struct ath9k_htc_target_sta tsta;
367 int ret = 0, sta_idx;
370 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
371 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
376 sta_idx = ffz(priv->sta_slot);
377 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
385 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
386 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
388 hvif.opmode = HTC_M_MONITOR;
389 hvif.index = ffz(priv->vif_slot);
391 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
396 * Assign the monitor interface index as a special case here.
397 * This is needed when the interface is brought down.
399 priv->mon_vif_idx = hvif.index;
400 priv->vif_slot |= (1 << hvif.index);
403 * Set the hardware mode to monitor only if there are no
407 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
412 * Associate a station with the interface for packet injection.
414 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
416 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
419 tsta.sta_index = sta_idx;
420 tsta.vif_index = hvif.index;
421 tsta.maxampdu = cpu_to_be16(0xffff);
423 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
425 ath_err(common, "Unable to add station entry for monitor mode\n");
429 priv->sta_slot |= (1 << sta_idx);
431 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
432 priv->ah->is_monitoring = true;
434 ath_dbg(common, CONFIG,
435 "Attached a monitor interface at idx: %d, sta idx: %d\n",
436 priv->mon_vif_idx, sta_idx);
442 * Remove the interface from the target.
444 __ath9k_htc_remove_monitor_interface(priv);
446 ath_dbg(common, FATAL, "Unable to attach a monitor interface\n");
451 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
453 struct ath_common *common = ath9k_hw_common(priv->ah);
457 __ath9k_htc_remove_monitor_interface(priv);
459 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
461 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
463 ath_err(common, "Unable to remove station entry for monitor mode\n");
467 priv->sta_slot &= ~(1 << sta_idx);
469 priv->ah->is_monitoring = false;
471 ath_dbg(common, CONFIG,
472 "Removed a monitor interface at idx: %d, sta idx: %d\n",
473 priv->mon_vif_idx, sta_idx);
478 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
479 struct ieee80211_vif *vif,
480 struct ieee80211_sta *sta)
482 struct ath_common *common = ath9k_hw_common(priv->ah);
483 struct ath9k_htc_target_sta tsta;
484 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
485 struct ath9k_htc_sta *ista;
490 if (priv->nstations >= ATH9K_HTC_MAX_STA)
493 sta_idx = ffz(priv->sta_slot);
494 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
497 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
500 ista = (struct ath9k_htc_sta *) sta->drv_priv;
501 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
502 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
503 ista->index = sta_idx;
505 maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
506 sta->ht_cap.ampdu_factor);
507 tsta.maxampdu = cpu_to_be16(maxampdu);
509 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
511 tsta.maxampdu = cpu_to_be16(0xffff);
514 tsta.sta_index = sta_idx;
515 tsta.vif_index = avp->index;
517 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
521 "Unable to add station entry for: %pM\n",
527 ath_dbg(common, CONFIG,
528 "Added a station entry for: %pM (idx: %d)\n",
529 sta->addr, tsta.sta_index);
531 ath_dbg(common, CONFIG,
532 "Added a station entry for VIF %d (idx: %d)\n",
533 avp->index, tsta.sta_index);
536 priv->sta_slot |= (1 << sta_idx);
539 priv->vif_sta_pos[avp->index] = sta_idx;
544 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
545 struct ieee80211_vif *vif,
546 struct ieee80211_sta *sta)
548 struct ath_common *common = ath9k_hw_common(priv->ah);
549 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
550 struct ath9k_htc_sta *ista;
555 ista = (struct ath9k_htc_sta *) sta->drv_priv;
556 sta_idx = ista->index;
558 sta_idx = priv->vif_sta_pos[avp->index];
561 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
565 "Unable to remove station entry for: %pM\n",
571 ath_dbg(common, CONFIG,
572 "Removed a station entry for: %pM (idx: %d)\n",
575 ath_dbg(common, CONFIG,
576 "Removed a station entry for VIF %d (idx: %d)\n",
577 avp->index, sta_idx);
580 priv->sta_slot &= ~(1 << sta_idx);
586 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
589 struct ath9k_htc_cap_target tcap;
593 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
595 tcap.ampdu_limit = cpu_to_be32(0xffff);
596 tcap.ampdu_subframes = 0xff;
597 tcap.enable_coex = enable_coex;
598 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
600 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
605 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
606 struct ieee80211_sta *sta,
607 struct ath9k_htc_target_rate *trate)
609 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
610 struct ieee80211_supported_band *sband;
614 sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band];
616 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
617 if (sta->supp_rates[sband->band] & BIT(i)) {
618 trate->rates.legacy_rates.rs_rates[j]
619 = (sband->bitrates[i].bitrate * 2) / 10;
623 trate->rates.legacy_rates.rs_nrates = j;
625 if (sta->ht_cap.ht_supported) {
626 for (i = 0, j = 0; i < 77; i++) {
627 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
628 trate->rates.ht_rates.rs_rates[j++] = i;
629 if (j == ATH_HTC_RATE_MAX)
632 trate->rates.ht_rates.rs_nrates = j;
634 caps = WLAN_RC_HT_FLAG;
635 if (sta->ht_cap.mcs.rx_mask[1])
636 caps |= WLAN_RC_DS_FLAG;
637 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
638 (conf_is_ht40(&priv->hw->conf)))
639 caps |= WLAN_RC_40_FLAG;
640 if (conf_is_ht40(&priv->hw->conf) &&
641 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
642 caps |= WLAN_RC_SGI_FLAG;
643 else if (conf_is_ht20(&priv->hw->conf) &&
644 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
645 caps |= WLAN_RC_SGI_FLAG;
648 trate->sta_index = ista->index;
650 trate->capflags = cpu_to_be32(caps);
653 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
654 struct ath9k_htc_target_rate *trate)
656 struct ath_common *common = ath9k_hw_common(priv->ah);
660 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
663 "Unable to initialize Rate information on target\n");
669 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
670 struct ieee80211_sta *sta)
672 struct ath_common *common = ath9k_hw_common(priv->ah);
673 struct ath9k_htc_target_rate trate;
676 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
677 ath9k_htc_setup_rate(priv, sta, &trate);
678 ret = ath9k_htc_send_rate_cmd(priv, &trate);
680 ath_dbg(common, CONFIG,
681 "Updated target sta: %pM, rate caps: 0x%X\n",
682 sta->addr, be32_to_cpu(trate.capflags));
685 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
686 struct ieee80211_vif *vif,
687 struct ieee80211_bss_conf *bss_conf)
689 struct ath_common *common = ath9k_hw_common(priv->ah);
690 struct ath9k_htc_target_rate trate;
691 struct ieee80211_sta *sta;
694 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
697 sta = ieee80211_find_sta(vif, bss_conf->bssid);
702 ath9k_htc_setup_rate(priv, sta, &trate);
705 ret = ath9k_htc_send_rate_cmd(priv, &trate);
707 ath_dbg(common, CONFIG,
708 "Updated target sta: %pM, rate caps: 0x%X\n",
709 bss_conf->bssid, be32_to_cpu(trate.capflags));
712 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
713 struct ieee80211_vif *vif,
714 struct ieee80211_sta *sta,
715 enum ieee80211_ampdu_mlme_action action,
718 struct ath_common *common = ath9k_hw_common(priv->ah);
719 struct ath9k_htc_target_aggr aggr;
720 struct ath9k_htc_sta *ista;
724 if (tid >= ATH9K_HTC_MAX_TID)
727 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
728 ista = (struct ath9k_htc_sta *) sta->drv_priv;
730 aggr.sta_index = ista->index;
731 aggr.tidno = tid & 0xf;
732 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
734 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
736 ath_dbg(common, CONFIG,
737 "Unable to %s TX aggregation for (%pM, %d)\n",
738 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
740 ath_dbg(common, CONFIG,
741 "%s TX aggregation for (%pM, %d)\n",
742 (aggr.aggr_enable) ? "Starting" : "Stopping",
745 spin_lock_bh(&priv->tx.tx_lock);
746 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
747 spin_unlock_bh(&priv->tx.tx_lock);
756 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
758 struct ath_common *common = ath9k_hw_common(priv->ah);
759 unsigned long timestamp = jiffies_to_msecs(jiffies);
761 common->ani.longcal_timer = timestamp;
762 common->ani.shortcal_timer = timestamp;
763 common->ani.checkani_timer = timestamp;
765 set_bit(OP_ANI_RUNNING, &priv->op_flags);
767 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
768 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
771 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
773 cancel_delayed_work_sync(&priv->ani_work);
774 clear_bit(OP_ANI_RUNNING, &priv->op_flags);
777 void ath9k_htc_ani_work(struct work_struct *work)
779 struct ath9k_htc_priv *priv =
780 container_of(work, struct ath9k_htc_priv, ani_work.work);
781 struct ath_hw *ah = priv->ah;
782 struct ath_common *common = ath9k_hw_common(ah);
783 bool longcal = false;
784 bool shortcal = false;
785 bool aniflag = false;
786 unsigned int timestamp = jiffies_to_msecs(jiffies);
787 u32 cal_interval, short_cal_interval;
789 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
790 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
792 /* Only calibrate if awake */
793 if (ah->power_mode != ATH9K_PM_AWAKE)
796 /* Long calibration runs independently of short calibration. */
797 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
799 ath_dbg(common, ANI, "longcal @%lu\n", jiffies);
800 common->ani.longcal_timer = timestamp;
803 /* Short calibration applies only while caldone is false */
804 if (!common->ani.caldone) {
805 if ((timestamp - common->ani.shortcal_timer) >=
806 short_cal_interval) {
808 ath_dbg(common, ANI, "shortcal @%lu\n", jiffies);
809 common->ani.shortcal_timer = timestamp;
810 common->ani.resetcal_timer = timestamp;
813 if ((timestamp - common->ani.resetcal_timer) >=
814 ATH_RESTART_CALINTERVAL) {
815 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
816 if (common->ani.caldone)
817 common->ani.resetcal_timer = timestamp;
821 /* Verify whether we must check ANI */
822 if (ah->config.enable_ani &&
823 (timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
825 common->ani.checkani_timer = timestamp;
828 /* Skip all processing if there's nothing to do. */
829 if (longcal || shortcal || aniflag) {
831 ath9k_htc_ps_wakeup(priv);
833 /* Call ANI routine if necessary */
835 ath9k_hw_ani_monitor(ah, ah->curchan);
837 /* Perform calibration if necessary */
838 if (longcal || shortcal)
839 common->ani.caldone =
840 ath9k_hw_calibrate(ah, ah->curchan,
841 ah->rxchainmask, longcal);
843 ath9k_htc_ps_restore(priv);
848 * Set timer interval based on previous results.
849 * The interval must be the shortest necessary to satisfy ANI,
850 * short calibration and long calibration.
852 cal_interval = ATH_LONG_CALINTERVAL;
853 if (ah->config.enable_ani)
854 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
855 if (!common->ani.caldone)
856 cal_interval = min(cal_interval, (u32)short_cal_interval);
858 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
859 msecs_to_jiffies(cal_interval));
862 /**********************/
863 /* mac80211 Callbacks */
864 /**********************/
866 static void ath9k_htc_tx(struct ieee80211_hw *hw,
867 struct ieee80211_tx_control *control,
870 struct ieee80211_hdr *hdr;
871 struct ath9k_htc_priv *priv = hw->priv;
872 struct ath_common *common = ath9k_hw_common(priv->ah);
873 int padpos, padsize, ret, slot;
875 hdr = (struct ieee80211_hdr *) skb->data;
877 /* Add the padding after the header if this is not already done */
878 padpos = ieee80211_hdrlen(hdr->frame_control);
879 padsize = padpos & 3;
880 if (padsize && skb->len > padpos) {
881 if (skb_headroom(skb) < padsize) {
882 ath_dbg(common, XMIT, "No room for padding\n");
885 skb_push(skb, padsize);
886 memmove(skb->data, skb->data + padsize, padpos);
889 slot = ath9k_htc_tx_get_slot(priv);
891 ath_dbg(common, XMIT, "No free TX slot\n");
895 ret = ath9k_htc_tx_start(priv, control->sta, skb, slot, false);
897 ath_dbg(common, XMIT, "Tx failed\n");
901 ath9k_htc_check_stop_queues(priv);
906 ath9k_htc_tx_clear_slot(priv, slot);
908 dev_kfree_skb_any(skb);
911 static int ath9k_htc_start(struct ieee80211_hw *hw)
913 struct ath9k_htc_priv *priv = hw->priv;
914 struct ath_hw *ah = priv->ah;
915 struct ath_common *common = ath9k_hw_common(ah);
916 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
917 struct ath9k_channel *init_channel;
919 enum htc_phymode mode;
923 mutex_lock(&priv->mutex);
925 ath_dbg(common, CONFIG,
926 "Starting driver with initial channel: %d MHz\n",
927 curchan->center_freq);
929 /* Ensure that HW is awake before flushing RX */
930 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
931 WMI_CMD(WMI_FLUSH_RECV_CMDID);
933 /* setup initial channel */
934 init_channel = ath9k_cmn_get_curchannel(hw, ah);
936 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
939 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
940 ret, curchan->center_freq);
941 mutex_unlock(&priv->mutex);
945 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
948 mode = ath9k_htc_get_curmode(priv, init_channel);
949 htc_mode = cpu_to_be16(mode);
950 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
951 WMI_CMD(WMI_ATH_INIT_CMDID);
952 WMI_CMD(WMI_START_RECV_CMDID);
954 ath9k_host_rx_init(priv);
956 ret = ath9k_htc_update_cap_target(priv, 0);
958 ath_dbg(common, CONFIG,
959 "Failed to update capability in target\n");
961 clear_bit(OP_INVALID, &priv->op_flags);
962 htc_start(priv->htc);
964 spin_lock_bh(&priv->tx.tx_lock);
965 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
966 spin_unlock_bh(&priv->tx.tx_lock);
968 ieee80211_wake_queues(hw);
970 mod_timer(&priv->tx.cleanup_timer,
971 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
973 ath9k_htc_start_btcoex(priv);
975 mutex_unlock(&priv->mutex);
980 static void ath9k_htc_stop(struct ieee80211_hw *hw)
982 struct ath9k_htc_priv *priv = hw->priv;
983 struct ath_hw *ah = priv->ah;
984 struct ath_common *common = ath9k_hw_common(ah);
985 int ret __attribute__ ((unused));
988 mutex_lock(&priv->mutex);
990 if (test_bit(OP_INVALID, &priv->op_flags)) {
991 ath_dbg(common, ANY, "Device not present\n");
992 mutex_unlock(&priv->mutex);
996 ath9k_htc_ps_wakeup(priv);
998 WMI_CMD(WMI_DISABLE_INTR_CMDID);
999 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1000 WMI_CMD(WMI_STOP_RECV_CMDID);
1002 tasklet_kill(&priv->rx_tasklet);
1004 del_timer_sync(&priv->tx.cleanup_timer);
1005 ath9k_htc_tx_drain(priv);
1006 ath9k_wmi_event_drain(priv);
1008 mutex_unlock(&priv->mutex);
1010 /* Cancel all the running timers/work .. */
1011 cancel_work_sync(&priv->fatal_work);
1012 cancel_work_sync(&priv->ps_work);
1014 #ifdef CONFIG_MAC80211_LEDS
1015 cancel_work_sync(&priv->led_work);
1017 ath9k_htc_stop_ani(priv);
1019 mutex_lock(&priv->mutex);
1021 ath9k_htc_stop_btcoex(priv);
1023 /* Remove a monitor interface if it's present. */
1024 if (priv->ah->is_monitoring)
1025 ath9k_htc_remove_monitor_interface(priv);
1027 ath9k_hw_phy_disable(ah);
1028 ath9k_hw_disable(ah);
1029 ath9k_htc_ps_restore(priv);
1030 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1032 set_bit(OP_INVALID, &priv->op_flags);
1034 ath_dbg(common, CONFIG, "Driver halt\n");
1035 mutex_unlock(&priv->mutex);
1038 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1039 struct ieee80211_vif *vif)
1041 struct ath9k_htc_priv *priv = hw->priv;
1042 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1043 struct ath_common *common = ath9k_hw_common(priv->ah);
1044 struct ath9k_htc_target_vif hvif;
1048 mutex_lock(&priv->mutex);
1050 ath9k_htc_ps_wakeup(priv);
1051 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1052 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1054 switch (vif->type) {
1055 case NL80211_IFTYPE_STATION:
1056 hvif.opmode = HTC_M_STA;
1058 case NL80211_IFTYPE_ADHOC:
1059 hvif.opmode = HTC_M_IBSS;
1061 case NL80211_IFTYPE_AP:
1062 hvif.opmode = HTC_M_HOSTAP;
1066 "Interface type %d not yet supported\n", vif->type);
1071 /* Index starts from zero on the target */
1072 avp->index = hvif.index = ffz(priv->vif_slot);
1073 hvif.rtsthreshold = cpu_to_be16(2304);
1074 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1079 * We need a node in target to tx mgmt frames
1080 * before association.
1082 ret = ath9k_htc_add_station(priv, vif, NULL);
1084 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1088 ath9k_htc_set_mac_bssid_mask(priv, vif);
1090 priv->vif_slot |= (1 << avp->index);
1093 INC_VIF(priv, vif->type);
1095 if ((vif->type == NL80211_IFTYPE_AP) ||
1096 (vif->type == NL80211_IFTYPE_ADHOC))
1097 ath9k_htc_assign_bslot(priv, vif);
1099 ath9k_htc_set_opmode(priv);
1101 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1102 !test_bit(OP_ANI_RUNNING, &priv->op_flags)) {
1103 ath9k_hw_set_tsfadjust(priv->ah, true);
1104 ath9k_htc_start_ani(priv);
1107 ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n",
1108 vif->type, avp->index);
1111 ath9k_htc_ps_restore(priv);
1112 mutex_unlock(&priv->mutex);
1117 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1118 struct ieee80211_vif *vif)
1120 struct ath9k_htc_priv *priv = hw->priv;
1121 struct ath_common *common = ath9k_hw_common(priv->ah);
1122 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1123 struct ath9k_htc_target_vif hvif;
1127 mutex_lock(&priv->mutex);
1128 ath9k_htc_ps_wakeup(priv);
1130 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1131 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1132 hvif.index = avp->index;
1133 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1135 ath_err(common, "Unable to remove interface at idx: %d\n",
1139 priv->vif_slot &= ~(1 << avp->index);
1141 ath9k_htc_remove_station(priv, vif, NULL);
1143 DEC_VIF(priv, vif->type);
1145 if ((vif->type == NL80211_IFTYPE_AP) ||
1146 (vif->type == NL80211_IFTYPE_ADHOC))
1147 ath9k_htc_remove_bslot(priv, vif);
1149 ath9k_htc_set_opmode(priv);
1151 ath9k_htc_set_mac_bssid_mask(priv, vif);
1154 * Stop ANI only if there are no associated station interfaces.
1156 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1157 priv->rearm_ani = false;
1158 ieee80211_iterate_active_interfaces_atomic(
1159 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1160 ath9k_htc_vif_iter, priv);
1161 if (!priv->rearm_ani)
1162 ath9k_htc_stop_ani(priv);
1165 ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index);
1167 ath9k_htc_ps_restore(priv);
1168 mutex_unlock(&priv->mutex);
1171 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1173 struct ath9k_htc_priv *priv = hw->priv;
1174 struct ath_common *common = ath9k_hw_common(priv->ah);
1175 struct ieee80211_conf *conf = &hw->conf;
1176 bool chip_reset = false;
1179 mutex_lock(&priv->mutex);
1180 ath9k_htc_ps_wakeup(priv);
1182 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1183 mutex_lock(&priv->htc_pm_lock);
1185 priv->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1189 mutex_unlock(&priv->htc_pm_lock);
1193 * Monitor interface should be added before
1194 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1196 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1197 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1198 !priv->ah->is_monitoring)
1199 ath9k_htc_add_monitor_interface(priv);
1200 else if (priv->ah->is_monitoring)
1201 ath9k_htc_remove_monitor_interface(priv);
1204 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
1205 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
1206 enum nl80211_channel_type channel_type =
1207 cfg80211_get_chandef_type(&hw->conf.chandef);
1208 int pos = curchan->hw_value;
1210 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
1211 curchan->center_freq);
1213 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1214 hw->conf.chandef.chan,
1217 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1218 ath_err(common, "Unable to set channel\n");
1225 if (changed & IEEE80211_CONF_CHANGE_PS) {
1226 if (conf->flags & IEEE80211_CONF_PS) {
1227 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1228 priv->ps_enabled = true;
1230 priv->ps_enabled = false;
1231 cancel_work_sync(&priv->ps_work);
1232 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1236 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1237 priv->txpowlimit = 2 * conf->power_level;
1238 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1239 priv->txpowlimit, &priv->curtxpow);
1243 ath9k_htc_ps_restore(priv);
1244 mutex_unlock(&priv->mutex);
1248 #define SUPPORTED_FILTERS \
1249 (FIF_PROMISC_IN_BSS | \
1254 FIF_BCN_PRBRESP_PROMISC | \
1258 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1259 unsigned int changed_flags,
1260 unsigned int *total_flags,
1263 struct ath9k_htc_priv *priv = hw->priv;
1266 mutex_lock(&priv->mutex);
1267 changed_flags &= SUPPORTED_FILTERS;
1268 *total_flags &= SUPPORTED_FILTERS;
1270 if (test_bit(OP_INVALID, &priv->op_flags)) {
1271 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1272 "Unable to configure filter on invalid state\n");
1273 mutex_unlock(&priv->mutex);
1276 ath9k_htc_ps_wakeup(priv);
1278 priv->rxfilter = *total_flags;
1279 rfilt = ath9k_htc_calcrxfilter(priv);
1280 ath9k_hw_setrxfilter(priv->ah, rfilt);
1282 ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n",
1285 ath9k_htc_ps_restore(priv);
1286 mutex_unlock(&priv->mutex);
1289 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1290 struct ieee80211_vif *vif,
1291 struct ieee80211_sta *sta)
1293 struct ath9k_htc_priv *priv = hw->priv;
1296 mutex_lock(&priv->mutex);
1297 ath9k_htc_ps_wakeup(priv);
1298 ret = ath9k_htc_add_station(priv, vif, sta);
1300 ath9k_htc_init_rate(priv, sta);
1301 ath9k_htc_ps_restore(priv);
1302 mutex_unlock(&priv->mutex);
1307 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1308 struct ieee80211_vif *vif,
1309 struct ieee80211_sta *sta)
1311 struct ath9k_htc_priv *priv = hw->priv;
1312 struct ath9k_htc_sta *ista;
1315 mutex_lock(&priv->mutex);
1316 ath9k_htc_ps_wakeup(priv);
1317 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1318 htc_sta_drain(priv->htc, ista->index);
1319 ret = ath9k_htc_remove_station(priv, vif, sta);
1320 ath9k_htc_ps_restore(priv);
1321 mutex_unlock(&priv->mutex);
1326 static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
1327 struct ieee80211_vif *vif,
1328 struct ieee80211_sta *sta, u32 changed)
1330 struct ath9k_htc_priv *priv = hw->priv;
1331 struct ath_common *common = ath9k_hw_common(priv->ah);
1332 struct ath9k_htc_target_rate trate;
1334 if (!(changed & IEEE80211_RC_SUPP_RATES_CHANGED))
1337 mutex_lock(&priv->mutex);
1338 ath9k_htc_ps_wakeup(priv);
1340 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
1341 ath9k_htc_setup_rate(priv, sta, &trate);
1342 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1343 ath_dbg(common, CONFIG,
1344 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1345 sta->addr, be32_to_cpu(trate.capflags));
1347 ath_dbg(common, CONFIG,
1348 "Unable to update supported rates for sta: %pM\n",
1351 ath9k_htc_ps_restore(priv);
1352 mutex_unlock(&priv->mutex);
1355 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
1356 struct ieee80211_vif *vif, u16 queue,
1357 const struct ieee80211_tx_queue_params *params)
1359 struct ath9k_htc_priv *priv = hw->priv;
1360 struct ath_common *common = ath9k_hw_common(priv->ah);
1361 struct ath9k_tx_queue_info qi;
1364 if (queue >= IEEE80211_NUM_ACS)
1367 mutex_lock(&priv->mutex);
1368 ath9k_htc_ps_wakeup(priv);
1370 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1372 qi.tqi_aifs = params->aifs;
1373 qi.tqi_cwmin = params->cw_min;
1374 qi.tqi_cwmax = params->cw_max;
1375 qi.tqi_burstTime = params->txop * 32;
1377 qnum = get_hw_qnum(queue, priv->hwq_map);
1379 ath_dbg(common, CONFIG,
1380 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1381 queue, qnum, params->aifs, params->cw_min,
1382 params->cw_max, params->txop);
1384 ret = ath_htc_txq_update(priv, qnum, &qi);
1386 ath_err(common, "TXQ Update failed\n");
1390 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1391 (qnum == priv->hwq_map[IEEE80211_AC_BE]))
1392 ath9k_htc_beaconq_config(priv);
1394 ath9k_htc_ps_restore(priv);
1395 mutex_unlock(&priv->mutex);
1400 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1401 enum set_key_cmd cmd,
1402 struct ieee80211_vif *vif,
1403 struct ieee80211_sta *sta,
1404 struct ieee80211_key_conf *key)
1406 struct ath9k_htc_priv *priv = hw->priv;
1407 struct ath_common *common = ath9k_hw_common(priv->ah);
1410 if (htc_modparam_nohwcrypt)
1413 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1414 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1415 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1416 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1417 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1419 * For now, disable hw crypto for the RSN IBSS group keys. This
1420 * could be optimized in the future to use a modified key cache
1421 * design to support per-STA RX GTK, but until that gets
1422 * implemented, use of software crypto for group addressed
1423 * frames is a acceptable to allow RSN IBSS to be used.
1428 mutex_lock(&priv->mutex);
1429 ath_dbg(common, CONFIG, "Set HW Key\n");
1430 ath9k_htc_ps_wakeup(priv);
1434 ret = ath_key_config(common, vif, sta, key);
1436 key->hw_key_idx = ret;
1437 /* push IV and Michael MIC generation to stack */
1438 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1439 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1440 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1441 if (priv->ah->sw_mgmt_crypto &&
1442 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1443 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1448 ath_key_delete(common, key);
1454 ath9k_htc_ps_restore(priv);
1455 mutex_unlock(&priv->mutex);
1460 static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv)
1462 struct ath_common *common = ath9k_hw_common(priv->ah);
1464 ath9k_hw_write_associd(priv->ah);
1465 ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
1466 common->curbssid, common->curaid);
1469 static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1471 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1472 struct ath_common *common = ath9k_hw_common(priv->ah);
1473 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1475 if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) {
1476 common->curaid = bss_conf->aid;
1477 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1481 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv)
1483 if (priv->num_sta_assoc_vif == 1) {
1484 ieee80211_iterate_active_interfaces_atomic(
1485 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1486 ath9k_htc_bss_iter, priv);
1487 ath9k_htc_set_bssid(priv);
1491 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1492 struct ieee80211_vif *vif,
1493 struct ieee80211_bss_conf *bss_conf,
1496 struct ath9k_htc_priv *priv = hw->priv;
1497 struct ath_hw *ah = priv->ah;
1498 struct ath_common *common = ath9k_hw_common(ah);
1500 mutex_lock(&priv->mutex);
1501 ath9k_htc_ps_wakeup(priv);
1503 if (changed & BSS_CHANGED_ASSOC) {
1504 ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n",
1508 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1510 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1511 ath9k_htc_choose_set_bssid(priv);
1512 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
1513 ath9k_htc_start_ani(priv);
1514 else if (priv->num_sta_assoc_vif == 0)
1515 ath9k_htc_stop_ani(priv);
1519 if (changed & BSS_CHANGED_IBSS) {
1520 if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
1521 common->curaid = bss_conf->aid;
1522 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1523 ath9k_htc_set_bssid(priv);
1527 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1528 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1530 ath9k_htc_set_tsfadjust(priv, vif);
1531 set_bit(OP_ENABLE_BEACON, &priv->op_flags);
1532 ath9k_htc_beacon_config(priv, vif);
1535 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1537 * Disable SWBA interrupt only if there are no
1538 * AP/IBSS interfaces.
1540 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1541 ath_dbg(common, CONFIG,
1542 "Beacon disabled for BSS: %pM\n",
1544 clear_bit(OP_ENABLE_BEACON, &priv->op_flags);
1545 ath9k_htc_beacon_config(priv, vif);
1549 if (changed & BSS_CHANGED_BEACON_INT) {
1551 * Reset the HW TSF for the first AP interface.
1553 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1554 (priv->nvifs == 1) &&
1555 (priv->num_ap_vif == 1) &&
1556 (vif->type == NL80211_IFTYPE_AP)) {
1557 set_bit(OP_TSF_RESET, &priv->op_flags);
1559 ath_dbg(common, CONFIG,
1560 "Beacon interval changed for BSS: %pM\n",
1562 ath9k_htc_beacon_config(priv, vif);
1565 if (changed & BSS_CHANGED_ERP_SLOT) {
1566 if (bss_conf->use_short_slot)
1571 ath9k_hw_init_global_settings(ah);
1574 if (changed & BSS_CHANGED_HT)
1575 ath9k_htc_update_rate(priv, vif, bss_conf);
1577 ath9k_htc_ps_restore(priv);
1578 mutex_unlock(&priv->mutex);
1581 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw,
1582 struct ieee80211_vif *vif)
1584 struct ath9k_htc_priv *priv = hw->priv;
1587 mutex_lock(&priv->mutex);
1588 ath9k_htc_ps_wakeup(priv);
1589 tsf = ath9k_hw_gettsf64(priv->ah);
1590 ath9k_htc_ps_restore(priv);
1591 mutex_unlock(&priv->mutex);
1596 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw,
1597 struct ieee80211_vif *vif, u64 tsf)
1599 struct ath9k_htc_priv *priv = hw->priv;
1601 mutex_lock(&priv->mutex);
1602 ath9k_htc_ps_wakeup(priv);
1603 ath9k_hw_settsf64(priv->ah, tsf);
1604 ath9k_htc_ps_restore(priv);
1605 mutex_unlock(&priv->mutex);
1608 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw,
1609 struct ieee80211_vif *vif)
1611 struct ath9k_htc_priv *priv = hw->priv;
1613 mutex_lock(&priv->mutex);
1614 ath9k_htc_ps_wakeup(priv);
1615 ath9k_hw_reset_tsf(priv->ah);
1616 ath9k_htc_ps_restore(priv);
1617 mutex_unlock(&priv->mutex);
1620 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1621 struct ieee80211_vif *vif,
1622 enum ieee80211_ampdu_mlme_action action,
1623 struct ieee80211_sta *sta,
1624 u16 tid, u16 *ssn, u8 buf_size)
1626 struct ath9k_htc_priv *priv = hw->priv;
1627 struct ath9k_htc_sta *ista;
1630 mutex_lock(&priv->mutex);
1631 ath9k_htc_ps_wakeup(priv);
1634 case IEEE80211_AMPDU_RX_START:
1636 case IEEE80211_AMPDU_RX_STOP:
1638 case IEEE80211_AMPDU_TX_START:
1639 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1641 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1643 case IEEE80211_AMPDU_TX_STOP_CONT:
1644 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1645 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1646 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1647 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1649 case IEEE80211_AMPDU_TX_OPERATIONAL:
1650 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1651 spin_lock_bh(&priv->tx.tx_lock);
1652 ista->tid_state[tid] = AGGR_OPERATIONAL;
1653 spin_unlock_bh(&priv->tx.tx_lock);
1656 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1659 ath9k_htc_ps_restore(priv);
1660 mutex_unlock(&priv->mutex);
1665 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1667 struct ath9k_htc_priv *priv = hw->priv;
1669 mutex_lock(&priv->mutex);
1670 spin_lock_bh(&priv->beacon_lock);
1671 set_bit(OP_SCANNING, &priv->op_flags);
1672 spin_unlock_bh(&priv->beacon_lock);
1673 cancel_work_sync(&priv->ps_work);
1674 ath9k_htc_stop_ani(priv);
1675 mutex_unlock(&priv->mutex);
1678 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1680 struct ath9k_htc_priv *priv = hw->priv;
1682 mutex_lock(&priv->mutex);
1683 spin_lock_bh(&priv->beacon_lock);
1684 clear_bit(OP_SCANNING, &priv->op_flags);
1685 spin_unlock_bh(&priv->beacon_lock);
1686 ath9k_htc_ps_wakeup(priv);
1687 ath9k_htc_vif_reconfig(priv);
1688 ath9k_htc_ps_restore(priv);
1689 mutex_unlock(&priv->mutex);
1692 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1697 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1700 struct ath9k_htc_priv *priv = hw->priv;
1702 mutex_lock(&priv->mutex);
1703 ath9k_htc_ps_wakeup(priv);
1704 priv->ah->coverage_class = coverage_class;
1705 ath9k_hw_init_global_settings(priv->ah);
1706 ath9k_htc_ps_restore(priv);
1707 mutex_unlock(&priv->mutex);
1711 * Currently, this is used only for selecting the minimum rate
1712 * for management frames, rate selection for data frames remain
1715 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw,
1716 struct ieee80211_vif *vif,
1717 const struct cfg80211_bitrate_mask *mask)
1719 struct ath9k_htc_priv *priv = hw->priv;
1720 struct ath_common *common = ath9k_hw_common(priv->ah);
1721 struct ath9k_htc_target_rate_mask tmask;
1722 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1726 memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask));
1728 tmask.vif_index = avp->index;
1729 tmask.band = IEEE80211_BAND_2GHZ;
1730 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy);
1732 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1735 "Unable to set 2G rate mask for "
1736 "interface at idx: %d\n", avp->index);
1740 tmask.band = IEEE80211_BAND_5GHZ;
1741 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy);
1743 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1746 "Unable to set 5G rate mask for "
1747 "interface at idx: %d\n", avp->index);
1751 ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n",
1752 mask->control[IEEE80211_BAND_2GHZ].legacy,
1753 mask->control[IEEE80211_BAND_5GHZ].legacy);
1759 static int ath9k_htc_get_stats(struct ieee80211_hw *hw,
1760 struct ieee80211_low_level_stats *stats)
1762 struct ath9k_htc_priv *priv = hw->priv;
1763 struct ath_hw *ah = priv->ah;
1764 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1766 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1767 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1768 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1769 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1774 struct ieee80211_ops ath9k_htc_ops = {
1776 .start = ath9k_htc_start,
1777 .stop = ath9k_htc_stop,
1778 .add_interface = ath9k_htc_add_interface,
1779 .remove_interface = ath9k_htc_remove_interface,
1780 .config = ath9k_htc_config,
1781 .configure_filter = ath9k_htc_configure_filter,
1782 .sta_add = ath9k_htc_sta_add,
1783 .sta_remove = ath9k_htc_sta_remove,
1784 .conf_tx = ath9k_htc_conf_tx,
1785 .sta_rc_update = ath9k_htc_sta_rc_update,
1786 .bss_info_changed = ath9k_htc_bss_info_changed,
1787 .set_key = ath9k_htc_set_key,
1788 .get_tsf = ath9k_htc_get_tsf,
1789 .set_tsf = ath9k_htc_set_tsf,
1790 .reset_tsf = ath9k_htc_reset_tsf,
1791 .ampdu_action = ath9k_htc_ampdu_action,
1792 .sw_scan_start = ath9k_htc_sw_scan_start,
1793 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1794 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1795 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1796 .set_coverage_class = ath9k_htc_set_coverage_class,
1797 .set_bitrate_mask = ath9k_htc_set_bitrate_mask,
1798 .get_stats = ath9k_htc_get_stats,