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 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
28 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
29 struct ath9k_channel *ichan)
31 enum htc_phymode mode;
35 switch (ichan->chanmode) {
38 case CHANNEL_G_HT40PLUS:
39 case CHANNEL_G_HT40MINUS:
44 case CHANNEL_A_HT40PLUS:
45 case CHANNEL_A_HT40MINUS:
55 bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
56 enum ath9k_power_mode mode)
60 mutex_lock(&priv->htc_pm_lock);
61 ret = ath9k_hw_setpower(priv->ah, mode);
62 mutex_unlock(&priv->htc_pm_lock);
67 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
69 mutex_lock(&priv->htc_pm_lock);
70 if (++priv->ps_usecount != 1)
72 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
75 mutex_unlock(&priv->htc_pm_lock);
78 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
80 mutex_lock(&priv->htc_pm_lock);
81 if (--priv->ps_usecount != 0)
85 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
86 else if (priv->ps_enabled)
87 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
90 mutex_unlock(&priv->htc_pm_lock);
93 void ath9k_ps_work(struct work_struct *work)
95 struct ath9k_htc_priv *priv =
96 container_of(work, struct ath9k_htc_priv,
98 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
100 /* The chip wakes up after receiving the first beacon
101 while network sleep is enabled. For the driver to
102 be in sync with the hw, set the chip to awake and
103 only then set it to sleep.
105 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
108 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
110 struct ath_hw *ah = priv->ah;
111 struct ath_common *common = ath9k_hw_common(ah);
112 struct ieee80211_channel *channel = priv->hw->conf.channel;
113 struct ath9k_hw_cal_data *caldata = NULL;
114 enum htc_phymode mode;
119 mutex_lock(&priv->mutex);
120 ath9k_htc_ps_wakeup(priv);
122 if (priv->op_flags & OP_ASSOCIATED)
123 cancel_delayed_work_sync(&priv->ath9k_ani_work);
125 ieee80211_stop_queues(priv->hw);
127 WMI_CMD(WMI_DISABLE_INTR_CMDID);
128 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
129 WMI_CMD(WMI_STOP_RECV_CMDID);
131 caldata = &priv->caldata;
132 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
135 "Unable to reset device (%u Mhz) reset status %d\n",
136 channel->center_freq, ret);
139 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
142 WMI_CMD(WMI_START_RECV_CMDID);
143 ath9k_host_rx_init(priv);
145 mode = ath9k_htc_get_curmode(priv, ah->curchan);
146 htc_mode = cpu_to_be16(mode);
147 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
149 WMI_CMD(WMI_ENABLE_INTR_CMDID);
150 htc_start(priv->htc);
152 if (priv->op_flags & OP_ASSOCIATED) {
153 ath9k_htc_beacon_config(priv, priv->vif);
157 ieee80211_wake_queues(priv->hw);
159 ath9k_htc_ps_restore(priv);
160 mutex_unlock(&priv->mutex);
163 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
164 struct ieee80211_hw *hw,
165 struct ath9k_channel *hchan)
167 struct ath_hw *ah = priv->ah;
168 struct ath_common *common = ath9k_hw_common(ah);
169 struct ieee80211_conf *conf = &common->hw->conf;
171 struct ieee80211_channel *channel = hw->conf.channel;
172 struct ath9k_hw_cal_data *caldata = NULL;
173 enum htc_phymode mode;
178 if (priv->op_flags & OP_INVALID)
181 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
183 ath9k_htc_ps_wakeup(priv);
185 WMI_CMD(WMI_DISABLE_INTR_CMDID);
186 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
187 WMI_CMD(WMI_STOP_RECV_CMDID);
189 ath_dbg(common, ATH_DBG_CONFIG,
190 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
191 priv->ah->curchan->channel,
192 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
196 caldata = &priv->caldata;
197 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
200 "Unable to reset channel (%u Mhz) reset status %d\n",
201 channel->center_freq, ret);
205 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
208 WMI_CMD(WMI_START_RECV_CMDID);
212 ath9k_host_rx_init(priv);
214 mode = ath9k_htc_get_curmode(priv, hchan);
215 htc_mode = cpu_to_be16(mode);
216 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
220 WMI_CMD(WMI_ENABLE_INTR_CMDID);
224 htc_start(priv->htc);
226 ath9k_htc_ps_restore(priv);
230 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
232 struct ath_common *common = ath9k_hw_common(priv->ah);
233 struct ath9k_htc_target_vif hvif;
237 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
238 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
239 hvif.index = 0; /* Should do for now */
240 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
244 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
246 struct ath_common *common = ath9k_hw_common(priv->ah);
247 struct ath9k_htc_target_vif hvif;
248 struct ath9k_htc_target_sta tsta;
255 if (priv->nstations >= ATH9K_HTC_MAX_STA)
262 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
263 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
265 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
266 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
267 hvif.index = priv->nvifs;
269 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
276 * Associate a station with the interface for packet injection.
279 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
281 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
284 tsta.sta_index = priv->nstations;
285 tsta.vif_index = hvif.index;
286 tsta.maxampdu = 0xffff;
288 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
290 ath_err(common, "Unable to add station entry for monitor mode\n");
297 * Set chainmask etc. on the target.
299 ret = ath9k_htc_update_cap_target(priv);
301 ath_dbg(common, ATH_DBG_CONFIG,
302 "Failed to update capability in target\n");
304 priv->ah->is_monitoring = true;
310 * Remove the interface from the target.
312 __ath9k_htc_remove_monitor_interface(priv);
316 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
318 struct ath_common *common = ath9k_hw_common(priv->ah);
322 __ath9k_htc_remove_monitor_interface(priv);
324 sta_idx = 0; /* Only single interface, for now */
326 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
328 ath_err(common, "Unable to remove station entry for monitor mode\n");
333 priv->ah->is_monitoring = false;
338 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
339 struct ieee80211_vif *vif,
340 struct ieee80211_sta *sta)
342 struct ath_common *common = ath9k_hw_common(priv->ah);
343 struct ath9k_htc_target_sta tsta;
344 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
345 struct ath9k_htc_sta *ista;
349 if (priv->nstations >= ATH9K_HTC_MAX_STA)
352 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
355 ista = (struct ath9k_htc_sta *) sta->drv_priv;
356 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
357 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
358 tsta.associd = common->curaid;
361 ista->index = priv->nstations;
363 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
367 tsta.sta_index = priv->nstations;
368 tsta.vif_index = avp->index;
369 tsta.maxampdu = 0xffff;
370 if (sta && sta->ht_cap.ht_supported)
371 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
373 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
377 "Unable to add station entry for: %pM\n",
383 ath_dbg(common, ATH_DBG_CONFIG,
384 "Added a station entry for: %pM (idx: %d)\n",
385 sta->addr, tsta.sta_index);
391 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
392 struct ieee80211_vif *vif,
393 struct ieee80211_sta *sta)
395 struct ath_common *common = ath9k_hw_common(priv->ah);
396 struct ath9k_htc_sta *ista;
401 ista = (struct ath9k_htc_sta *) sta->drv_priv;
402 sta_idx = ista->index;
407 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
411 "Unable to remove station entry for: %pM\n",
417 ath_dbg(common, ATH_DBG_CONFIG,
418 "Removed a station entry for: %pM (idx: %d)\n",
425 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
427 struct ath9k_htc_cap_target tcap;
431 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
433 /* FIXME: Values are hardcoded */
434 tcap.flags = 0x240c40;
435 tcap.flags_ext = 0x80601000;
436 tcap.ampdu_limit = 0xffff0000;
437 tcap.ampdu_subframes = 20;
438 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
440 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
442 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
447 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
448 struct ieee80211_sta *sta,
449 struct ath9k_htc_target_rate *trate)
451 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
452 struct ieee80211_supported_band *sband;
456 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
458 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
459 if (sta->supp_rates[sband->band] & BIT(i)) {
460 trate->rates.legacy_rates.rs_rates[j]
461 = (sband->bitrates[i].bitrate * 2) / 10;
465 trate->rates.legacy_rates.rs_nrates = j;
467 if (sta->ht_cap.ht_supported) {
468 for (i = 0, j = 0; i < 77; i++) {
469 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
470 trate->rates.ht_rates.rs_rates[j++] = i;
471 if (j == ATH_HTC_RATE_MAX)
474 trate->rates.ht_rates.rs_nrates = j;
476 caps = WLAN_RC_HT_FLAG;
477 if (sta->ht_cap.mcs.rx_mask[1])
478 caps |= WLAN_RC_DS_FLAG;
479 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
480 (conf_is_ht40(&priv->hw->conf)))
481 caps |= WLAN_RC_40_FLAG;
482 if (conf_is_ht40(&priv->hw->conf) &&
483 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
484 caps |= WLAN_RC_SGI_FLAG;
485 else if (conf_is_ht20(&priv->hw->conf) &&
486 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
487 caps |= WLAN_RC_SGI_FLAG;
490 trate->sta_index = ista->index;
492 trate->capflags = cpu_to_be32(caps);
495 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
496 struct ath9k_htc_target_rate *trate)
498 struct ath_common *common = ath9k_hw_common(priv->ah);
502 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
505 "Unable to initialize Rate information on target\n");
511 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
512 struct ieee80211_sta *sta)
514 struct ath_common *common = ath9k_hw_common(priv->ah);
515 struct ath9k_htc_target_rate trate;
518 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
519 ath9k_htc_setup_rate(priv, sta, &trate);
520 ret = ath9k_htc_send_rate_cmd(priv, &trate);
522 ath_dbg(common, ATH_DBG_CONFIG,
523 "Updated target sta: %pM, rate caps: 0x%X\n",
524 sta->addr, be32_to_cpu(trate.capflags));
527 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
528 struct ieee80211_vif *vif,
529 struct ieee80211_bss_conf *bss_conf)
531 struct ath_common *common = ath9k_hw_common(priv->ah);
532 struct ath9k_htc_target_rate trate;
533 struct ieee80211_sta *sta;
536 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
539 sta = ieee80211_find_sta(vif, bss_conf->bssid);
544 ath9k_htc_setup_rate(priv, sta, &trate);
547 ret = ath9k_htc_send_rate_cmd(priv, &trate);
549 ath_dbg(common, ATH_DBG_CONFIG,
550 "Updated target sta: %pM, rate caps: 0x%X\n",
551 bss_conf->bssid, be32_to_cpu(trate.capflags));
554 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
555 struct ieee80211_vif *vif,
556 struct ieee80211_sta *sta,
557 enum ieee80211_ampdu_mlme_action action,
560 struct ath_common *common = ath9k_hw_common(priv->ah);
561 struct ath9k_htc_target_aggr aggr;
562 struct ath9k_htc_sta *ista;
566 if (tid >= ATH9K_HTC_MAX_TID)
569 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
570 ista = (struct ath9k_htc_sta *) sta->drv_priv;
572 aggr.sta_index = ista->index;
573 aggr.tidno = tid & 0xf;
574 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
576 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
578 ath_dbg(common, ATH_DBG_CONFIG,
579 "Unable to %s TX aggregation for (%pM, %d)\n",
580 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
582 ath_dbg(common, ATH_DBG_CONFIG,
583 "%s TX aggregation for (%pM, %d)\n",
584 (aggr.aggr_enable) ? "Starting" : "Stopping",
587 spin_lock_bh(&priv->tx_lock);
588 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
589 spin_unlock_bh(&priv->tx_lock);
598 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
600 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
602 file->private_data = inode->i_private;
606 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
607 size_t count, loff_t *ppos)
609 struct ath9k_htc_priv *priv = file->private_data;
610 struct ath9k_htc_target_stats cmd_rsp;
612 unsigned int len = 0;
615 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
617 WMI_CMD(WMI_TGT_STATS_CMDID);
622 len += snprintf(buf + len, sizeof(buf) - len,
623 "%19s : %10u\n", "TX Short Retries",
624 be32_to_cpu(cmd_rsp.tx_shortretry));
625 len += snprintf(buf + len, sizeof(buf) - len,
626 "%19s : %10u\n", "TX Long Retries",
627 be32_to_cpu(cmd_rsp.tx_longretry));
628 len += snprintf(buf + len, sizeof(buf) - len,
629 "%19s : %10u\n", "TX Xretries",
630 be32_to_cpu(cmd_rsp.tx_xretries));
631 len += snprintf(buf + len, sizeof(buf) - len,
632 "%19s : %10u\n", "TX Unaggr. Xretries",
633 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
634 len += snprintf(buf + len, sizeof(buf) - len,
635 "%19s : %10u\n", "TX Xretries (HT)",
636 be32_to_cpu(cmd_rsp.ht_tx_xretries));
637 len += snprintf(buf + len, sizeof(buf) - len,
638 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
640 if (len > sizeof(buf))
643 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
646 static const struct file_operations fops_tgt_stats = {
647 .read = read_file_tgt_stats,
648 .open = ath9k_debugfs_open,
649 .owner = THIS_MODULE,
650 .llseek = default_llseek,
653 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
654 size_t count, loff_t *ppos)
656 struct ath9k_htc_priv *priv = file->private_data;
658 unsigned int len = 0;
660 len += snprintf(buf + len, sizeof(buf) - len,
661 "%20s : %10u\n", "Buffers queued",
662 priv->debug.tx_stats.buf_queued);
663 len += snprintf(buf + len, sizeof(buf) - len,
664 "%20s : %10u\n", "Buffers completed",
665 priv->debug.tx_stats.buf_completed);
666 len += snprintf(buf + len, sizeof(buf) - len,
667 "%20s : %10u\n", "SKBs queued",
668 priv->debug.tx_stats.skb_queued);
669 len += snprintf(buf + len, sizeof(buf) - len,
670 "%20s : %10u\n", "SKBs completed",
671 priv->debug.tx_stats.skb_completed);
672 len += snprintf(buf + len, sizeof(buf) - len,
673 "%20s : %10u\n", "SKBs dropped",
674 priv->debug.tx_stats.skb_dropped);
676 len += snprintf(buf + len, sizeof(buf) - len,
677 "%20s : %10u\n", "BE queued",
678 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
679 len += snprintf(buf + len, sizeof(buf) - len,
680 "%20s : %10u\n", "BK queued",
681 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
682 len += snprintf(buf + len, sizeof(buf) - len,
683 "%20s : %10u\n", "VI queued",
684 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
685 len += snprintf(buf + len, sizeof(buf) - len,
686 "%20s : %10u\n", "VO queued",
687 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
689 if (len > sizeof(buf))
692 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
695 static const struct file_operations fops_xmit = {
696 .read = read_file_xmit,
697 .open = ath9k_debugfs_open,
698 .owner = THIS_MODULE,
699 .llseek = default_llseek,
702 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
703 size_t count, loff_t *ppos)
705 struct ath9k_htc_priv *priv = file->private_data;
707 unsigned int len = 0;
709 len += snprintf(buf + len, sizeof(buf) - len,
710 "%20s : %10u\n", "SKBs allocated",
711 priv->debug.rx_stats.skb_allocated);
712 len += snprintf(buf + len, sizeof(buf) - len,
713 "%20s : %10u\n", "SKBs completed",
714 priv->debug.rx_stats.skb_completed);
715 len += snprintf(buf + len, sizeof(buf) - len,
716 "%20s : %10u\n", "SKBs Dropped",
717 priv->debug.rx_stats.skb_dropped);
719 if (len > sizeof(buf))
722 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
725 static const struct file_operations fops_recv = {
726 .read = read_file_recv,
727 .open = ath9k_debugfs_open,
728 .owner = THIS_MODULE,
729 .llseek = default_llseek,
732 int ath9k_htc_init_debug(struct ath_hw *ah)
734 struct ath_common *common = ath9k_hw_common(ah);
735 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
737 if (!ath9k_debugfs_root)
740 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
742 if (!priv->debug.debugfs_phy)
745 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
746 priv->debug.debugfs_phy,
747 priv, &fops_tgt_stats);
748 if (!priv->debug.debugfs_tgt_stats)
752 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
753 priv->debug.debugfs_phy,
755 if (!priv->debug.debugfs_xmit)
758 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
759 priv->debug.debugfs_phy,
761 if (!priv->debug.debugfs_recv)
767 ath9k_htc_exit_debug(ah);
771 void ath9k_htc_exit_debug(struct ath_hw *ah)
773 struct ath_common *common = ath9k_hw_common(ah);
774 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
776 debugfs_remove(priv->debug.debugfs_recv);
777 debugfs_remove(priv->debug.debugfs_xmit);
778 debugfs_remove(priv->debug.debugfs_tgt_stats);
779 debugfs_remove(priv->debug.debugfs_phy);
782 int ath9k_htc_debug_create_root(void)
784 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
785 if (!ath9k_debugfs_root)
791 void ath9k_htc_debug_remove_root(void)
793 debugfs_remove(ath9k_debugfs_root);
794 ath9k_debugfs_root = NULL;
797 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
803 void ath_start_ani(struct ath9k_htc_priv *priv)
805 struct ath_common *common = ath9k_hw_common(priv->ah);
806 unsigned long timestamp = jiffies_to_msecs(jiffies);
808 common->ani.longcal_timer = timestamp;
809 common->ani.shortcal_timer = timestamp;
810 common->ani.checkani_timer = timestamp;
812 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
813 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
816 void ath9k_ani_work(struct work_struct *work)
818 struct ath9k_htc_priv *priv =
819 container_of(work, struct ath9k_htc_priv,
820 ath9k_ani_work.work);
821 struct ath_hw *ah = priv->ah;
822 struct ath_common *common = ath9k_hw_common(ah);
823 bool longcal = false;
824 bool shortcal = false;
825 bool aniflag = false;
826 unsigned int timestamp = jiffies_to_msecs(jiffies);
827 u32 cal_interval, short_cal_interval;
829 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
831 /* Only calibrate if awake */
832 if (ah->power_mode != ATH9K_PM_AWAKE)
835 /* Long calibration runs independently of short calibration. */
836 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
838 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
839 common->ani.longcal_timer = timestamp;
842 /* Short calibration applies only while caldone is false */
843 if (!common->ani.caldone) {
844 if ((timestamp - common->ani.shortcal_timer) >=
845 short_cal_interval) {
847 ath_dbg(common, ATH_DBG_ANI,
848 "shortcal @%lu\n", jiffies);
849 common->ani.shortcal_timer = timestamp;
850 common->ani.resetcal_timer = timestamp;
853 if ((timestamp - common->ani.resetcal_timer) >=
854 ATH_RESTART_CALINTERVAL) {
855 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
856 if (common->ani.caldone)
857 common->ani.resetcal_timer = timestamp;
861 /* Verify whether we must check ANI */
862 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
864 common->ani.checkani_timer = timestamp;
867 /* Skip all processing if there's nothing to do. */
868 if (longcal || shortcal || aniflag) {
870 ath9k_htc_ps_wakeup(priv);
872 /* Call ANI routine if necessary */
874 ath9k_hw_ani_monitor(ah, ah->curchan);
876 /* Perform calibration if necessary */
877 if (longcal || shortcal)
878 common->ani.caldone =
879 ath9k_hw_calibrate(ah, ah->curchan,
880 common->rx_chainmask,
883 ath9k_htc_ps_restore(priv);
888 * Set timer interval based on previous results.
889 * The interval must be the shortest necessary to satisfy ANI,
890 * short calibration and long calibration.
892 cal_interval = ATH_LONG_CALINTERVAL;
893 if (priv->ah->config.enable_ani)
894 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
895 if (!common->ani.caldone)
896 cal_interval = min(cal_interval, (u32)short_cal_interval);
898 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
899 msecs_to_jiffies(cal_interval));
902 /**********************/
903 /* mac80211 Callbacks */
904 /**********************/
906 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
908 struct ieee80211_hdr *hdr;
909 struct ath9k_htc_priv *priv = hw->priv;
910 int padpos, padsize, ret;
912 hdr = (struct ieee80211_hdr *) skb->data;
914 /* Add the padding after the header if this is not already done */
915 padpos = ath9k_cmn_padpos(hdr->frame_control);
916 padsize = padpos & 3;
917 if (padsize && skb->len > padpos) {
918 if (skb_headroom(skb) < padsize)
920 skb_push(skb, padsize);
921 memmove(skb->data, skb->data + padsize, padpos);
924 ret = ath9k_htc_tx_start(priv, skb);
926 if (ret == -ENOMEM) {
927 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
928 "Stopping TX queues\n");
929 ieee80211_stop_queues(hw);
930 spin_lock_bh(&priv->tx_lock);
931 priv->tx_queues_stop = true;
932 spin_unlock_bh(&priv->tx_lock);
934 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
943 dev_kfree_skb_any(skb);
947 static int ath9k_htc_start(struct ieee80211_hw *hw)
949 struct ath9k_htc_priv *priv = hw->priv;
950 struct ath_hw *ah = priv->ah;
951 struct ath_common *common = ath9k_hw_common(ah);
952 struct ieee80211_channel *curchan = hw->conf.channel;
953 struct ath9k_channel *init_channel;
955 enum htc_phymode mode;
959 mutex_lock(&priv->mutex);
961 ath_dbg(common, ATH_DBG_CONFIG,
962 "Starting driver with initial channel: %d MHz\n",
963 curchan->center_freq);
965 /* Ensure that HW is awake before flushing RX */
966 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
967 WMI_CMD(WMI_FLUSH_RECV_CMDID);
969 /* setup initial channel */
970 init_channel = ath9k_cmn_get_curchannel(hw, ah);
972 ath9k_hw_htc_resetinit(ah);
973 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
976 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
977 ret, curchan->center_freq);
978 mutex_unlock(&priv->mutex);
982 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
985 mode = ath9k_htc_get_curmode(priv, init_channel);
986 htc_mode = cpu_to_be16(mode);
987 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
988 WMI_CMD(WMI_ATH_INIT_CMDID);
989 WMI_CMD(WMI_START_RECV_CMDID);
991 ath9k_host_rx_init(priv);
993 priv->op_flags &= ~OP_INVALID;
994 htc_start(priv->htc);
996 spin_lock_bh(&priv->tx_lock);
997 priv->tx_queues_stop = false;
998 spin_unlock_bh(&priv->tx_lock);
1000 ieee80211_wake_queues(hw);
1002 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
1003 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1004 AR_STOMP_LOW_WLAN_WGHT);
1005 ath9k_hw_btcoex_enable(ah);
1006 ath_htc_resume_btcoex_work(priv);
1008 mutex_unlock(&priv->mutex);
1013 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1015 struct ath9k_htc_priv *priv = hw->priv;
1016 struct ath_hw *ah = priv->ah;
1017 struct ath_common *common = ath9k_hw_common(ah);
1021 mutex_lock(&priv->mutex);
1023 if (priv->op_flags & OP_INVALID) {
1024 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
1025 mutex_unlock(&priv->mutex);
1029 ath9k_htc_ps_wakeup(priv);
1030 htc_stop(priv->htc);
1031 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1032 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1033 WMI_CMD(WMI_STOP_RECV_CMDID);
1035 tasklet_kill(&priv->swba_tasklet);
1036 tasklet_kill(&priv->rx_tasklet);
1037 tasklet_kill(&priv->tx_tasklet);
1039 skb_queue_purge(&priv->tx_queue);
1041 mutex_unlock(&priv->mutex);
1043 /* Cancel all the running timers/work .. */
1044 cancel_work_sync(&priv->fatal_work);
1045 cancel_work_sync(&priv->ps_work);
1046 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1047 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1048 ath9k_led_stop_brightness(priv);
1050 mutex_lock(&priv->mutex);
1052 /* Remove monitor interface here */
1053 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1054 if (ath9k_htc_remove_monitor_interface(priv))
1055 ath_err(common, "Unable to remove monitor interface\n");
1057 ath_dbg(common, ATH_DBG_CONFIG,
1058 "Monitor interface removed\n");
1061 if (ah->btcoex_hw.enabled) {
1062 ath9k_hw_btcoex_disable(ah);
1063 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
1064 ath_htc_cancel_btcoex_work(priv);
1067 ath9k_hw_phy_disable(ah);
1068 ath9k_hw_disable(ah);
1069 ath9k_htc_ps_restore(priv);
1070 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1072 priv->op_flags |= OP_INVALID;
1074 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1075 mutex_unlock(&priv->mutex);
1078 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1079 struct ieee80211_vif *vif)
1081 struct ath9k_htc_priv *priv = hw->priv;
1082 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1083 struct ath_common *common = ath9k_hw_common(priv->ah);
1084 struct ath9k_htc_target_vif hvif;
1088 mutex_lock(&priv->mutex);
1090 /* Only one interface for now */
1091 if (priv->nvifs > 0) {
1096 ath9k_htc_ps_wakeup(priv);
1097 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1098 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1100 switch (vif->type) {
1101 case NL80211_IFTYPE_STATION:
1102 hvif.opmode = cpu_to_be32(HTC_M_STA);
1104 case NL80211_IFTYPE_ADHOC:
1105 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1109 "Interface type %d not yet supported\n", vif->type);
1114 ath_dbg(common, ATH_DBG_CONFIG,
1115 "Attach a VIF of type: %d\n", vif->type);
1117 priv->ah->opmode = vif->type;
1119 /* Index starts from zero on the target */
1120 avp->index = hvif.index = priv->nvifs;
1121 hvif.rtsthreshold = cpu_to_be16(2304);
1122 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1129 * We need a node in target to tx mgmt frames
1130 * before association.
1132 ret = ath9k_htc_add_station(priv, vif, NULL);
1136 ret = ath9k_htc_update_cap_target(priv);
1138 ath_dbg(common, ATH_DBG_CONFIG,
1139 "Failed to update capability in target\n");
1143 ath9k_htc_ps_restore(priv);
1144 mutex_unlock(&priv->mutex);
1149 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1150 struct ieee80211_vif *vif)
1152 struct ath9k_htc_priv *priv = hw->priv;
1153 struct ath_common *common = ath9k_hw_common(priv->ah);
1154 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1155 struct ath9k_htc_target_vif hvif;
1159 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface\n");
1161 mutex_lock(&priv->mutex);
1162 ath9k_htc_ps_wakeup(priv);
1164 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1165 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1166 hvif.index = avp->index;
1167 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1170 ath9k_htc_remove_station(priv, vif, NULL);
1173 ath9k_htc_ps_restore(priv);
1174 mutex_unlock(&priv->mutex);
1177 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1179 struct ath9k_htc_priv *priv = hw->priv;
1180 struct ath_common *common = ath9k_hw_common(priv->ah);
1181 struct ieee80211_conf *conf = &hw->conf;
1183 mutex_lock(&priv->mutex);
1185 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1186 bool enable_radio = false;
1187 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1189 mutex_lock(&priv->htc_pm_lock);
1190 if (!idle && priv->ps_idle)
1191 enable_radio = true;
1192 priv->ps_idle = idle;
1193 mutex_unlock(&priv->htc_pm_lock);
1196 ath_dbg(common, ATH_DBG_CONFIG,
1197 "not-idle: enabling radio\n");
1198 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1199 ath9k_htc_radio_enable(hw);
1204 * Monitor interface should be added before
1205 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1207 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1208 if (conf->flags & IEEE80211_CONF_MONITOR) {
1209 if (ath9k_htc_add_monitor_interface(priv))
1210 ath_err(common, "Failed to set monitor mode\n");
1212 ath_dbg(common, ATH_DBG_CONFIG,
1213 "HW opmode set to Monitor mode\n");
1217 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1218 struct ieee80211_channel *curchan = hw->conf.channel;
1219 int pos = curchan->hw_value;
1221 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1222 curchan->center_freq);
1224 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1226 hw->conf.channel_type);
1228 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1229 ath_err(common, "Unable to set channel\n");
1230 mutex_unlock(&priv->mutex);
1236 if (changed & IEEE80211_CONF_CHANGE_PS) {
1237 if (conf->flags & IEEE80211_CONF_PS) {
1238 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1239 priv->ps_enabled = true;
1241 priv->ps_enabled = false;
1242 cancel_work_sync(&priv->ps_work);
1243 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1247 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1248 priv->txpowlimit = 2 * conf->power_level;
1249 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1250 priv->txpowlimit, &priv->curtxpow);
1253 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1254 mutex_lock(&priv->htc_pm_lock);
1255 if (!priv->ps_idle) {
1256 mutex_unlock(&priv->htc_pm_lock);
1259 mutex_unlock(&priv->htc_pm_lock);
1261 ath_dbg(common, ATH_DBG_CONFIG,
1262 "idle: disabling radio\n");
1263 ath9k_htc_radio_disable(hw);
1267 mutex_unlock(&priv->mutex);
1271 #define SUPPORTED_FILTERS \
1272 (FIF_PROMISC_IN_BSS | \
1277 FIF_BCN_PRBRESP_PROMISC | \
1281 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1282 unsigned int changed_flags,
1283 unsigned int *total_flags,
1286 struct ath9k_htc_priv *priv = hw->priv;
1289 mutex_lock(&priv->mutex);
1290 ath9k_htc_ps_wakeup(priv);
1292 changed_flags &= SUPPORTED_FILTERS;
1293 *total_flags &= SUPPORTED_FILTERS;
1295 priv->rxfilter = *total_flags;
1296 rfilt = ath9k_htc_calcrxfilter(priv);
1297 ath9k_hw_setrxfilter(priv->ah, rfilt);
1299 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1300 "Set HW RX filter: 0x%x\n", rfilt);
1302 ath9k_htc_ps_restore(priv);
1303 mutex_unlock(&priv->mutex);
1306 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1307 struct ieee80211_vif *vif,
1308 struct ieee80211_sta *sta)
1310 struct ath9k_htc_priv *priv = hw->priv;
1313 mutex_lock(&priv->mutex);
1314 ath9k_htc_ps_wakeup(priv);
1315 ret = ath9k_htc_add_station(priv, vif, sta);
1317 ath9k_htc_init_rate(priv, sta);
1318 ath9k_htc_ps_restore(priv);
1319 mutex_unlock(&priv->mutex);
1324 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1325 struct ieee80211_vif *vif,
1326 struct ieee80211_sta *sta)
1328 struct ath9k_htc_priv *priv = hw->priv;
1331 mutex_lock(&priv->mutex);
1332 ath9k_htc_ps_wakeup(priv);
1333 ret = ath9k_htc_remove_station(priv, vif, sta);
1334 ath9k_htc_ps_restore(priv);
1335 mutex_unlock(&priv->mutex);
1340 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1341 const struct ieee80211_tx_queue_params *params)
1343 struct ath9k_htc_priv *priv = hw->priv;
1344 struct ath_common *common = ath9k_hw_common(priv->ah);
1345 struct ath9k_tx_queue_info qi;
1348 if (queue >= WME_NUM_AC)
1351 mutex_lock(&priv->mutex);
1352 ath9k_htc_ps_wakeup(priv);
1354 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1356 qi.tqi_aifs = params->aifs;
1357 qi.tqi_cwmin = params->cw_min;
1358 qi.tqi_cwmax = params->cw_max;
1359 qi.tqi_burstTime = params->txop;
1361 qnum = get_hw_qnum(queue, priv->hwq_map);
1363 ath_dbg(common, ATH_DBG_CONFIG,
1364 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1365 queue, qnum, params->aifs, params->cw_min,
1366 params->cw_max, params->txop);
1368 ret = ath_htc_txq_update(priv, qnum, &qi);
1370 ath_err(common, "TXQ Update failed\n");
1374 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1375 (qnum == priv->hwq_map[WME_AC_BE]))
1376 ath9k_htc_beaconq_config(priv);
1378 ath9k_htc_ps_restore(priv);
1379 mutex_unlock(&priv->mutex);
1384 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1385 enum set_key_cmd cmd,
1386 struct ieee80211_vif *vif,
1387 struct ieee80211_sta *sta,
1388 struct ieee80211_key_conf *key)
1390 struct ath9k_htc_priv *priv = hw->priv;
1391 struct ath_common *common = ath9k_hw_common(priv->ah);
1394 if (htc_modparam_nohwcrypt)
1397 mutex_lock(&priv->mutex);
1398 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1399 ath9k_htc_ps_wakeup(priv);
1403 ret = ath_key_config(common, vif, sta, key);
1405 key->hw_key_idx = ret;
1406 /* push IV and Michael MIC generation to stack */
1407 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1408 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1409 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1410 if (priv->ah->sw_mgmt_crypto &&
1411 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1412 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1417 ath_key_delete(common, key);
1423 ath9k_htc_ps_restore(priv);
1424 mutex_unlock(&priv->mutex);
1429 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1430 struct ieee80211_vif *vif,
1431 struct ieee80211_bss_conf *bss_conf,
1434 struct ath9k_htc_priv *priv = hw->priv;
1435 struct ath_hw *ah = priv->ah;
1436 struct ath_common *common = ath9k_hw_common(ah);
1438 mutex_lock(&priv->mutex);
1439 ath9k_htc_ps_wakeup(priv);
1441 if (changed & BSS_CHANGED_ASSOC) {
1442 common->curaid = bss_conf->assoc ?
1444 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1447 if (bss_conf->assoc) {
1448 priv->op_flags |= OP_ASSOCIATED;
1449 ath_start_ani(priv);
1451 priv->op_flags &= ~OP_ASSOCIATED;
1452 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1456 if (changed & BSS_CHANGED_BSSID) {
1458 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1459 ath9k_hw_write_associd(ah);
1461 ath_dbg(common, ATH_DBG_CONFIG,
1462 "BSSID: %pM aid: 0x%x\n",
1463 common->curbssid, common->curaid);
1466 if ((changed & BSS_CHANGED_BEACON_INT) ||
1467 (changed & BSS_CHANGED_BEACON) ||
1468 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1469 bss_conf->enable_beacon)) {
1470 priv->op_flags |= OP_ENABLE_BEACON;
1471 ath9k_htc_beacon_config(priv, vif);
1474 if ((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_ERP_PREAMBLE) {
1481 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1482 bss_conf->use_short_preamble);
1483 if (bss_conf->use_short_preamble)
1484 priv->op_flags |= OP_PREAMBLE_SHORT;
1486 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1489 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1490 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1491 bss_conf->use_cts_prot);
1492 if (bss_conf->use_cts_prot &&
1493 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1494 priv->op_flags |= OP_PROTECT_ENABLE;
1496 priv->op_flags &= ~OP_PROTECT_ENABLE;
1499 if (changed & BSS_CHANGED_ERP_SLOT) {
1500 if (bss_conf->use_short_slot)
1505 ath9k_hw_init_global_settings(ah);
1508 if (changed & BSS_CHANGED_HT)
1509 ath9k_htc_update_rate(priv, vif, bss_conf);
1511 ath9k_htc_ps_restore(priv);
1512 mutex_unlock(&priv->mutex);
1515 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1517 struct ath9k_htc_priv *priv = hw->priv;
1520 mutex_lock(&priv->mutex);
1521 ath9k_htc_ps_wakeup(priv);
1522 tsf = ath9k_hw_gettsf64(priv->ah);
1523 ath9k_htc_ps_restore(priv);
1524 mutex_unlock(&priv->mutex);
1529 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1531 struct ath9k_htc_priv *priv = hw->priv;
1533 mutex_lock(&priv->mutex);
1534 ath9k_htc_ps_wakeup(priv);
1535 ath9k_hw_settsf64(priv->ah, tsf);
1536 ath9k_htc_ps_restore(priv);
1537 mutex_unlock(&priv->mutex);
1540 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1542 struct ath9k_htc_priv *priv = hw->priv;
1544 mutex_lock(&priv->mutex);
1545 ath9k_htc_ps_wakeup(priv);
1546 ath9k_hw_reset_tsf(priv->ah);
1547 ath9k_htc_ps_restore(priv);
1548 mutex_unlock(&priv->mutex);
1551 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1552 struct ieee80211_vif *vif,
1553 enum ieee80211_ampdu_mlme_action action,
1554 struct ieee80211_sta *sta,
1555 u16 tid, u16 *ssn, u8 buf_size)
1557 struct ath9k_htc_priv *priv = hw->priv;
1558 struct ath9k_htc_sta *ista;
1562 case IEEE80211_AMPDU_RX_START:
1564 case IEEE80211_AMPDU_RX_STOP:
1566 case IEEE80211_AMPDU_TX_START:
1567 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1569 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1571 case IEEE80211_AMPDU_TX_STOP:
1572 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1573 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1575 case IEEE80211_AMPDU_TX_OPERATIONAL:
1576 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1577 spin_lock_bh(&priv->tx_lock);
1578 ista->tid_state[tid] = AGGR_OPERATIONAL;
1579 spin_unlock_bh(&priv->tx_lock);
1582 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1588 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1590 struct ath9k_htc_priv *priv = hw->priv;
1592 mutex_lock(&priv->mutex);
1593 spin_lock_bh(&priv->beacon_lock);
1594 priv->op_flags |= OP_SCANNING;
1595 spin_unlock_bh(&priv->beacon_lock);
1596 cancel_work_sync(&priv->ps_work);
1597 if (priv->op_flags & OP_ASSOCIATED)
1598 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1599 mutex_unlock(&priv->mutex);
1602 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1604 struct ath9k_htc_priv *priv = hw->priv;
1606 mutex_lock(&priv->mutex);
1607 ath9k_htc_ps_wakeup(priv);
1608 spin_lock_bh(&priv->beacon_lock);
1609 priv->op_flags &= ~OP_SCANNING;
1610 spin_unlock_bh(&priv->beacon_lock);
1611 if (priv->op_flags & OP_ASSOCIATED) {
1612 ath9k_htc_beacon_config(priv, priv->vif);
1613 ath_start_ani(priv);
1615 ath9k_htc_ps_restore(priv);
1616 mutex_unlock(&priv->mutex);
1619 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1624 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1627 struct ath9k_htc_priv *priv = hw->priv;
1629 mutex_lock(&priv->mutex);
1630 ath9k_htc_ps_wakeup(priv);
1631 priv->ah->coverage_class = coverage_class;
1632 ath9k_hw_init_global_settings(priv->ah);
1633 ath9k_htc_ps_restore(priv);
1634 mutex_unlock(&priv->mutex);
1637 struct ieee80211_ops ath9k_htc_ops = {
1639 .start = ath9k_htc_start,
1640 .stop = ath9k_htc_stop,
1641 .add_interface = ath9k_htc_add_interface,
1642 .remove_interface = ath9k_htc_remove_interface,
1643 .config = ath9k_htc_config,
1644 .configure_filter = ath9k_htc_configure_filter,
1645 .sta_add = ath9k_htc_sta_add,
1646 .sta_remove = ath9k_htc_sta_remove,
1647 .conf_tx = ath9k_htc_conf_tx,
1648 .bss_info_changed = ath9k_htc_bss_info_changed,
1649 .set_key = ath9k_htc_set_key,
1650 .get_tsf = ath9k_htc_get_tsf,
1651 .set_tsf = ath9k_htc_set_tsf,
1652 .reset_tsf = ath9k_htc_reset_tsf,
1653 .ampdu_action = ath9k_htc_ampdu_action,
1654 .sw_scan_start = ath9k_htc_sw_scan_start,
1655 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1656 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1657 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1658 .set_coverage_class = ath9k_htc_set_coverage_class,