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 if (IS_CHAN_5GHZ(ichan))
33 bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
34 enum ath9k_power_mode mode)
38 mutex_lock(&priv->htc_pm_lock);
39 ret = ath9k_hw_setpower(priv->ah, mode);
40 mutex_unlock(&priv->htc_pm_lock);
45 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
47 mutex_lock(&priv->htc_pm_lock);
48 if (++priv->ps_usecount != 1)
50 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
53 mutex_unlock(&priv->htc_pm_lock);
56 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
60 mutex_lock(&priv->htc_pm_lock);
61 if (--priv->ps_usecount != 0)
65 ath9k_hw_setrxabort(priv->ah, true);
66 ath9k_hw_stopdmarecv(priv->ah, &reset);
67 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
68 } else if (priv->ps_enabled) {
69 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
73 mutex_unlock(&priv->htc_pm_lock);
76 void ath9k_ps_work(struct work_struct *work)
78 struct ath9k_htc_priv *priv =
79 container_of(work, struct ath9k_htc_priv,
81 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
83 /* The chip wakes up after receiving the first beacon
84 while network sleep is enabled. For the driver to
85 be in sync with the hw, set the chip to awake and
86 only then set it to sleep.
88 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
91 static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
93 struct ath9k_htc_priv *priv = data;
94 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
96 if ((vif->type == NL80211_IFTYPE_AP ||
97 vif->type == NL80211_IFTYPE_MESH_POINT) &&
98 bss_conf->enable_beacon) {
99 priv->reconfig_beacon = true;
100 priv->rearm_ani = true;
103 if (bss_conf->assoc) {
104 priv->rearm_ani = true;
105 priv->reconfig_beacon = true;
109 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv)
111 priv->rearm_ani = false;
112 priv->reconfig_beacon = false;
114 ieee80211_iterate_active_interfaces_atomic(
115 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
116 ath9k_htc_vif_iter, priv);
118 ath9k_htc_start_ani(priv);
120 if (priv->reconfig_beacon) {
121 ath9k_htc_ps_wakeup(priv);
122 ath9k_htc_beacon_reconfig(priv);
123 ath9k_htc_ps_restore(priv);
127 static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
129 struct ath9k_vif_iter_data *iter_data = data;
132 if (iter_data->hw_macaddr != NULL) {
133 for (i = 0; i < ETH_ALEN; i++)
134 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
136 iter_data->hw_macaddr = mac;
140 static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
141 struct ieee80211_vif *vif)
143 struct ath_common *common = ath9k_hw_common(priv->ah);
144 struct ath9k_vif_iter_data iter_data;
147 * Pick the MAC address of the first interface as the new hardware
148 * MAC address. The hardware will use it together with the BSSID mask
149 * when matching addresses.
151 iter_data.hw_macaddr = NULL;
152 memset(&iter_data.mask, 0xff, ETH_ALEN);
155 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
157 /* Get list of all active MAC addresses */
158 ieee80211_iterate_active_interfaces_atomic(
159 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
160 ath9k_htc_bssid_iter, &iter_data);
162 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
164 if (iter_data.hw_macaddr)
165 memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
167 ath_hw_setbssidmask(common);
170 static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv)
172 if (priv->num_ibss_vif)
173 priv->ah->opmode = NL80211_IFTYPE_ADHOC;
174 else if (priv->num_ap_vif)
175 priv->ah->opmode = NL80211_IFTYPE_AP;
176 else if (priv->num_mbss_vif)
177 priv->ah->opmode = NL80211_IFTYPE_MESH_POINT;
179 priv->ah->opmode = NL80211_IFTYPE_STATION;
181 ath9k_hw_setopmode(priv->ah);
184 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
186 struct ath_hw *ah = priv->ah;
187 struct ath_common *common = ath9k_hw_common(ah);
188 struct ieee80211_channel *channel = priv->hw->conf.chandef.chan;
189 struct ath9k_hw_cal_data *caldata = NULL;
190 enum htc_phymode mode;
195 mutex_lock(&priv->mutex);
196 ath9k_htc_ps_wakeup(priv);
198 ath9k_htc_stop_ani(priv);
199 ieee80211_stop_queues(priv->hw);
201 del_timer_sync(&priv->tx.cleanup_timer);
202 ath9k_htc_tx_drain(priv);
204 WMI_CMD(WMI_DISABLE_INTR_CMDID);
205 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
206 WMI_CMD(WMI_STOP_RECV_CMDID);
208 ath9k_wmi_event_drain(priv);
210 caldata = &priv->caldata;
211 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
214 "Unable to reset device (%u Mhz) reset status %d\n",
215 channel->center_freq, ret);
218 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
221 WMI_CMD(WMI_START_RECV_CMDID);
222 ath9k_host_rx_init(priv);
224 mode = ath9k_htc_get_curmode(priv, ah->curchan);
225 htc_mode = cpu_to_be16(mode);
226 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
228 WMI_CMD(WMI_ENABLE_INTR_CMDID);
229 htc_start(priv->htc);
230 ath9k_htc_vif_reconfig(priv);
231 ieee80211_wake_queues(priv->hw);
233 mod_timer(&priv->tx.cleanup_timer,
234 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
236 ath9k_htc_ps_restore(priv);
237 mutex_unlock(&priv->mutex);
240 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
241 struct ieee80211_hw *hw,
242 struct ath9k_channel *hchan)
244 struct ath_hw *ah = priv->ah;
245 struct ath_common *common = ath9k_hw_common(ah);
246 struct ieee80211_conf *conf = &common->hw->conf;
248 struct ieee80211_channel *channel = hw->conf.chandef.chan;
249 struct ath9k_hw_cal_data *caldata = NULL;
250 enum htc_phymode mode;
255 if (test_bit(ATH_OP_INVALID, &common->op_flags))
258 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
260 ath9k_htc_ps_wakeup(priv);
262 ath9k_htc_stop_ani(priv);
263 del_timer_sync(&priv->tx.cleanup_timer);
264 ath9k_htc_tx_drain(priv);
266 WMI_CMD(WMI_DISABLE_INTR_CMDID);
267 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
268 WMI_CMD(WMI_STOP_RECV_CMDID);
270 ath9k_wmi_event_drain(priv);
272 ath_dbg(common, CONFIG,
273 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
274 priv->ah->curchan->channel,
275 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
279 caldata = &priv->caldata;
281 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
284 "Unable to reset channel (%u Mhz) reset status %d\n",
285 channel->center_freq, ret);
289 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
292 WMI_CMD(WMI_START_RECV_CMDID);
296 ath9k_host_rx_init(priv);
298 mode = ath9k_htc_get_curmode(priv, hchan);
299 htc_mode = cpu_to_be16(mode);
300 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
304 WMI_CMD(WMI_ENABLE_INTR_CMDID);
308 htc_start(priv->htc);
310 if (!test_bit(ATH_OP_SCANNING, &common->op_flags) &&
311 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
312 ath9k_htc_vif_reconfig(priv);
314 mod_timer(&priv->tx.cleanup_timer,
315 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
318 ath9k_htc_ps_restore(priv);
323 * Monitor mode handling is a tad complicated because the firmware requires
324 * an interface to be created exclusively, while mac80211 doesn't associate
325 * an interface with the mode.
327 * So, for now, only one monitor interface can be configured.
329 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
331 struct ath_common *common = ath9k_hw_common(priv->ah);
332 struct ath9k_htc_target_vif hvif;
336 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
337 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
338 hvif.index = priv->mon_vif_idx;
339 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
341 ath_err(common, "Unable to remove monitor interface at idx: %d\n",
346 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
349 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
351 struct ath_common *common = ath9k_hw_common(priv->ah);
352 struct ath9k_htc_target_vif hvif;
353 struct ath9k_htc_target_sta tsta;
354 int ret = 0, sta_idx;
357 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
358 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
363 sta_idx = ffz(priv->sta_slot);
364 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
372 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
373 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
375 hvif.opmode = HTC_M_MONITOR;
376 hvif.index = ffz(priv->vif_slot);
378 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
383 * Assign the monitor interface index as a special case here.
384 * This is needed when the interface is brought down.
386 priv->mon_vif_idx = hvif.index;
387 priv->vif_slot |= (1 << hvif.index);
390 * Set the hardware mode to monitor only if there are no
394 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
399 * Associate a station with the interface for packet injection.
401 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
403 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
406 tsta.sta_index = sta_idx;
407 tsta.vif_index = hvif.index;
408 tsta.maxampdu = cpu_to_be16(0xffff);
410 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
412 ath_err(common, "Unable to add station entry for monitor mode\n");
416 priv->sta_slot |= (1 << sta_idx);
418 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
419 priv->ah->is_monitoring = true;
421 ath_dbg(common, CONFIG,
422 "Attached a monitor interface at idx: %d, sta idx: %d\n",
423 priv->mon_vif_idx, sta_idx);
429 * Remove the interface from the target.
431 __ath9k_htc_remove_monitor_interface(priv);
433 ath_dbg(common, FATAL, "Unable to attach a monitor interface\n");
438 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
440 struct ath_common *common = ath9k_hw_common(priv->ah);
444 __ath9k_htc_remove_monitor_interface(priv);
446 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
448 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
450 ath_err(common, "Unable to remove station entry for monitor mode\n");
454 priv->sta_slot &= ~(1 << sta_idx);
456 priv->ah->is_monitoring = false;
458 ath_dbg(common, CONFIG,
459 "Removed a monitor interface at idx: %d, sta idx: %d\n",
460 priv->mon_vif_idx, sta_idx);
465 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
466 struct ieee80211_vif *vif,
467 struct ieee80211_sta *sta)
469 struct ath_common *common = ath9k_hw_common(priv->ah);
470 struct ath9k_htc_target_sta tsta;
471 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
472 struct ath9k_htc_sta *ista;
477 if (priv->nstations >= ATH9K_HTC_MAX_STA)
480 sta_idx = ffz(priv->sta_slot);
481 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
484 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
487 ista = (struct ath9k_htc_sta *) sta->drv_priv;
488 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
489 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
490 ista->index = sta_idx;
492 maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
493 sta->ht_cap.ampdu_factor);
494 tsta.maxampdu = cpu_to_be16(maxampdu);
496 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
498 tsta.maxampdu = cpu_to_be16(0xffff);
501 tsta.sta_index = sta_idx;
502 tsta.vif_index = avp->index;
504 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
508 "Unable to add station entry for: %pM\n",
514 ath_dbg(common, CONFIG,
515 "Added a station entry for: %pM (idx: %d)\n",
516 sta->addr, tsta.sta_index);
518 ath_dbg(common, CONFIG,
519 "Added a station entry for VIF %d (idx: %d)\n",
520 avp->index, tsta.sta_index);
523 priv->sta_slot |= (1 << sta_idx);
526 priv->vif_sta_pos[avp->index] = sta_idx;
531 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
532 struct ieee80211_vif *vif,
533 struct ieee80211_sta *sta)
535 struct ath_common *common = ath9k_hw_common(priv->ah);
536 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
537 struct ath9k_htc_sta *ista;
542 ista = (struct ath9k_htc_sta *) sta->drv_priv;
543 sta_idx = ista->index;
545 sta_idx = priv->vif_sta_pos[avp->index];
548 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
552 "Unable to remove station entry for: %pM\n",
558 ath_dbg(common, CONFIG,
559 "Removed a station entry for: %pM (idx: %d)\n",
562 ath_dbg(common, CONFIG,
563 "Removed a station entry for VIF %d (idx: %d)\n",
564 avp->index, sta_idx);
567 priv->sta_slot &= ~(1 << sta_idx);
573 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
576 struct ath9k_htc_cap_target tcap;
580 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
582 tcap.ampdu_limit = cpu_to_be32(0xffff);
583 tcap.ampdu_subframes = 0xff;
584 tcap.enable_coex = enable_coex;
585 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
587 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
592 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
593 struct ieee80211_sta *sta,
594 struct ath9k_htc_target_rate *trate)
596 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
597 struct ieee80211_supported_band *sband;
601 sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band];
603 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
604 if (sta->supp_rates[sband->band] & BIT(i)) {
605 trate->rates.legacy_rates.rs_rates[j]
606 = (sband->bitrates[i].bitrate * 2) / 10;
610 trate->rates.legacy_rates.rs_nrates = j;
612 if (sta->ht_cap.ht_supported) {
613 for (i = 0, j = 0; i < 77; i++) {
614 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
615 trate->rates.ht_rates.rs_rates[j++] = i;
616 if (j == ATH_HTC_RATE_MAX)
619 trate->rates.ht_rates.rs_nrates = j;
621 caps = WLAN_RC_HT_FLAG;
622 if (sta->ht_cap.cap & IEEE80211_HT_CAP_RX_STBC)
623 caps |= ATH_RC_TX_STBC_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(ATH_OP_ANI_RUN, &common->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 struct ath_common *common = ath9k_hw_common(priv->ah);
763 cancel_delayed_work_sync(&priv->ani_work);
764 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
767 void ath9k_htc_ani_work(struct work_struct *work)
769 struct ath9k_htc_priv *priv =
770 container_of(work, struct ath9k_htc_priv, ani_work.work);
771 struct ath_hw *ah = priv->ah;
772 struct ath_common *common = ath9k_hw_common(ah);
773 bool longcal = false;
774 bool shortcal = false;
775 bool aniflag = false;
776 unsigned int timestamp = jiffies_to_msecs(jiffies);
777 u32 cal_interval, short_cal_interval;
779 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
780 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
782 /* Only calibrate if awake */
783 if (ah->power_mode != ATH9K_PM_AWAKE)
786 /* Long calibration runs independently of short calibration. */
787 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
789 ath_dbg(common, ANI, "longcal @%lu\n", jiffies);
790 common->ani.longcal_timer = timestamp;
793 /* Short calibration applies only while caldone is false */
794 if (!common->ani.caldone) {
795 if ((timestamp - common->ani.shortcal_timer) >=
796 short_cal_interval) {
798 ath_dbg(common, ANI, "shortcal @%lu\n", jiffies);
799 common->ani.shortcal_timer = timestamp;
800 common->ani.resetcal_timer = timestamp;
803 if ((timestamp - common->ani.resetcal_timer) >=
804 ATH_RESTART_CALINTERVAL) {
805 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
806 if (common->ani.caldone)
807 common->ani.resetcal_timer = timestamp;
811 /* Verify whether we must check ANI */
812 if ((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 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
843 if (!common->ani.caldone)
844 cal_interval = min(cal_interval, (u32)short_cal_interval);
846 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
847 msecs_to_jiffies(cal_interval));
850 /**********************/
851 /* mac80211 Callbacks */
852 /**********************/
854 static void ath9k_htc_tx(struct ieee80211_hw *hw,
855 struct ieee80211_tx_control *control,
858 struct ieee80211_hdr *hdr;
859 struct ath9k_htc_priv *priv = hw->priv;
860 struct ath_common *common = ath9k_hw_common(priv->ah);
861 int padpos, padsize, ret, slot;
863 hdr = (struct ieee80211_hdr *) skb->data;
865 /* Add the padding after the header if this is not already done */
866 padpos = ieee80211_hdrlen(hdr->frame_control);
867 padsize = padpos & 3;
868 if (padsize && skb->len > padpos) {
869 if (skb_headroom(skb) < padsize) {
870 ath_dbg(common, XMIT, "No room for padding\n");
873 skb_push(skb, padsize);
874 memmove(skb->data, skb->data + padsize, padpos);
877 slot = ath9k_htc_tx_get_slot(priv);
879 ath_dbg(common, XMIT, "No free TX slot\n");
883 ret = ath9k_htc_tx_start(priv, control->sta, skb, slot, false);
885 ath_dbg(common, XMIT, "Tx failed\n");
889 ath9k_htc_check_stop_queues(priv);
894 ath9k_htc_tx_clear_slot(priv, slot);
896 dev_kfree_skb_any(skb);
899 static int ath9k_htc_start(struct ieee80211_hw *hw)
901 struct ath9k_htc_priv *priv = hw->priv;
902 struct ath_hw *ah = priv->ah;
903 struct ath_common *common = ath9k_hw_common(ah);
904 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
905 struct ath9k_channel *init_channel;
907 enum htc_phymode mode;
911 mutex_lock(&priv->mutex);
913 ath_dbg(common, CONFIG,
914 "Starting driver with initial channel: %d MHz\n",
915 curchan->center_freq);
917 /* Ensure that HW is awake before flushing RX */
918 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
919 WMI_CMD(WMI_FLUSH_RECV_CMDID);
921 /* setup initial channel */
922 init_channel = ath9k_cmn_get_channel(hw, ah, &hw->conf.chandef);
924 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
927 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
928 ret, curchan->center_freq);
929 mutex_unlock(&priv->mutex);
933 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
936 mode = ath9k_htc_get_curmode(priv, init_channel);
937 htc_mode = cpu_to_be16(mode);
938 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
939 WMI_CMD(WMI_ATH_INIT_CMDID);
940 WMI_CMD(WMI_START_RECV_CMDID);
942 ath9k_host_rx_init(priv);
944 ret = ath9k_htc_update_cap_target(priv, 0);
946 ath_dbg(common, CONFIG,
947 "Failed to update capability in target\n");
949 clear_bit(ATH_OP_INVALID, &common->op_flags);
950 htc_start(priv->htc);
952 spin_lock_bh(&priv->tx.tx_lock);
953 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
954 spin_unlock_bh(&priv->tx.tx_lock);
956 ieee80211_wake_queues(hw);
958 mod_timer(&priv->tx.cleanup_timer,
959 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
961 ath9k_htc_start_btcoex(priv);
963 mutex_unlock(&priv->mutex);
968 static void ath9k_htc_stop(struct ieee80211_hw *hw)
970 struct ath9k_htc_priv *priv = hw->priv;
971 struct ath_hw *ah = priv->ah;
972 struct ath_common *common = ath9k_hw_common(ah);
973 int ret __attribute__ ((unused));
976 mutex_lock(&priv->mutex);
978 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
979 ath_dbg(common, ANY, "Device not present\n");
980 mutex_unlock(&priv->mutex);
984 ath9k_htc_ps_wakeup(priv);
986 WMI_CMD(WMI_DISABLE_INTR_CMDID);
987 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
988 WMI_CMD(WMI_STOP_RECV_CMDID);
990 tasklet_kill(&priv->rx_tasklet);
992 del_timer_sync(&priv->tx.cleanup_timer);
993 ath9k_htc_tx_drain(priv);
994 ath9k_wmi_event_drain(priv);
996 mutex_unlock(&priv->mutex);
998 /* Cancel all the running timers/work .. */
999 cancel_work_sync(&priv->fatal_work);
1000 cancel_work_sync(&priv->ps_work);
1002 #ifdef CONFIG_MAC80211_LEDS
1003 cancel_work_sync(&priv->led_work);
1005 ath9k_htc_stop_ani(priv);
1007 mutex_lock(&priv->mutex);
1009 ath9k_htc_stop_btcoex(priv);
1011 /* Remove a monitor interface if it's present. */
1012 if (priv->ah->is_monitoring)
1013 ath9k_htc_remove_monitor_interface(priv);
1015 ath9k_hw_phy_disable(ah);
1016 ath9k_hw_disable(ah);
1017 ath9k_htc_ps_restore(priv);
1018 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1020 set_bit(ATH_OP_INVALID, &common->op_flags);
1022 ath_dbg(common, CONFIG, "Driver halt\n");
1023 mutex_unlock(&priv->mutex);
1026 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1027 struct ieee80211_vif *vif)
1029 struct ath9k_htc_priv *priv = hw->priv;
1030 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1031 struct ath_common *common = ath9k_hw_common(priv->ah);
1032 struct ath9k_htc_target_vif hvif;
1036 mutex_lock(&priv->mutex);
1038 ath9k_htc_ps_wakeup(priv);
1039 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1040 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1042 switch (vif->type) {
1043 case NL80211_IFTYPE_STATION:
1044 hvif.opmode = HTC_M_STA;
1046 case NL80211_IFTYPE_ADHOC:
1047 hvif.opmode = HTC_M_IBSS;
1049 case NL80211_IFTYPE_AP:
1050 hvif.opmode = HTC_M_HOSTAP;
1052 case NL80211_IFTYPE_MESH_POINT:
1053 hvif.opmode = HTC_M_WDS; /* close enough */
1057 "Interface type %d not yet supported\n", vif->type);
1062 /* Index starts from zero on the target */
1063 avp->index = hvif.index = ffz(priv->vif_slot);
1064 hvif.rtsthreshold = cpu_to_be16(2304);
1065 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1070 * We need a node in target to tx mgmt frames
1071 * before association.
1073 ret = ath9k_htc_add_station(priv, vif, NULL);
1075 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1079 ath9k_htc_set_mac_bssid_mask(priv, vif);
1081 priv->vif_slot |= (1 << avp->index);
1084 INC_VIF(priv, vif->type);
1086 if ((vif->type == NL80211_IFTYPE_AP) ||
1087 (vif->type == NL80211_IFTYPE_MESH_POINT) ||
1088 (vif->type == NL80211_IFTYPE_ADHOC))
1089 ath9k_htc_assign_bslot(priv, vif);
1091 ath9k_htc_set_opmode(priv);
1093 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1094 !test_bit(ATH_OP_ANI_RUN, &common->op_flags)) {
1095 ath9k_hw_set_tsfadjust(priv->ah, true);
1096 ath9k_htc_start_ani(priv);
1099 ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n",
1100 vif->type, avp->index);
1103 ath9k_htc_ps_restore(priv);
1104 mutex_unlock(&priv->mutex);
1109 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1110 struct ieee80211_vif *vif)
1112 struct ath9k_htc_priv *priv = hw->priv;
1113 struct ath_common *common = ath9k_hw_common(priv->ah);
1114 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1115 struct ath9k_htc_target_vif hvif;
1119 mutex_lock(&priv->mutex);
1120 ath9k_htc_ps_wakeup(priv);
1122 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1123 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1124 hvif.index = avp->index;
1125 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1127 ath_err(common, "Unable to remove interface at idx: %d\n",
1131 priv->vif_slot &= ~(1 << avp->index);
1133 ath9k_htc_remove_station(priv, vif, NULL);
1135 DEC_VIF(priv, vif->type);
1137 if ((vif->type == NL80211_IFTYPE_AP) ||
1138 vif->type == NL80211_IFTYPE_MESH_POINT ||
1139 (vif->type == NL80211_IFTYPE_ADHOC))
1140 ath9k_htc_remove_bslot(priv, vif);
1142 ath9k_htc_set_opmode(priv);
1144 ath9k_htc_set_mac_bssid_mask(priv, vif);
1147 * Stop ANI only if there are no associated station interfaces.
1149 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1150 priv->rearm_ani = false;
1151 ieee80211_iterate_active_interfaces_atomic(
1152 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1153 ath9k_htc_vif_iter, priv);
1154 if (!priv->rearm_ani)
1155 ath9k_htc_stop_ani(priv);
1158 ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index);
1160 ath9k_htc_ps_restore(priv);
1161 mutex_unlock(&priv->mutex);
1164 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1166 struct ath9k_htc_priv *priv = hw->priv;
1167 struct ath_common *common = ath9k_hw_common(priv->ah);
1168 struct ieee80211_conf *conf = &hw->conf;
1169 bool chip_reset = false;
1172 mutex_lock(&priv->mutex);
1173 ath9k_htc_ps_wakeup(priv);
1175 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1176 mutex_lock(&priv->htc_pm_lock);
1178 priv->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1182 mutex_unlock(&priv->htc_pm_lock);
1186 * Monitor interface should be added before
1187 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1189 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1190 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1191 !priv->ah->is_monitoring)
1192 ath9k_htc_add_monitor_interface(priv);
1193 else if (priv->ah->is_monitoring)
1194 ath9k_htc_remove_monitor_interface(priv);
1197 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
1198 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
1199 int pos = curchan->hw_value;
1201 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
1202 curchan->center_freq);
1204 ath9k_cmn_get_channel(hw, priv->ah, &hw->conf.chandef);
1205 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1206 ath_err(common, "Unable to set channel\n");
1213 if (changed & IEEE80211_CONF_CHANGE_PS) {
1214 if (conf->flags & IEEE80211_CONF_PS) {
1215 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1216 priv->ps_enabled = true;
1218 priv->ps_enabled = false;
1219 cancel_work_sync(&priv->ps_work);
1220 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1224 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1225 priv->txpowlimit = 2 * conf->power_level;
1226 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1227 priv->txpowlimit, &priv->curtxpow);
1231 ath9k_htc_ps_restore(priv);
1232 mutex_unlock(&priv->mutex);
1236 #define SUPPORTED_FILTERS \
1237 (FIF_PROMISC_IN_BSS | \
1242 FIF_BCN_PRBRESP_PROMISC | \
1246 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1247 unsigned int changed_flags,
1248 unsigned int *total_flags,
1251 struct ath9k_htc_priv *priv = hw->priv;
1252 struct ath_common *common = ath9k_hw_common(priv->ah);
1255 mutex_lock(&priv->mutex);
1256 changed_flags &= SUPPORTED_FILTERS;
1257 *total_flags &= SUPPORTED_FILTERS;
1259 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
1260 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1261 "Unable to configure filter on invalid state\n");
1262 mutex_unlock(&priv->mutex);
1265 ath9k_htc_ps_wakeup(priv);
1267 priv->rxfilter = *total_flags;
1268 rfilt = ath9k_htc_calcrxfilter(priv);
1269 ath9k_hw_setrxfilter(priv->ah, rfilt);
1271 ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n",
1274 ath9k_htc_ps_restore(priv);
1275 mutex_unlock(&priv->mutex);
1278 static void ath9k_htc_sta_rc_update_work(struct work_struct *work)
1280 struct ath9k_htc_sta *ista =
1281 container_of(work, struct ath9k_htc_sta, rc_update_work);
1282 struct ieee80211_sta *sta =
1283 container_of((void *)ista, struct ieee80211_sta, drv_priv);
1284 struct ath9k_htc_priv *priv = ista->htc_priv;
1285 struct ath_common *common = ath9k_hw_common(priv->ah);
1286 struct ath9k_htc_target_rate trate;
1288 mutex_lock(&priv->mutex);
1289 ath9k_htc_ps_wakeup(priv);
1291 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
1292 ath9k_htc_setup_rate(priv, sta, &trate);
1293 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1294 ath_dbg(common, CONFIG,
1295 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1296 sta->addr, be32_to_cpu(trate.capflags));
1298 ath_dbg(common, CONFIG,
1299 "Unable to update supported rates for sta: %pM\n",
1302 ath9k_htc_ps_restore(priv);
1303 mutex_unlock(&priv->mutex);
1306 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1307 struct ieee80211_vif *vif,
1308 struct ieee80211_sta *sta)
1310 struct ath9k_htc_priv *priv = hw->priv;
1311 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1314 mutex_lock(&priv->mutex);
1315 ath9k_htc_ps_wakeup(priv);
1316 ret = ath9k_htc_add_station(priv, vif, sta);
1318 INIT_WORK(&ista->rc_update_work, ath9k_htc_sta_rc_update_work);
1319 ista->htc_priv = priv;
1320 ath9k_htc_init_rate(priv, sta);
1322 ath9k_htc_ps_restore(priv);
1323 mutex_unlock(&priv->mutex);
1328 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1329 struct ieee80211_vif *vif,
1330 struct ieee80211_sta *sta)
1332 struct ath9k_htc_priv *priv = hw->priv;
1333 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1336 cancel_work_sync(&ista->rc_update_work);
1338 mutex_lock(&priv->mutex);
1339 ath9k_htc_ps_wakeup(priv);
1340 htc_sta_drain(priv->htc, ista->index);
1341 ret = ath9k_htc_remove_station(priv, vif, sta);
1342 ath9k_htc_ps_restore(priv);
1343 mutex_unlock(&priv->mutex);
1348 static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
1349 struct ieee80211_vif *vif,
1350 struct ieee80211_sta *sta, u32 changed)
1352 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1354 if (!(changed & IEEE80211_RC_SUPP_RATES_CHANGED))
1357 schedule_work(&ista->rc_update_work);
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 >= IEEE80211_NUM_ACS)
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[IEEE80211_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_TX;
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 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
1483 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1484 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1488 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv)
1490 if (priv->num_sta_assoc_vif == 1) {
1491 ieee80211_iterate_active_interfaces_atomic(
1492 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1493 ath9k_htc_bss_iter, priv);
1494 ath9k_htc_set_bssid(priv);
1498 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1499 struct ieee80211_vif *vif,
1500 struct ieee80211_bss_conf *bss_conf,
1503 struct ath9k_htc_priv *priv = hw->priv;
1504 struct ath_hw *ah = priv->ah;
1505 struct ath_common *common = ath9k_hw_common(ah);
1508 mutex_lock(&priv->mutex);
1509 ath9k_htc_ps_wakeup(priv);
1511 if (changed & BSS_CHANGED_ASSOC) {
1512 ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n",
1516 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1518 if (!bss_conf->assoc)
1519 clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1521 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1522 ath9k_htc_choose_set_bssid(priv);
1523 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
1524 ath9k_htc_start_ani(priv);
1525 else if (priv->num_sta_assoc_vif == 0)
1526 ath9k_htc_stop_ani(priv);
1530 if (changed & BSS_CHANGED_IBSS) {
1531 if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
1532 common->curaid = bss_conf->aid;
1533 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1534 ath9k_htc_set_bssid(priv);
1538 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1539 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1541 ath9k_htc_set_tsfadjust(priv, vif);
1542 priv->cur_beacon_conf.enable_beacon = 1;
1543 ath9k_htc_beacon_config(priv, vif);
1546 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1548 * Disable SWBA interrupt only if there are no
1549 * concurrent AP/mesh or IBSS interfaces.
1551 if ((priv->num_ap_vif + priv->num_mbss_vif <= 1) ||
1552 priv->num_ibss_vif) {
1553 ath_dbg(common, CONFIG,
1554 "Beacon disabled for BSS: %pM\n",
1556 priv->cur_beacon_conf.enable_beacon = 0;
1557 ath9k_htc_beacon_config(priv, vif);
1561 if (changed & BSS_CHANGED_BEACON_INT) {
1563 * Reset the HW TSF for the first AP or mesh interface.
1565 if (priv->nvifs == 1 &&
1566 ((priv->ah->opmode == NL80211_IFTYPE_AP &&
1567 vif->type == NL80211_IFTYPE_AP &&
1568 priv->num_ap_vif == 1) ||
1569 (priv->ah->opmode == NL80211_IFTYPE_MESH_POINT &&
1570 vif->type == NL80211_IFTYPE_MESH_POINT &&
1571 priv->num_mbss_vif == 1))) {
1572 set_bit(OP_TSF_RESET, &priv->op_flags);
1574 ath_dbg(common, CONFIG,
1575 "Beacon interval changed for BSS: %pM\n",
1577 ath9k_htc_beacon_config(priv, vif);
1580 if (changed & BSS_CHANGED_ERP_SLOT) {
1581 if (bss_conf->use_short_slot)
1585 if (vif->type == NL80211_IFTYPE_AP) {
1587 * Defer update, so that connected stations can adjust
1588 * their settings at the same time.
1589 * See beacon.c for more details
1591 priv->beacon.slottime = slottime;
1592 priv->beacon.updateslot = UPDATE;
1594 ah->slottime = slottime;
1595 ath9k_hw_init_global_settings(ah);
1599 if (changed & BSS_CHANGED_HT)
1600 ath9k_htc_update_rate(priv, vif, bss_conf);
1602 ath9k_htc_ps_restore(priv);
1603 mutex_unlock(&priv->mutex);
1606 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw,
1607 struct ieee80211_vif *vif)
1609 struct ath9k_htc_priv *priv = hw->priv;
1612 mutex_lock(&priv->mutex);
1613 ath9k_htc_ps_wakeup(priv);
1614 tsf = ath9k_hw_gettsf64(priv->ah);
1615 ath9k_htc_ps_restore(priv);
1616 mutex_unlock(&priv->mutex);
1621 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw,
1622 struct ieee80211_vif *vif, u64 tsf)
1624 struct ath9k_htc_priv *priv = hw->priv;
1626 mutex_lock(&priv->mutex);
1627 ath9k_htc_ps_wakeup(priv);
1628 ath9k_hw_settsf64(priv->ah, tsf);
1629 ath9k_htc_ps_restore(priv);
1630 mutex_unlock(&priv->mutex);
1633 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw,
1634 struct ieee80211_vif *vif)
1636 struct ath9k_htc_priv *priv = hw->priv;
1638 mutex_lock(&priv->mutex);
1639 ath9k_htc_ps_wakeup(priv);
1640 ath9k_hw_reset_tsf(priv->ah);
1641 ath9k_htc_ps_restore(priv);
1642 mutex_unlock(&priv->mutex);
1645 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1646 struct ieee80211_vif *vif,
1647 enum ieee80211_ampdu_mlme_action action,
1648 struct ieee80211_sta *sta,
1649 u16 tid, u16 *ssn, u8 buf_size)
1651 struct ath9k_htc_priv *priv = hw->priv;
1652 struct ath9k_htc_sta *ista;
1655 mutex_lock(&priv->mutex);
1656 ath9k_htc_ps_wakeup(priv);
1659 case IEEE80211_AMPDU_RX_START:
1661 case IEEE80211_AMPDU_RX_STOP:
1663 case IEEE80211_AMPDU_TX_START:
1664 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1666 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1668 case IEEE80211_AMPDU_TX_STOP_CONT:
1669 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1670 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1671 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1672 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1674 case IEEE80211_AMPDU_TX_OPERATIONAL:
1675 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1676 spin_lock_bh(&priv->tx.tx_lock);
1677 ista->tid_state[tid] = AGGR_OPERATIONAL;
1678 spin_unlock_bh(&priv->tx.tx_lock);
1681 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1684 ath9k_htc_ps_restore(priv);
1685 mutex_unlock(&priv->mutex);
1690 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1692 struct ath9k_htc_priv *priv = hw->priv;
1693 struct ath_common *common = ath9k_hw_common(priv->ah);
1695 mutex_lock(&priv->mutex);
1696 spin_lock_bh(&priv->beacon_lock);
1697 set_bit(ATH_OP_SCANNING, &common->op_flags);
1698 spin_unlock_bh(&priv->beacon_lock);
1699 cancel_work_sync(&priv->ps_work);
1700 ath9k_htc_stop_ani(priv);
1701 mutex_unlock(&priv->mutex);
1704 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1706 struct ath9k_htc_priv *priv = hw->priv;
1707 struct ath_common *common = ath9k_hw_common(priv->ah);
1709 mutex_lock(&priv->mutex);
1710 spin_lock_bh(&priv->beacon_lock);
1711 clear_bit(ATH_OP_SCANNING, &common->op_flags);
1712 spin_unlock_bh(&priv->beacon_lock);
1713 ath9k_htc_ps_wakeup(priv);
1714 ath9k_htc_vif_reconfig(priv);
1715 ath9k_htc_ps_restore(priv);
1716 mutex_unlock(&priv->mutex);
1719 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1724 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1727 struct ath9k_htc_priv *priv = hw->priv;
1729 mutex_lock(&priv->mutex);
1730 ath9k_htc_ps_wakeup(priv);
1731 priv->ah->coverage_class = coverage_class;
1732 ath9k_hw_init_global_settings(priv->ah);
1733 ath9k_htc_ps_restore(priv);
1734 mutex_unlock(&priv->mutex);
1738 * Currently, this is used only for selecting the minimum rate
1739 * for management frames, rate selection for data frames remain
1742 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw,
1743 struct ieee80211_vif *vif,
1744 const struct cfg80211_bitrate_mask *mask)
1746 struct ath9k_htc_priv *priv = hw->priv;
1747 struct ath_common *common = ath9k_hw_common(priv->ah);
1748 struct ath9k_htc_target_rate_mask tmask;
1749 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1753 memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask));
1755 tmask.vif_index = avp->index;
1756 tmask.band = IEEE80211_BAND_2GHZ;
1757 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy);
1759 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1762 "Unable to set 2G rate mask for "
1763 "interface at idx: %d\n", avp->index);
1767 tmask.band = IEEE80211_BAND_5GHZ;
1768 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy);
1770 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1773 "Unable to set 5G rate mask for "
1774 "interface at idx: %d\n", avp->index);
1778 ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n",
1779 mask->control[IEEE80211_BAND_2GHZ].legacy,
1780 mask->control[IEEE80211_BAND_5GHZ].legacy);
1786 static int ath9k_htc_get_stats(struct ieee80211_hw *hw,
1787 struct ieee80211_low_level_stats *stats)
1789 struct ath9k_htc_priv *priv = hw->priv;
1790 struct ath_hw *ah = priv->ah;
1791 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1793 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1794 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1795 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1796 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1801 struct base_eep_header *ath9k_htc_get_eeprom_base(struct ath9k_htc_priv *priv)
1803 struct base_eep_header *pBase = NULL;
1805 * This can be done since all the 3 EEPROM families have the
1806 * same base header upto a certain point, and we are interested in
1807 * the data only upto that point.
1810 if (AR_SREV_9271(priv->ah))
1811 pBase = (struct base_eep_header *)
1812 &priv->ah->eeprom.map4k.baseEepHeader;
1813 else if (priv->ah->hw_version.usbdev == AR9280_USB)
1814 pBase = (struct base_eep_header *)
1815 &priv->ah->eeprom.def.baseEepHeader;
1816 else if (priv->ah->hw_version.usbdev == AR9287_USB)
1817 pBase = (struct base_eep_header *)
1818 &priv->ah->eeprom.map9287.baseEepHeader;
1823 static int ath9k_htc_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant,
1826 struct ath9k_htc_priv *priv = hw->priv;
1827 struct base_eep_header *pBase = ath9k_htc_get_eeprom_base(priv);
1829 *tx_ant = pBase->txMask;
1830 *rx_ant = pBase->rxMask;
1838 struct ieee80211_ops ath9k_htc_ops = {
1840 .start = ath9k_htc_start,
1841 .stop = ath9k_htc_stop,
1842 .add_interface = ath9k_htc_add_interface,
1843 .remove_interface = ath9k_htc_remove_interface,
1844 .config = ath9k_htc_config,
1845 .configure_filter = ath9k_htc_configure_filter,
1846 .sta_add = ath9k_htc_sta_add,
1847 .sta_remove = ath9k_htc_sta_remove,
1848 .conf_tx = ath9k_htc_conf_tx,
1849 .sta_rc_update = ath9k_htc_sta_rc_update,
1850 .bss_info_changed = ath9k_htc_bss_info_changed,
1851 .set_key = ath9k_htc_set_key,
1852 .get_tsf = ath9k_htc_get_tsf,
1853 .set_tsf = ath9k_htc_set_tsf,
1854 .reset_tsf = ath9k_htc_reset_tsf,
1855 .ampdu_action = ath9k_htc_ampdu_action,
1856 .sw_scan_start = ath9k_htc_sw_scan_start,
1857 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1858 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1859 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1860 .set_coverage_class = ath9k_htc_set_coverage_class,
1861 .set_bitrate_mask = ath9k_htc_set_bitrate_mask,
1862 .get_stats = ath9k_htc_get_stats,
1863 .get_antenna = ath9k_htc_get_antenna,
1865 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
1866 .get_et_sset_count = ath9k_htc_get_et_sset_count,
1867 .get_et_stats = ath9k_htc_get_et_stats,
1868 .get_et_strings = ath9k_htc_get_et_strings,