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.
19 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
20 static struct dentry *ath9k_debugfs_root;
27 void ath_update_txpow(struct ath9k_htc_priv *priv)
29 struct ath_hw *ah = priv->ah;
31 if (priv->curtxpow != priv->txpowlimit) {
32 ath9k_hw_set_txpowerlimit(ah, priv->txpowlimit, false);
33 /* read back in case value is clamped */
34 priv->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
38 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
39 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
40 struct ath9k_channel *ichan)
42 enum htc_phymode mode;
46 switch (ichan->chanmode) {
49 case CHANNEL_G_HT40PLUS:
50 case CHANNEL_G_HT40MINUS:
55 case CHANNEL_A_HT40PLUS:
56 case CHANNEL_A_HT40MINUS:
66 bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
67 enum ath9k_power_mode mode)
71 mutex_lock(&priv->htc_pm_lock);
72 ret = ath9k_hw_setpower(priv->ah, mode);
73 mutex_unlock(&priv->htc_pm_lock);
78 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
80 mutex_lock(&priv->htc_pm_lock);
81 if (++priv->ps_usecount != 1)
83 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
86 mutex_unlock(&priv->htc_pm_lock);
89 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
91 mutex_lock(&priv->htc_pm_lock);
92 if (--priv->ps_usecount != 0)
96 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
97 else if (priv->ps_enabled)
98 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
101 mutex_unlock(&priv->htc_pm_lock);
104 void ath9k_ps_work(struct work_struct *work)
106 struct ath9k_htc_priv *priv =
107 container_of(work, struct ath9k_htc_priv,
109 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
111 /* The chip wakes up after receiving the first beacon
112 while network sleep is enabled. For the driver to
113 be in sync with the hw, set the chip to awake and
114 only then set it to sleep.
116 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
119 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
121 struct ath_hw *ah = priv->ah;
122 struct ath_common *common = ath9k_hw_common(ah);
123 struct ieee80211_channel *channel = priv->hw->conf.channel;
124 struct ath9k_hw_cal_data *caldata = NULL;
125 enum htc_phymode mode;
130 mutex_lock(&priv->mutex);
131 ath9k_htc_ps_wakeup(priv);
133 if (priv->op_flags & OP_ASSOCIATED)
134 cancel_delayed_work_sync(&priv->ath9k_ani_work);
136 ieee80211_stop_queues(priv->hw);
138 WMI_CMD(WMI_DISABLE_INTR_CMDID);
139 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
140 WMI_CMD(WMI_STOP_RECV_CMDID);
142 caldata = &priv->caldata;
143 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
146 "Unable to reset device (%u Mhz) reset status %d\n",
147 channel->center_freq, ret);
150 ath_update_txpow(priv);
152 WMI_CMD(WMI_START_RECV_CMDID);
153 ath9k_host_rx_init(priv);
155 mode = ath9k_htc_get_curmode(priv, ah->curchan);
156 htc_mode = cpu_to_be16(mode);
157 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
159 WMI_CMD(WMI_ENABLE_INTR_CMDID);
160 htc_start(priv->htc);
162 if (priv->op_flags & OP_ASSOCIATED) {
163 ath9k_htc_beacon_config(priv, priv->vif);
167 ieee80211_wake_queues(priv->hw);
169 ath9k_htc_ps_restore(priv);
170 mutex_unlock(&priv->mutex);
173 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
174 struct ieee80211_hw *hw,
175 struct ath9k_channel *hchan)
177 struct ath_hw *ah = priv->ah;
178 struct ath_common *common = ath9k_hw_common(ah);
179 struct ieee80211_conf *conf = &common->hw->conf;
181 struct ieee80211_channel *channel = hw->conf.channel;
182 struct ath9k_hw_cal_data *caldata;
183 enum htc_phymode mode;
188 if (priv->op_flags & OP_INVALID)
191 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
193 ath9k_htc_ps_wakeup(priv);
195 WMI_CMD(WMI_DISABLE_INTR_CMDID);
196 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
197 WMI_CMD(WMI_STOP_RECV_CMDID);
199 ath_dbg(common, ATH_DBG_CONFIG,
200 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
201 priv->ah->curchan->channel,
202 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
206 caldata = &priv->caldata;
207 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
210 "Unable to reset channel (%u Mhz) reset status %d\n",
211 channel->center_freq, ret);
215 ath_update_txpow(priv);
217 WMI_CMD(WMI_START_RECV_CMDID);
221 ath9k_host_rx_init(priv);
223 mode = ath9k_htc_get_curmode(priv, hchan);
224 htc_mode = cpu_to_be16(mode);
225 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
229 WMI_CMD(WMI_ENABLE_INTR_CMDID);
233 htc_start(priv->htc);
235 ath9k_htc_ps_restore(priv);
239 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
241 struct ath_common *common = ath9k_hw_common(priv->ah);
242 struct ath9k_htc_target_vif hvif;
246 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
247 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
248 hvif.index = 0; /* Should do for now */
249 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
253 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
255 struct ath_common *common = ath9k_hw_common(priv->ah);
256 struct ath9k_htc_target_vif hvif;
257 struct ath9k_htc_target_sta tsta;
264 if (priv->nstations >= ATH9K_HTC_MAX_STA)
271 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
272 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
274 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
275 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
276 hvif.index = priv->nvifs;
278 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
285 * Associate a station with the interface for packet injection.
288 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
290 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
293 tsta.sta_index = priv->nstations;
294 tsta.vif_index = hvif.index;
295 tsta.maxampdu = 0xffff;
297 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
299 ath_err(common, "Unable to add station entry for monitor mode\n");
306 * Set chainmask etc. on the target.
308 ret = ath9k_htc_update_cap_target(priv);
310 ath_dbg(common, ATH_DBG_CONFIG,
311 "Failed to update capability in target\n");
313 priv->ah->is_monitoring = true;
319 * Remove the interface from the target.
321 __ath9k_htc_remove_monitor_interface(priv);
325 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
327 struct ath_common *common = ath9k_hw_common(priv->ah);
331 __ath9k_htc_remove_monitor_interface(priv);
333 sta_idx = 0; /* Only single interface, for now */
335 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
337 ath_err(common, "Unable to remove station entry for monitor mode\n");
342 priv->ah->is_monitoring = false;
347 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
348 struct ieee80211_vif *vif,
349 struct ieee80211_sta *sta)
351 struct ath_common *common = ath9k_hw_common(priv->ah);
352 struct ath9k_htc_target_sta tsta;
353 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
354 struct ath9k_htc_sta *ista;
358 if (priv->nstations >= ATH9K_HTC_MAX_STA)
361 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
364 ista = (struct ath9k_htc_sta *) sta->drv_priv;
365 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
366 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
367 tsta.associd = common->curaid;
370 ista->index = priv->nstations;
372 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
376 tsta.sta_index = priv->nstations;
377 tsta.vif_index = avp->index;
378 tsta.maxampdu = 0xffff;
379 if (sta && sta->ht_cap.ht_supported)
380 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
382 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
386 "Unable to add station entry for: %pM\n",
392 ath_dbg(common, ATH_DBG_CONFIG,
393 "Added a station entry for: %pM (idx: %d)\n",
394 sta->addr, tsta.sta_index);
400 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
401 struct ieee80211_vif *vif,
402 struct ieee80211_sta *sta)
404 struct ath_common *common = ath9k_hw_common(priv->ah);
405 struct ath9k_htc_sta *ista;
410 ista = (struct ath9k_htc_sta *) sta->drv_priv;
411 sta_idx = ista->index;
416 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
420 "Unable to remove station entry for: %pM\n",
426 ath_dbg(common, ATH_DBG_CONFIG,
427 "Removed a station entry for: %pM (idx: %d)\n",
434 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
436 struct ath9k_htc_cap_target tcap;
440 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
442 /* FIXME: Values are hardcoded */
443 tcap.flags = 0x240c40;
444 tcap.flags_ext = 0x80601000;
445 tcap.ampdu_limit = 0xffff0000;
446 tcap.ampdu_subframes = 20;
447 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
449 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
451 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
456 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
457 struct ieee80211_sta *sta,
458 struct ath9k_htc_target_rate *trate)
460 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
461 struct ieee80211_supported_band *sband;
465 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
467 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
468 if (sta->supp_rates[sband->band] & BIT(i)) {
469 trate->rates.legacy_rates.rs_rates[j]
470 = (sband->bitrates[i].bitrate * 2) / 10;
474 trate->rates.legacy_rates.rs_nrates = j;
476 if (sta->ht_cap.ht_supported) {
477 for (i = 0, j = 0; i < 77; i++) {
478 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
479 trate->rates.ht_rates.rs_rates[j++] = i;
480 if (j == ATH_HTC_RATE_MAX)
483 trate->rates.ht_rates.rs_nrates = j;
485 caps = WLAN_RC_HT_FLAG;
486 if (sta->ht_cap.mcs.rx_mask[1])
487 caps |= WLAN_RC_DS_FLAG;
488 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
489 (conf_is_ht40(&priv->hw->conf)))
490 caps |= WLAN_RC_40_FLAG;
491 if (conf_is_ht40(&priv->hw->conf) &&
492 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
493 caps |= WLAN_RC_SGI_FLAG;
494 else if (conf_is_ht20(&priv->hw->conf) &&
495 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
496 caps |= WLAN_RC_SGI_FLAG;
499 trate->sta_index = ista->index;
501 trate->capflags = cpu_to_be32(caps);
504 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
505 struct ath9k_htc_target_rate *trate)
507 struct ath_common *common = ath9k_hw_common(priv->ah);
511 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
514 "Unable to initialize Rate information on target\n");
520 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
521 struct ieee80211_sta *sta)
523 struct ath_common *common = ath9k_hw_common(priv->ah);
524 struct ath9k_htc_target_rate trate;
527 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
528 ath9k_htc_setup_rate(priv, sta, &trate);
529 ret = ath9k_htc_send_rate_cmd(priv, &trate);
531 ath_dbg(common, ATH_DBG_CONFIG,
532 "Updated target sta: %pM, rate caps: 0x%X\n",
533 sta->addr, be32_to_cpu(trate.capflags));
536 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
537 struct ieee80211_vif *vif,
538 struct ieee80211_bss_conf *bss_conf)
540 struct ath_common *common = ath9k_hw_common(priv->ah);
541 struct ath9k_htc_target_rate trate;
542 struct ieee80211_sta *sta;
545 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
548 sta = ieee80211_find_sta(vif, bss_conf->bssid);
553 ath9k_htc_setup_rate(priv, sta, &trate);
556 ret = ath9k_htc_send_rate_cmd(priv, &trate);
558 ath_dbg(common, ATH_DBG_CONFIG,
559 "Updated target sta: %pM, rate caps: 0x%X\n",
560 bss_conf->bssid, be32_to_cpu(trate.capflags));
563 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
564 struct ieee80211_vif *vif,
565 struct ieee80211_sta *sta,
566 enum ieee80211_ampdu_mlme_action action,
569 struct ath_common *common = ath9k_hw_common(priv->ah);
570 struct ath9k_htc_target_aggr aggr;
571 struct ath9k_htc_sta *ista;
575 if (tid >= ATH9K_HTC_MAX_TID)
578 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
579 ista = (struct ath9k_htc_sta *) sta->drv_priv;
581 aggr.sta_index = ista->index;
582 aggr.tidno = tid & 0xf;
583 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
585 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
587 ath_dbg(common, ATH_DBG_CONFIG,
588 "Unable to %s TX aggregation for (%pM, %d)\n",
589 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
591 ath_dbg(common, ATH_DBG_CONFIG,
592 "%s TX aggregation for (%pM, %d)\n",
593 (aggr.aggr_enable) ? "Starting" : "Stopping",
596 spin_lock_bh(&priv->tx_lock);
597 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
598 spin_unlock_bh(&priv->tx_lock);
607 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
609 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
611 file->private_data = inode->i_private;
615 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
616 size_t count, loff_t *ppos)
618 struct ath9k_htc_priv *priv = file->private_data;
619 struct ath9k_htc_target_stats cmd_rsp;
621 unsigned int len = 0;
624 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
626 WMI_CMD(WMI_TGT_STATS_CMDID);
631 len += snprintf(buf + len, sizeof(buf) - len,
632 "%19s : %10u\n", "TX Short Retries",
633 be32_to_cpu(cmd_rsp.tx_shortretry));
634 len += snprintf(buf + len, sizeof(buf) - len,
635 "%19s : %10u\n", "TX Long Retries",
636 be32_to_cpu(cmd_rsp.tx_longretry));
637 len += snprintf(buf + len, sizeof(buf) - len,
638 "%19s : %10u\n", "TX Xretries",
639 be32_to_cpu(cmd_rsp.tx_xretries));
640 len += snprintf(buf + len, sizeof(buf) - len,
641 "%19s : %10u\n", "TX Unaggr. Xretries",
642 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
643 len += snprintf(buf + len, sizeof(buf) - len,
644 "%19s : %10u\n", "TX Xretries (HT)",
645 be32_to_cpu(cmd_rsp.ht_tx_xretries));
646 len += snprintf(buf + len, sizeof(buf) - len,
647 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
649 if (len > sizeof(buf))
652 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
655 static const struct file_operations fops_tgt_stats = {
656 .read = read_file_tgt_stats,
657 .open = ath9k_debugfs_open,
658 .owner = THIS_MODULE,
659 .llseek = default_llseek,
662 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
663 size_t count, loff_t *ppos)
665 struct ath9k_htc_priv *priv = file->private_data;
667 unsigned int len = 0;
669 len += snprintf(buf + len, sizeof(buf) - len,
670 "%20s : %10u\n", "Buffers queued",
671 priv->debug.tx_stats.buf_queued);
672 len += snprintf(buf + len, sizeof(buf) - len,
673 "%20s : %10u\n", "Buffers completed",
674 priv->debug.tx_stats.buf_completed);
675 len += snprintf(buf + len, sizeof(buf) - len,
676 "%20s : %10u\n", "SKBs queued",
677 priv->debug.tx_stats.skb_queued);
678 len += snprintf(buf + len, sizeof(buf) - len,
679 "%20s : %10u\n", "SKBs completed",
680 priv->debug.tx_stats.skb_completed);
681 len += snprintf(buf + len, sizeof(buf) - len,
682 "%20s : %10u\n", "SKBs dropped",
683 priv->debug.tx_stats.skb_dropped);
685 len += snprintf(buf + len, sizeof(buf) - len,
686 "%20s : %10u\n", "BE queued",
687 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
688 len += snprintf(buf + len, sizeof(buf) - len,
689 "%20s : %10u\n", "BK queued",
690 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
691 len += snprintf(buf + len, sizeof(buf) - len,
692 "%20s : %10u\n", "VI queued",
693 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
694 len += snprintf(buf + len, sizeof(buf) - len,
695 "%20s : %10u\n", "VO queued",
696 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
698 if (len > sizeof(buf))
701 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
704 static const struct file_operations fops_xmit = {
705 .read = read_file_xmit,
706 .open = ath9k_debugfs_open,
707 .owner = THIS_MODULE,
708 .llseek = default_llseek,
711 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
712 size_t count, loff_t *ppos)
714 struct ath9k_htc_priv *priv = file->private_data;
716 unsigned int len = 0;
718 len += snprintf(buf + len, sizeof(buf) - len,
719 "%20s : %10u\n", "SKBs allocated",
720 priv->debug.rx_stats.skb_allocated);
721 len += snprintf(buf + len, sizeof(buf) - len,
722 "%20s : %10u\n", "SKBs completed",
723 priv->debug.rx_stats.skb_completed);
724 len += snprintf(buf + len, sizeof(buf) - len,
725 "%20s : %10u\n", "SKBs Dropped",
726 priv->debug.rx_stats.skb_dropped);
728 if (len > sizeof(buf))
731 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
734 static const struct file_operations fops_recv = {
735 .read = read_file_recv,
736 .open = ath9k_debugfs_open,
737 .owner = THIS_MODULE,
738 .llseek = default_llseek,
741 int ath9k_htc_init_debug(struct ath_hw *ah)
743 struct ath_common *common = ath9k_hw_common(ah);
744 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
746 if (!ath9k_debugfs_root)
749 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
751 if (!priv->debug.debugfs_phy)
754 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
755 priv->debug.debugfs_phy,
756 priv, &fops_tgt_stats);
757 if (!priv->debug.debugfs_tgt_stats)
761 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
762 priv->debug.debugfs_phy,
764 if (!priv->debug.debugfs_xmit)
767 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
768 priv->debug.debugfs_phy,
770 if (!priv->debug.debugfs_recv)
776 ath9k_htc_exit_debug(ah);
780 void ath9k_htc_exit_debug(struct ath_hw *ah)
782 struct ath_common *common = ath9k_hw_common(ah);
783 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
785 debugfs_remove(priv->debug.debugfs_recv);
786 debugfs_remove(priv->debug.debugfs_xmit);
787 debugfs_remove(priv->debug.debugfs_tgt_stats);
788 debugfs_remove(priv->debug.debugfs_phy);
791 int ath9k_htc_debug_create_root(void)
793 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
794 if (!ath9k_debugfs_root)
800 void ath9k_htc_debug_remove_root(void)
802 debugfs_remove(ath9k_debugfs_root);
803 ath9k_debugfs_root = NULL;
806 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
812 void ath_start_ani(struct ath9k_htc_priv *priv)
814 struct ath_common *common = ath9k_hw_common(priv->ah);
815 unsigned long timestamp = jiffies_to_msecs(jiffies);
817 common->ani.longcal_timer = timestamp;
818 common->ani.shortcal_timer = timestamp;
819 common->ani.checkani_timer = timestamp;
821 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
822 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
825 void ath9k_ani_work(struct work_struct *work)
827 struct ath9k_htc_priv *priv =
828 container_of(work, struct ath9k_htc_priv,
829 ath9k_ani_work.work);
830 struct ath_hw *ah = priv->ah;
831 struct ath_common *common = ath9k_hw_common(ah);
832 bool longcal = false;
833 bool shortcal = false;
834 bool aniflag = false;
835 unsigned int timestamp = jiffies_to_msecs(jiffies);
836 u32 cal_interval, short_cal_interval;
838 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
840 /* Only calibrate if awake */
841 if (ah->power_mode != ATH9K_PM_AWAKE)
844 /* Long calibration runs independently of short calibration. */
845 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
847 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
848 common->ani.longcal_timer = timestamp;
851 /* Short calibration applies only while caldone is false */
852 if (!common->ani.caldone) {
853 if ((timestamp - common->ani.shortcal_timer) >=
854 short_cal_interval) {
856 ath_dbg(common, ATH_DBG_ANI,
857 "shortcal @%lu\n", jiffies);
858 common->ani.shortcal_timer = timestamp;
859 common->ani.resetcal_timer = timestamp;
862 if ((timestamp - common->ani.resetcal_timer) >=
863 ATH_RESTART_CALINTERVAL) {
864 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
865 if (common->ani.caldone)
866 common->ani.resetcal_timer = timestamp;
870 /* Verify whether we must check ANI */
871 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
873 common->ani.checkani_timer = timestamp;
876 /* Skip all processing if there's nothing to do. */
877 if (longcal || shortcal || aniflag) {
879 ath9k_htc_ps_wakeup(priv);
881 /* Call ANI routine if necessary */
883 ath9k_hw_ani_monitor(ah, ah->curchan);
885 /* Perform calibration if necessary */
886 if (longcal || shortcal)
887 common->ani.caldone =
888 ath9k_hw_calibrate(ah, ah->curchan,
889 common->rx_chainmask,
892 ath9k_htc_ps_restore(priv);
897 * Set timer interval based on previous results.
898 * The interval must be the shortest necessary to satisfy ANI,
899 * short calibration and long calibration.
901 cal_interval = ATH_LONG_CALINTERVAL;
902 if (priv->ah->config.enable_ani)
903 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
904 if (!common->ani.caldone)
905 cal_interval = min(cal_interval, (u32)short_cal_interval);
907 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
908 msecs_to_jiffies(cal_interval));
911 /**********************/
912 /* mac80211 Callbacks */
913 /**********************/
915 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
917 struct ieee80211_hdr *hdr;
918 struct ath9k_htc_priv *priv = hw->priv;
919 int padpos, padsize, ret;
921 hdr = (struct ieee80211_hdr *) skb->data;
923 /* Add the padding after the header if this is not already done */
924 padpos = ath9k_cmn_padpos(hdr->frame_control);
925 padsize = padpos & 3;
926 if (padsize && skb->len > padpos) {
927 if (skb_headroom(skb) < padsize)
929 skb_push(skb, padsize);
930 memmove(skb->data, skb->data + padsize, padpos);
933 ret = ath9k_htc_tx_start(priv, skb);
935 if (ret == -ENOMEM) {
936 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
937 "Stopping TX queues\n");
938 ieee80211_stop_queues(hw);
939 spin_lock_bh(&priv->tx_lock);
940 priv->tx_queues_stop = true;
941 spin_unlock_bh(&priv->tx_lock);
943 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
952 dev_kfree_skb_any(skb);
956 static int ath9k_htc_start(struct ieee80211_hw *hw)
958 struct ath9k_htc_priv *priv = hw->priv;
959 struct ath_hw *ah = priv->ah;
960 struct ath_common *common = ath9k_hw_common(ah);
961 struct ieee80211_channel *curchan = hw->conf.channel;
962 struct ath9k_channel *init_channel;
964 enum htc_phymode mode;
968 mutex_lock(&priv->mutex);
970 ath_dbg(common, ATH_DBG_CONFIG,
971 "Starting driver with initial channel: %d MHz\n",
972 curchan->center_freq);
974 /* Ensure that HW is awake before flushing RX */
975 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
976 WMI_CMD(WMI_FLUSH_RECV_CMDID);
978 /* setup initial channel */
979 init_channel = ath9k_cmn_get_curchannel(hw, ah);
981 ath9k_hw_htc_resetinit(ah);
982 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
985 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
986 ret, curchan->center_freq);
987 mutex_unlock(&priv->mutex);
991 ath_update_txpow(priv);
993 mode = ath9k_htc_get_curmode(priv, init_channel);
994 htc_mode = cpu_to_be16(mode);
995 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
996 WMI_CMD(WMI_ATH_INIT_CMDID);
997 WMI_CMD(WMI_START_RECV_CMDID);
999 ath9k_host_rx_init(priv);
1001 priv->op_flags &= ~OP_INVALID;
1002 htc_start(priv->htc);
1004 spin_lock_bh(&priv->tx_lock);
1005 priv->tx_queues_stop = false;
1006 spin_unlock_bh(&priv->tx_lock);
1008 ieee80211_wake_queues(hw);
1010 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
1011 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1012 AR_STOMP_LOW_WLAN_WGHT);
1013 ath9k_hw_btcoex_enable(ah);
1014 ath_htc_resume_btcoex_work(priv);
1016 mutex_unlock(&priv->mutex);
1021 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1023 struct ath9k_htc_priv *priv = hw->priv;
1024 struct ath_hw *ah = priv->ah;
1025 struct ath_common *common = ath9k_hw_common(ah);
1029 mutex_lock(&priv->mutex);
1031 if (priv->op_flags & OP_INVALID) {
1032 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
1033 mutex_unlock(&priv->mutex);
1037 ath9k_htc_ps_wakeup(priv);
1038 htc_stop(priv->htc);
1039 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1040 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1041 WMI_CMD(WMI_STOP_RECV_CMDID);
1043 tasklet_kill(&priv->swba_tasklet);
1044 tasklet_kill(&priv->rx_tasklet);
1045 tasklet_kill(&priv->tx_tasklet);
1047 skb_queue_purge(&priv->tx_queue);
1049 mutex_unlock(&priv->mutex);
1051 /* Cancel all the running timers/work .. */
1052 cancel_work_sync(&priv->fatal_work);
1053 cancel_work_sync(&priv->ps_work);
1054 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1055 ath9k_led_stop_brightness(priv);
1057 mutex_lock(&priv->mutex);
1059 /* Remove monitor interface here */
1060 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1061 if (ath9k_htc_remove_monitor_interface(priv))
1062 ath_err(common, "Unable to remove monitor interface\n");
1064 ath_dbg(common, ATH_DBG_CONFIG,
1065 "Monitor interface removed\n");
1068 if (ah->btcoex_hw.enabled) {
1069 ath9k_hw_btcoex_disable(ah);
1070 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
1071 ath_htc_cancel_btcoex_work(priv);
1074 ath9k_hw_phy_disable(ah);
1075 ath9k_hw_disable(ah);
1076 ath9k_htc_ps_restore(priv);
1077 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1079 priv->op_flags |= OP_INVALID;
1081 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1082 mutex_unlock(&priv->mutex);
1085 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1086 struct ieee80211_vif *vif)
1088 struct ath9k_htc_priv *priv = hw->priv;
1089 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1090 struct ath_common *common = ath9k_hw_common(priv->ah);
1091 struct ath9k_htc_target_vif hvif;
1095 mutex_lock(&priv->mutex);
1097 /* Only one interface for now */
1098 if (priv->nvifs > 0) {
1103 ath9k_htc_ps_wakeup(priv);
1104 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1105 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1107 switch (vif->type) {
1108 case NL80211_IFTYPE_STATION:
1109 hvif.opmode = cpu_to_be32(HTC_M_STA);
1111 case NL80211_IFTYPE_ADHOC:
1112 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1116 "Interface type %d not yet supported\n", vif->type);
1121 ath_dbg(common, ATH_DBG_CONFIG,
1122 "Attach a VIF of type: %d\n", vif->type);
1124 priv->ah->opmode = vif->type;
1126 /* Index starts from zero on the target */
1127 avp->index = hvif.index = priv->nvifs;
1128 hvif.rtsthreshold = cpu_to_be16(2304);
1129 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1136 * We need a node in target to tx mgmt frames
1137 * before association.
1139 ret = ath9k_htc_add_station(priv, vif, NULL);
1143 ret = ath9k_htc_update_cap_target(priv);
1145 ath_dbg(common, ATH_DBG_CONFIG,
1146 "Failed to update capability in target\n");
1150 ath9k_htc_ps_restore(priv);
1151 mutex_unlock(&priv->mutex);
1156 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1157 struct ieee80211_vif *vif)
1159 struct ath9k_htc_priv *priv = hw->priv;
1160 struct ath_common *common = ath9k_hw_common(priv->ah);
1161 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1162 struct ath9k_htc_target_vif hvif;
1166 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface\n");
1168 mutex_lock(&priv->mutex);
1169 ath9k_htc_ps_wakeup(priv);
1171 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1172 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1173 hvif.index = avp->index;
1174 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1177 ath9k_htc_remove_station(priv, vif, NULL);
1180 ath9k_htc_ps_restore(priv);
1181 mutex_unlock(&priv->mutex);
1184 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1186 struct ath9k_htc_priv *priv = hw->priv;
1187 struct ath_common *common = ath9k_hw_common(priv->ah);
1188 struct ieee80211_conf *conf = &hw->conf;
1190 mutex_lock(&priv->mutex);
1192 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1193 bool enable_radio = false;
1194 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1196 mutex_lock(&priv->htc_pm_lock);
1197 if (!idle && priv->ps_idle)
1198 enable_radio = true;
1199 priv->ps_idle = idle;
1200 mutex_unlock(&priv->htc_pm_lock);
1203 ath_dbg(common, ATH_DBG_CONFIG,
1204 "not-idle: enabling radio\n");
1205 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1206 ath9k_htc_radio_enable(hw);
1211 * Monitor interface should be added before
1212 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1214 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1215 if (conf->flags & IEEE80211_CONF_MONITOR) {
1216 if (ath9k_htc_add_monitor_interface(priv))
1217 ath_err(common, "Failed to set monitor mode\n");
1219 ath_dbg(common, ATH_DBG_CONFIG,
1220 "HW opmode set to Monitor mode\n");
1224 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1225 struct ieee80211_channel *curchan = hw->conf.channel;
1226 int pos = curchan->hw_value;
1228 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1229 curchan->center_freq);
1231 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1233 hw->conf.channel_type);
1235 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1236 ath_err(common, "Unable to set channel\n");
1237 mutex_unlock(&priv->mutex);
1243 if (changed & IEEE80211_CONF_CHANGE_PS) {
1244 if (conf->flags & IEEE80211_CONF_PS) {
1245 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1246 priv->ps_enabled = true;
1248 priv->ps_enabled = false;
1249 cancel_work_sync(&priv->ps_work);
1250 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1254 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1255 priv->txpowlimit = 2 * conf->power_level;
1256 ath_update_txpow(priv);
1259 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1260 mutex_lock(&priv->htc_pm_lock);
1261 if (!priv->ps_idle) {
1262 mutex_unlock(&priv->htc_pm_lock);
1265 mutex_unlock(&priv->htc_pm_lock);
1267 ath_dbg(common, ATH_DBG_CONFIG,
1268 "idle: disabling radio\n");
1269 ath9k_htc_radio_disable(hw);
1273 mutex_unlock(&priv->mutex);
1277 #define SUPPORTED_FILTERS \
1278 (FIF_PROMISC_IN_BSS | \
1283 FIF_BCN_PRBRESP_PROMISC | \
1287 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1288 unsigned int changed_flags,
1289 unsigned int *total_flags,
1292 struct ath9k_htc_priv *priv = hw->priv;
1295 mutex_lock(&priv->mutex);
1296 ath9k_htc_ps_wakeup(priv);
1298 changed_flags &= SUPPORTED_FILTERS;
1299 *total_flags &= SUPPORTED_FILTERS;
1301 priv->rxfilter = *total_flags;
1302 rfilt = ath9k_htc_calcrxfilter(priv);
1303 ath9k_hw_setrxfilter(priv->ah, rfilt);
1305 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1306 "Set HW RX filter: 0x%x\n", rfilt);
1308 ath9k_htc_ps_restore(priv);
1309 mutex_unlock(&priv->mutex);
1312 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1313 struct ieee80211_vif *vif,
1314 struct ieee80211_sta *sta)
1316 struct ath9k_htc_priv *priv = hw->priv;
1319 mutex_lock(&priv->mutex);
1320 ath9k_htc_ps_wakeup(priv);
1321 ret = ath9k_htc_add_station(priv, vif, sta);
1323 ath9k_htc_init_rate(priv, sta);
1324 ath9k_htc_ps_restore(priv);
1325 mutex_unlock(&priv->mutex);
1330 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1331 struct ieee80211_vif *vif,
1332 struct ieee80211_sta *sta)
1334 struct ath9k_htc_priv *priv = hw->priv;
1337 mutex_lock(&priv->mutex);
1338 ath9k_htc_ps_wakeup(priv);
1339 ret = ath9k_htc_remove_station(priv, vif, sta);
1340 ath9k_htc_ps_restore(priv);
1341 mutex_unlock(&priv->mutex);
1346 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1347 const struct ieee80211_tx_queue_params *params)
1349 struct ath9k_htc_priv *priv = hw->priv;
1350 struct ath_common *common = ath9k_hw_common(priv->ah);
1351 struct ath9k_tx_queue_info qi;
1354 if (queue >= WME_NUM_AC)
1357 mutex_lock(&priv->mutex);
1358 ath9k_htc_ps_wakeup(priv);
1360 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1362 qi.tqi_aifs = params->aifs;
1363 qi.tqi_cwmin = params->cw_min;
1364 qi.tqi_cwmax = params->cw_max;
1365 qi.tqi_burstTime = params->txop;
1367 qnum = get_hw_qnum(queue, priv->hwq_map);
1369 ath_dbg(common, ATH_DBG_CONFIG,
1370 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1371 queue, qnum, params->aifs, params->cw_min,
1372 params->cw_max, params->txop);
1374 ret = ath_htc_txq_update(priv, qnum, &qi);
1376 ath_err(common, "TXQ Update failed\n");
1380 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1381 (qnum == priv->hwq_map[WME_AC_BE]))
1382 ath9k_htc_beaconq_config(priv);
1384 ath9k_htc_ps_restore(priv);
1385 mutex_unlock(&priv->mutex);
1390 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1391 enum set_key_cmd cmd,
1392 struct ieee80211_vif *vif,
1393 struct ieee80211_sta *sta,
1394 struct ieee80211_key_conf *key)
1396 struct ath9k_htc_priv *priv = hw->priv;
1397 struct ath_common *common = ath9k_hw_common(priv->ah);
1400 if (htc_modparam_nohwcrypt)
1403 mutex_lock(&priv->mutex);
1404 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1405 ath9k_htc_ps_wakeup(priv);
1409 ret = ath_key_config(common, vif, sta, key);
1411 key->hw_key_idx = ret;
1412 /* push IV and Michael MIC generation to stack */
1413 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1414 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1415 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1416 if (priv->ah->sw_mgmt_crypto &&
1417 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1418 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1423 ath_key_delete(common, key);
1429 ath9k_htc_ps_restore(priv);
1430 mutex_unlock(&priv->mutex);
1435 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1436 struct ieee80211_vif *vif,
1437 struct ieee80211_bss_conf *bss_conf,
1440 struct ath9k_htc_priv *priv = hw->priv;
1441 struct ath_hw *ah = priv->ah;
1442 struct ath_common *common = ath9k_hw_common(ah);
1444 mutex_lock(&priv->mutex);
1445 ath9k_htc_ps_wakeup(priv);
1447 if (changed & BSS_CHANGED_ASSOC) {
1448 common->curaid = bss_conf->assoc ?
1450 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1453 if (bss_conf->assoc) {
1454 priv->op_flags |= OP_ASSOCIATED;
1455 ath_start_ani(priv);
1457 priv->op_flags &= ~OP_ASSOCIATED;
1458 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1462 if (changed & BSS_CHANGED_BSSID) {
1464 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1465 ath9k_hw_write_associd(ah);
1467 ath_dbg(common, ATH_DBG_CONFIG,
1468 "BSSID: %pM aid: 0x%x\n",
1469 common->curbssid, common->curaid);
1472 if ((changed & BSS_CHANGED_BEACON_INT) ||
1473 (changed & BSS_CHANGED_BEACON) ||
1474 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1475 bss_conf->enable_beacon)) {
1476 priv->op_flags |= OP_ENABLE_BEACON;
1477 ath9k_htc_beacon_config(priv, vif);
1480 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1481 !bss_conf->enable_beacon) {
1482 priv->op_flags &= ~OP_ENABLE_BEACON;
1483 ath9k_htc_beacon_config(priv, vif);
1486 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1487 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1488 bss_conf->use_short_preamble);
1489 if (bss_conf->use_short_preamble)
1490 priv->op_flags |= OP_PREAMBLE_SHORT;
1492 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1495 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1496 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1497 bss_conf->use_cts_prot);
1498 if (bss_conf->use_cts_prot &&
1499 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1500 priv->op_flags |= OP_PROTECT_ENABLE;
1502 priv->op_flags &= ~OP_PROTECT_ENABLE;
1505 if (changed & BSS_CHANGED_ERP_SLOT) {
1506 if (bss_conf->use_short_slot)
1511 ath9k_hw_init_global_settings(ah);
1514 if (changed & BSS_CHANGED_HT)
1515 ath9k_htc_update_rate(priv, vif, bss_conf);
1517 ath9k_htc_ps_restore(priv);
1518 mutex_unlock(&priv->mutex);
1521 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1523 struct ath9k_htc_priv *priv = hw->priv;
1526 mutex_lock(&priv->mutex);
1527 ath9k_htc_ps_wakeup(priv);
1528 tsf = ath9k_hw_gettsf64(priv->ah);
1529 ath9k_htc_ps_restore(priv);
1530 mutex_unlock(&priv->mutex);
1535 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1537 struct ath9k_htc_priv *priv = hw->priv;
1539 mutex_lock(&priv->mutex);
1540 ath9k_htc_ps_wakeup(priv);
1541 ath9k_hw_settsf64(priv->ah, tsf);
1542 ath9k_htc_ps_restore(priv);
1543 mutex_unlock(&priv->mutex);
1546 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1548 struct ath9k_htc_priv *priv = hw->priv;
1550 mutex_lock(&priv->mutex);
1551 ath9k_htc_ps_wakeup(priv);
1552 ath9k_hw_reset_tsf(priv->ah);
1553 ath9k_htc_ps_restore(priv);
1554 mutex_unlock(&priv->mutex);
1557 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1558 struct ieee80211_vif *vif,
1559 enum ieee80211_ampdu_mlme_action action,
1560 struct ieee80211_sta *sta,
1561 u16 tid, u16 *ssn, u8 buf_size)
1563 struct ath9k_htc_priv *priv = hw->priv;
1564 struct ath9k_htc_sta *ista;
1568 case IEEE80211_AMPDU_RX_START:
1570 case IEEE80211_AMPDU_RX_STOP:
1572 case IEEE80211_AMPDU_TX_START:
1573 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1575 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1577 case IEEE80211_AMPDU_TX_STOP:
1578 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1579 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1581 case IEEE80211_AMPDU_TX_OPERATIONAL:
1582 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1583 spin_lock_bh(&priv->tx_lock);
1584 ista->tid_state[tid] = AGGR_OPERATIONAL;
1585 spin_unlock_bh(&priv->tx_lock);
1588 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1594 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1596 struct ath9k_htc_priv *priv = hw->priv;
1598 mutex_lock(&priv->mutex);
1599 spin_lock_bh(&priv->beacon_lock);
1600 priv->op_flags |= OP_SCANNING;
1601 spin_unlock_bh(&priv->beacon_lock);
1602 cancel_work_sync(&priv->ps_work);
1603 if (priv->op_flags & OP_ASSOCIATED)
1604 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1605 mutex_unlock(&priv->mutex);
1608 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1610 struct ath9k_htc_priv *priv = hw->priv;
1612 mutex_lock(&priv->mutex);
1613 ath9k_htc_ps_wakeup(priv);
1614 spin_lock_bh(&priv->beacon_lock);
1615 priv->op_flags &= ~OP_SCANNING;
1616 spin_unlock_bh(&priv->beacon_lock);
1617 if (priv->op_flags & OP_ASSOCIATED) {
1618 ath9k_htc_beacon_config(priv, priv->vif);
1619 ath_start_ani(priv);
1621 ath9k_htc_ps_restore(priv);
1622 mutex_unlock(&priv->mutex);
1625 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1630 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1633 struct ath9k_htc_priv *priv = hw->priv;
1635 mutex_lock(&priv->mutex);
1636 ath9k_htc_ps_wakeup(priv);
1637 priv->ah->coverage_class = coverage_class;
1638 ath9k_hw_init_global_settings(priv->ah);
1639 ath9k_htc_ps_restore(priv);
1640 mutex_unlock(&priv->mutex);
1643 struct ieee80211_ops ath9k_htc_ops = {
1645 .start = ath9k_htc_start,
1646 .stop = ath9k_htc_stop,
1647 .add_interface = ath9k_htc_add_interface,
1648 .remove_interface = ath9k_htc_remove_interface,
1649 .config = ath9k_htc_config,
1650 .configure_filter = ath9k_htc_configure_filter,
1651 .sta_add = ath9k_htc_sta_add,
1652 .sta_remove = ath9k_htc_sta_remove,
1653 .conf_tx = ath9k_htc_conf_tx,
1654 .bss_info_changed = ath9k_htc_bss_info_changed,
1655 .set_key = ath9k_htc_set_key,
1656 .get_tsf = ath9k_htc_get_tsf,
1657 .set_tsf = ath9k_htc_set_tsf,
1658 .reset_tsf = ath9k_htc_reset_tsf,
1659 .ampdu_action = ath9k_htc_ampdu_action,
1660 .sw_scan_start = ath9k_htc_sw_scan_start,
1661 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1662 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1663 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1664 .set_coverage_class = ath9k_htc_set_coverage_class,