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;
101 if (bss_conf->assoc) {
102 priv->rearm_ani = true;
103 priv->reconfig_beacon = true;
107 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv)
109 priv->rearm_ani = false;
110 priv->reconfig_beacon = false;
112 ieee80211_iterate_active_interfaces_atomic(
113 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
114 ath9k_htc_vif_iter, priv);
116 ath9k_htc_start_ani(priv);
118 if (priv->reconfig_beacon) {
119 ath9k_htc_ps_wakeup(priv);
120 ath9k_htc_beacon_reconfig(priv);
121 ath9k_htc_ps_restore(priv);
125 static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
127 struct ath9k_vif_iter_data *iter_data = data;
130 if (iter_data->hw_macaddr != NULL) {
131 for (i = 0; i < ETH_ALEN; i++)
132 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
134 iter_data->hw_macaddr = mac;
138 static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
139 struct ieee80211_vif *vif)
141 struct ath_common *common = ath9k_hw_common(priv->ah);
142 struct ath9k_vif_iter_data iter_data;
145 * Pick the MAC address of the first interface as the new hardware
146 * MAC address. The hardware will use it together with the BSSID mask
147 * when matching addresses.
149 iter_data.hw_macaddr = NULL;
150 memset(&iter_data.mask, 0xff, ETH_ALEN);
153 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
155 /* Get list of all active MAC addresses */
156 ieee80211_iterate_active_interfaces_atomic(
157 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
158 ath9k_htc_bssid_iter, &iter_data);
160 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
162 if (iter_data.hw_macaddr)
163 memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
165 ath_hw_setbssidmask(common);
168 static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv)
170 if (priv->num_ibss_vif)
171 priv->ah->opmode = NL80211_IFTYPE_ADHOC;
172 else if (priv->num_ap_vif)
173 priv->ah->opmode = NL80211_IFTYPE_AP;
174 else if (priv->num_mbss_vif)
175 priv->ah->opmode = NL80211_IFTYPE_MESH_POINT;
177 priv->ah->opmode = NL80211_IFTYPE_STATION;
179 ath9k_hw_setopmode(priv->ah);
182 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
184 struct ath_hw *ah = priv->ah;
185 struct ath_common *common = ath9k_hw_common(ah);
186 struct ieee80211_channel *channel = priv->hw->conf.chandef.chan;
187 struct ath9k_hw_cal_data *caldata = NULL;
188 enum htc_phymode mode;
193 mutex_lock(&priv->mutex);
194 ath9k_htc_ps_wakeup(priv);
196 ath9k_htc_stop_ani(priv);
197 ieee80211_stop_queues(priv->hw);
199 del_timer_sync(&priv->tx.cleanup_timer);
200 ath9k_htc_tx_drain(priv);
202 WMI_CMD(WMI_DISABLE_INTR_CMDID);
203 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
204 WMI_CMD(WMI_STOP_RECV_CMDID);
206 ath9k_wmi_event_drain(priv);
208 caldata = &priv->caldata;
209 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
212 "Unable to reset device (%u Mhz) reset status %d\n",
213 channel->center_freq, ret);
216 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
219 WMI_CMD(WMI_START_RECV_CMDID);
220 ath9k_host_rx_init(priv);
222 mode = ath9k_htc_get_curmode(priv, ah->curchan);
223 htc_mode = cpu_to_be16(mode);
224 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
226 WMI_CMD(WMI_ENABLE_INTR_CMDID);
227 htc_start(priv->htc);
228 ath9k_htc_vif_reconfig(priv);
229 ieee80211_wake_queues(priv->hw);
231 mod_timer(&priv->tx.cleanup_timer,
232 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
234 ath9k_htc_ps_restore(priv);
235 mutex_unlock(&priv->mutex);
238 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
239 struct ieee80211_hw *hw,
240 struct ath9k_channel *hchan)
242 struct ath_hw *ah = priv->ah;
243 struct ath_common *common = ath9k_hw_common(ah);
244 struct ieee80211_conf *conf = &common->hw->conf;
246 struct ieee80211_channel *channel = hw->conf.chandef.chan;
247 struct ath9k_hw_cal_data *caldata = NULL;
248 enum htc_phymode mode;
253 if (test_bit(ATH_OP_INVALID, &common->op_flags))
256 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
258 ath9k_htc_ps_wakeup(priv);
260 del_timer_sync(&priv->tx.cleanup_timer);
261 ath9k_htc_tx_drain(priv);
263 WMI_CMD(WMI_DISABLE_INTR_CMDID);
264 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
265 WMI_CMD(WMI_STOP_RECV_CMDID);
267 ath9k_wmi_event_drain(priv);
269 ath_dbg(common, CONFIG,
270 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
271 priv->ah->curchan->channel,
272 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
276 caldata = &priv->caldata;
278 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
281 "Unable to reset channel (%u Mhz) reset status %d\n",
282 channel->center_freq, ret);
286 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
289 WMI_CMD(WMI_START_RECV_CMDID);
293 ath9k_host_rx_init(priv);
295 mode = ath9k_htc_get_curmode(priv, hchan);
296 htc_mode = cpu_to_be16(mode);
297 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
301 WMI_CMD(WMI_ENABLE_INTR_CMDID);
305 htc_start(priv->htc);
307 if (!test_bit(ATH_OP_SCANNING, &common->op_flags) &&
308 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
309 ath9k_htc_vif_reconfig(priv);
311 mod_timer(&priv->tx.cleanup_timer,
312 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
315 ath9k_htc_ps_restore(priv);
320 * Monitor mode handling is a tad complicated because the firmware requires
321 * an interface to be created exclusively, while mac80211 doesn't associate
322 * an interface with the mode.
324 * So, for now, only one monitor interface can be configured.
326 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
328 struct ath_common *common = ath9k_hw_common(priv->ah);
329 struct ath9k_htc_target_vif hvif;
333 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
334 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
335 hvif.index = priv->mon_vif_idx;
336 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
338 ath_err(common, "Unable to remove monitor interface at idx: %d\n",
343 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
346 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
348 struct ath_common *common = ath9k_hw_common(priv->ah);
349 struct ath9k_htc_target_vif hvif;
350 struct ath9k_htc_target_sta tsta;
351 int ret = 0, sta_idx;
354 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
355 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
360 sta_idx = ffz(priv->sta_slot);
361 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
369 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
370 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
372 hvif.opmode = HTC_M_MONITOR;
373 hvif.index = ffz(priv->vif_slot);
375 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
380 * Assign the monitor interface index as a special case here.
381 * This is needed when the interface is brought down.
383 priv->mon_vif_idx = hvif.index;
384 priv->vif_slot |= (1 << hvif.index);
387 * Set the hardware mode to monitor only if there are no
391 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
396 * Associate a station with the interface for packet injection.
398 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
400 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
403 tsta.sta_index = sta_idx;
404 tsta.vif_index = hvif.index;
405 tsta.maxampdu = cpu_to_be16(0xffff);
407 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
409 ath_err(common, "Unable to add station entry for monitor mode\n");
413 priv->sta_slot |= (1 << sta_idx);
415 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
416 priv->ah->is_monitoring = true;
418 ath_dbg(common, CONFIG,
419 "Attached a monitor interface at idx: %d, sta idx: %d\n",
420 priv->mon_vif_idx, sta_idx);
426 * Remove the interface from the target.
428 __ath9k_htc_remove_monitor_interface(priv);
430 ath_dbg(common, FATAL, "Unable to attach a monitor interface\n");
435 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
437 struct ath_common *common = ath9k_hw_common(priv->ah);
441 __ath9k_htc_remove_monitor_interface(priv);
443 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
445 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
447 ath_err(common, "Unable to remove station entry for monitor mode\n");
451 priv->sta_slot &= ~(1 << sta_idx);
453 priv->ah->is_monitoring = false;
455 ath_dbg(common, CONFIG,
456 "Removed a monitor interface at idx: %d, sta idx: %d\n",
457 priv->mon_vif_idx, sta_idx);
462 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
463 struct ieee80211_vif *vif,
464 struct ieee80211_sta *sta)
466 struct ath_common *common = ath9k_hw_common(priv->ah);
467 struct ath9k_htc_target_sta tsta;
468 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
469 struct ath9k_htc_sta *ista;
474 if (priv->nstations >= ATH9K_HTC_MAX_STA)
477 sta_idx = ffz(priv->sta_slot);
478 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
481 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
484 ista = (struct ath9k_htc_sta *) sta->drv_priv;
485 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
486 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
487 ista->index = sta_idx;
489 maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
490 sta->ht_cap.ampdu_factor);
491 tsta.maxampdu = cpu_to_be16(maxampdu);
493 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
495 tsta.maxampdu = cpu_to_be16(0xffff);
498 tsta.sta_index = sta_idx;
499 tsta.vif_index = avp->index;
501 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
505 "Unable to add station entry for: %pM\n",
511 ath_dbg(common, CONFIG,
512 "Added a station entry for: %pM (idx: %d)\n",
513 sta->addr, tsta.sta_index);
515 ath_dbg(common, CONFIG,
516 "Added a station entry for VIF %d (idx: %d)\n",
517 avp->index, tsta.sta_index);
520 priv->sta_slot |= (1 << sta_idx);
523 priv->vif_sta_pos[avp->index] = sta_idx;
528 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
529 struct ieee80211_vif *vif,
530 struct ieee80211_sta *sta)
532 struct ath_common *common = ath9k_hw_common(priv->ah);
533 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
534 struct ath9k_htc_sta *ista;
539 ista = (struct ath9k_htc_sta *) sta->drv_priv;
540 sta_idx = ista->index;
542 sta_idx = priv->vif_sta_pos[avp->index];
545 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
549 "Unable to remove station entry for: %pM\n",
555 ath_dbg(common, CONFIG,
556 "Removed a station entry for: %pM (idx: %d)\n",
559 ath_dbg(common, CONFIG,
560 "Removed a station entry for VIF %d (idx: %d)\n",
561 avp->index, sta_idx);
564 priv->sta_slot &= ~(1 << sta_idx);
570 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
573 struct ath9k_htc_cap_target tcap;
577 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
579 tcap.ampdu_limit = cpu_to_be32(0xffff);
580 tcap.ampdu_subframes = 0xff;
581 tcap.enable_coex = enable_coex;
582 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
584 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
589 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
590 struct ieee80211_sta *sta,
591 struct ath9k_htc_target_rate *trate)
593 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
594 struct ieee80211_supported_band *sband;
598 sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band];
600 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
601 if (sta->supp_rates[sband->band] & BIT(i)) {
602 trate->rates.legacy_rates.rs_rates[j]
603 = (sband->bitrates[i].bitrate * 2) / 10;
607 trate->rates.legacy_rates.rs_nrates = j;
609 if (sta->ht_cap.ht_supported) {
610 for (i = 0, j = 0; i < 77; i++) {
611 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
612 trate->rates.ht_rates.rs_rates[j++] = i;
613 if (j == ATH_HTC_RATE_MAX)
616 trate->rates.ht_rates.rs_nrates = j;
618 caps = WLAN_RC_HT_FLAG;
619 if (sta->ht_cap.cap & IEEE80211_HT_CAP_RX_STBC)
620 caps |= ATH_RC_TX_STBC_FLAG;
621 if (sta->ht_cap.mcs.rx_mask[1])
622 caps |= WLAN_RC_DS_FLAG;
623 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
624 (conf_is_ht40(&priv->hw->conf)))
625 caps |= WLAN_RC_40_FLAG;
626 if (conf_is_ht40(&priv->hw->conf) &&
627 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
628 caps |= WLAN_RC_SGI_FLAG;
629 else if (conf_is_ht20(&priv->hw->conf) &&
630 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
631 caps |= WLAN_RC_SGI_FLAG;
634 trate->sta_index = ista->index;
636 trate->capflags = cpu_to_be32(caps);
639 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
640 struct ath9k_htc_target_rate *trate)
642 struct ath_common *common = ath9k_hw_common(priv->ah);
646 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
649 "Unable to initialize Rate information on target\n");
655 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
656 struct ieee80211_sta *sta)
658 struct ath_common *common = ath9k_hw_common(priv->ah);
659 struct ath9k_htc_target_rate trate;
662 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
663 ath9k_htc_setup_rate(priv, sta, &trate);
664 ret = ath9k_htc_send_rate_cmd(priv, &trate);
666 ath_dbg(common, CONFIG,
667 "Updated target sta: %pM, rate caps: 0x%X\n",
668 sta->addr, be32_to_cpu(trate.capflags));
671 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
672 struct ieee80211_vif *vif,
673 struct ieee80211_bss_conf *bss_conf)
675 struct ath_common *common = ath9k_hw_common(priv->ah);
676 struct ath9k_htc_target_rate trate;
677 struct ieee80211_sta *sta;
680 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
683 sta = ieee80211_find_sta(vif, bss_conf->bssid);
688 ath9k_htc_setup_rate(priv, sta, &trate);
691 ret = ath9k_htc_send_rate_cmd(priv, &trate);
693 ath_dbg(common, CONFIG,
694 "Updated target sta: %pM, rate caps: 0x%X\n",
695 bss_conf->bssid, be32_to_cpu(trate.capflags));
698 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
699 struct ieee80211_vif *vif,
700 struct ieee80211_sta *sta,
701 enum ieee80211_ampdu_mlme_action action,
704 struct ath_common *common = ath9k_hw_common(priv->ah);
705 struct ath9k_htc_target_aggr aggr;
706 struct ath9k_htc_sta *ista;
710 if (tid >= ATH9K_HTC_MAX_TID)
713 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
714 ista = (struct ath9k_htc_sta *) sta->drv_priv;
716 aggr.sta_index = ista->index;
717 aggr.tidno = tid & 0xf;
718 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
720 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
722 ath_dbg(common, CONFIG,
723 "Unable to %s TX aggregation for (%pM, %d)\n",
724 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
726 ath_dbg(common, CONFIG,
727 "%s TX aggregation for (%pM, %d)\n",
728 (aggr.aggr_enable) ? "Starting" : "Stopping",
731 spin_lock_bh(&priv->tx.tx_lock);
732 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
733 spin_unlock_bh(&priv->tx.tx_lock);
742 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
744 struct ath_common *common = ath9k_hw_common(priv->ah);
745 unsigned long timestamp = jiffies_to_msecs(jiffies);
747 common->ani.longcal_timer = timestamp;
748 common->ani.shortcal_timer = timestamp;
749 common->ani.checkani_timer = timestamp;
751 set_bit(ATH_OP_ANI_RUN, &common->op_flags);
753 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
754 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
757 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
759 struct ath_common *common = ath9k_hw_common(priv->ah);
760 cancel_delayed_work_sync(&priv->ani_work);
761 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
764 void ath9k_htc_ani_work(struct work_struct *work)
766 struct ath9k_htc_priv *priv =
767 container_of(work, struct ath9k_htc_priv, ani_work.work);
768 struct ath_hw *ah = priv->ah;
769 struct ath_common *common = ath9k_hw_common(ah);
770 bool longcal = false;
771 bool shortcal = false;
772 bool aniflag = false;
773 unsigned int timestamp = jiffies_to_msecs(jiffies);
774 u32 cal_interval, short_cal_interval;
776 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
777 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
779 /* Only calibrate if awake */
780 if (ah->power_mode != ATH9K_PM_AWAKE)
783 /* Long calibration runs independently of short calibration. */
784 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
786 ath_dbg(common, ANI, "longcal @%lu\n", jiffies);
787 common->ani.longcal_timer = timestamp;
790 /* Short calibration applies only while caldone is false */
791 if (!common->ani.caldone) {
792 if ((timestamp - common->ani.shortcal_timer) >=
793 short_cal_interval) {
795 ath_dbg(common, ANI, "shortcal @%lu\n", jiffies);
796 common->ani.shortcal_timer = timestamp;
797 common->ani.resetcal_timer = timestamp;
800 if ((timestamp - common->ani.resetcal_timer) >=
801 ATH_RESTART_CALINTERVAL) {
802 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
803 if (common->ani.caldone)
804 common->ani.resetcal_timer = timestamp;
808 /* Verify whether we must check ANI */
809 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
811 common->ani.checkani_timer = timestamp;
814 /* Skip all processing if there's nothing to do. */
815 if (longcal || shortcal || aniflag) {
817 ath9k_htc_ps_wakeup(priv);
819 /* Call ANI routine if necessary */
821 ath9k_hw_ani_monitor(ah, ah->curchan);
823 /* Perform calibration if necessary */
824 if (longcal || shortcal)
825 common->ani.caldone =
826 ath9k_hw_calibrate(ah, ah->curchan,
827 ah->rxchainmask, longcal);
829 ath9k_htc_ps_restore(priv);
834 * Set timer interval based on previous results.
835 * The interval must be the shortest necessary to satisfy ANI,
836 * short calibration and long calibration.
838 cal_interval = ATH_LONG_CALINTERVAL;
839 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
840 if (!common->ani.caldone)
841 cal_interval = min(cal_interval, (u32)short_cal_interval);
843 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
844 msecs_to_jiffies(cal_interval));
847 /**********************/
848 /* mac80211 Callbacks */
849 /**********************/
851 static void ath9k_htc_tx(struct ieee80211_hw *hw,
852 struct ieee80211_tx_control *control,
855 struct ieee80211_hdr *hdr;
856 struct ath9k_htc_priv *priv = hw->priv;
857 struct ath_common *common = ath9k_hw_common(priv->ah);
858 int padpos, padsize, ret, slot;
860 hdr = (struct ieee80211_hdr *) skb->data;
862 /* Add the padding after the header if this is not already done */
863 padpos = ieee80211_hdrlen(hdr->frame_control);
864 padsize = padpos & 3;
865 if (padsize && skb->len > padpos) {
866 if (skb_headroom(skb) < padsize) {
867 ath_dbg(common, XMIT, "No room for padding\n");
870 skb_push(skb, padsize);
871 memmove(skb->data, skb->data + padsize, padpos);
874 slot = ath9k_htc_tx_get_slot(priv);
876 ath_dbg(common, XMIT, "No free TX slot\n");
880 ret = ath9k_htc_tx_start(priv, control->sta, skb, slot, false);
882 ath_dbg(common, XMIT, "Tx failed\n");
886 ath9k_htc_check_stop_queues(priv);
891 ath9k_htc_tx_clear_slot(priv, slot);
893 dev_kfree_skb_any(skb);
896 static int ath9k_htc_start(struct ieee80211_hw *hw)
898 struct ath9k_htc_priv *priv = hw->priv;
899 struct ath_hw *ah = priv->ah;
900 struct ath_common *common = ath9k_hw_common(ah);
901 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
902 struct ath9k_channel *init_channel;
904 enum htc_phymode mode;
908 mutex_lock(&priv->mutex);
910 ath_dbg(common, CONFIG,
911 "Starting driver with initial channel: %d MHz\n",
912 curchan->center_freq);
914 /* Ensure that HW is awake before flushing RX */
915 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
916 WMI_CMD(WMI_FLUSH_RECV_CMDID);
918 /* setup initial channel */
919 init_channel = ath9k_cmn_get_channel(hw, ah, &hw->conf.chandef);
921 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
924 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
925 ret, curchan->center_freq);
926 mutex_unlock(&priv->mutex);
930 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
933 mode = ath9k_htc_get_curmode(priv, init_channel);
934 htc_mode = cpu_to_be16(mode);
935 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
936 WMI_CMD(WMI_ATH_INIT_CMDID);
937 WMI_CMD(WMI_START_RECV_CMDID);
939 ath9k_host_rx_init(priv);
941 ret = ath9k_htc_update_cap_target(priv, 0);
943 ath_dbg(common, CONFIG,
944 "Failed to update capability in target\n");
946 clear_bit(ATH_OP_INVALID, &common->op_flags);
947 htc_start(priv->htc);
949 spin_lock_bh(&priv->tx.tx_lock);
950 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
951 spin_unlock_bh(&priv->tx.tx_lock);
953 ieee80211_wake_queues(hw);
955 mod_timer(&priv->tx.cleanup_timer,
956 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
958 ath9k_htc_start_btcoex(priv);
960 mutex_unlock(&priv->mutex);
965 static void ath9k_htc_stop(struct ieee80211_hw *hw)
967 struct ath9k_htc_priv *priv = hw->priv;
968 struct ath_hw *ah = priv->ah;
969 struct ath_common *common = ath9k_hw_common(ah);
970 int ret __attribute__ ((unused));
973 mutex_lock(&priv->mutex);
975 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
976 ath_dbg(common, ANY, "Device not present\n");
977 mutex_unlock(&priv->mutex);
981 ath9k_htc_ps_wakeup(priv);
983 WMI_CMD(WMI_DISABLE_INTR_CMDID);
984 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
985 WMI_CMD(WMI_STOP_RECV_CMDID);
987 tasklet_kill(&priv->rx_tasklet);
989 del_timer_sync(&priv->tx.cleanup_timer);
990 ath9k_htc_tx_drain(priv);
991 ath9k_wmi_event_drain(priv);
993 mutex_unlock(&priv->mutex);
995 /* Cancel all the running timers/work .. */
996 cancel_work_sync(&priv->fatal_work);
997 cancel_work_sync(&priv->ps_work);
999 #ifdef CONFIG_MAC80211_LEDS
1000 cancel_work_sync(&priv->led_work);
1002 ath9k_htc_stop_ani(priv);
1004 mutex_lock(&priv->mutex);
1006 ath9k_htc_stop_btcoex(priv);
1008 /* Remove a monitor interface if it's present. */
1009 if (priv->ah->is_monitoring)
1010 ath9k_htc_remove_monitor_interface(priv);
1012 ath9k_hw_phy_disable(ah);
1013 ath9k_hw_disable(ah);
1014 ath9k_htc_ps_restore(priv);
1015 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1017 set_bit(ATH_OP_INVALID, &common->op_flags);
1019 ath_dbg(common, CONFIG, "Driver halt\n");
1020 mutex_unlock(&priv->mutex);
1023 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1024 struct ieee80211_vif *vif)
1026 struct ath9k_htc_priv *priv = hw->priv;
1027 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1028 struct ath_common *common = ath9k_hw_common(priv->ah);
1029 struct ath9k_htc_target_vif hvif;
1033 mutex_lock(&priv->mutex);
1035 ath9k_htc_ps_wakeup(priv);
1036 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1037 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1039 switch (vif->type) {
1040 case NL80211_IFTYPE_STATION:
1041 hvif.opmode = HTC_M_STA;
1043 case NL80211_IFTYPE_ADHOC:
1044 hvif.opmode = HTC_M_IBSS;
1046 case NL80211_IFTYPE_AP:
1047 hvif.opmode = HTC_M_HOSTAP;
1049 case NL80211_IFTYPE_MESH_POINT:
1050 hvif.opmode = HTC_M_WDS; /* close enough */
1054 "Interface type %d not yet supported\n", vif->type);
1059 /* Index starts from zero on the target */
1060 avp->index = hvif.index = ffz(priv->vif_slot);
1061 hvif.rtsthreshold = cpu_to_be16(2304);
1062 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1067 * We need a node in target to tx mgmt frames
1068 * before association.
1070 ret = ath9k_htc_add_station(priv, vif, NULL);
1072 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1076 ath9k_htc_set_mac_bssid_mask(priv, vif);
1078 priv->vif_slot |= (1 << avp->index);
1081 INC_VIF(priv, vif->type);
1083 if ((vif->type == NL80211_IFTYPE_AP) ||
1084 (vif->type == NL80211_IFTYPE_MESH_POINT) ||
1085 (vif->type == NL80211_IFTYPE_ADHOC))
1086 ath9k_htc_assign_bslot(priv, vif);
1088 ath9k_htc_set_opmode(priv);
1090 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1091 !test_bit(ATH_OP_ANI_RUN, &common->op_flags)) {
1092 ath9k_hw_set_tsfadjust(priv->ah, true);
1093 ath9k_htc_start_ani(priv);
1096 ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n",
1097 vif->type, avp->index);
1100 ath9k_htc_ps_restore(priv);
1101 mutex_unlock(&priv->mutex);
1106 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1107 struct ieee80211_vif *vif)
1109 struct ath9k_htc_priv *priv = hw->priv;
1110 struct ath_common *common = ath9k_hw_common(priv->ah);
1111 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1112 struct ath9k_htc_target_vif hvif;
1116 mutex_lock(&priv->mutex);
1117 ath9k_htc_ps_wakeup(priv);
1119 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1120 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1121 hvif.index = avp->index;
1122 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1124 ath_err(common, "Unable to remove interface at idx: %d\n",
1128 priv->vif_slot &= ~(1 << avp->index);
1130 ath9k_htc_remove_station(priv, vif, NULL);
1132 DEC_VIF(priv, vif->type);
1134 if ((vif->type == NL80211_IFTYPE_AP) ||
1135 vif->type == NL80211_IFTYPE_MESH_POINT ||
1136 (vif->type == NL80211_IFTYPE_ADHOC))
1137 ath9k_htc_remove_bslot(priv, vif);
1139 ath9k_htc_set_opmode(priv);
1141 ath9k_htc_set_mac_bssid_mask(priv, vif);
1144 * Stop ANI only if there are no associated station interfaces.
1146 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1147 priv->rearm_ani = false;
1148 ieee80211_iterate_active_interfaces_atomic(
1149 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1150 ath9k_htc_vif_iter, priv);
1151 if (!priv->rearm_ani)
1152 ath9k_htc_stop_ani(priv);
1155 ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index);
1157 ath9k_htc_ps_restore(priv);
1158 mutex_unlock(&priv->mutex);
1161 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1163 struct ath9k_htc_priv *priv = hw->priv;
1164 struct ath_common *common = ath9k_hw_common(priv->ah);
1165 struct ieee80211_conf *conf = &hw->conf;
1166 bool chip_reset = false;
1169 mutex_lock(&priv->mutex);
1170 ath9k_htc_ps_wakeup(priv);
1172 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1173 mutex_lock(&priv->htc_pm_lock);
1175 priv->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1179 mutex_unlock(&priv->htc_pm_lock);
1183 * Monitor interface should be added before
1184 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1186 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1187 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1188 !priv->ah->is_monitoring)
1189 ath9k_htc_add_monitor_interface(priv);
1190 else if (priv->ah->is_monitoring)
1191 ath9k_htc_remove_monitor_interface(priv);
1194 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
1195 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
1196 int pos = curchan->hw_value;
1198 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
1199 curchan->center_freq);
1201 ath9k_cmn_get_channel(hw, priv->ah, &hw->conf.chandef);
1202 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1203 ath_err(common, "Unable to set channel\n");
1210 if (changed & IEEE80211_CONF_CHANGE_PS) {
1211 if (conf->flags & IEEE80211_CONF_PS) {
1212 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1213 priv->ps_enabled = true;
1215 priv->ps_enabled = false;
1216 cancel_work_sync(&priv->ps_work);
1217 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1221 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1222 priv->txpowlimit = 2 * conf->power_level;
1223 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1224 priv->txpowlimit, &priv->curtxpow);
1228 ath9k_htc_ps_restore(priv);
1229 mutex_unlock(&priv->mutex);
1233 #define SUPPORTED_FILTERS \
1234 (FIF_PROMISC_IN_BSS | \
1239 FIF_BCN_PRBRESP_PROMISC | \
1243 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1244 unsigned int changed_flags,
1245 unsigned int *total_flags,
1248 struct ath9k_htc_priv *priv = hw->priv;
1249 struct ath_common *common = ath9k_hw_common(priv->ah);
1252 mutex_lock(&priv->mutex);
1253 changed_flags &= SUPPORTED_FILTERS;
1254 *total_flags &= SUPPORTED_FILTERS;
1256 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
1257 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1258 "Unable to configure filter on invalid state\n");
1259 mutex_unlock(&priv->mutex);
1262 ath9k_htc_ps_wakeup(priv);
1264 priv->rxfilter = *total_flags;
1265 rfilt = ath9k_htc_calcrxfilter(priv);
1266 ath9k_hw_setrxfilter(priv->ah, rfilt);
1268 ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n",
1271 ath9k_htc_ps_restore(priv);
1272 mutex_unlock(&priv->mutex);
1275 static void ath9k_htc_sta_rc_update_work(struct work_struct *work)
1277 struct ath9k_htc_sta *ista =
1278 container_of(work, struct ath9k_htc_sta, rc_update_work);
1279 struct ieee80211_sta *sta =
1280 container_of((void *)ista, struct ieee80211_sta, drv_priv);
1281 struct ath9k_htc_priv *priv = ista->htc_priv;
1282 struct ath_common *common = ath9k_hw_common(priv->ah);
1283 struct ath9k_htc_target_rate trate;
1285 mutex_lock(&priv->mutex);
1286 ath9k_htc_ps_wakeup(priv);
1288 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
1289 ath9k_htc_setup_rate(priv, sta, &trate);
1290 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1291 ath_dbg(common, CONFIG,
1292 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1293 sta->addr, be32_to_cpu(trate.capflags));
1295 ath_dbg(common, CONFIG,
1296 "Unable to update supported rates for sta: %pM\n",
1299 ath9k_htc_ps_restore(priv);
1300 mutex_unlock(&priv->mutex);
1303 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1304 struct ieee80211_vif *vif,
1305 struct ieee80211_sta *sta)
1307 struct ath9k_htc_priv *priv = hw->priv;
1308 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1311 mutex_lock(&priv->mutex);
1312 ath9k_htc_ps_wakeup(priv);
1313 ret = ath9k_htc_add_station(priv, vif, sta);
1315 INIT_WORK(&ista->rc_update_work, ath9k_htc_sta_rc_update_work);
1316 ista->htc_priv = priv;
1317 ath9k_htc_init_rate(priv, sta);
1319 ath9k_htc_ps_restore(priv);
1320 mutex_unlock(&priv->mutex);
1325 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1326 struct ieee80211_vif *vif,
1327 struct ieee80211_sta *sta)
1329 struct ath9k_htc_priv *priv = hw->priv;
1330 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1333 cancel_work_sync(&ista->rc_update_work);
1335 mutex_lock(&priv->mutex);
1336 ath9k_htc_ps_wakeup(priv);
1337 htc_sta_drain(priv->htc, ista->index);
1338 ret = ath9k_htc_remove_station(priv, vif, sta);
1339 ath9k_htc_ps_restore(priv);
1340 mutex_unlock(&priv->mutex);
1345 static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
1346 struct ieee80211_vif *vif,
1347 struct ieee80211_sta *sta, u32 changed)
1349 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1351 if (!(changed & IEEE80211_RC_SUPP_RATES_CHANGED))
1354 schedule_work(&ista->rc_update_work);
1357 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
1358 struct ieee80211_vif *vif, u16 queue,
1359 const struct ieee80211_tx_queue_params *params)
1361 struct ath9k_htc_priv *priv = hw->priv;
1362 struct ath_common *common = ath9k_hw_common(priv->ah);
1363 struct ath9k_tx_queue_info qi;
1366 if (queue >= IEEE80211_NUM_ACS)
1369 mutex_lock(&priv->mutex);
1370 ath9k_htc_ps_wakeup(priv);
1372 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1374 qi.tqi_aifs = params->aifs;
1375 qi.tqi_cwmin = params->cw_min;
1376 qi.tqi_cwmax = params->cw_max;
1377 qi.tqi_burstTime = params->txop * 32;
1379 qnum = get_hw_qnum(queue, priv->hwq_map);
1381 ath_dbg(common, CONFIG,
1382 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1383 queue, qnum, params->aifs, params->cw_min,
1384 params->cw_max, params->txop);
1386 ret = ath_htc_txq_update(priv, qnum, &qi);
1388 ath_err(common, "TXQ Update failed\n");
1392 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1393 (qnum == priv->hwq_map[IEEE80211_AC_BE]))
1394 ath9k_htc_beaconq_config(priv);
1396 ath9k_htc_ps_restore(priv);
1397 mutex_unlock(&priv->mutex);
1402 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1403 enum set_key_cmd cmd,
1404 struct ieee80211_vif *vif,
1405 struct ieee80211_sta *sta,
1406 struct ieee80211_key_conf *key)
1408 struct ath9k_htc_priv *priv = hw->priv;
1409 struct ath_common *common = ath9k_hw_common(priv->ah);
1412 if (htc_modparam_nohwcrypt)
1415 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1416 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1417 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1418 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1419 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1421 * For now, disable hw crypto for the RSN IBSS group keys. This
1422 * could be optimized in the future to use a modified key cache
1423 * design to support per-STA RX GTK, but until that gets
1424 * implemented, use of software crypto for group addressed
1425 * frames is a acceptable to allow RSN IBSS to be used.
1430 mutex_lock(&priv->mutex);
1431 ath_dbg(common, CONFIG, "Set HW Key\n");
1432 ath9k_htc_ps_wakeup(priv);
1436 ret = ath_key_config(common, vif, sta, key);
1438 key->hw_key_idx = ret;
1439 /* push IV and Michael MIC generation to stack */
1440 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1441 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1442 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1443 if (priv->ah->sw_mgmt_crypto &&
1444 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1445 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1450 ath_key_delete(common, key);
1456 ath9k_htc_ps_restore(priv);
1457 mutex_unlock(&priv->mutex);
1462 static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv)
1464 struct ath_common *common = ath9k_hw_common(priv->ah);
1466 ath9k_hw_write_associd(priv->ah);
1467 ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
1468 common->curbssid, common->curaid);
1471 static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1473 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1474 struct ath_common *common = ath9k_hw_common(priv->ah);
1475 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1477 if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) {
1478 common->curaid = bss_conf->aid;
1479 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
1480 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1481 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1485 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv)
1487 if (priv->num_sta_assoc_vif == 1) {
1488 ieee80211_iterate_active_interfaces_atomic(
1489 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1490 ath9k_htc_bss_iter, priv);
1491 ath9k_htc_set_bssid(priv);
1495 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1496 struct ieee80211_vif *vif,
1497 struct ieee80211_bss_conf *bss_conf,
1500 struct ath9k_htc_priv *priv = hw->priv;
1501 struct ath_hw *ah = priv->ah;
1502 struct ath_common *common = ath9k_hw_common(ah);
1505 mutex_lock(&priv->mutex);
1506 ath9k_htc_ps_wakeup(priv);
1508 if (changed & BSS_CHANGED_ASSOC) {
1509 ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n",
1513 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1515 if (!bss_conf->assoc)
1516 clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1518 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1519 ath9k_htc_choose_set_bssid(priv);
1520 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
1521 ath9k_htc_start_ani(priv);
1522 else if (priv->num_sta_assoc_vif == 0)
1523 ath9k_htc_stop_ani(priv);
1527 if (changed & BSS_CHANGED_IBSS) {
1528 if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
1529 common->curaid = bss_conf->aid;
1530 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1531 ath9k_htc_set_bssid(priv);
1535 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1536 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1538 ath9k_htc_set_tsfadjust(priv, vif);
1539 priv->cur_beacon_conf.enable_beacon = 1;
1540 ath9k_htc_beacon_config(priv, vif);
1543 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1545 * Disable SWBA interrupt only if there are no
1546 * concurrent AP/mesh or IBSS interfaces.
1548 if ((priv->num_ap_vif + priv->num_mbss_vif <= 1) ||
1549 priv->num_ibss_vif) {
1550 ath_dbg(common, CONFIG,
1551 "Beacon disabled for BSS: %pM\n",
1553 priv->cur_beacon_conf.enable_beacon = 0;
1554 ath9k_htc_beacon_config(priv, vif);
1558 if (changed & BSS_CHANGED_BEACON_INT) {
1560 * Reset the HW TSF for the first AP or mesh interface.
1562 if (priv->nvifs == 1 &&
1563 ((priv->ah->opmode == NL80211_IFTYPE_AP &&
1564 vif->type == NL80211_IFTYPE_AP &&
1565 priv->num_ap_vif == 1) ||
1566 (priv->ah->opmode == NL80211_IFTYPE_MESH_POINT &&
1567 vif->type == NL80211_IFTYPE_MESH_POINT &&
1568 priv->num_mbss_vif == 1))) {
1569 set_bit(OP_TSF_RESET, &priv->op_flags);
1571 ath_dbg(common, CONFIG,
1572 "Beacon interval changed for BSS: %pM\n",
1574 ath9k_htc_beacon_config(priv, vif);
1577 if (changed & BSS_CHANGED_ERP_SLOT) {
1578 if (bss_conf->use_short_slot)
1582 if (vif->type == NL80211_IFTYPE_AP) {
1584 * Defer update, so that connected stations can adjust
1585 * their settings at the same time.
1586 * See beacon.c for more details
1588 priv->beacon.slottime = slottime;
1589 priv->beacon.updateslot = UPDATE;
1591 ah->slottime = slottime;
1592 ath9k_hw_init_global_settings(ah);
1596 if (changed & BSS_CHANGED_HT)
1597 ath9k_htc_update_rate(priv, vif, bss_conf);
1599 ath9k_htc_ps_restore(priv);
1600 mutex_unlock(&priv->mutex);
1603 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw,
1604 struct ieee80211_vif *vif)
1606 struct ath9k_htc_priv *priv = hw->priv;
1609 mutex_lock(&priv->mutex);
1610 ath9k_htc_ps_wakeup(priv);
1611 tsf = ath9k_hw_gettsf64(priv->ah);
1612 ath9k_htc_ps_restore(priv);
1613 mutex_unlock(&priv->mutex);
1618 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw,
1619 struct ieee80211_vif *vif, u64 tsf)
1621 struct ath9k_htc_priv *priv = hw->priv;
1623 mutex_lock(&priv->mutex);
1624 ath9k_htc_ps_wakeup(priv);
1625 ath9k_hw_settsf64(priv->ah, tsf);
1626 ath9k_htc_ps_restore(priv);
1627 mutex_unlock(&priv->mutex);
1630 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw,
1631 struct ieee80211_vif *vif)
1633 struct ath9k_htc_priv *priv = hw->priv;
1635 mutex_lock(&priv->mutex);
1636 ath9k_htc_ps_wakeup(priv);
1637 ath9k_hw_reset_tsf(priv->ah);
1638 ath9k_htc_ps_restore(priv);
1639 mutex_unlock(&priv->mutex);
1642 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1643 struct ieee80211_vif *vif,
1644 enum ieee80211_ampdu_mlme_action action,
1645 struct ieee80211_sta *sta,
1646 u16 tid, u16 *ssn, u8 buf_size)
1648 struct ath9k_htc_priv *priv = hw->priv;
1649 struct ath9k_htc_sta *ista;
1652 mutex_lock(&priv->mutex);
1653 ath9k_htc_ps_wakeup(priv);
1656 case IEEE80211_AMPDU_RX_START:
1658 case IEEE80211_AMPDU_RX_STOP:
1660 case IEEE80211_AMPDU_TX_START:
1661 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1663 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1665 case IEEE80211_AMPDU_TX_STOP_CONT:
1666 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1667 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1668 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1669 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1671 case IEEE80211_AMPDU_TX_OPERATIONAL:
1672 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1673 spin_lock_bh(&priv->tx.tx_lock);
1674 ista->tid_state[tid] = AGGR_OPERATIONAL;
1675 spin_unlock_bh(&priv->tx.tx_lock);
1678 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1681 ath9k_htc_ps_restore(priv);
1682 mutex_unlock(&priv->mutex);
1687 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1689 struct ath9k_htc_priv *priv = hw->priv;
1690 struct ath_common *common = ath9k_hw_common(priv->ah);
1692 mutex_lock(&priv->mutex);
1693 spin_lock_bh(&priv->beacon_lock);
1694 set_bit(ATH_OP_SCANNING, &common->op_flags);
1695 spin_unlock_bh(&priv->beacon_lock);
1696 cancel_work_sync(&priv->ps_work);
1697 ath9k_htc_stop_ani(priv);
1698 mutex_unlock(&priv->mutex);
1701 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1703 struct ath9k_htc_priv *priv = hw->priv;
1704 struct ath_common *common = ath9k_hw_common(priv->ah);
1706 mutex_lock(&priv->mutex);
1707 spin_lock_bh(&priv->beacon_lock);
1708 clear_bit(ATH_OP_SCANNING, &common->op_flags);
1709 spin_unlock_bh(&priv->beacon_lock);
1710 ath9k_htc_ps_wakeup(priv);
1711 ath9k_htc_vif_reconfig(priv);
1712 ath9k_htc_ps_restore(priv);
1713 mutex_unlock(&priv->mutex);
1716 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1721 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1724 struct ath9k_htc_priv *priv = hw->priv;
1726 mutex_lock(&priv->mutex);
1727 ath9k_htc_ps_wakeup(priv);
1728 priv->ah->coverage_class = coverage_class;
1729 ath9k_hw_init_global_settings(priv->ah);
1730 ath9k_htc_ps_restore(priv);
1731 mutex_unlock(&priv->mutex);
1735 * Currently, this is used only for selecting the minimum rate
1736 * for management frames, rate selection for data frames remain
1739 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw,
1740 struct ieee80211_vif *vif,
1741 const struct cfg80211_bitrate_mask *mask)
1743 struct ath9k_htc_priv *priv = hw->priv;
1744 struct ath_common *common = ath9k_hw_common(priv->ah);
1745 struct ath9k_htc_target_rate_mask tmask;
1746 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1750 memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask));
1752 tmask.vif_index = avp->index;
1753 tmask.band = IEEE80211_BAND_2GHZ;
1754 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy);
1756 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1759 "Unable to set 2G rate mask for "
1760 "interface at idx: %d\n", avp->index);
1764 tmask.band = IEEE80211_BAND_5GHZ;
1765 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy);
1767 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1770 "Unable to set 5G rate mask for "
1771 "interface at idx: %d\n", avp->index);
1775 ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n",
1776 mask->control[IEEE80211_BAND_2GHZ].legacy,
1777 mask->control[IEEE80211_BAND_5GHZ].legacy);
1783 static int ath9k_htc_get_stats(struct ieee80211_hw *hw,
1784 struct ieee80211_low_level_stats *stats)
1786 struct ath9k_htc_priv *priv = hw->priv;
1787 struct ath_hw *ah = priv->ah;
1788 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1790 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1791 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1792 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1793 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1798 struct base_eep_header *ath9k_htc_get_eeprom_base(struct ath9k_htc_priv *priv)
1800 struct base_eep_header *pBase = NULL;
1802 * This can be done since all the 3 EEPROM families have the
1803 * same base header upto a certain point, and we are interested in
1804 * the data only upto that point.
1807 if (AR_SREV_9271(priv->ah))
1808 pBase = (struct base_eep_header *)
1809 &priv->ah->eeprom.map4k.baseEepHeader;
1810 else if (priv->ah->hw_version.usbdev == AR9280_USB)
1811 pBase = (struct base_eep_header *)
1812 &priv->ah->eeprom.def.baseEepHeader;
1813 else if (priv->ah->hw_version.usbdev == AR9287_USB)
1814 pBase = (struct base_eep_header *)
1815 &priv->ah->eeprom.map9287.baseEepHeader;
1820 static int ath9k_htc_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant,
1823 struct ath9k_htc_priv *priv = hw->priv;
1824 struct base_eep_header *pBase = ath9k_htc_get_eeprom_base(priv);
1826 *tx_ant = pBase->txMask;
1827 *rx_ant = pBase->rxMask;
1835 struct ieee80211_ops ath9k_htc_ops = {
1837 .start = ath9k_htc_start,
1838 .stop = ath9k_htc_stop,
1839 .add_interface = ath9k_htc_add_interface,
1840 .remove_interface = ath9k_htc_remove_interface,
1841 .config = ath9k_htc_config,
1842 .configure_filter = ath9k_htc_configure_filter,
1843 .sta_add = ath9k_htc_sta_add,
1844 .sta_remove = ath9k_htc_sta_remove,
1845 .conf_tx = ath9k_htc_conf_tx,
1846 .sta_rc_update = ath9k_htc_sta_rc_update,
1847 .bss_info_changed = ath9k_htc_bss_info_changed,
1848 .set_key = ath9k_htc_set_key,
1849 .get_tsf = ath9k_htc_get_tsf,
1850 .set_tsf = ath9k_htc_set_tsf,
1851 .reset_tsf = ath9k_htc_reset_tsf,
1852 .ampdu_action = ath9k_htc_ampdu_action,
1853 .sw_scan_start = ath9k_htc_sw_scan_start,
1854 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1855 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1856 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1857 .set_coverage_class = ath9k_htc_set_coverage_class,
1858 .set_bitrate_mask = ath9k_htc_set_bitrate_mask,
1859 .get_stats = ath9k_htc_get_stats,
1860 .get_antenna = ath9k_htc_get_antenna,
1862 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
1863 .get_et_sset_count = ath9k_htc_get_et_sset_count,
1864 .get_et_stats = ath9k_htc_get_et_stats,
1865 .get_et_strings = ath9k_htc_get_et_strings,