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 for (i = 0; i < ETH_ALEN; i++)
131 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
134 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
135 struct ieee80211_vif *vif)
137 struct ath_common *common = ath9k_hw_common(priv->ah);
138 struct ath9k_vif_iter_data iter_data;
141 * Use the hardware MAC address as reference, the hardware uses it
142 * together with the BSSID mask when matching addresses.
144 iter_data.hw_macaddr = common->macaddr;
145 memset(&iter_data.mask, 0xff, ETH_ALEN);
148 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
150 /* Get list of all active MAC addresses */
151 ieee80211_iterate_active_interfaces_atomic(
152 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
153 ath9k_htc_bssid_iter, &iter_data);
155 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
156 ath_hw_setbssidmask(common);
159 static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv)
161 if (priv->num_ibss_vif)
162 priv->ah->opmode = NL80211_IFTYPE_ADHOC;
163 else if (priv->num_ap_vif)
164 priv->ah->opmode = NL80211_IFTYPE_AP;
165 else if (priv->num_mbss_vif)
166 priv->ah->opmode = NL80211_IFTYPE_MESH_POINT;
168 priv->ah->opmode = NL80211_IFTYPE_STATION;
170 ath9k_hw_setopmode(priv->ah);
173 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
175 struct ath_hw *ah = priv->ah;
176 struct ath_common *common = ath9k_hw_common(ah);
177 struct ieee80211_channel *channel = priv->hw->conf.chandef.chan;
178 struct ath9k_hw_cal_data *caldata = NULL;
179 enum htc_phymode mode;
184 mutex_lock(&priv->mutex);
185 ath9k_htc_ps_wakeup(priv);
187 ath9k_htc_stop_ani(priv);
188 ieee80211_stop_queues(priv->hw);
190 del_timer_sync(&priv->tx.cleanup_timer);
191 ath9k_htc_tx_drain(priv);
193 WMI_CMD(WMI_DISABLE_INTR_CMDID);
194 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
195 WMI_CMD(WMI_STOP_RECV_CMDID);
197 ath9k_wmi_event_drain(priv);
199 caldata = &priv->caldata;
200 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
203 "Unable to reset device (%u Mhz) reset status %d\n",
204 channel->center_freq, ret);
207 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
210 WMI_CMD(WMI_START_RECV_CMDID);
211 ath9k_host_rx_init(priv);
213 mode = ath9k_htc_get_curmode(priv, ah->curchan);
214 htc_mode = cpu_to_be16(mode);
215 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
217 WMI_CMD(WMI_ENABLE_INTR_CMDID);
218 htc_start(priv->htc);
219 ath9k_htc_vif_reconfig(priv);
220 ieee80211_wake_queues(priv->hw);
222 mod_timer(&priv->tx.cleanup_timer,
223 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
225 ath9k_htc_ps_restore(priv);
226 mutex_unlock(&priv->mutex);
229 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
230 struct ieee80211_hw *hw,
231 struct ath9k_channel *hchan)
233 struct ath_hw *ah = priv->ah;
234 struct ath_common *common = ath9k_hw_common(ah);
235 struct ieee80211_conf *conf = &common->hw->conf;
237 struct ieee80211_channel *channel = hw->conf.chandef.chan;
238 struct ath9k_hw_cal_data *caldata = NULL;
239 enum htc_phymode mode;
244 if (test_bit(OP_INVALID, &priv->op_flags))
247 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
249 ath9k_htc_ps_wakeup(priv);
251 del_timer_sync(&priv->tx.cleanup_timer);
252 ath9k_htc_tx_drain(priv);
254 WMI_CMD(WMI_DISABLE_INTR_CMDID);
255 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
256 WMI_CMD(WMI_STOP_RECV_CMDID);
258 ath9k_wmi_event_drain(priv);
260 ath_dbg(common, CONFIG,
261 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
262 priv->ah->curchan->channel,
263 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
267 caldata = &priv->caldata;
269 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
272 "Unable to reset channel (%u Mhz) reset status %d\n",
273 channel->center_freq, ret);
277 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
280 WMI_CMD(WMI_START_RECV_CMDID);
284 ath9k_host_rx_init(priv);
286 mode = ath9k_htc_get_curmode(priv, hchan);
287 htc_mode = cpu_to_be16(mode);
288 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
292 WMI_CMD(WMI_ENABLE_INTR_CMDID);
296 htc_start(priv->htc);
298 if (!test_bit(OP_SCANNING, &priv->op_flags) &&
299 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
300 ath9k_htc_vif_reconfig(priv);
302 mod_timer(&priv->tx.cleanup_timer,
303 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
306 ath9k_htc_ps_restore(priv);
311 * Monitor mode handling is a tad complicated because the firmware requires
312 * an interface to be created exclusively, while mac80211 doesn't associate
313 * an interface with the mode.
315 * So, for now, only one monitor interface can be configured.
317 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
319 struct ath_common *common = ath9k_hw_common(priv->ah);
320 struct ath9k_htc_target_vif hvif;
324 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
325 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
326 hvif.index = priv->mon_vif_idx;
327 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
329 ath_err(common, "Unable to remove monitor interface at idx: %d\n",
334 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
337 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
339 struct ath_common *common = ath9k_hw_common(priv->ah);
340 struct ath9k_htc_target_vif hvif;
341 struct ath9k_htc_target_sta tsta;
342 int ret = 0, sta_idx;
345 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
346 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
351 sta_idx = ffz(priv->sta_slot);
352 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
360 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
361 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
363 hvif.opmode = HTC_M_MONITOR;
364 hvif.index = ffz(priv->vif_slot);
366 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
371 * Assign the monitor interface index as a special case here.
372 * This is needed when the interface is brought down.
374 priv->mon_vif_idx = hvif.index;
375 priv->vif_slot |= (1 << hvif.index);
378 * Set the hardware mode to monitor only if there are no
382 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
387 * Associate a station with the interface for packet injection.
389 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
391 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
394 tsta.sta_index = sta_idx;
395 tsta.vif_index = hvif.index;
396 tsta.maxampdu = cpu_to_be16(0xffff);
398 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
400 ath_err(common, "Unable to add station entry for monitor mode\n");
404 priv->sta_slot |= (1 << sta_idx);
406 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
407 priv->ah->is_monitoring = true;
409 ath_dbg(common, CONFIG,
410 "Attached a monitor interface at idx: %d, sta idx: %d\n",
411 priv->mon_vif_idx, sta_idx);
417 * Remove the interface from the target.
419 __ath9k_htc_remove_monitor_interface(priv);
421 ath_dbg(common, FATAL, "Unable to attach a monitor interface\n");
426 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
428 struct ath_common *common = ath9k_hw_common(priv->ah);
432 __ath9k_htc_remove_monitor_interface(priv);
434 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
436 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
438 ath_err(common, "Unable to remove station entry for monitor mode\n");
442 priv->sta_slot &= ~(1 << sta_idx);
444 priv->ah->is_monitoring = false;
446 ath_dbg(common, CONFIG,
447 "Removed a monitor interface at idx: %d, sta idx: %d\n",
448 priv->mon_vif_idx, sta_idx);
453 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
454 struct ieee80211_vif *vif,
455 struct ieee80211_sta *sta)
457 struct ath_common *common = ath9k_hw_common(priv->ah);
458 struct ath9k_htc_target_sta tsta;
459 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
460 struct ath9k_htc_sta *ista;
465 if (priv->nstations >= ATH9K_HTC_MAX_STA)
468 sta_idx = ffz(priv->sta_slot);
469 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
472 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
475 ista = (struct ath9k_htc_sta *) sta->drv_priv;
476 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
477 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
478 ista->index = sta_idx;
480 maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
481 sta->ht_cap.ampdu_factor);
482 tsta.maxampdu = cpu_to_be16(maxampdu);
484 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
486 tsta.maxampdu = cpu_to_be16(0xffff);
489 tsta.sta_index = sta_idx;
490 tsta.vif_index = avp->index;
492 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
496 "Unable to add station entry for: %pM\n",
502 ath_dbg(common, CONFIG,
503 "Added a station entry for: %pM (idx: %d)\n",
504 sta->addr, tsta.sta_index);
506 ath_dbg(common, CONFIG,
507 "Added a station entry for VIF %d (idx: %d)\n",
508 avp->index, tsta.sta_index);
511 priv->sta_slot |= (1 << sta_idx);
514 priv->vif_sta_pos[avp->index] = sta_idx;
519 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
520 struct ieee80211_vif *vif,
521 struct ieee80211_sta *sta)
523 struct ath_common *common = ath9k_hw_common(priv->ah);
524 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
525 struct ath9k_htc_sta *ista;
530 ista = (struct ath9k_htc_sta *) sta->drv_priv;
531 sta_idx = ista->index;
533 sta_idx = priv->vif_sta_pos[avp->index];
536 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
540 "Unable to remove station entry for: %pM\n",
546 ath_dbg(common, CONFIG,
547 "Removed a station entry for: %pM (idx: %d)\n",
550 ath_dbg(common, CONFIG,
551 "Removed a station entry for VIF %d (idx: %d)\n",
552 avp->index, sta_idx);
555 priv->sta_slot &= ~(1 << sta_idx);
561 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv,
564 struct ath9k_htc_cap_target tcap;
568 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
570 tcap.ampdu_limit = cpu_to_be32(0xffff);
571 tcap.ampdu_subframes = 0xff;
572 tcap.enable_coex = enable_coex;
573 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
575 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
580 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
581 struct ieee80211_sta *sta,
582 struct ath9k_htc_target_rate *trate)
584 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
585 struct ieee80211_supported_band *sband;
589 sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band];
591 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
592 if (sta->supp_rates[sband->band] & BIT(i)) {
593 trate->rates.legacy_rates.rs_rates[j]
594 = (sband->bitrates[i].bitrate * 2) / 10;
598 trate->rates.legacy_rates.rs_nrates = j;
600 if (sta->ht_cap.ht_supported) {
601 for (i = 0, j = 0; i < 77; i++) {
602 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
603 trate->rates.ht_rates.rs_rates[j++] = i;
604 if (j == ATH_HTC_RATE_MAX)
607 trate->rates.ht_rates.rs_nrates = j;
609 caps = WLAN_RC_HT_FLAG;
610 if (sta->ht_cap.cap & IEEE80211_HT_CAP_RX_STBC)
611 caps |= ATH_RC_TX_STBC_FLAG;
612 if (sta->ht_cap.mcs.rx_mask[1])
613 caps |= WLAN_RC_DS_FLAG;
614 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
615 (conf_is_ht40(&priv->hw->conf)))
616 caps |= WLAN_RC_40_FLAG;
617 if (conf_is_ht40(&priv->hw->conf) &&
618 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
619 caps |= WLAN_RC_SGI_FLAG;
620 else if (conf_is_ht20(&priv->hw->conf) &&
621 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
622 caps |= WLAN_RC_SGI_FLAG;
625 trate->sta_index = ista->index;
627 trate->capflags = cpu_to_be32(caps);
630 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
631 struct ath9k_htc_target_rate *trate)
633 struct ath_common *common = ath9k_hw_common(priv->ah);
637 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
640 "Unable to initialize Rate information on target\n");
646 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
647 struct ieee80211_sta *sta)
649 struct ath_common *common = ath9k_hw_common(priv->ah);
650 struct ath9k_htc_target_rate trate;
653 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
654 ath9k_htc_setup_rate(priv, sta, &trate);
655 ret = ath9k_htc_send_rate_cmd(priv, &trate);
657 ath_dbg(common, CONFIG,
658 "Updated target sta: %pM, rate caps: 0x%X\n",
659 sta->addr, be32_to_cpu(trate.capflags));
662 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
663 struct ieee80211_vif *vif,
664 struct ieee80211_bss_conf *bss_conf)
666 struct ath_common *common = ath9k_hw_common(priv->ah);
667 struct ath9k_htc_target_rate trate;
668 struct ieee80211_sta *sta;
671 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
674 sta = ieee80211_find_sta(vif, bss_conf->bssid);
679 ath9k_htc_setup_rate(priv, sta, &trate);
682 ret = ath9k_htc_send_rate_cmd(priv, &trate);
684 ath_dbg(common, CONFIG,
685 "Updated target sta: %pM, rate caps: 0x%X\n",
686 bss_conf->bssid, be32_to_cpu(trate.capflags));
689 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
690 struct ieee80211_vif *vif,
691 struct ieee80211_sta *sta,
692 enum ieee80211_ampdu_mlme_action action,
695 struct ath_common *common = ath9k_hw_common(priv->ah);
696 struct ath9k_htc_target_aggr aggr;
697 struct ath9k_htc_sta *ista;
701 if (tid >= ATH9K_HTC_MAX_TID)
704 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
705 ista = (struct ath9k_htc_sta *) sta->drv_priv;
707 aggr.sta_index = ista->index;
708 aggr.tidno = tid & 0xf;
709 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
711 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
713 ath_dbg(common, CONFIG,
714 "Unable to %s TX aggregation for (%pM, %d)\n",
715 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
717 ath_dbg(common, CONFIG,
718 "%s TX aggregation for (%pM, %d)\n",
719 (aggr.aggr_enable) ? "Starting" : "Stopping",
722 spin_lock_bh(&priv->tx.tx_lock);
723 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
724 spin_unlock_bh(&priv->tx.tx_lock);
733 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
735 struct ath_common *common = ath9k_hw_common(priv->ah);
736 unsigned long timestamp = jiffies_to_msecs(jiffies);
738 common->ani.longcal_timer = timestamp;
739 common->ani.shortcal_timer = timestamp;
740 common->ani.checkani_timer = timestamp;
742 set_bit(OP_ANI_RUNNING, &priv->op_flags);
744 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
745 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
748 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
750 cancel_delayed_work_sync(&priv->ani_work);
751 clear_bit(OP_ANI_RUNNING, &priv->op_flags);
754 void ath9k_htc_ani_work(struct work_struct *work)
756 struct ath9k_htc_priv *priv =
757 container_of(work, struct ath9k_htc_priv, ani_work.work);
758 struct ath_hw *ah = priv->ah;
759 struct ath_common *common = ath9k_hw_common(ah);
760 bool longcal = false;
761 bool shortcal = false;
762 bool aniflag = false;
763 unsigned int timestamp = jiffies_to_msecs(jiffies);
764 u32 cal_interval, short_cal_interval;
766 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
767 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
769 /* Only calibrate if awake */
770 if (ah->power_mode != ATH9K_PM_AWAKE)
773 /* Long calibration runs independently of short calibration. */
774 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
776 ath_dbg(common, ANI, "longcal @%lu\n", jiffies);
777 common->ani.longcal_timer = timestamp;
780 /* Short calibration applies only while caldone is false */
781 if (!common->ani.caldone) {
782 if ((timestamp - common->ani.shortcal_timer) >=
783 short_cal_interval) {
785 ath_dbg(common, ANI, "shortcal @%lu\n", jiffies);
786 common->ani.shortcal_timer = timestamp;
787 common->ani.resetcal_timer = timestamp;
790 if ((timestamp - common->ani.resetcal_timer) >=
791 ATH_RESTART_CALINTERVAL) {
792 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
793 if (common->ani.caldone)
794 common->ani.resetcal_timer = timestamp;
798 /* Verify whether we must check ANI */
799 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
801 common->ani.checkani_timer = timestamp;
804 /* Skip all processing if there's nothing to do. */
805 if (longcal || shortcal || aniflag) {
807 ath9k_htc_ps_wakeup(priv);
809 /* Call ANI routine if necessary */
811 ath9k_hw_ani_monitor(ah, ah->curchan);
813 /* Perform calibration if necessary */
814 if (longcal || shortcal)
815 common->ani.caldone =
816 ath9k_hw_calibrate(ah, ah->curchan,
817 ah->rxchainmask, longcal);
819 ath9k_htc_ps_restore(priv);
824 * Set timer interval based on previous results.
825 * The interval must be the shortest necessary to satisfy ANI,
826 * short calibration and long calibration.
828 cal_interval = ATH_LONG_CALINTERVAL;
829 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
830 if (!common->ani.caldone)
831 cal_interval = min(cal_interval, (u32)short_cal_interval);
833 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
834 msecs_to_jiffies(cal_interval));
837 /**********************/
838 /* mac80211 Callbacks */
839 /**********************/
841 static void ath9k_htc_tx(struct ieee80211_hw *hw,
842 struct ieee80211_tx_control *control,
845 struct ieee80211_hdr *hdr;
846 struct ath9k_htc_priv *priv = hw->priv;
847 struct ath_common *common = ath9k_hw_common(priv->ah);
848 int padpos, padsize, ret, slot;
850 hdr = (struct ieee80211_hdr *) skb->data;
852 /* Add the padding after the header if this is not already done */
853 padpos = ieee80211_hdrlen(hdr->frame_control);
854 padsize = padpos & 3;
855 if (padsize && skb->len > padpos) {
856 if (skb_headroom(skb) < padsize) {
857 ath_dbg(common, XMIT, "No room for padding\n");
860 skb_push(skb, padsize);
861 memmove(skb->data, skb->data + padsize, padpos);
864 slot = ath9k_htc_tx_get_slot(priv);
866 ath_dbg(common, XMIT, "No free TX slot\n");
870 ret = ath9k_htc_tx_start(priv, control->sta, skb, slot, false);
872 ath_dbg(common, XMIT, "Tx failed\n");
876 ath9k_htc_check_stop_queues(priv);
881 ath9k_htc_tx_clear_slot(priv, slot);
883 dev_kfree_skb_any(skb);
886 static int ath9k_htc_start(struct ieee80211_hw *hw)
888 struct ath9k_htc_priv *priv = hw->priv;
889 struct ath_hw *ah = priv->ah;
890 struct ath_common *common = ath9k_hw_common(ah);
891 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
892 struct ath9k_channel *init_channel;
894 enum htc_phymode mode;
898 mutex_lock(&priv->mutex);
900 ath_dbg(common, CONFIG,
901 "Starting driver with initial channel: %d MHz\n",
902 curchan->center_freq);
904 /* Ensure that HW is awake before flushing RX */
905 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
906 WMI_CMD(WMI_FLUSH_RECV_CMDID);
908 /* setup initial channel */
909 init_channel = ath9k_cmn_get_channel(hw, ah, &hw->conf.chandef);
911 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
914 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
915 ret, curchan->center_freq);
916 mutex_unlock(&priv->mutex);
920 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
923 mode = ath9k_htc_get_curmode(priv, init_channel);
924 htc_mode = cpu_to_be16(mode);
925 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
926 WMI_CMD(WMI_ATH_INIT_CMDID);
927 WMI_CMD(WMI_START_RECV_CMDID);
929 ath9k_host_rx_init(priv);
931 ret = ath9k_htc_update_cap_target(priv, 0);
933 ath_dbg(common, CONFIG,
934 "Failed to update capability in target\n");
936 clear_bit(OP_INVALID, &priv->op_flags);
937 htc_start(priv->htc);
939 spin_lock_bh(&priv->tx.tx_lock);
940 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
941 spin_unlock_bh(&priv->tx.tx_lock);
943 ieee80211_wake_queues(hw);
945 mod_timer(&priv->tx.cleanup_timer,
946 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
948 ath9k_htc_start_btcoex(priv);
950 mutex_unlock(&priv->mutex);
955 static void ath9k_htc_stop(struct ieee80211_hw *hw)
957 struct ath9k_htc_priv *priv = hw->priv;
958 struct ath_hw *ah = priv->ah;
959 struct ath_common *common = ath9k_hw_common(ah);
960 int ret __attribute__ ((unused));
963 mutex_lock(&priv->mutex);
965 if (test_bit(OP_INVALID, &priv->op_flags)) {
966 ath_dbg(common, ANY, "Device not present\n");
967 mutex_unlock(&priv->mutex);
971 ath9k_htc_ps_wakeup(priv);
973 WMI_CMD(WMI_DISABLE_INTR_CMDID);
974 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
975 WMI_CMD(WMI_STOP_RECV_CMDID);
977 tasklet_kill(&priv->rx_tasklet);
979 del_timer_sync(&priv->tx.cleanup_timer);
980 ath9k_htc_tx_drain(priv);
981 ath9k_wmi_event_drain(priv);
983 mutex_unlock(&priv->mutex);
985 /* Cancel all the running timers/work .. */
986 cancel_work_sync(&priv->fatal_work);
987 cancel_work_sync(&priv->ps_work);
989 #ifdef CONFIG_MAC80211_LEDS
990 cancel_work_sync(&priv->led_work);
992 ath9k_htc_stop_ani(priv);
994 mutex_lock(&priv->mutex);
996 ath9k_htc_stop_btcoex(priv);
998 /* Remove a monitor interface if it's present. */
999 if (priv->ah->is_monitoring)
1000 ath9k_htc_remove_monitor_interface(priv);
1002 ath9k_hw_phy_disable(ah);
1003 ath9k_hw_disable(ah);
1004 ath9k_htc_ps_restore(priv);
1005 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1007 set_bit(OP_INVALID, &priv->op_flags);
1009 ath_dbg(common, CONFIG, "Driver halt\n");
1010 mutex_unlock(&priv->mutex);
1013 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1014 struct ieee80211_vif *vif)
1016 struct ath9k_htc_priv *priv = hw->priv;
1017 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1018 struct ath_common *common = ath9k_hw_common(priv->ah);
1019 struct ath9k_htc_target_vif hvif;
1023 mutex_lock(&priv->mutex);
1025 ath9k_htc_ps_wakeup(priv);
1026 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1027 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1029 switch (vif->type) {
1030 case NL80211_IFTYPE_STATION:
1031 hvif.opmode = HTC_M_STA;
1033 case NL80211_IFTYPE_ADHOC:
1034 hvif.opmode = HTC_M_IBSS;
1036 case NL80211_IFTYPE_AP:
1037 hvif.opmode = HTC_M_HOSTAP;
1039 case NL80211_IFTYPE_MESH_POINT:
1040 hvif.opmode = HTC_M_WDS; /* close enough */
1044 "Interface type %d not yet supported\n", vif->type);
1049 /* Index starts from zero on the target */
1050 avp->index = hvif.index = ffz(priv->vif_slot);
1051 hvif.rtsthreshold = cpu_to_be16(2304);
1052 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1057 * We need a node in target to tx mgmt frames
1058 * before association.
1060 ret = ath9k_htc_add_station(priv, vif, NULL);
1062 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1066 ath9k_htc_set_bssid_mask(priv, vif);
1068 priv->vif_slot |= (1 << avp->index);
1071 INC_VIF(priv, vif->type);
1073 if ((vif->type == NL80211_IFTYPE_AP) ||
1074 (vif->type == NL80211_IFTYPE_MESH_POINT) ||
1075 (vif->type == NL80211_IFTYPE_ADHOC))
1076 ath9k_htc_assign_bslot(priv, vif);
1078 ath9k_htc_set_opmode(priv);
1080 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1081 !test_bit(OP_ANI_RUNNING, &priv->op_flags)) {
1082 ath9k_hw_set_tsfadjust(priv->ah, true);
1083 ath9k_htc_start_ani(priv);
1086 ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n",
1087 vif->type, avp->index);
1090 ath9k_htc_ps_restore(priv);
1091 mutex_unlock(&priv->mutex);
1096 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1097 struct ieee80211_vif *vif)
1099 struct ath9k_htc_priv *priv = hw->priv;
1100 struct ath_common *common = ath9k_hw_common(priv->ah);
1101 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1102 struct ath9k_htc_target_vif hvif;
1106 mutex_lock(&priv->mutex);
1107 ath9k_htc_ps_wakeup(priv);
1109 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1110 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1111 hvif.index = avp->index;
1112 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1114 ath_err(common, "Unable to remove interface at idx: %d\n",
1118 priv->vif_slot &= ~(1 << avp->index);
1120 ath9k_htc_remove_station(priv, vif, NULL);
1122 DEC_VIF(priv, vif->type);
1124 if ((vif->type == NL80211_IFTYPE_AP) ||
1125 vif->type == NL80211_IFTYPE_MESH_POINT ||
1126 (vif->type == NL80211_IFTYPE_ADHOC))
1127 ath9k_htc_remove_bslot(priv, vif);
1129 ath9k_htc_set_opmode(priv);
1131 ath9k_htc_set_bssid_mask(priv, vif);
1134 * Stop ANI only if there are no associated station interfaces.
1136 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1137 priv->rearm_ani = false;
1138 ieee80211_iterate_active_interfaces_atomic(
1139 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1140 ath9k_htc_vif_iter, priv);
1141 if (!priv->rearm_ani)
1142 ath9k_htc_stop_ani(priv);
1145 ath_dbg(common, CONFIG, "Detach Interface at idx: %d\n", avp->index);
1147 ath9k_htc_ps_restore(priv);
1148 mutex_unlock(&priv->mutex);
1151 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1153 struct ath9k_htc_priv *priv = hw->priv;
1154 struct ath_common *common = ath9k_hw_common(priv->ah);
1155 struct ieee80211_conf *conf = &hw->conf;
1156 bool chip_reset = false;
1159 mutex_lock(&priv->mutex);
1160 ath9k_htc_ps_wakeup(priv);
1162 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1163 mutex_lock(&priv->htc_pm_lock);
1165 priv->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1169 mutex_unlock(&priv->htc_pm_lock);
1173 * Monitor interface should be added before
1174 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1176 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1177 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1178 !priv->ah->is_monitoring)
1179 ath9k_htc_add_monitor_interface(priv);
1180 else if (priv->ah->is_monitoring)
1181 ath9k_htc_remove_monitor_interface(priv);
1184 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
1185 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
1186 int pos = curchan->hw_value;
1188 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
1189 curchan->center_freq);
1191 ath9k_cmn_get_channel(hw, priv->ah, &hw->conf.chandef);
1192 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1193 ath_err(common, "Unable to set channel\n");
1200 if (changed & IEEE80211_CONF_CHANGE_PS) {
1201 if (conf->flags & IEEE80211_CONF_PS) {
1202 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1203 priv->ps_enabled = true;
1205 priv->ps_enabled = false;
1206 cancel_work_sync(&priv->ps_work);
1207 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1211 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1212 priv->txpowlimit = 2 * conf->power_level;
1213 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1214 priv->txpowlimit, &priv->curtxpow);
1218 ath9k_htc_ps_restore(priv);
1219 mutex_unlock(&priv->mutex);
1223 #define SUPPORTED_FILTERS \
1224 (FIF_PROMISC_IN_BSS | \
1229 FIF_BCN_PRBRESP_PROMISC | \
1233 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1234 unsigned int changed_flags,
1235 unsigned int *total_flags,
1238 struct ath9k_htc_priv *priv = hw->priv;
1241 mutex_lock(&priv->mutex);
1242 changed_flags &= SUPPORTED_FILTERS;
1243 *total_flags &= SUPPORTED_FILTERS;
1245 if (test_bit(OP_INVALID, &priv->op_flags)) {
1246 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1247 "Unable to configure filter on invalid state\n");
1248 mutex_unlock(&priv->mutex);
1251 ath9k_htc_ps_wakeup(priv);
1253 priv->rxfilter = *total_flags;
1254 rfilt = ath9k_htc_calcrxfilter(priv);
1255 ath9k_hw_setrxfilter(priv->ah, rfilt);
1257 ath_dbg(ath9k_hw_common(priv->ah), CONFIG, "Set HW RX filter: 0x%x\n",
1260 ath9k_htc_ps_restore(priv);
1261 mutex_unlock(&priv->mutex);
1264 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1265 struct ieee80211_vif *vif,
1266 struct ieee80211_sta *sta)
1268 struct ath9k_htc_priv *priv = hw->priv;
1271 mutex_lock(&priv->mutex);
1272 ath9k_htc_ps_wakeup(priv);
1273 ret = ath9k_htc_add_station(priv, vif, sta);
1275 ath9k_htc_init_rate(priv, sta);
1276 ath9k_htc_ps_restore(priv);
1277 mutex_unlock(&priv->mutex);
1282 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1283 struct ieee80211_vif *vif,
1284 struct ieee80211_sta *sta)
1286 struct ath9k_htc_priv *priv = hw->priv;
1287 struct ath9k_htc_sta *ista;
1290 mutex_lock(&priv->mutex);
1291 ath9k_htc_ps_wakeup(priv);
1292 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1293 htc_sta_drain(priv->htc, ista->index);
1294 ret = ath9k_htc_remove_station(priv, vif, sta);
1295 ath9k_htc_ps_restore(priv);
1296 mutex_unlock(&priv->mutex);
1301 static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
1302 struct ieee80211_vif *vif,
1303 struct ieee80211_sta *sta, u32 changed)
1305 struct ath9k_htc_priv *priv = hw->priv;
1306 struct ath_common *common = ath9k_hw_common(priv->ah);
1307 struct ath9k_htc_target_rate trate;
1309 mutex_lock(&priv->mutex);
1310 ath9k_htc_ps_wakeup(priv);
1312 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
1313 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
1314 ath9k_htc_setup_rate(priv, sta, &trate);
1315 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1316 ath_dbg(common, CONFIG,
1317 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1318 sta->addr, be32_to_cpu(trate.capflags));
1320 ath_dbg(common, CONFIG,
1321 "Unable to update supported rates for sta: %pM\n",
1325 ath9k_htc_ps_restore(priv);
1326 mutex_unlock(&priv->mutex);
1329 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
1330 struct ieee80211_vif *vif, u16 queue,
1331 const struct ieee80211_tx_queue_params *params)
1333 struct ath9k_htc_priv *priv = hw->priv;
1334 struct ath_common *common = ath9k_hw_common(priv->ah);
1335 struct ath9k_tx_queue_info qi;
1338 if (queue >= IEEE80211_NUM_ACS)
1341 mutex_lock(&priv->mutex);
1342 ath9k_htc_ps_wakeup(priv);
1344 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1346 qi.tqi_aifs = params->aifs;
1347 qi.tqi_cwmin = params->cw_min;
1348 qi.tqi_cwmax = params->cw_max;
1349 qi.tqi_burstTime = params->txop * 32;
1351 qnum = get_hw_qnum(queue, priv->hwq_map);
1353 ath_dbg(common, CONFIG,
1354 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1355 queue, qnum, params->aifs, params->cw_min,
1356 params->cw_max, params->txop);
1358 ret = ath_htc_txq_update(priv, qnum, &qi);
1360 ath_err(common, "TXQ Update failed\n");
1364 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1365 (qnum == priv->hwq_map[IEEE80211_AC_BE]))
1366 ath9k_htc_beaconq_config(priv);
1368 ath9k_htc_ps_restore(priv);
1369 mutex_unlock(&priv->mutex);
1374 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1375 enum set_key_cmd cmd,
1376 struct ieee80211_vif *vif,
1377 struct ieee80211_sta *sta,
1378 struct ieee80211_key_conf *key)
1380 struct ath9k_htc_priv *priv = hw->priv;
1381 struct ath_common *common = ath9k_hw_common(priv->ah);
1384 if (htc_modparam_nohwcrypt)
1387 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1388 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1389 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1390 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1391 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1393 * For now, disable hw crypto for the RSN IBSS group keys. This
1394 * could be optimized in the future to use a modified key cache
1395 * design to support per-STA RX GTK, but until that gets
1396 * implemented, use of software crypto for group addressed
1397 * frames is a acceptable to allow RSN IBSS to be used.
1402 mutex_lock(&priv->mutex);
1403 ath_dbg(common, CONFIG, "Set HW Key\n");
1404 ath9k_htc_ps_wakeup(priv);
1408 ret = ath_key_config(common, vif, sta, key);
1410 key->hw_key_idx = ret;
1411 /* push IV and Michael MIC generation to stack */
1412 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1413 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1414 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1415 if (priv->ah->sw_mgmt_crypto &&
1416 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1417 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1422 ath_key_delete(common, key);
1428 ath9k_htc_ps_restore(priv);
1429 mutex_unlock(&priv->mutex);
1434 static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv)
1436 struct ath_common *common = ath9k_hw_common(priv->ah);
1438 ath9k_hw_write_associd(priv->ah);
1439 ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
1440 common->curbssid, common->curaid);
1443 static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1445 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1446 struct ath_common *common = ath9k_hw_common(priv->ah);
1447 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1449 if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) {
1450 common->curaid = bss_conf->aid;
1451 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1455 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv)
1457 if (priv->num_sta_assoc_vif == 1) {
1458 ieee80211_iterate_active_interfaces_atomic(
1459 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1460 ath9k_htc_bss_iter, priv);
1461 ath9k_htc_set_bssid(priv);
1465 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1466 struct ieee80211_vif *vif,
1467 struct ieee80211_bss_conf *bss_conf,
1470 struct ath9k_htc_priv *priv = hw->priv;
1471 struct ath_hw *ah = priv->ah;
1472 struct ath_common *common = ath9k_hw_common(ah);
1474 mutex_lock(&priv->mutex);
1475 ath9k_htc_ps_wakeup(priv);
1477 if (changed & BSS_CHANGED_ASSOC) {
1478 ath_dbg(common, CONFIG, "BSS Changed ASSOC %d\n",
1482 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1484 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1485 ath9k_htc_choose_set_bssid(priv);
1486 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
1487 ath9k_htc_start_ani(priv);
1488 else if (priv->num_sta_assoc_vif == 0)
1489 ath9k_htc_stop_ani(priv);
1493 if (changed & BSS_CHANGED_IBSS) {
1494 if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
1495 common->curaid = bss_conf->aid;
1496 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1497 ath9k_htc_set_bssid(priv);
1501 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1502 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1504 ath9k_htc_set_tsfadjust(priv, vif);
1505 set_bit(OP_ENABLE_BEACON, &priv->op_flags);
1506 ath9k_htc_beacon_config(priv, vif);
1509 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1511 * Disable SWBA interrupt only if there are no
1512 * concurrent AP/mesh or IBSS interfaces.
1514 if ((priv->num_ap_vif + priv->num_mbss_vif <= 1) ||
1515 priv->num_ibss_vif) {
1516 ath_dbg(common, CONFIG,
1517 "Beacon disabled for BSS: %pM\n",
1519 clear_bit(OP_ENABLE_BEACON, &priv->op_flags);
1520 ath9k_htc_beacon_config(priv, vif);
1524 if (changed & BSS_CHANGED_BEACON_INT) {
1526 * Reset the HW TSF for the first AP or mesh interface.
1528 if (priv->nvifs == 1 &&
1529 ((priv->ah->opmode == NL80211_IFTYPE_AP &&
1530 vif->type == NL80211_IFTYPE_AP &&
1531 priv->num_ap_vif == 1) ||
1532 (priv->ah->opmode == NL80211_IFTYPE_MESH_POINT &&
1533 vif->type == NL80211_IFTYPE_MESH_POINT &&
1534 priv->num_mbss_vif == 1))) {
1535 set_bit(OP_TSF_RESET, &priv->op_flags);
1537 ath_dbg(common, CONFIG,
1538 "Beacon interval changed for BSS: %pM\n",
1540 ath9k_htc_beacon_config(priv, vif);
1543 if (changed & BSS_CHANGED_ERP_SLOT) {
1544 if (bss_conf->use_short_slot)
1549 ath9k_hw_init_global_settings(ah);
1552 if (changed & BSS_CHANGED_HT)
1553 ath9k_htc_update_rate(priv, vif, bss_conf);
1555 ath9k_htc_ps_restore(priv);
1556 mutex_unlock(&priv->mutex);
1559 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw,
1560 struct ieee80211_vif *vif)
1562 struct ath9k_htc_priv *priv = hw->priv;
1565 mutex_lock(&priv->mutex);
1566 ath9k_htc_ps_wakeup(priv);
1567 tsf = ath9k_hw_gettsf64(priv->ah);
1568 ath9k_htc_ps_restore(priv);
1569 mutex_unlock(&priv->mutex);
1574 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw,
1575 struct ieee80211_vif *vif, u64 tsf)
1577 struct ath9k_htc_priv *priv = hw->priv;
1579 mutex_lock(&priv->mutex);
1580 ath9k_htc_ps_wakeup(priv);
1581 ath9k_hw_settsf64(priv->ah, tsf);
1582 ath9k_htc_ps_restore(priv);
1583 mutex_unlock(&priv->mutex);
1586 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw,
1587 struct ieee80211_vif *vif)
1589 struct ath9k_htc_priv *priv = hw->priv;
1591 mutex_lock(&priv->mutex);
1592 ath9k_htc_ps_wakeup(priv);
1593 ath9k_hw_reset_tsf(priv->ah);
1594 ath9k_htc_ps_restore(priv);
1595 mutex_unlock(&priv->mutex);
1598 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1599 struct ieee80211_vif *vif,
1600 enum ieee80211_ampdu_mlme_action action,
1601 struct ieee80211_sta *sta,
1602 u16 tid, u16 *ssn, u8 buf_size)
1604 struct ath9k_htc_priv *priv = hw->priv;
1605 struct ath9k_htc_sta *ista;
1608 mutex_lock(&priv->mutex);
1609 ath9k_htc_ps_wakeup(priv);
1612 case IEEE80211_AMPDU_RX_START:
1614 case IEEE80211_AMPDU_RX_STOP:
1616 case IEEE80211_AMPDU_TX_START:
1617 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1619 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1621 case IEEE80211_AMPDU_TX_STOP_CONT:
1622 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1623 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1624 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1625 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1627 case IEEE80211_AMPDU_TX_OPERATIONAL:
1628 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1629 spin_lock_bh(&priv->tx.tx_lock);
1630 ista->tid_state[tid] = AGGR_OPERATIONAL;
1631 spin_unlock_bh(&priv->tx.tx_lock);
1634 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1637 ath9k_htc_ps_restore(priv);
1638 mutex_unlock(&priv->mutex);
1643 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1645 struct ath9k_htc_priv *priv = hw->priv;
1647 mutex_lock(&priv->mutex);
1648 spin_lock_bh(&priv->beacon_lock);
1649 set_bit(OP_SCANNING, &priv->op_flags);
1650 spin_unlock_bh(&priv->beacon_lock);
1651 cancel_work_sync(&priv->ps_work);
1652 ath9k_htc_stop_ani(priv);
1653 mutex_unlock(&priv->mutex);
1656 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1658 struct ath9k_htc_priv *priv = hw->priv;
1660 mutex_lock(&priv->mutex);
1661 spin_lock_bh(&priv->beacon_lock);
1662 clear_bit(OP_SCANNING, &priv->op_flags);
1663 spin_unlock_bh(&priv->beacon_lock);
1664 ath9k_htc_ps_wakeup(priv);
1665 ath9k_htc_vif_reconfig(priv);
1666 ath9k_htc_ps_restore(priv);
1667 mutex_unlock(&priv->mutex);
1670 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1675 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1678 struct ath9k_htc_priv *priv = hw->priv;
1680 mutex_lock(&priv->mutex);
1681 ath9k_htc_ps_wakeup(priv);
1682 priv->ah->coverage_class = coverage_class;
1683 ath9k_hw_init_global_settings(priv->ah);
1684 ath9k_htc_ps_restore(priv);
1685 mutex_unlock(&priv->mutex);
1689 * Currently, this is used only for selecting the minimum rate
1690 * for management frames, rate selection for data frames remain
1693 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw,
1694 struct ieee80211_vif *vif,
1695 const struct cfg80211_bitrate_mask *mask)
1697 struct ath9k_htc_priv *priv = hw->priv;
1698 struct ath_common *common = ath9k_hw_common(priv->ah);
1699 struct ath9k_htc_target_rate_mask tmask;
1700 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1704 memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask));
1706 tmask.vif_index = avp->index;
1707 tmask.band = IEEE80211_BAND_2GHZ;
1708 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy);
1710 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1713 "Unable to set 2G rate mask for "
1714 "interface at idx: %d\n", avp->index);
1718 tmask.band = IEEE80211_BAND_5GHZ;
1719 tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy);
1721 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask);
1724 "Unable to set 5G rate mask for "
1725 "interface at idx: %d\n", avp->index);
1729 ath_dbg(common, CONFIG, "Set bitrate masks: 0x%x, 0x%x\n",
1730 mask->control[IEEE80211_BAND_2GHZ].legacy,
1731 mask->control[IEEE80211_BAND_5GHZ].legacy);
1737 static int ath9k_htc_get_stats(struct ieee80211_hw *hw,
1738 struct ieee80211_low_level_stats *stats)
1740 struct ath9k_htc_priv *priv = hw->priv;
1741 struct ath_hw *ah = priv->ah;
1742 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1744 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1745 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1746 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1747 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1752 struct base_eep_header *ath9k_htc_get_eeprom_base(struct ath9k_htc_priv *priv)
1754 struct base_eep_header *pBase = NULL;
1756 * This can be done since all the 3 EEPROM families have the
1757 * same base header upto a certain point, and we are interested in
1758 * the data only upto that point.
1761 if (AR_SREV_9271(priv->ah))
1762 pBase = (struct base_eep_header *)
1763 &priv->ah->eeprom.map4k.baseEepHeader;
1764 else if (priv->ah->hw_version.usbdev == AR9280_USB)
1765 pBase = (struct base_eep_header *)
1766 &priv->ah->eeprom.def.baseEepHeader;
1767 else if (priv->ah->hw_version.usbdev == AR9287_USB)
1768 pBase = (struct base_eep_header *)
1769 &priv->ah->eeprom.map9287.baseEepHeader;
1774 static int ath9k_htc_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant,
1777 struct ath9k_htc_priv *priv = hw->priv;
1778 struct base_eep_header *pBase = ath9k_htc_get_eeprom_base(priv);
1780 *tx_ant = pBase->txMask;
1781 *rx_ant = pBase->rxMask;
1789 struct ieee80211_ops ath9k_htc_ops = {
1791 .start = ath9k_htc_start,
1792 .stop = ath9k_htc_stop,
1793 .add_interface = ath9k_htc_add_interface,
1794 .remove_interface = ath9k_htc_remove_interface,
1795 .config = ath9k_htc_config,
1796 .configure_filter = ath9k_htc_configure_filter,
1797 .sta_add = ath9k_htc_sta_add,
1798 .sta_remove = ath9k_htc_sta_remove,
1799 .conf_tx = ath9k_htc_conf_tx,
1800 .sta_rc_update = ath9k_htc_sta_rc_update,
1801 .bss_info_changed = ath9k_htc_bss_info_changed,
1802 .set_key = ath9k_htc_set_key,
1803 .get_tsf = ath9k_htc_get_tsf,
1804 .set_tsf = ath9k_htc_set_tsf,
1805 .reset_tsf = ath9k_htc_reset_tsf,
1806 .ampdu_action = ath9k_htc_ampdu_action,
1807 .sw_scan_start = ath9k_htc_sw_scan_start,
1808 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1809 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1810 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1811 .set_coverage_class = ath9k_htc_set_coverage_class,
1812 .set_bitrate_mask = ath9k_htc_set_bitrate_mask,
1813 .get_stats = ath9k_htc_get_stats,
1814 .get_antenna = ath9k_htc_get_antenna,
1816 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
1817 .get_et_sset_count = ath9k_htc_get_et_sset_count,
1818 .get_et_stats = ath9k_htc_get_et_stats,
1819 .get_et_strings = ath9k_htc_get_et_strings,