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;
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[channel->hw_value];
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),
205 caldata = &priv->caldata[channel->hw_value];
206 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
209 "Unable to reset channel (%u Mhz) reset status %d\n",
210 channel->center_freq, ret);
214 ath_update_txpow(priv);
216 WMI_CMD(WMI_START_RECV_CMDID);
220 ath9k_host_rx_init(priv);
222 mode = ath9k_htc_get_curmode(priv, hchan);
223 htc_mode = cpu_to_be16(mode);
224 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
228 WMI_CMD(WMI_ENABLE_INTR_CMDID);
232 htc_start(priv->htc);
234 ath9k_htc_ps_restore(priv);
238 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
240 struct ath_common *common = ath9k_hw_common(priv->ah);
241 struct ath9k_htc_target_vif hvif;
248 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
249 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
251 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
252 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
253 hvif.index = priv->nvifs;
255 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
263 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
265 struct ath_common *common = ath9k_hw_common(priv->ah);
266 struct ath9k_htc_target_vif hvif;
270 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
271 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
272 hvif.index = 0; /* Should do for now */
273 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
279 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
280 struct ieee80211_vif *vif,
281 struct ieee80211_sta *sta)
283 struct ath_common *common = ath9k_hw_common(priv->ah);
284 struct ath9k_htc_target_sta tsta;
285 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
286 struct ath9k_htc_sta *ista;
290 if (priv->nstations >= ATH9K_HTC_MAX_STA)
293 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
296 ista = (struct ath9k_htc_sta *) sta->drv_priv;
297 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
298 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
299 tsta.associd = common->curaid;
302 ista->index = priv->nstations;
304 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
308 tsta.sta_index = priv->nstations;
309 tsta.vif_index = avp->index;
310 tsta.maxampdu = 0xffff;
311 if (sta && sta->ht_cap.ht_supported)
312 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
314 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
318 "Unable to add station entry for: %pM\n",
324 ath_dbg(common, ATH_DBG_CONFIG,
325 "Added a station entry for: %pM (idx: %d)\n",
326 sta->addr, tsta.sta_index);
332 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
333 struct ieee80211_vif *vif,
334 struct ieee80211_sta *sta)
336 struct ath_common *common = ath9k_hw_common(priv->ah);
337 struct ath9k_htc_sta *ista;
342 ista = (struct ath9k_htc_sta *) sta->drv_priv;
343 sta_idx = ista->index;
348 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
352 "Unable to remove station entry for: %pM\n",
358 ath_dbg(common, ATH_DBG_CONFIG,
359 "Removed a station entry for: %pM (idx: %d)\n",
366 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
368 struct ath9k_htc_cap_target tcap;
372 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
374 /* FIXME: Values are hardcoded */
375 tcap.flags = 0x240c40;
376 tcap.flags_ext = 0x80601000;
377 tcap.ampdu_limit = 0xffff0000;
378 tcap.ampdu_subframes = 20;
379 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
381 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
383 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
388 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
389 struct ieee80211_sta *sta,
390 struct ath9k_htc_target_rate *trate)
392 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
393 struct ieee80211_supported_band *sband;
397 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
399 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
400 if (sta->supp_rates[sband->band] & BIT(i)) {
401 trate->rates.legacy_rates.rs_rates[j]
402 = (sband->bitrates[i].bitrate * 2) / 10;
406 trate->rates.legacy_rates.rs_nrates = j;
408 if (sta->ht_cap.ht_supported) {
409 for (i = 0, j = 0; i < 77; i++) {
410 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
411 trate->rates.ht_rates.rs_rates[j++] = i;
412 if (j == ATH_HTC_RATE_MAX)
415 trate->rates.ht_rates.rs_nrates = j;
417 caps = WLAN_RC_HT_FLAG;
418 if (sta->ht_cap.mcs.rx_mask[1])
419 caps |= WLAN_RC_DS_FLAG;
420 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
421 (conf_is_ht40(&priv->hw->conf)))
422 caps |= WLAN_RC_40_FLAG;
423 if (conf_is_ht40(&priv->hw->conf) &&
424 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
425 caps |= WLAN_RC_SGI_FLAG;
426 else if (conf_is_ht20(&priv->hw->conf) &&
427 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
428 caps |= WLAN_RC_SGI_FLAG;
431 trate->sta_index = ista->index;
433 trate->capflags = cpu_to_be32(caps);
436 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
437 struct ath9k_htc_target_rate *trate)
439 struct ath_common *common = ath9k_hw_common(priv->ah);
443 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
446 "Unable to initialize Rate information on target\n");
452 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
453 struct ieee80211_sta *sta)
455 struct ath_common *common = ath9k_hw_common(priv->ah);
456 struct ath9k_htc_target_rate trate;
459 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
460 ath9k_htc_setup_rate(priv, sta, &trate);
461 ret = ath9k_htc_send_rate_cmd(priv, &trate);
463 ath_dbg(common, ATH_DBG_CONFIG,
464 "Updated target sta: %pM, rate caps: 0x%X\n",
465 sta->addr, be32_to_cpu(trate.capflags));
468 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
469 struct ieee80211_vif *vif,
470 struct ieee80211_bss_conf *bss_conf)
472 struct ath_common *common = ath9k_hw_common(priv->ah);
473 struct ath9k_htc_target_rate trate;
474 struct ieee80211_sta *sta;
477 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
480 sta = ieee80211_find_sta(vif, bss_conf->bssid);
485 ath9k_htc_setup_rate(priv, sta, &trate);
488 ret = ath9k_htc_send_rate_cmd(priv, &trate);
490 ath_dbg(common, ATH_DBG_CONFIG,
491 "Updated target sta: %pM, rate caps: 0x%X\n",
492 bss_conf->bssid, be32_to_cpu(trate.capflags));
495 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
496 struct ieee80211_vif *vif,
497 struct ieee80211_sta *sta,
498 enum ieee80211_ampdu_mlme_action action,
501 struct ath_common *common = ath9k_hw_common(priv->ah);
502 struct ath9k_htc_target_aggr aggr;
503 struct ath9k_htc_sta *ista;
507 if (tid >= ATH9K_HTC_MAX_TID)
510 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
511 ista = (struct ath9k_htc_sta *) sta->drv_priv;
513 aggr.sta_index = ista->index;
514 aggr.tidno = tid & 0xf;
515 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
517 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
519 ath_dbg(common, ATH_DBG_CONFIG,
520 "Unable to %s TX aggregation for (%pM, %d)\n",
521 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
523 ath_dbg(common, ATH_DBG_CONFIG,
524 "%s TX aggregation for (%pM, %d)\n",
525 (aggr.aggr_enable) ? "Starting" : "Stopping",
528 spin_lock_bh(&priv->tx_lock);
529 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
530 spin_unlock_bh(&priv->tx_lock);
539 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
541 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
543 file->private_data = inode->i_private;
547 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
548 size_t count, loff_t *ppos)
550 struct ath9k_htc_priv *priv = file->private_data;
551 struct ath9k_htc_target_stats cmd_rsp;
553 unsigned int len = 0;
556 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
558 WMI_CMD(WMI_TGT_STATS_CMDID);
563 len += snprintf(buf + len, sizeof(buf) - len,
564 "%19s : %10u\n", "TX Short Retries",
565 be32_to_cpu(cmd_rsp.tx_shortretry));
566 len += snprintf(buf + len, sizeof(buf) - len,
567 "%19s : %10u\n", "TX Long Retries",
568 be32_to_cpu(cmd_rsp.tx_longretry));
569 len += snprintf(buf + len, sizeof(buf) - len,
570 "%19s : %10u\n", "TX Xretries",
571 be32_to_cpu(cmd_rsp.tx_xretries));
572 len += snprintf(buf + len, sizeof(buf) - len,
573 "%19s : %10u\n", "TX Unaggr. Xretries",
574 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
575 len += snprintf(buf + len, sizeof(buf) - len,
576 "%19s : %10u\n", "TX Xretries (HT)",
577 be32_to_cpu(cmd_rsp.ht_tx_xretries));
578 len += snprintf(buf + len, sizeof(buf) - len,
579 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
581 if (len > sizeof(buf))
584 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
587 static const struct file_operations fops_tgt_stats = {
588 .read = read_file_tgt_stats,
589 .open = ath9k_debugfs_open,
590 .owner = THIS_MODULE,
591 .llseek = default_llseek,
594 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
595 size_t count, loff_t *ppos)
597 struct ath9k_htc_priv *priv = file->private_data;
599 unsigned int len = 0;
601 len += snprintf(buf + len, sizeof(buf) - len,
602 "%20s : %10u\n", "Buffers queued",
603 priv->debug.tx_stats.buf_queued);
604 len += snprintf(buf + len, sizeof(buf) - len,
605 "%20s : %10u\n", "Buffers completed",
606 priv->debug.tx_stats.buf_completed);
607 len += snprintf(buf + len, sizeof(buf) - len,
608 "%20s : %10u\n", "SKBs queued",
609 priv->debug.tx_stats.skb_queued);
610 len += snprintf(buf + len, sizeof(buf) - len,
611 "%20s : %10u\n", "SKBs completed",
612 priv->debug.tx_stats.skb_completed);
613 len += snprintf(buf + len, sizeof(buf) - len,
614 "%20s : %10u\n", "SKBs dropped",
615 priv->debug.tx_stats.skb_dropped);
617 len += snprintf(buf + len, sizeof(buf) - len,
618 "%20s : %10u\n", "BE queued",
619 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
620 len += snprintf(buf + len, sizeof(buf) - len,
621 "%20s : %10u\n", "BK queued",
622 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
623 len += snprintf(buf + len, sizeof(buf) - len,
624 "%20s : %10u\n", "VI queued",
625 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
626 len += snprintf(buf + len, sizeof(buf) - len,
627 "%20s : %10u\n", "VO queued",
628 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
630 if (len > sizeof(buf))
633 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
636 static const struct file_operations fops_xmit = {
637 .read = read_file_xmit,
638 .open = ath9k_debugfs_open,
639 .owner = THIS_MODULE,
640 .llseek = default_llseek,
643 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
644 size_t count, loff_t *ppos)
646 struct ath9k_htc_priv *priv = file->private_data;
648 unsigned int len = 0;
650 len += snprintf(buf + len, sizeof(buf) - len,
651 "%20s : %10u\n", "SKBs allocated",
652 priv->debug.rx_stats.skb_allocated);
653 len += snprintf(buf + len, sizeof(buf) - len,
654 "%20s : %10u\n", "SKBs completed",
655 priv->debug.rx_stats.skb_completed);
656 len += snprintf(buf + len, sizeof(buf) - len,
657 "%20s : %10u\n", "SKBs Dropped",
658 priv->debug.rx_stats.skb_dropped);
660 if (len > sizeof(buf))
663 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
666 static const struct file_operations fops_recv = {
667 .read = read_file_recv,
668 .open = ath9k_debugfs_open,
669 .owner = THIS_MODULE,
670 .llseek = default_llseek,
673 int ath9k_htc_init_debug(struct ath_hw *ah)
675 struct ath_common *common = ath9k_hw_common(ah);
676 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
678 if (!ath9k_debugfs_root)
681 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
683 if (!priv->debug.debugfs_phy)
686 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
687 priv->debug.debugfs_phy,
688 priv, &fops_tgt_stats);
689 if (!priv->debug.debugfs_tgt_stats)
693 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
694 priv->debug.debugfs_phy,
696 if (!priv->debug.debugfs_xmit)
699 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
700 priv->debug.debugfs_phy,
702 if (!priv->debug.debugfs_recv)
708 ath9k_htc_exit_debug(ah);
712 void ath9k_htc_exit_debug(struct ath_hw *ah)
714 struct ath_common *common = ath9k_hw_common(ah);
715 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
717 debugfs_remove(priv->debug.debugfs_recv);
718 debugfs_remove(priv->debug.debugfs_xmit);
719 debugfs_remove(priv->debug.debugfs_tgt_stats);
720 debugfs_remove(priv->debug.debugfs_phy);
723 int ath9k_htc_debug_create_root(void)
725 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
726 if (!ath9k_debugfs_root)
732 void ath9k_htc_debug_remove_root(void)
734 debugfs_remove(ath9k_debugfs_root);
735 ath9k_debugfs_root = NULL;
738 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
744 void ath_start_ani(struct ath9k_htc_priv *priv)
746 struct ath_common *common = ath9k_hw_common(priv->ah);
747 unsigned long timestamp = jiffies_to_msecs(jiffies);
749 common->ani.longcal_timer = timestamp;
750 common->ani.shortcal_timer = timestamp;
751 common->ani.checkani_timer = timestamp;
753 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
754 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
757 void ath9k_ani_work(struct work_struct *work)
759 struct ath9k_htc_priv *priv =
760 container_of(work, struct ath9k_htc_priv,
761 ath9k_ani_work.work);
762 struct ath_hw *ah = priv->ah;
763 struct ath_common *common = ath9k_hw_common(ah);
764 bool longcal = false;
765 bool shortcal = false;
766 bool aniflag = false;
767 unsigned int timestamp = jiffies_to_msecs(jiffies);
768 u32 cal_interval, short_cal_interval;
770 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
772 /* Only calibrate if awake */
773 if (ah->power_mode != ATH9K_PM_AWAKE)
776 /* Long calibration runs independently of short calibration. */
777 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
779 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
780 common->ani.longcal_timer = timestamp;
783 /* Short calibration applies only while caldone is false */
784 if (!common->ani.caldone) {
785 if ((timestamp - common->ani.shortcal_timer) >=
786 short_cal_interval) {
788 ath_dbg(common, ATH_DBG_ANI,
789 "shortcal @%lu\n", jiffies);
790 common->ani.shortcal_timer = timestamp;
791 common->ani.resetcal_timer = timestamp;
794 if ((timestamp - common->ani.resetcal_timer) >=
795 ATH_RESTART_CALINTERVAL) {
796 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
797 if (common->ani.caldone)
798 common->ani.resetcal_timer = timestamp;
802 /* Verify whether we must check ANI */
803 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
805 common->ani.checkani_timer = timestamp;
808 /* Skip all processing if there's nothing to do. */
809 if (longcal || shortcal || aniflag) {
811 ath9k_htc_ps_wakeup(priv);
813 /* Call ANI routine if necessary */
815 ath9k_hw_ani_monitor(ah, ah->curchan);
817 /* Perform calibration if necessary */
818 if (longcal || shortcal)
819 common->ani.caldone =
820 ath9k_hw_calibrate(ah, ah->curchan,
821 common->rx_chainmask,
824 ath9k_htc_ps_restore(priv);
829 * Set timer interval based on previous results.
830 * The interval must be the shortest necessary to satisfy ANI,
831 * short calibration and long calibration.
833 cal_interval = ATH_LONG_CALINTERVAL;
834 if (priv->ah->config.enable_ani)
835 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
836 if (!common->ani.caldone)
837 cal_interval = min(cal_interval, (u32)short_cal_interval);
839 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
840 msecs_to_jiffies(cal_interval));
843 /**********************/
844 /* mac80211 Callbacks */
845 /**********************/
847 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
849 struct ieee80211_hdr *hdr;
850 struct ath9k_htc_priv *priv = hw->priv;
851 int padpos, padsize, ret;
853 hdr = (struct ieee80211_hdr *) skb->data;
855 /* Add the padding after the header if this is not already done */
856 padpos = ath9k_cmn_padpos(hdr->frame_control);
857 padsize = padpos & 3;
858 if (padsize && skb->len > padpos) {
859 if (skb_headroom(skb) < padsize)
861 skb_push(skb, padsize);
862 memmove(skb->data, skb->data + padsize, padpos);
865 ret = ath9k_htc_tx_start(priv, skb);
867 if (ret == -ENOMEM) {
868 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
869 "Stopping TX queues\n");
870 ieee80211_stop_queues(hw);
871 spin_lock_bh(&priv->tx_lock);
872 priv->tx_queues_stop = true;
873 spin_unlock_bh(&priv->tx_lock);
875 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
884 dev_kfree_skb_any(skb);
888 static int ath9k_htc_start(struct ieee80211_hw *hw)
890 struct ath9k_htc_priv *priv = hw->priv;
891 struct ath_hw *ah = priv->ah;
892 struct ath_common *common = ath9k_hw_common(ah);
893 struct ieee80211_channel *curchan = hw->conf.channel;
894 struct ath9k_channel *init_channel;
896 enum htc_phymode mode;
900 mutex_lock(&priv->mutex);
902 ath_dbg(common, ATH_DBG_CONFIG,
903 "Starting driver with initial channel: %d MHz\n",
904 curchan->center_freq);
906 /* Ensure that HW is awake before flushing RX */
907 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
908 WMI_CMD(WMI_FLUSH_RECV_CMDID);
910 /* setup initial channel */
911 init_channel = ath9k_cmn_get_curchannel(hw, ah);
913 ath9k_hw_htc_resetinit(ah);
914 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
917 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
918 ret, curchan->center_freq);
919 mutex_unlock(&priv->mutex);
923 ath_update_txpow(priv);
925 mode = ath9k_htc_get_curmode(priv, init_channel);
926 htc_mode = cpu_to_be16(mode);
927 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
928 WMI_CMD(WMI_ATH_INIT_CMDID);
929 WMI_CMD(WMI_START_RECV_CMDID);
931 ath9k_host_rx_init(priv);
933 priv->op_flags &= ~OP_INVALID;
934 htc_start(priv->htc);
936 spin_lock_bh(&priv->tx_lock);
937 priv->tx_queues_stop = false;
938 spin_unlock_bh(&priv->tx_lock);
940 ieee80211_wake_queues(hw);
942 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
943 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
944 AR_STOMP_LOW_WLAN_WGHT);
945 ath9k_hw_btcoex_enable(ah);
946 ath_htc_resume_btcoex_work(priv);
948 mutex_unlock(&priv->mutex);
953 static void ath9k_htc_stop(struct ieee80211_hw *hw)
955 struct ath9k_htc_priv *priv = hw->priv;
956 struct ath_hw *ah = priv->ah;
957 struct ath_common *common = ath9k_hw_common(ah);
961 /* Cancel all the running timers/work .. */
962 cancel_work_sync(&priv->fatal_work);
963 cancel_work_sync(&priv->ps_work);
964 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
965 ath9k_led_stop_brightness(priv);
967 mutex_lock(&priv->mutex);
969 if (priv->op_flags & OP_INVALID) {
970 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
971 mutex_unlock(&priv->mutex);
975 ath9k_htc_ps_wakeup(priv);
977 WMI_CMD(WMI_DISABLE_INTR_CMDID);
978 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
979 WMI_CMD(WMI_STOP_RECV_CMDID);
980 skb_queue_purge(&priv->tx_queue);
982 /* Remove monitor interface here */
983 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
984 if (ath9k_htc_remove_monitor_interface(priv))
985 ath_err(common, "Unable to remove monitor interface\n");
987 ath_dbg(common, ATH_DBG_CONFIG,
988 "Monitor interface removed\n");
991 if (ah->btcoex_hw.enabled) {
992 ath9k_hw_btcoex_disable(ah);
993 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
994 ath_htc_cancel_btcoex_work(priv);
997 ath9k_hw_phy_disable(ah);
998 ath9k_hw_disable(ah);
999 ath9k_htc_ps_restore(priv);
1000 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1002 priv->op_flags |= OP_INVALID;
1004 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1005 mutex_unlock(&priv->mutex);
1008 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1009 struct ieee80211_vif *vif)
1011 struct ath9k_htc_priv *priv = hw->priv;
1012 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1013 struct ath_common *common = ath9k_hw_common(priv->ah);
1014 struct ath9k_htc_target_vif hvif;
1018 mutex_lock(&priv->mutex);
1020 /* Only one interface for now */
1021 if (priv->nvifs > 0) {
1026 ath9k_htc_ps_wakeup(priv);
1027 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1028 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1030 switch (vif->type) {
1031 case NL80211_IFTYPE_STATION:
1032 hvif.opmode = cpu_to_be32(HTC_M_STA);
1034 case NL80211_IFTYPE_ADHOC:
1035 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1039 "Interface type %d not yet supported\n", vif->type);
1044 ath_dbg(common, ATH_DBG_CONFIG,
1045 "Attach a VIF of type: %d\n", vif->type);
1047 priv->ah->opmode = vif->type;
1049 /* Index starts from zero on the target */
1050 avp->index = hvif.index = priv->nvifs;
1051 hvif.rtsthreshold = cpu_to_be16(2304);
1052 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1059 * We need a node in target to tx mgmt frames
1060 * before association.
1062 ret = ath9k_htc_add_station(priv, vif, NULL);
1066 ret = ath9k_htc_update_cap_target(priv);
1068 ath_dbg(common, ATH_DBG_CONFIG,
1069 "Failed to update capability in target\n");
1073 ath9k_htc_ps_restore(priv);
1074 mutex_unlock(&priv->mutex);
1079 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1080 struct ieee80211_vif *vif)
1082 struct ath9k_htc_priv *priv = hw->priv;
1083 struct ath_common *common = ath9k_hw_common(priv->ah);
1084 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1085 struct ath9k_htc_target_vif hvif;
1089 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface\n");
1091 mutex_lock(&priv->mutex);
1092 ath9k_htc_ps_wakeup(priv);
1094 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1095 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1096 hvif.index = avp->index;
1097 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1100 ath9k_htc_remove_station(priv, vif, NULL);
1103 ath9k_htc_ps_restore(priv);
1104 mutex_unlock(&priv->mutex);
1107 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1109 struct ath9k_htc_priv *priv = hw->priv;
1110 struct ath_common *common = ath9k_hw_common(priv->ah);
1111 struct ieee80211_conf *conf = &hw->conf;
1113 mutex_lock(&priv->mutex);
1115 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1116 bool enable_radio = false;
1117 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1119 mutex_lock(&priv->htc_pm_lock);
1120 if (!idle && priv->ps_idle)
1121 enable_radio = true;
1122 priv->ps_idle = idle;
1123 mutex_unlock(&priv->htc_pm_lock);
1126 ath_dbg(common, ATH_DBG_CONFIG,
1127 "not-idle: enabling radio\n");
1128 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1129 ath9k_htc_radio_enable(hw);
1133 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1134 struct ieee80211_channel *curchan = hw->conf.channel;
1135 int pos = curchan->hw_value;
1137 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1138 curchan->center_freq);
1140 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1142 hw->conf.channel_type);
1144 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1145 ath_err(common, "Unable to set channel\n");
1146 mutex_unlock(&priv->mutex);
1152 if (changed & IEEE80211_CONF_CHANGE_PS) {
1153 if (conf->flags & IEEE80211_CONF_PS) {
1154 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1155 priv->ps_enabled = true;
1157 priv->ps_enabled = false;
1158 cancel_work_sync(&priv->ps_work);
1159 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1163 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1164 priv->txpowlimit = 2 * conf->power_level;
1165 ath_update_txpow(priv);
1168 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1169 if (conf->flags & IEEE80211_CONF_MONITOR) {
1170 if (ath9k_htc_add_monitor_interface(priv))
1171 ath_err(common, "Failed to set monitor mode\n");
1173 ath_dbg(common, ATH_DBG_CONFIG,
1174 "HW opmode set to Monitor mode\n");
1178 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1179 mutex_lock(&priv->htc_pm_lock);
1180 if (!priv->ps_idle) {
1181 mutex_unlock(&priv->htc_pm_lock);
1184 mutex_unlock(&priv->htc_pm_lock);
1186 ath_dbg(common, ATH_DBG_CONFIG,
1187 "idle: disabling radio\n");
1188 ath9k_htc_radio_disable(hw);
1192 mutex_unlock(&priv->mutex);
1196 #define SUPPORTED_FILTERS \
1197 (FIF_PROMISC_IN_BSS | \
1202 FIF_BCN_PRBRESP_PROMISC | \
1206 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1207 unsigned int changed_flags,
1208 unsigned int *total_flags,
1211 struct ath9k_htc_priv *priv = hw->priv;
1214 mutex_lock(&priv->mutex);
1215 ath9k_htc_ps_wakeup(priv);
1217 changed_flags &= SUPPORTED_FILTERS;
1218 *total_flags &= SUPPORTED_FILTERS;
1220 priv->rxfilter = *total_flags;
1221 rfilt = ath9k_htc_calcrxfilter(priv);
1222 ath9k_hw_setrxfilter(priv->ah, rfilt);
1224 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1225 "Set HW RX filter: 0x%x\n", rfilt);
1227 ath9k_htc_ps_restore(priv);
1228 mutex_unlock(&priv->mutex);
1231 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1232 struct ieee80211_vif *vif,
1233 struct ieee80211_sta *sta)
1235 struct ath9k_htc_priv *priv = hw->priv;
1238 mutex_lock(&priv->mutex);
1239 ath9k_htc_ps_wakeup(priv);
1240 ret = ath9k_htc_add_station(priv, vif, sta);
1242 ath9k_htc_init_rate(priv, sta);
1243 ath9k_htc_ps_restore(priv);
1244 mutex_unlock(&priv->mutex);
1249 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1250 struct ieee80211_vif *vif,
1251 struct ieee80211_sta *sta)
1253 struct ath9k_htc_priv *priv = hw->priv;
1256 mutex_lock(&priv->mutex);
1257 ath9k_htc_ps_wakeup(priv);
1258 ret = ath9k_htc_remove_station(priv, vif, sta);
1259 ath9k_htc_ps_restore(priv);
1260 mutex_unlock(&priv->mutex);
1265 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1266 const struct ieee80211_tx_queue_params *params)
1268 struct ath9k_htc_priv *priv = hw->priv;
1269 struct ath_common *common = ath9k_hw_common(priv->ah);
1270 struct ath9k_tx_queue_info qi;
1273 if (queue >= WME_NUM_AC)
1276 mutex_lock(&priv->mutex);
1277 ath9k_htc_ps_wakeup(priv);
1279 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1281 qi.tqi_aifs = params->aifs;
1282 qi.tqi_cwmin = params->cw_min;
1283 qi.tqi_cwmax = params->cw_max;
1284 qi.tqi_burstTime = params->txop;
1286 qnum = get_hw_qnum(queue, priv->hwq_map);
1288 ath_dbg(common, ATH_DBG_CONFIG,
1289 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1290 queue, qnum, params->aifs, params->cw_min,
1291 params->cw_max, params->txop);
1293 ret = ath_htc_txq_update(priv, qnum, &qi);
1295 ath_err(common, "TXQ Update failed\n");
1299 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1300 (qnum == priv->hwq_map[WME_AC_BE]))
1301 ath9k_htc_beaconq_config(priv);
1303 ath9k_htc_ps_restore(priv);
1304 mutex_unlock(&priv->mutex);
1309 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1310 enum set_key_cmd cmd,
1311 struct ieee80211_vif *vif,
1312 struct ieee80211_sta *sta,
1313 struct ieee80211_key_conf *key)
1315 struct ath9k_htc_priv *priv = hw->priv;
1316 struct ath_common *common = ath9k_hw_common(priv->ah);
1319 if (htc_modparam_nohwcrypt)
1322 mutex_lock(&priv->mutex);
1323 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1324 ath9k_htc_ps_wakeup(priv);
1328 ret = ath_key_config(common, vif, sta, key);
1330 key->hw_key_idx = ret;
1331 /* push IV and Michael MIC generation to stack */
1332 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1333 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1334 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1335 if (priv->ah->sw_mgmt_crypto &&
1336 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1337 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1342 ath_key_delete(common, key);
1348 ath9k_htc_ps_restore(priv);
1349 mutex_unlock(&priv->mutex);
1354 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1355 struct ieee80211_vif *vif,
1356 struct ieee80211_bss_conf *bss_conf,
1359 struct ath9k_htc_priv *priv = hw->priv;
1360 struct ath_hw *ah = priv->ah;
1361 struct ath_common *common = ath9k_hw_common(ah);
1363 mutex_lock(&priv->mutex);
1364 ath9k_htc_ps_wakeup(priv);
1366 if (changed & BSS_CHANGED_ASSOC) {
1367 common->curaid = bss_conf->assoc ?
1369 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1372 if (bss_conf->assoc) {
1373 priv->op_flags |= OP_ASSOCIATED;
1374 ath_start_ani(priv);
1376 priv->op_flags &= ~OP_ASSOCIATED;
1377 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1381 if (changed & BSS_CHANGED_BSSID) {
1383 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1384 ath9k_hw_write_associd(ah);
1386 ath_dbg(common, ATH_DBG_CONFIG,
1387 "BSSID: %pM aid: 0x%x\n",
1388 common->curbssid, common->curaid);
1391 if ((changed & BSS_CHANGED_BEACON_INT) ||
1392 (changed & BSS_CHANGED_BEACON) ||
1393 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1394 bss_conf->enable_beacon)) {
1395 priv->op_flags |= OP_ENABLE_BEACON;
1396 ath9k_htc_beacon_config(priv, vif);
1399 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1400 !bss_conf->enable_beacon) {
1401 priv->op_flags &= ~OP_ENABLE_BEACON;
1402 ath9k_htc_beacon_config(priv, vif);
1405 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1406 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1407 bss_conf->use_short_preamble);
1408 if (bss_conf->use_short_preamble)
1409 priv->op_flags |= OP_PREAMBLE_SHORT;
1411 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1414 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1415 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1416 bss_conf->use_cts_prot);
1417 if (bss_conf->use_cts_prot &&
1418 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1419 priv->op_flags |= OP_PROTECT_ENABLE;
1421 priv->op_flags &= ~OP_PROTECT_ENABLE;
1424 if (changed & BSS_CHANGED_ERP_SLOT) {
1425 if (bss_conf->use_short_slot)
1430 ath9k_hw_init_global_settings(ah);
1433 if (changed & BSS_CHANGED_HT)
1434 ath9k_htc_update_rate(priv, vif, bss_conf);
1436 ath9k_htc_ps_restore(priv);
1437 mutex_unlock(&priv->mutex);
1440 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1442 struct ath9k_htc_priv *priv = hw->priv;
1445 mutex_lock(&priv->mutex);
1446 ath9k_htc_ps_wakeup(priv);
1447 tsf = ath9k_hw_gettsf64(priv->ah);
1448 ath9k_htc_ps_restore(priv);
1449 mutex_unlock(&priv->mutex);
1454 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1456 struct ath9k_htc_priv *priv = hw->priv;
1458 mutex_lock(&priv->mutex);
1459 ath9k_htc_ps_wakeup(priv);
1460 ath9k_hw_settsf64(priv->ah, tsf);
1461 ath9k_htc_ps_restore(priv);
1462 mutex_unlock(&priv->mutex);
1465 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1467 struct ath9k_htc_priv *priv = hw->priv;
1469 mutex_lock(&priv->mutex);
1470 ath9k_htc_ps_wakeup(priv);
1471 ath9k_hw_reset_tsf(priv->ah);
1472 ath9k_htc_ps_restore(priv);
1473 mutex_unlock(&priv->mutex);
1476 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1477 struct ieee80211_vif *vif,
1478 enum ieee80211_ampdu_mlme_action action,
1479 struct ieee80211_sta *sta,
1482 struct ath9k_htc_priv *priv = hw->priv;
1483 struct ath9k_htc_sta *ista;
1487 case IEEE80211_AMPDU_RX_START:
1489 case IEEE80211_AMPDU_RX_STOP:
1491 case IEEE80211_AMPDU_TX_START:
1492 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1494 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1496 case IEEE80211_AMPDU_TX_STOP:
1497 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1498 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1500 case IEEE80211_AMPDU_TX_OPERATIONAL:
1501 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1502 spin_lock_bh(&priv->tx_lock);
1503 ista->tid_state[tid] = AGGR_OPERATIONAL;
1504 spin_unlock_bh(&priv->tx_lock);
1507 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1513 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1515 struct ath9k_htc_priv *priv = hw->priv;
1517 mutex_lock(&priv->mutex);
1518 spin_lock_bh(&priv->beacon_lock);
1519 priv->op_flags |= OP_SCANNING;
1520 spin_unlock_bh(&priv->beacon_lock);
1521 cancel_work_sync(&priv->ps_work);
1522 if (priv->op_flags & OP_ASSOCIATED)
1523 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1524 mutex_unlock(&priv->mutex);
1527 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1529 struct ath9k_htc_priv *priv = hw->priv;
1531 mutex_lock(&priv->mutex);
1532 ath9k_htc_ps_wakeup(priv);
1533 spin_lock_bh(&priv->beacon_lock);
1534 priv->op_flags &= ~OP_SCANNING;
1535 spin_unlock_bh(&priv->beacon_lock);
1536 if (priv->op_flags & OP_ASSOCIATED) {
1537 ath9k_htc_beacon_config(priv, priv->vif);
1538 ath_start_ani(priv);
1540 ath9k_htc_ps_restore(priv);
1541 mutex_unlock(&priv->mutex);
1544 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1549 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1552 struct ath9k_htc_priv *priv = hw->priv;
1554 mutex_lock(&priv->mutex);
1555 ath9k_htc_ps_wakeup(priv);
1556 priv->ah->coverage_class = coverage_class;
1557 ath9k_hw_init_global_settings(priv->ah);
1558 ath9k_htc_ps_restore(priv);
1559 mutex_unlock(&priv->mutex);
1562 struct ieee80211_ops ath9k_htc_ops = {
1564 .start = ath9k_htc_start,
1565 .stop = ath9k_htc_stop,
1566 .add_interface = ath9k_htc_add_interface,
1567 .remove_interface = ath9k_htc_remove_interface,
1568 .config = ath9k_htc_config,
1569 .configure_filter = ath9k_htc_configure_filter,
1570 .sta_add = ath9k_htc_sta_add,
1571 .sta_remove = ath9k_htc_sta_remove,
1572 .conf_tx = ath9k_htc_conf_tx,
1573 .bss_info_changed = ath9k_htc_bss_info_changed,
1574 .set_key = ath9k_htc_set_key,
1575 .get_tsf = ath9k_htc_get_tsf,
1576 .set_tsf = ath9k_htc_set_tsf,
1577 .reset_tsf = ath9k_htc_reset_tsf,
1578 .ampdu_action = ath9k_htc_ampdu_action,
1579 .sw_scan_start = ath9k_htc_sw_scan_start,
1580 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1581 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1582 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1583 .set_coverage_class = ath9k_htc_set_coverage_class,