2 * Copyright (c) 2010 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
24 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
25 struct ath9k_channel *ichan)
27 enum htc_phymode mode;
31 switch (ichan->chanmode) {
34 case CHANNEL_G_HT40PLUS:
35 case CHANNEL_G_HT40MINUS:
40 case CHANNEL_A_HT40PLUS:
41 case CHANNEL_A_HT40MINUS:
51 bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
52 enum ath9k_power_mode mode)
56 mutex_lock(&priv->htc_pm_lock);
57 ret = ath9k_hw_setpower(priv->ah, mode);
58 mutex_unlock(&priv->htc_pm_lock);
63 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
65 mutex_lock(&priv->htc_pm_lock);
66 if (++priv->ps_usecount != 1)
68 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
71 mutex_unlock(&priv->htc_pm_lock);
74 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
76 mutex_lock(&priv->htc_pm_lock);
77 if (--priv->ps_usecount != 0)
81 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
82 else if (priv->ps_enabled)
83 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
86 mutex_unlock(&priv->htc_pm_lock);
89 void ath9k_ps_work(struct work_struct *work)
91 struct ath9k_htc_priv *priv =
92 container_of(work, struct ath9k_htc_priv,
94 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
96 /* The chip wakes up after receiving the first beacon
97 while network sleep is enabled. For the driver to
98 be in sync with the hw, set the chip to awake and
99 only then set it to sleep.
101 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
104 static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
106 struct ath9k_htc_priv *priv = data;
107 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
109 if ((vif->type == NL80211_IFTYPE_AP) && bss_conf->enable_beacon)
110 priv->reconfig_beacon = true;
112 if (bss_conf->assoc) {
113 priv->rearm_ani = true;
114 priv->reconfig_beacon = true;
118 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv)
120 priv->rearm_ani = false;
121 priv->reconfig_beacon = false;
123 ieee80211_iterate_active_interfaces_atomic(priv->hw,
124 ath9k_htc_vif_iter, priv);
126 ath9k_htc_start_ani(priv);
128 if (priv->reconfig_beacon) {
129 ath9k_htc_ps_wakeup(priv);
130 ath9k_htc_beacon_reconfig(priv);
131 ath9k_htc_ps_restore(priv);
135 static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
137 struct ath9k_vif_iter_data *iter_data = data;
140 for (i = 0; i < ETH_ALEN; i++)
141 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
144 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
145 struct ieee80211_vif *vif)
147 struct ath_common *common = ath9k_hw_common(priv->ah);
148 struct ath9k_vif_iter_data iter_data;
151 * Use the hardware MAC address as reference, the hardware uses it
152 * together with the BSSID mask when matching addresses.
154 iter_data.hw_macaddr = common->macaddr;
155 memset(&iter_data.mask, 0xff, ETH_ALEN);
158 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
160 /* Get list of all active MAC addresses */
161 ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter,
164 memcpy(common->bssidmask, iter_data.mask, 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;
175 priv->ah->opmode = NL80211_IFTYPE_STATION;
177 ath9k_hw_setopmode(priv->ah);
180 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
182 struct ath_hw *ah = priv->ah;
183 struct ath_common *common = ath9k_hw_common(ah);
184 struct ieee80211_channel *channel = priv->hw->conf.channel;
185 struct ath9k_hw_cal_data *caldata = NULL;
186 enum htc_phymode mode;
191 mutex_lock(&priv->mutex);
192 ath9k_htc_ps_wakeup(priv);
194 ath9k_htc_stop_ani(priv);
195 ieee80211_stop_queues(priv->hw);
197 ath9k_htc_tx_drain(priv);
199 WMI_CMD(WMI_DISABLE_INTR_CMDID);
200 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
201 WMI_CMD(WMI_STOP_RECV_CMDID);
203 ath9k_wmi_event_drain(priv);
205 caldata = &priv->caldata;
206 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
209 "Unable to reset device (%u Mhz) reset status %d\n",
210 channel->center_freq, ret);
213 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
216 WMI_CMD(WMI_START_RECV_CMDID);
217 ath9k_host_rx_init(priv);
219 mode = ath9k_htc_get_curmode(priv, ah->curchan);
220 htc_mode = cpu_to_be16(mode);
221 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
223 WMI_CMD(WMI_ENABLE_INTR_CMDID);
224 htc_start(priv->htc);
225 ath9k_htc_vif_reconfig(priv);
226 ieee80211_wake_queues(priv->hw);
228 ath9k_htc_ps_restore(priv);
229 mutex_unlock(&priv->mutex);
232 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
233 struct ieee80211_hw *hw,
234 struct ath9k_channel *hchan)
236 struct ath_hw *ah = priv->ah;
237 struct ath_common *common = ath9k_hw_common(ah);
238 struct ieee80211_conf *conf = &common->hw->conf;
240 struct ieee80211_channel *channel = hw->conf.channel;
241 struct ath9k_hw_cal_data *caldata = NULL;
242 enum htc_phymode mode;
247 if (priv->op_flags & OP_INVALID)
250 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
252 ath9k_htc_ps_wakeup(priv);
254 ath9k_htc_tx_drain(priv);
256 WMI_CMD(WMI_DISABLE_INTR_CMDID);
257 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
258 WMI_CMD(WMI_STOP_RECV_CMDID);
260 ath9k_wmi_event_drain(priv);
262 ath_dbg(common, ATH_DBG_CONFIG,
263 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
264 priv->ah->curchan->channel,
265 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
269 caldata = &priv->caldata;
271 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
274 "Unable to reset channel (%u Mhz) reset status %d\n",
275 channel->center_freq, ret);
279 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
282 WMI_CMD(WMI_START_RECV_CMDID);
286 ath9k_host_rx_init(priv);
288 mode = ath9k_htc_get_curmode(priv, hchan);
289 htc_mode = cpu_to_be16(mode);
290 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
294 WMI_CMD(WMI_ENABLE_INTR_CMDID);
298 htc_start(priv->htc);
300 if (!(priv->op_flags & OP_SCANNING) &&
301 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
302 ath9k_htc_vif_reconfig(priv);
305 ath9k_htc_ps_restore(priv);
310 * Monitor mode handling is a tad complicated because the firmware requires
311 * an interface to be created exclusively, while mac80211 doesn't associate
312 * an interface with the mode.
314 * So, for now, only one monitor interface can be configured.
316 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
318 struct ath_common *common = ath9k_hw_common(priv->ah);
319 struct ath9k_htc_target_vif hvif;
323 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
324 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
325 hvif.index = priv->mon_vif_idx;
326 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
328 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
331 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
333 struct ath_common *common = ath9k_hw_common(priv->ah);
334 struct ath9k_htc_target_vif hvif;
335 struct ath9k_htc_target_sta tsta;
336 int ret = 0, sta_idx;
339 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
340 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
345 sta_idx = ffz(priv->sta_slot);
346 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
354 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
355 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
357 hvif.opmode = HTC_M_MONITOR;
358 hvif.index = ffz(priv->vif_slot);
360 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
365 * Assign the monitor interface index as a special case here.
366 * This is needed when the interface is brought down.
368 priv->mon_vif_idx = hvif.index;
369 priv->vif_slot |= (1 << hvif.index);
372 * Set the hardware mode to monitor only if there are no
376 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
381 * Associate a station with the interface for packet injection.
383 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
385 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
388 tsta.sta_index = sta_idx;
389 tsta.vif_index = hvif.index;
390 tsta.maxampdu = cpu_to_be16(0xffff);
392 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
394 ath_err(common, "Unable to add station entry for monitor mode\n");
398 priv->sta_slot |= (1 << sta_idx);
400 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
401 priv->ah->is_monitoring = true;
403 ath_dbg(common, ATH_DBG_CONFIG,
404 "Attached a monitor interface at idx: %d, sta idx: %d\n",
405 priv->mon_vif_idx, sta_idx);
411 * Remove the interface from the target.
413 __ath9k_htc_remove_monitor_interface(priv);
415 ath_dbg(common, ATH_DBG_FATAL, "Unable to attach a monitor interface\n");
420 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
422 struct ath_common *common = ath9k_hw_common(priv->ah);
426 __ath9k_htc_remove_monitor_interface(priv);
428 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
430 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
432 ath_err(common, "Unable to remove station entry for monitor mode\n");
436 priv->sta_slot &= ~(1 << sta_idx);
438 priv->ah->is_monitoring = false;
440 ath_dbg(common, ATH_DBG_CONFIG,
441 "Removed a monitor interface at idx: %d, sta idx: %d\n",
442 priv->mon_vif_idx, sta_idx);
447 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
448 struct ieee80211_vif *vif,
449 struct ieee80211_sta *sta)
451 struct ath_common *common = ath9k_hw_common(priv->ah);
452 struct ath9k_htc_target_sta tsta;
453 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
454 struct ath9k_htc_sta *ista;
458 if (priv->nstations >= ATH9K_HTC_MAX_STA)
461 sta_idx = ffz(priv->sta_slot);
462 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
465 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
468 ista = (struct ath9k_htc_sta *) sta->drv_priv;
469 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
470 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
472 ista->index = sta_idx;
474 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
478 tsta.sta_index = sta_idx;
479 tsta.vif_index = avp->index;
480 tsta.maxampdu = cpu_to_be16(0xffff);
481 if (sta && sta->ht_cap.ht_supported)
482 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
484 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
488 "Unable to add station entry for: %pM\n",
494 ath_dbg(common, ATH_DBG_CONFIG,
495 "Added a station entry for: %pM (idx: %d)\n",
496 sta->addr, tsta.sta_index);
498 ath_dbg(common, ATH_DBG_CONFIG,
499 "Added a station entry for VIF %d (idx: %d)\n",
500 avp->index, tsta.sta_index);
503 priv->sta_slot |= (1 << sta_idx);
506 priv->vif_sta_pos[avp->index] = sta_idx;
511 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
512 struct ieee80211_vif *vif,
513 struct ieee80211_sta *sta)
515 struct ath_common *common = ath9k_hw_common(priv->ah);
516 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
517 struct ath9k_htc_sta *ista;
522 ista = (struct ath9k_htc_sta *) sta->drv_priv;
523 sta_idx = ista->index;
525 sta_idx = priv->vif_sta_pos[avp->index];
528 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
532 "Unable to remove station entry for: %pM\n",
538 ath_dbg(common, ATH_DBG_CONFIG,
539 "Removed a station entry for: %pM (idx: %d)\n",
542 ath_dbg(common, ATH_DBG_CONFIG,
543 "Removed a station entry for VIF %d (idx: %d)\n",
544 avp->index, sta_idx);
547 priv->sta_slot &= ~(1 << sta_idx);
553 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
555 struct ath9k_htc_cap_target tcap;
559 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
561 /* FIXME: Values are hardcoded */
562 tcap.flags = 0x240c40;
563 tcap.flags_ext = 0x80601000;
564 tcap.ampdu_limit = 0xffff0000;
565 tcap.ampdu_subframes = 20;
566 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
568 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
570 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
575 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
576 struct ieee80211_sta *sta,
577 struct ath9k_htc_target_rate *trate)
579 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
580 struct ieee80211_supported_band *sband;
584 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
586 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
587 if (sta->supp_rates[sband->band] & BIT(i)) {
588 trate->rates.legacy_rates.rs_rates[j]
589 = (sband->bitrates[i].bitrate * 2) / 10;
593 trate->rates.legacy_rates.rs_nrates = j;
595 if (sta->ht_cap.ht_supported) {
596 for (i = 0, j = 0; i < 77; i++) {
597 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
598 trate->rates.ht_rates.rs_rates[j++] = i;
599 if (j == ATH_HTC_RATE_MAX)
602 trate->rates.ht_rates.rs_nrates = j;
604 caps = WLAN_RC_HT_FLAG;
605 if (sta->ht_cap.mcs.rx_mask[1])
606 caps |= WLAN_RC_DS_FLAG;
607 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
608 (conf_is_ht40(&priv->hw->conf)))
609 caps |= WLAN_RC_40_FLAG;
610 if (conf_is_ht40(&priv->hw->conf) &&
611 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
612 caps |= WLAN_RC_SGI_FLAG;
613 else if (conf_is_ht20(&priv->hw->conf) &&
614 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
615 caps |= WLAN_RC_SGI_FLAG;
618 trate->sta_index = ista->index;
620 trate->capflags = cpu_to_be32(caps);
623 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
624 struct ath9k_htc_target_rate *trate)
626 struct ath_common *common = ath9k_hw_common(priv->ah);
630 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
633 "Unable to initialize Rate information on target\n");
639 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
640 struct ieee80211_sta *sta)
642 struct ath_common *common = ath9k_hw_common(priv->ah);
643 struct ath9k_htc_target_rate trate;
646 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
647 ath9k_htc_setup_rate(priv, sta, &trate);
648 ret = ath9k_htc_send_rate_cmd(priv, &trate);
650 ath_dbg(common, ATH_DBG_CONFIG,
651 "Updated target sta: %pM, rate caps: 0x%X\n",
652 sta->addr, be32_to_cpu(trate.capflags));
655 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
656 struct ieee80211_vif *vif,
657 struct ieee80211_bss_conf *bss_conf)
659 struct ath_common *common = ath9k_hw_common(priv->ah);
660 struct ath9k_htc_target_rate trate;
661 struct ieee80211_sta *sta;
664 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
667 sta = ieee80211_find_sta(vif, bss_conf->bssid);
672 ath9k_htc_setup_rate(priv, sta, &trate);
675 ret = ath9k_htc_send_rate_cmd(priv, &trate);
677 ath_dbg(common, ATH_DBG_CONFIG,
678 "Updated target sta: %pM, rate caps: 0x%X\n",
679 bss_conf->bssid, be32_to_cpu(trate.capflags));
682 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
683 struct ieee80211_vif *vif,
684 struct ieee80211_sta *sta,
685 enum ieee80211_ampdu_mlme_action action,
688 struct ath_common *common = ath9k_hw_common(priv->ah);
689 struct ath9k_htc_target_aggr aggr;
690 struct ath9k_htc_sta *ista;
694 if (tid >= ATH9K_HTC_MAX_TID)
697 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
698 ista = (struct ath9k_htc_sta *) sta->drv_priv;
700 aggr.sta_index = ista->index;
701 aggr.tidno = tid & 0xf;
702 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
704 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
706 ath_dbg(common, ATH_DBG_CONFIG,
707 "Unable to %s TX aggregation for (%pM, %d)\n",
708 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
710 ath_dbg(common, ATH_DBG_CONFIG,
711 "%s TX aggregation for (%pM, %d)\n",
712 (aggr.aggr_enable) ? "Starting" : "Stopping",
715 spin_lock_bh(&priv->tx.tx_lock);
716 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
717 spin_unlock_bh(&priv->tx.tx_lock);
726 void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
728 struct ath_common *common = ath9k_hw_common(priv->ah);
729 unsigned long timestamp = jiffies_to_msecs(jiffies);
731 common->ani.longcal_timer = timestamp;
732 common->ani.shortcal_timer = timestamp;
733 common->ani.checkani_timer = timestamp;
735 priv->op_flags |= OP_ANI_RUNNING;
737 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
738 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
741 void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
743 cancel_delayed_work_sync(&priv->ani_work);
744 priv->op_flags &= ~OP_ANI_RUNNING;
747 void ath9k_htc_ani_work(struct work_struct *work)
749 struct ath9k_htc_priv *priv =
750 container_of(work, struct ath9k_htc_priv, ani_work.work);
751 struct ath_hw *ah = priv->ah;
752 struct ath_common *common = ath9k_hw_common(ah);
753 bool longcal = false;
754 bool shortcal = false;
755 bool aniflag = false;
756 unsigned int timestamp = jiffies_to_msecs(jiffies);
757 u32 cal_interval, short_cal_interval;
759 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
760 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
762 /* Only calibrate if awake */
763 if (ah->power_mode != ATH9K_PM_AWAKE)
766 /* Long calibration runs independently of short calibration. */
767 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
769 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
770 common->ani.longcal_timer = timestamp;
773 /* Short calibration applies only while caldone is false */
774 if (!common->ani.caldone) {
775 if ((timestamp - common->ani.shortcal_timer) >=
776 short_cal_interval) {
778 ath_dbg(common, ATH_DBG_ANI,
779 "shortcal @%lu\n", jiffies);
780 common->ani.shortcal_timer = timestamp;
781 common->ani.resetcal_timer = timestamp;
784 if ((timestamp - common->ani.resetcal_timer) >=
785 ATH_RESTART_CALINTERVAL) {
786 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
787 if (common->ani.caldone)
788 common->ani.resetcal_timer = timestamp;
792 /* Verify whether we must check ANI */
793 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
795 common->ani.checkani_timer = timestamp;
798 /* Skip all processing if there's nothing to do. */
799 if (longcal || shortcal || aniflag) {
801 ath9k_htc_ps_wakeup(priv);
803 /* Call ANI routine if necessary */
805 ath9k_hw_ani_monitor(ah, ah->curchan);
807 /* Perform calibration if necessary */
808 if (longcal || shortcal)
809 common->ani.caldone =
810 ath9k_hw_calibrate(ah, ah->curchan,
811 common->rx_chainmask,
814 ath9k_htc_ps_restore(priv);
819 * Set timer interval based on previous results.
820 * The interval must be the shortest necessary to satisfy ANI,
821 * short calibration and long calibration.
823 cal_interval = ATH_LONG_CALINTERVAL;
824 if (priv->ah->config.enable_ani)
825 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
826 if (!common->ani.caldone)
827 cal_interval = min(cal_interval, (u32)short_cal_interval);
829 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
830 msecs_to_jiffies(cal_interval));
833 /**********************/
834 /* mac80211 Callbacks */
835 /**********************/
837 static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
839 struct ieee80211_hdr *hdr;
840 struct ath9k_htc_priv *priv = hw->priv;
841 struct ath_common *common = ath9k_hw_common(priv->ah);
842 int padpos, padsize, ret, slot;
844 hdr = (struct ieee80211_hdr *) skb->data;
846 /* Add the padding after the header if this is not already done */
847 padpos = ath9k_cmn_padpos(hdr->frame_control);
848 padsize = padpos & 3;
849 if (padsize && skb->len > padpos) {
850 if (skb_headroom(skb) < padsize) {
851 ath_dbg(common, ATH_DBG_XMIT, "No room for padding\n");
854 skb_push(skb, padsize);
855 memmove(skb->data, skb->data + padsize, padpos);
858 slot = ath9k_htc_tx_get_slot(priv);
860 ath_dbg(common, ATH_DBG_XMIT, "No free TX slot\n");
864 ret = ath9k_htc_tx_start(priv, skb, slot, false);
866 ath_dbg(common, ATH_DBG_XMIT, "Tx failed\n");
870 ath9k_htc_check_stop_queues(priv);
875 ath9k_htc_tx_clear_slot(priv, slot);
877 dev_kfree_skb_any(skb);
880 static int ath9k_htc_start(struct ieee80211_hw *hw)
882 struct ath9k_htc_priv *priv = hw->priv;
883 struct ath_hw *ah = priv->ah;
884 struct ath_common *common = ath9k_hw_common(ah);
885 struct ieee80211_channel *curchan = hw->conf.channel;
886 struct ath9k_channel *init_channel;
888 enum htc_phymode mode;
892 mutex_lock(&priv->mutex);
894 ath_dbg(common, ATH_DBG_CONFIG,
895 "Starting driver with initial channel: %d MHz\n",
896 curchan->center_freq);
898 /* Ensure that HW is awake before flushing RX */
899 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
900 WMI_CMD(WMI_FLUSH_RECV_CMDID);
902 /* setup initial channel */
903 init_channel = ath9k_cmn_get_curchannel(hw, ah);
905 ath9k_hw_htc_resetinit(ah);
906 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
909 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
910 ret, curchan->center_freq);
911 mutex_unlock(&priv->mutex);
915 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
918 mode = ath9k_htc_get_curmode(priv, init_channel);
919 htc_mode = cpu_to_be16(mode);
920 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
921 WMI_CMD(WMI_ATH_INIT_CMDID);
922 WMI_CMD(WMI_START_RECV_CMDID);
924 ath9k_host_rx_init(priv);
926 ret = ath9k_htc_update_cap_target(priv);
928 ath_dbg(common, ATH_DBG_CONFIG,
929 "Failed to update capability in target\n");
931 priv->op_flags &= ~OP_INVALID;
932 htc_start(priv->htc);
934 spin_lock_bh(&priv->tx.tx_lock);
935 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
936 spin_unlock_bh(&priv->tx.tx_lock);
938 ieee80211_wake_queues(hw);
940 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
941 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
942 AR_STOMP_LOW_WLAN_WGHT);
943 ath9k_hw_btcoex_enable(ah);
944 ath_htc_resume_btcoex_work(priv);
946 mutex_unlock(&priv->mutex);
951 static void ath9k_htc_stop(struct ieee80211_hw *hw)
953 struct ath9k_htc_priv *priv = hw->priv;
954 struct ath_hw *ah = priv->ah;
955 struct ath_common *common = ath9k_hw_common(ah);
959 mutex_lock(&priv->mutex);
961 if (priv->op_flags & OP_INVALID) {
962 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
963 mutex_unlock(&priv->mutex);
967 ath9k_htc_ps_wakeup(priv);
969 WMI_CMD(WMI_DISABLE_INTR_CMDID);
970 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
971 WMI_CMD(WMI_STOP_RECV_CMDID);
973 tasklet_kill(&priv->rx_tasklet);
975 ath9k_htc_tx_drain(priv);
976 ath9k_wmi_event_drain(priv);
978 mutex_unlock(&priv->mutex);
980 /* Cancel all the running timers/work .. */
981 cancel_work_sync(&priv->fatal_work);
982 cancel_work_sync(&priv->ps_work);
983 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
984 ath9k_htc_stop_ani(priv);
985 ath9k_led_stop_brightness(priv);
987 mutex_lock(&priv->mutex);
989 if (ah->btcoex_hw.enabled) {
990 ath9k_hw_btcoex_disable(ah);
991 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
992 ath_htc_cancel_btcoex_work(priv);
995 /* Remove a monitor interface if it's present. */
996 if (priv->ah->is_monitoring)
997 ath9k_htc_remove_monitor_interface(priv);
999 ath9k_hw_phy_disable(ah);
1000 ath9k_hw_disable(ah);
1001 ath9k_htc_ps_restore(priv);
1002 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1004 priv->op_flags |= OP_INVALID;
1006 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1007 mutex_unlock(&priv->mutex);
1010 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1011 struct ieee80211_vif *vif)
1013 struct ath9k_htc_priv *priv = hw->priv;
1014 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1015 struct ath_common *common = ath9k_hw_common(priv->ah);
1016 struct ath9k_htc_target_vif hvif;
1020 mutex_lock(&priv->mutex);
1022 if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1023 mutex_unlock(&priv->mutex);
1027 if (priv->num_ibss_vif ||
1028 (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
1029 ath_err(common, "IBSS coexistence with other modes is not allowed\n");
1030 mutex_unlock(&priv->mutex);
1034 if (((vif->type == NL80211_IFTYPE_AP) ||
1035 (vif->type == NL80211_IFTYPE_ADHOC)) &&
1036 ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) {
1037 ath_err(common, "Max. number of beaconing interfaces reached\n");
1038 mutex_unlock(&priv->mutex);
1042 ath9k_htc_ps_wakeup(priv);
1043 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1044 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1046 switch (vif->type) {
1047 case NL80211_IFTYPE_STATION:
1048 hvif.opmode = HTC_M_STA;
1050 case NL80211_IFTYPE_ADHOC:
1051 hvif.opmode = HTC_M_IBSS;
1053 case NL80211_IFTYPE_AP:
1054 hvif.opmode = HTC_M_HOSTAP;
1058 "Interface type %d not yet supported\n", vif->type);
1063 /* Index starts from zero on the target */
1064 avp->index = hvif.index = ffz(priv->vif_slot);
1065 hvif.rtsthreshold = cpu_to_be16(2304);
1066 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1071 * We need a node in target to tx mgmt frames
1072 * before association.
1074 ret = ath9k_htc_add_station(priv, vif, NULL);
1076 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1080 ath9k_htc_set_bssid_mask(priv, vif);
1082 priv->vif_slot |= (1 << avp->index);
1085 INC_VIF(priv, vif->type);
1087 if ((vif->type == NL80211_IFTYPE_AP) ||
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 !(priv->op_flags & OP_ANI_RUNNING)) {
1095 ath9k_hw_set_tsfadjust(priv->ah, 1);
1096 ath9k_htc_start_ani(priv);
1099 ath_dbg(common, ATH_DBG_CONFIG,
1100 "Attach a VIF of type: %d at idx: %d\n", 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 priv->vif_slot &= ~(1 << avp->index);
1129 ath9k_htc_remove_station(priv, vif, NULL);
1131 DEC_VIF(priv, vif->type);
1133 if ((vif->type == NL80211_IFTYPE_AP) ||
1134 (vif->type == NL80211_IFTYPE_ADHOC))
1135 ath9k_htc_remove_bslot(priv, vif);
1137 ath9k_htc_set_opmode(priv);
1140 * Stop ANI only if there are no associated station interfaces.
1142 if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) {
1143 priv->rearm_ani = false;
1144 ieee80211_iterate_active_interfaces_atomic(priv->hw,
1145 ath9k_htc_vif_iter, priv);
1146 if (!priv->rearm_ani)
1147 ath9k_htc_stop_ani(priv);
1150 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index);
1152 ath9k_htc_ps_restore(priv);
1153 mutex_unlock(&priv->mutex);
1156 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1158 struct ath9k_htc_priv *priv = hw->priv;
1159 struct ath_common *common = ath9k_hw_common(priv->ah);
1160 struct ieee80211_conf *conf = &hw->conf;
1162 mutex_lock(&priv->mutex);
1164 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1165 bool enable_radio = false;
1166 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1168 mutex_lock(&priv->htc_pm_lock);
1169 if (!idle && priv->ps_idle)
1170 enable_radio = true;
1171 priv->ps_idle = idle;
1172 mutex_unlock(&priv->htc_pm_lock);
1175 ath_dbg(common, ATH_DBG_CONFIG,
1176 "not-idle: enabling radio\n");
1177 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1178 ath9k_htc_radio_enable(hw);
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) {
1195 struct ieee80211_channel *curchan = hw->conf.channel;
1196 int pos = curchan->hw_value;
1198 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1199 curchan->center_freq);
1201 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1203 hw->conf.channel_type);
1205 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1206 ath_err(common, "Unable to set channel\n");
1207 mutex_unlock(&priv->mutex);
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);
1230 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1231 mutex_lock(&priv->htc_pm_lock);
1232 if (!priv->ps_idle) {
1233 mutex_unlock(&priv->htc_pm_lock);
1236 mutex_unlock(&priv->htc_pm_lock);
1238 ath_dbg(common, ATH_DBG_CONFIG,
1239 "idle: disabling radio\n");
1240 ath9k_htc_radio_disable(hw);
1244 mutex_unlock(&priv->mutex);
1248 #define SUPPORTED_FILTERS \
1249 (FIF_PROMISC_IN_BSS | \
1254 FIF_BCN_PRBRESP_PROMISC | \
1258 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1259 unsigned int changed_flags,
1260 unsigned int *total_flags,
1263 struct ath9k_htc_priv *priv = hw->priv;
1266 mutex_lock(&priv->mutex);
1267 ath9k_htc_ps_wakeup(priv);
1269 changed_flags &= SUPPORTED_FILTERS;
1270 *total_flags &= SUPPORTED_FILTERS;
1272 priv->rxfilter = *total_flags;
1273 rfilt = ath9k_htc_calcrxfilter(priv);
1274 ath9k_hw_setrxfilter(priv->ah, rfilt);
1276 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1277 "Set HW RX filter: 0x%x\n", rfilt);
1279 ath9k_htc_ps_restore(priv);
1280 mutex_unlock(&priv->mutex);
1283 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1284 struct ieee80211_vif *vif,
1285 struct ieee80211_sta *sta)
1287 struct ath9k_htc_priv *priv = hw->priv;
1290 mutex_lock(&priv->mutex);
1291 ath9k_htc_ps_wakeup(priv);
1292 ret = ath9k_htc_add_station(priv, vif, sta);
1294 ath9k_htc_init_rate(priv, sta);
1295 ath9k_htc_ps_restore(priv);
1296 mutex_unlock(&priv->mutex);
1301 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1302 struct ieee80211_vif *vif,
1303 struct ieee80211_sta *sta)
1305 struct ath9k_htc_priv *priv = hw->priv;
1308 mutex_lock(&priv->mutex);
1309 ath9k_htc_ps_wakeup(priv);
1310 ret = ath9k_htc_remove_station(priv, vif, sta);
1311 ath9k_htc_ps_restore(priv);
1312 mutex_unlock(&priv->mutex);
1317 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1318 const struct ieee80211_tx_queue_params *params)
1320 struct ath9k_htc_priv *priv = hw->priv;
1321 struct ath_common *common = ath9k_hw_common(priv->ah);
1322 struct ath9k_tx_queue_info qi;
1325 if (queue >= WME_NUM_AC)
1328 mutex_lock(&priv->mutex);
1329 ath9k_htc_ps_wakeup(priv);
1331 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1333 qi.tqi_aifs = params->aifs;
1334 qi.tqi_cwmin = params->cw_min;
1335 qi.tqi_cwmax = params->cw_max;
1336 qi.tqi_burstTime = params->txop;
1338 qnum = get_hw_qnum(queue, priv->hwq_map);
1340 ath_dbg(common, ATH_DBG_CONFIG,
1341 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1342 queue, qnum, params->aifs, params->cw_min,
1343 params->cw_max, params->txop);
1345 ret = ath_htc_txq_update(priv, qnum, &qi);
1347 ath_err(common, "TXQ Update failed\n");
1351 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1352 (qnum == priv->hwq_map[WME_AC_BE]))
1353 ath9k_htc_beaconq_config(priv);
1355 ath9k_htc_ps_restore(priv);
1356 mutex_unlock(&priv->mutex);
1361 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1362 enum set_key_cmd cmd,
1363 struct ieee80211_vif *vif,
1364 struct ieee80211_sta *sta,
1365 struct ieee80211_key_conf *key)
1367 struct ath9k_htc_priv *priv = hw->priv;
1368 struct ath_common *common = ath9k_hw_common(priv->ah);
1371 if (htc_modparam_nohwcrypt)
1374 mutex_lock(&priv->mutex);
1375 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1376 ath9k_htc_ps_wakeup(priv);
1380 ret = ath_key_config(common, vif, sta, key);
1382 key->hw_key_idx = ret;
1383 /* push IV and Michael MIC generation to stack */
1384 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1385 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1386 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1387 if (priv->ah->sw_mgmt_crypto &&
1388 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1389 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1394 ath_key_delete(common, key);
1400 ath9k_htc_ps_restore(priv);
1401 mutex_unlock(&priv->mutex);
1406 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1407 struct ieee80211_vif *vif,
1408 struct ieee80211_bss_conf *bss_conf,
1411 struct ath9k_htc_priv *priv = hw->priv;
1412 struct ath_hw *ah = priv->ah;
1413 struct ath_common *common = ath9k_hw_common(ah);
1416 mutex_lock(&priv->mutex);
1417 ath9k_htc_ps_wakeup(priv);
1420 * Set the HW AID/BSSID only for the first station interface
1423 set_assoc = !!((priv->ah->opmode == NL80211_IFTYPE_ADHOC) ||
1424 ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
1425 (priv->num_sta_vif == 1)));
1428 if (changed & BSS_CHANGED_ASSOC) {
1430 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1433 common->curaid = bss_conf->assoc ?
1436 if (bss_conf->assoc)
1437 ath9k_htc_start_ani(priv);
1439 ath9k_htc_stop_ani(priv);
1443 if (changed & BSS_CHANGED_BSSID) {
1445 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1446 ath9k_hw_write_associd(ah);
1448 ath_dbg(common, ATH_DBG_CONFIG,
1449 "BSSID: %pM aid: 0x%x\n",
1450 common->curbssid, common->curaid);
1454 if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) {
1455 ath_dbg(common, ATH_DBG_CONFIG,
1456 "Beacon enabled for BSS: %pM\n", bss_conf->bssid);
1457 ath9k_htc_set_tsfadjust(priv, vif);
1458 priv->op_flags |= OP_ENABLE_BEACON;
1459 ath9k_htc_beacon_config(priv, vif);
1462 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) {
1464 * Disable SWBA interrupt only if there are no
1465 * AP/IBSS interfaces.
1467 if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) {
1468 ath_dbg(common, ATH_DBG_CONFIG,
1469 "Beacon disabled for BSS: %pM\n",
1471 priv->op_flags &= ~OP_ENABLE_BEACON;
1472 ath9k_htc_beacon_config(priv, vif);
1476 if (changed & BSS_CHANGED_BEACON_INT) {
1478 * Reset the HW TSF for the first AP interface.
1480 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1481 (priv->nvifs == 1) &&
1482 (priv->num_ap_vif == 1) &&
1483 (vif->type == NL80211_IFTYPE_AP)) {
1484 priv->op_flags |= OP_TSF_RESET;
1486 ath_dbg(common, ATH_DBG_CONFIG,
1487 "Beacon interval changed for BSS: %pM\n",
1489 ath9k_htc_beacon_config(priv, vif);
1492 if (changed & BSS_CHANGED_ERP_SLOT) {
1493 if (bss_conf->use_short_slot)
1498 ath9k_hw_init_global_settings(ah);
1501 if (changed & BSS_CHANGED_HT)
1502 ath9k_htc_update_rate(priv, vif, bss_conf);
1504 ath9k_htc_ps_restore(priv);
1505 mutex_unlock(&priv->mutex);
1508 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1510 struct ath9k_htc_priv *priv = hw->priv;
1513 mutex_lock(&priv->mutex);
1514 ath9k_htc_ps_wakeup(priv);
1515 tsf = ath9k_hw_gettsf64(priv->ah);
1516 ath9k_htc_ps_restore(priv);
1517 mutex_unlock(&priv->mutex);
1522 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1524 struct ath9k_htc_priv *priv = hw->priv;
1526 mutex_lock(&priv->mutex);
1527 ath9k_htc_ps_wakeup(priv);
1528 ath9k_hw_settsf64(priv->ah, tsf);
1529 ath9k_htc_ps_restore(priv);
1530 mutex_unlock(&priv->mutex);
1533 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1535 struct ath9k_htc_priv *priv = hw->priv;
1537 mutex_lock(&priv->mutex);
1538 ath9k_htc_ps_wakeup(priv);
1539 ath9k_hw_reset_tsf(priv->ah);
1540 ath9k_htc_ps_restore(priv);
1541 mutex_unlock(&priv->mutex);
1544 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1545 struct ieee80211_vif *vif,
1546 enum ieee80211_ampdu_mlme_action action,
1547 struct ieee80211_sta *sta,
1548 u16 tid, u16 *ssn, u8 buf_size)
1550 struct ath9k_htc_priv *priv = hw->priv;
1551 struct ath9k_htc_sta *ista;
1554 mutex_lock(&priv->mutex);
1557 case IEEE80211_AMPDU_RX_START:
1559 case IEEE80211_AMPDU_RX_STOP:
1561 case IEEE80211_AMPDU_TX_START:
1562 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1564 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1566 case IEEE80211_AMPDU_TX_STOP:
1567 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1568 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1570 case IEEE80211_AMPDU_TX_OPERATIONAL:
1571 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1572 spin_lock_bh(&priv->tx.tx_lock);
1573 ista->tid_state[tid] = AGGR_OPERATIONAL;
1574 spin_unlock_bh(&priv->tx.tx_lock);
1577 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1580 mutex_unlock(&priv->mutex);
1585 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1587 struct ath9k_htc_priv *priv = hw->priv;
1589 mutex_lock(&priv->mutex);
1590 spin_lock_bh(&priv->beacon_lock);
1591 priv->op_flags |= OP_SCANNING;
1592 spin_unlock_bh(&priv->beacon_lock);
1593 cancel_work_sync(&priv->ps_work);
1594 ath9k_htc_stop_ani(priv);
1595 mutex_unlock(&priv->mutex);
1598 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1600 struct ath9k_htc_priv *priv = hw->priv;
1602 mutex_lock(&priv->mutex);
1603 spin_lock_bh(&priv->beacon_lock);
1604 priv->op_flags &= ~OP_SCANNING;
1605 spin_unlock_bh(&priv->beacon_lock);
1606 ath9k_htc_ps_wakeup(priv);
1607 ath9k_htc_vif_reconfig(priv);
1608 ath9k_htc_ps_restore(priv);
1609 mutex_unlock(&priv->mutex);
1612 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1617 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1620 struct ath9k_htc_priv *priv = hw->priv;
1622 mutex_lock(&priv->mutex);
1623 ath9k_htc_ps_wakeup(priv);
1624 priv->ah->coverage_class = coverage_class;
1625 ath9k_hw_init_global_settings(priv->ah);
1626 ath9k_htc_ps_restore(priv);
1627 mutex_unlock(&priv->mutex);
1630 struct ieee80211_ops ath9k_htc_ops = {
1632 .start = ath9k_htc_start,
1633 .stop = ath9k_htc_stop,
1634 .add_interface = ath9k_htc_add_interface,
1635 .remove_interface = ath9k_htc_remove_interface,
1636 .config = ath9k_htc_config,
1637 .configure_filter = ath9k_htc_configure_filter,
1638 .sta_add = ath9k_htc_sta_add,
1639 .sta_remove = ath9k_htc_sta_remove,
1640 .conf_tx = ath9k_htc_conf_tx,
1641 .bss_info_changed = ath9k_htc_bss_info_changed,
1642 .set_key = ath9k_htc_set_key,
1643 .get_tsf = ath9k_htc_get_tsf,
1644 .set_tsf = ath9k_htc_set_tsf,
1645 .reset_tsf = ath9k_htc_reset_tsf,
1646 .ampdu_action = ath9k_htc_ampdu_action,
1647 .sw_scan_start = ath9k_htc_sw_scan_start,
1648 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1649 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1650 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1651 .set_coverage_class = ath9k_htc_set_coverage_class,