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 static 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);
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 static 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 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
120 struct ieee80211_hw *hw,
121 struct ath9k_channel *hchan)
123 struct ath_hw *ah = priv->ah;
124 struct ath_common *common = ath9k_hw_common(ah);
125 struct ieee80211_conf *conf = &common->hw->conf;
127 struct ieee80211_channel *channel = hw->conf.channel;
128 enum htc_phymode mode;
133 if (priv->op_flags & OP_INVALID)
136 if (priv->op_flags & OP_FULL_RESET)
139 /* Fiddle around with fastcc later on, for now just use full reset */
141 ath9k_htc_ps_wakeup(priv);
143 WMI_CMD(WMI_DISABLE_INTR_CMDID);
144 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
145 WMI_CMD(WMI_STOP_RECV_CMDID);
147 ath_print(common, ATH_DBG_CONFIG,
148 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d\n",
149 priv->ah->curchan->channel,
150 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
152 ret = ath9k_hw_reset(ah, hchan, fastcc);
154 ath_print(common, ATH_DBG_FATAL,
155 "Unable to reset channel (%u Mhz) "
156 "reset status %d\n", channel->center_freq, ret);
160 ath_update_txpow(priv);
162 WMI_CMD(WMI_START_RECV_CMDID);
166 ath9k_host_rx_init(priv);
168 mode = ath9k_htc_get_curmode(priv, hchan);
169 htc_mode = cpu_to_be16(mode);
170 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
174 WMI_CMD(WMI_ENABLE_INTR_CMDID);
178 htc_start(priv->htc);
180 priv->op_flags &= ~OP_FULL_RESET;
182 ath9k_htc_ps_restore(priv);
186 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
188 struct ath_common *common = ath9k_hw_common(priv->ah);
189 struct ath9k_htc_target_vif hvif;
196 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
197 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
199 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
200 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
201 hvif.index = priv->nvifs;
203 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
211 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
213 struct ath_common *common = ath9k_hw_common(priv->ah);
214 struct ath9k_htc_target_vif hvif;
218 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
219 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
220 hvif.index = 0; /* Should do for now */
221 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
227 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
228 struct ieee80211_vif *vif,
229 struct ieee80211_sta *sta)
231 struct ath_common *common = ath9k_hw_common(priv->ah);
232 struct ath9k_htc_target_sta tsta;
233 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
234 struct ath9k_htc_sta *ista;
238 if (priv->nstations >= ATH9K_HTC_MAX_STA)
241 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
244 ista = (struct ath9k_htc_sta *) sta->drv_priv;
245 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
246 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
247 tsta.associd = common->curaid;
250 ista->index = priv->nstations;
252 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
256 tsta.sta_index = priv->nstations;
257 tsta.vif_index = avp->index;
258 tsta.maxampdu = 0xffff;
259 if (sta && sta->ht_cap.ht_supported)
260 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
262 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
265 ath_print(common, ATH_DBG_FATAL,
266 "Unable to add station entry for: %pM\n", sta->addr);
271 ath_print(common, ATH_DBG_CONFIG,
272 "Added a station entry for: %pM (idx: %d)\n",
273 sta->addr, tsta.sta_index);
279 static int ath9k_htc_remove_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_sta *ista;
289 ista = (struct ath9k_htc_sta *) sta->drv_priv;
290 sta_idx = ista->index;
295 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
298 ath_print(common, ATH_DBG_FATAL,
299 "Unable to remove station entry for: %pM\n",
305 ath_print(common, ATH_DBG_CONFIG,
306 "Removed a station entry for: %pM (idx: %d)\n",
313 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
315 struct ath9k_htc_cap_target tcap;
319 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
321 /* FIXME: Values are hardcoded */
322 tcap.flags = 0x240c40;
323 tcap.flags_ext = 0x80601000;
324 tcap.ampdu_limit = 0xffff0000;
325 tcap.ampdu_subframes = 20;
326 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
328 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
330 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
335 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
336 struct ieee80211_sta *sta,
337 struct ath9k_htc_target_rate *trate)
339 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
340 struct ieee80211_supported_band *sband;
344 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
346 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
347 if (sta->supp_rates[sband->band] & BIT(i)) {
348 trate->rates.legacy_rates.rs_rates[j]
349 = (sband->bitrates[i].bitrate * 2) / 10;
353 trate->rates.legacy_rates.rs_nrates = j;
355 if (sta->ht_cap.ht_supported) {
356 for (i = 0, j = 0; i < 77; i++) {
357 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
358 trate->rates.ht_rates.rs_rates[j++] = i;
359 if (j == ATH_HTC_RATE_MAX)
362 trate->rates.ht_rates.rs_nrates = j;
364 caps = WLAN_RC_HT_FLAG;
365 if (sta->ht_cap.mcs.rx_mask[1])
366 caps |= WLAN_RC_DS_FLAG;
367 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
368 caps |= WLAN_RC_40_FLAG;
369 if (conf_is_ht40(&priv->hw->conf) &&
370 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
371 caps |= WLAN_RC_SGI_FLAG;
372 else if (conf_is_ht20(&priv->hw->conf) &&
373 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
374 caps |= WLAN_RC_SGI_FLAG;
377 trate->sta_index = ista->index;
379 trate->capflags = cpu_to_be32(caps);
382 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
383 struct ath9k_htc_target_rate *trate)
385 struct ath_common *common = ath9k_hw_common(priv->ah);
389 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
391 ath_print(common, ATH_DBG_FATAL,
392 "Unable to initialize Rate information on target\n");
398 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
399 struct ieee80211_sta *sta)
401 struct ath_common *common = ath9k_hw_common(priv->ah);
402 struct ath9k_htc_target_rate trate;
405 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
406 ath9k_htc_setup_rate(priv, sta, &trate);
407 ret = ath9k_htc_send_rate_cmd(priv, &trate);
409 ath_print(common, ATH_DBG_CONFIG,
410 "Updated target sta: %pM, rate caps: 0x%X\n",
411 sta->addr, be32_to_cpu(trate.capflags));
414 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
415 struct ieee80211_vif *vif,
416 struct ieee80211_bss_conf *bss_conf)
418 struct ath_common *common = ath9k_hw_common(priv->ah);
419 struct ath9k_htc_target_rate trate;
420 struct ieee80211_sta *sta;
423 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
426 sta = ieee80211_find_sta(vif, bss_conf->bssid);
431 ath9k_htc_setup_rate(priv, sta, &trate);
434 ret = ath9k_htc_send_rate_cmd(priv, &trate);
436 ath_print(common, ATH_DBG_CONFIG,
437 "Updated target sta: %pM, rate caps: 0x%X\n",
438 bss_conf->bssid, be32_to_cpu(trate.capflags));
441 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv *priv,
442 struct ieee80211_vif *vif,
443 u8 *sta_addr, u8 tid, bool oper)
445 struct ath_common *common = ath9k_hw_common(priv->ah);
446 struct ath9k_htc_target_aggr aggr;
447 struct ieee80211_sta *sta = NULL;
448 struct ath9k_htc_sta *ista;
452 if (tid >= ATH9K_HTC_MAX_TID)
455 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
459 /* Check if we are able to retrieve the station */
460 sta = ieee80211_find_sta(vif, sta_addr);
466 ista = (struct ath9k_htc_sta *) sta->drv_priv;
469 ista->tid_state[tid] = AGGR_START;
471 ista->tid_state[tid] = AGGR_STOP;
473 aggr.sta_index = ista->index;
478 aggr.aggr_enable = oper;
480 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
482 ath_print(common, ATH_DBG_CONFIG,
483 "Unable to %s TX aggregation for (%pM, %d)\n",
484 (oper) ? "start" : "stop", sta->addr, tid);
486 ath_print(common, ATH_DBG_CONFIG,
487 "%s aggregation for (%pM, %d)\n",
488 (oper) ? "Starting" : "Stopping", sta->addr, tid);
493 void ath9k_htc_aggr_work(struct work_struct *work)
496 struct ath9k_htc_priv *priv =
497 container_of(work, struct ath9k_htc_priv,
498 ath9k_aggr_work.work);
499 struct ath9k_htc_aggr_work *wk = &priv->aggr_work;
501 mutex_lock(&wk->mutex);
503 switch (wk->action) {
504 case IEEE80211_AMPDU_TX_START:
505 ret = ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
508 ieee80211_start_tx_ba_cb_irqsafe(wk->vif, wk->sta_addr,
511 case IEEE80211_AMPDU_TX_STOP:
512 ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
514 ieee80211_stop_tx_ba_cb_irqsafe(wk->vif, wk->sta_addr, wk->tid);
517 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
518 "Unknown AMPDU action\n");
521 mutex_unlock(&wk->mutex);
528 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
530 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
532 file->private_data = inode->i_private;
536 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
537 size_t count, loff_t *ppos)
539 struct ath9k_htc_priv *priv =
540 (struct ath9k_htc_priv *) file->private_data;
541 struct ath9k_htc_target_stats cmd_rsp;
543 unsigned int len = 0;
546 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
548 WMI_CMD(WMI_TGT_STATS_CMDID);
553 len += snprintf(buf + len, sizeof(buf) - len,
554 "%19s : %10u\n", "TX Short Retries",
555 be32_to_cpu(cmd_rsp.tx_shortretry));
556 len += snprintf(buf + len, sizeof(buf) - len,
557 "%19s : %10u\n", "TX Long Retries",
558 be32_to_cpu(cmd_rsp.tx_longretry));
559 len += snprintf(buf + len, sizeof(buf) - len,
560 "%19s : %10u\n", "TX Xretries",
561 be32_to_cpu(cmd_rsp.tx_xretries));
562 len += snprintf(buf + len, sizeof(buf) - len,
563 "%19s : %10u\n", "TX Unaggr. Xretries",
564 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
565 len += snprintf(buf + len, sizeof(buf) - len,
566 "%19s : %10u\n", "TX Xretries (HT)",
567 be32_to_cpu(cmd_rsp.ht_tx_xretries));
568 len += snprintf(buf + len, sizeof(buf) - len,
569 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
571 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
574 static const struct file_operations fops_tgt_stats = {
575 .read = read_file_tgt_stats,
576 .open = ath9k_debugfs_open,
580 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
581 size_t count, loff_t *ppos)
583 struct ath9k_htc_priv *priv =
584 (struct ath9k_htc_priv *) file->private_data;
586 unsigned int len = 0;
588 len += snprintf(buf + len, sizeof(buf) - len,
589 "%20s : %10u\n", "Buffers queued",
590 priv->debug.tx_stats.buf_queued);
591 len += snprintf(buf + len, sizeof(buf) - len,
592 "%20s : %10u\n", "Buffers completed",
593 priv->debug.tx_stats.buf_completed);
594 len += snprintf(buf + len, sizeof(buf) - len,
595 "%20s : %10u\n", "SKBs queued",
596 priv->debug.tx_stats.skb_queued);
597 len += snprintf(buf + len, sizeof(buf) - len,
598 "%20s : %10u\n", "SKBs completed",
599 priv->debug.tx_stats.skb_completed);
600 len += snprintf(buf + len, sizeof(buf) - len,
601 "%20s : %10u\n", "SKBs dropped",
602 priv->debug.tx_stats.skb_dropped);
604 len += snprintf(buf + len, sizeof(buf) - len,
605 "%20s : %10u\n", "BE queued",
606 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
607 len += snprintf(buf + len, sizeof(buf) - len,
608 "%20s : %10u\n", "BK queued",
609 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
610 len += snprintf(buf + len, sizeof(buf) - len,
611 "%20s : %10u\n", "VI queued",
612 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
613 len += snprintf(buf + len, sizeof(buf) - len,
614 "%20s : %10u\n", "VO queued",
615 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
617 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
620 static const struct file_operations fops_xmit = {
621 .read = read_file_xmit,
622 .open = ath9k_debugfs_open,
626 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
627 size_t count, loff_t *ppos)
629 struct ath9k_htc_priv *priv =
630 (struct ath9k_htc_priv *) file->private_data;
632 unsigned int len = 0;
634 len += snprintf(buf + len, sizeof(buf) - len,
635 "%20s : %10u\n", "SKBs allocated",
636 priv->debug.rx_stats.skb_allocated);
637 len += snprintf(buf + len, sizeof(buf) - len,
638 "%20s : %10u\n", "SKBs completed",
639 priv->debug.rx_stats.skb_completed);
640 len += snprintf(buf + len, sizeof(buf) - len,
641 "%20s : %10u\n", "SKBs Dropped",
642 priv->debug.rx_stats.skb_dropped);
644 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
647 static const struct file_operations fops_recv = {
648 .read = read_file_recv,
649 .open = ath9k_debugfs_open,
653 int ath9k_htc_init_debug(struct ath_hw *ah)
655 struct ath_common *common = ath9k_hw_common(ah);
656 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
658 if (!ath9k_debugfs_root)
661 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
663 if (!priv->debug.debugfs_phy)
666 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
667 priv->debug.debugfs_phy,
668 priv, &fops_tgt_stats);
669 if (!priv->debug.debugfs_tgt_stats)
673 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
674 priv->debug.debugfs_phy,
676 if (!priv->debug.debugfs_xmit)
679 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
680 priv->debug.debugfs_phy,
682 if (!priv->debug.debugfs_recv)
688 ath9k_htc_exit_debug(ah);
692 void ath9k_htc_exit_debug(struct ath_hw *ah)
694 struct ath_common *common = ath9k_hw_common(ah);
695 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
697 debugfs_remove(priv->debug.debugfs_recv);
698 debugfs_remove(priv->debug.debugfs_xmit);
699 debugfs_remove(priv->debug.debugfs_tgt_stats);
700 debugfs_remove(priv->debug.debugfs_phy);
703 int ath9k_htc_debug_create_root(void)
705 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
706 if (!ath9k_debugfs_root)
712 void ath9k_htc_debug_remove_root(void)
714 debugfs_remove(ath9k_debugfs_root);
715 ath9k_debugfs_root = NULL;
718 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
724 static void ath_start_ani(struct ath9k_htc_priv *priv)
726 struct ath_common *common = ath9k_hw_common(priv->ah);
727 unsigned long timestamp = jiffies_to_msecs(jiffies);
729 common->ani.longcal_timer = timestamp;
730 common->ani.shortcal_timer = timestamp;
731 common->ani.checkani_timer = timestamp;
733 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
734 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
737 void ath9k_ani_work(struct work_struct *work)
739 struct ath9k_htc_priv *priv =
740 container_of(work, struct ath9k_htc_priv,
741 ath9k_ani_work.work);
742 struct ath_hw *ah = priv->ah;
743 struct ath_common *common = ath9k_hw_common(ah);
744 bool longcal = false;
745 bool shortcal = false;
746 bool aniflag = false;
747 unsigned int timestamp = jiffies_to_msecs(jiffies);
748 u32 cal_interval, short_cal_interval;
750 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
752 /* Only calibrate if awake */
753 if (ah->power_mode != ATH9K_PM_AWAKE)
756 /* Long calibration runs independently of short calibration. */
757 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
759 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
760 common->ani.longcal_timer = timestamp;
763 /* Short calibration applies only while caldone is false */
764 if (!common->ani.caldone) {
765 if ((timestamp - common->ani.shortcal_timer) >=
766 short_cal_interval) {
768 ath_print(common, ATH_DBG_ANI,
769 "shortcal @%lu\n", jiffies);
770 common->ani.shortcal_timer = timestamp;
771 common->ani.resetcal_timer = timestamp;
774 if ((timestamp - common->ani.resetcal_timer) >=
775 ATH_RESTART_CALINTERVAL) {
776 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
777 if (common->ani.caldone)
778 common->ani.resetcal_timer = timestamp;
782 /* Verify whether we must check ANI */
783 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
785 common->ani.checkani_timer = timestamp;
788 /* Skip all processing if there's nothing to do. */
789 if (longcal || shortcal || aniflag) {
791 ath9k_htc_ps_wakeup(priv);
793 /* Call ANI routine if necessary */
795 ath9k_hw_ani_monitor(ah, ah->curchan);
797 /* Perform calibration if necessary */
798 if (longcal || shortcal) {
799 common->ani.caldone =
800 ath9k_hw_calibrate(ah, ah->curchan,
801 common->rx_chainmask,
805 common->ani.noise_floor =
806 ath9k_hw_getchan_noise(ah, ah->curchan);
808 ath_print(common, ATH_DBG_ANI,
809 " calibrate chan %u/%x nf: %d\n",
810 ah->curchan->channel,
811 ah->curchan->channelFlags,
812 common->ani.noise_floor);
815 ath9k_htc_ps_restore(priv);
820 * Set timer interval based on previous results.
821 * The interval must be the shortest necessary to satisfy ANI,
822 * short calibration and long calibration.
824 cal_interval = ATH_LONG_CALINTERVAL;
825 if (priv->ah->config.enable_ani)
826 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
827 if (!common->ani.caldone)
828 cal_interval = min(cal_interval, (u32)short_cal_interval);
830 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
831 msecs_to_jiffies(cal_interval));
838 static void ath9k_led_blink_work(struct work_struct *work)
840 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
841 ath9k_led_blink_work.work);
843 if (!(priv->op_flags & OP_LED_ASSOCIATED))
846 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
847 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
848 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
850 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
851 (priv->op_flags & OP_LED_ON) ? 1 : 0);
853 ieee80211_queue_delayed_work(priv->hw,
854 &priv->ath9k_led_blink_work,
855 (priv->op_flags & OP_LED_ON) ?
856 msecs_to_jiffies(priv->led_off_duration) :
857 msecs_to_jiffies(priv->led_on_duration));
859 priv->led_on_duration = priv->led_on_cnt ?
860 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
861 ATH_LED_ON_DURATION_IDLE;
862 priv->led_off_duration = priv->led_off_cnt ?
863 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
864 ATH_LED_OFF_DURATION_IDLE;
865 priv->led_on_cnt = priv->led_off_cnt = 0;
867 if (priv->op_flags & OP_LED_ON)
868 priv->op_flags &= ~OP_LED_ON;
870 priv->op_flags |= OP_LED_ON;
873 static void ath9k_led_brightness_work(struct work_struct *work)
875 struct ath_led *led = container_of(work, struct ath_led,
876 brightness_work.work);
877 struct ath9k_htc_priv *priv = led->priv;
879 switch (led->brightness) {
881 if (led->led_type == ATH_LED_ASSOC ||
882 led->led_type == ATH_LED_RADIO) {
883 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
884 (led->led_type == ATH_LED_RADIO));
885 priv->op_flags &= ~OP_LED_ASSOCIATED;
886 if (led->led_type == ATH_LED_RADIO)
887 priv->op_flags &= ~OP_LED_ON;
893 if (led->led_type == ATH_LED_ASSOC) {
894 priv->op_flags |= OP_LED_ASSOCIATED;
895 ieee80211_queue_delayed_work(priv->hw,
896 &priv->ath9k_led_blink_work, 0);
897 } else if (led->led_type == ATH_LED_RADIO) {
898 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
899 priv->op_flags |= OP_LED_ON;
909 static void ath9k_led_brightness(struct led_classdev *led_cdev,
910 enum led_brightness brightness)
912 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
913 struct ath9k_htc_priv *priv = led->priv;
915 led->brightness = brightness;
916 if (!(priv->op_flags & OP_LED_DEINIT))
917 ieee80211_queue_delayed_work(priv->hw,
918 &led->brightness_work, 0);
921 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
923 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
924 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
925 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
926 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
929 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
935 led->led_cdev.name = led->name;
936 led->led_cdev.default_trigger = trigger;
937 led->led_cdev.brightness_set = ath9k_led_brightness;
939 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
941 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
942 "Failed to register led:%s", led->name);
946 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
951 static void ath9k_unregister_led(struct ath_led *led)
953 if (led->registered) {
954 led_classdev_unregister(&led->led_cdev);
959 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
961 priv->op_flags |= OP_LED_DEINIT;
962 ath9k_unregister_led(&priv->assoc_led);
963 priv->op_flags &= ~OP_LED_ASSOCIATED;
964 ath9k_unregister_led(&priv->tx_led);
965 ath9k_unregister_led(&priv->rx_led);
966 ath9k_unregister_led(&priv->radio_led);
969 void ath9k_init_leds(struct ath9k_htc_priv *priv)
974 if (AR_SREV_9287(priv->ah))
975 priv->ah->led_pin = ATH_LED_PIN_9287;
976 else if (AR_SREV_9271(priv->ah))
977 priv->ah->led_pin = ATH_LED_PIN_9271;
979 priv->ah->led_pin = ATH_LED_PIN_DEF;
981 /* Configure gpio 1 for output */
982 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
983 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
984 /* LED off, active low */
985 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
987 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
989 trigger = ieee80211_get_radio_led_name(priv->hw);
990 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
991 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
992 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
993 priv->radio_led.led_type = ATH_LED_RADIO;
997 trigger = ieee80211_get_assoc_led_name(priv->hw);
998 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
999 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
1000 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
1001 priv->assoc_led.led_type = ATH_LED_ASSOC;
1005 trigger = ieee80211_get_tx_led_name(priv->hw);
1006 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
1007 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
1008 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
1009 priv->tx_led.led_type = ATH_LED_TX;
1013 trigger = ieee80211_get_rx_led_name(priv->hw);
1014 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
1015 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
1016 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
1017 priv->rx_led.led_type = ATH_LED_RX;
1021 priv->op_flags &= ~OP_LED_DEINIT;
1026 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1027 ath9k_deinit_leds(priv);
1030 /*******************/
1032 /*******************/
1034 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1036 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1037 priv->ah->rfkill_polarity;
1040 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1042 struct ath9k_htc_priv *priv = hw->priv;
1043 bool blocked = !!ath_is_rfkill_set(priv);
1045 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1048 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1050 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1051 wiphy_rfkill_start_polling(priv->hw->wiphy);
1054 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1056 struct ath9k_htc_priv *priv = hw->priv;
1057 struct ath_hw *ah = priv->ah;
1058 struct ath_common *common = ath9k_hw_common(ah);
1063 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1066 ret = ath9k_hw_reset(ah, ah->curchan, false);
1068 ath_print(common, ATH_DBG_FATAL,
1069 "Unable to reset hardware; reset status %d "
1070 "(freq %u MHz)\n", ret, ah->curchan->channel);
1073 ath_update_txpow(priv);
1076 WMI_CMD(WMI_START_RECV_CMDID);
1077 ath9k_host_rx_init(priv);
1080 htc_start(priv->htc);
1081 spin_lock_bh(&priv->tx_lock);
1082 priv->tx_queues_stop = false;
1083 spin_unlock_bh(&priv->tx_lock);
1084 ieee80211_wake_queues(hw);
1086 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1089 ath9k_hw_cfg_output(ah, ah->led_pin,
1090 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1091 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1094 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1096 struct ath9k_htc_priv *priv = hw->priv;
1097 struct ath_hw *ah = priv->ah;
1098 struct ath_common *common = ath9k_hw_common(ah);
1102 ath9k_htc_ps_wakeup(priv);
1105 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1106 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1108 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1111 ieee80211_stop_queues(hw);
1112 htc_stop(priv->htc);
1113 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1114 skb_queue_purge(&priv->tx_queue);
1117 WMI_CMD(WMI_STOP_RECV_CMDID);
1120 * The MIB counters have to be disabled here,
1121 * since the target doesn't do it.
1123 ath9k_hw_disable_mib_counters(ah);
1126 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1129 ret = ath9k_hw_reset(ah, ah->curchan, false);
1131 ath_print(common, ATH_DBG_FATAL,
1132 "Unable to reset hardware; reset status %d "
1133 "(freq %u MHz)\n", ret, ah->curchan->channel);
1136 /* Disable the PHY */
1137 ath9k_hw_phy_disable(ah);
1139 ath9k_htc_ps_restore(priv);
1140 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1143 /**********************/
1144 /* mac80211 Callbacks */
1145 /**********************/
1147 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1149 struct ieee80211_hdr *hdr;
1150 struct ath9k_htc_priv *priv = hw->priv;
1151 int padpos, padsize, ret;
1153 hdr = (struct ieee80211_hdr *) skb->data;
1155 /* Add the padding after the header if this is not already done */
1156 padpos = ath9k_cmn_padpos(hdr->frame_control);
1157 padsize = padpos & 3;
1158 if (padsize && skb->len > padpos) {
1159 if (skb_headroom(skb) < padsize)
1161 skb_push(skb, padsize);
1162 memmove(skb->data, skb->data + padsize, padpos);
1165 ret = ath9k_htc_tx_start(priv, skb);
1167 if (ret == -ENOMEM) {
1168 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1169 "Stopping TX queues\n");
1170 ieee80211_stop_queues(hw);
1171 spin_lock_bh(&priv->tx_lock);
1172 priv->tx_queues_stop = true;
1173 spin_unlock_bh(&priv->tx_lock);
1175 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1184 dev_kfree_skb_any(skb);
1188 static int ath9k_htc_start(struct ieee80211_hw *hw)
1190 struct ath9k_htc_priv *priv = hw->priv;
1191 struct ath_hw *ah = priv->ah;
1192 struct ath_common *common = ath9k_hw_common(ah);
1193 struct ieee80211_channel *curchan = hw->conf.channel;
1194 struct ath9k_channel *init_channel;
1196 enum htc_phymode mode;
1200 mutex_lock(&priv->mutex);
1202 ath_print(common, ATH_DBG_CONFIG,
1203 "Starting driver with initial channel: %d MHz\n",
1204 curchan->center_freq);
1206 /* Ensure that HW is awake before flushing RX */
1207 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1208 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1210 /* setup initial channel */
1211 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1213 /* Reset SERDES registers */
1214 ath9k_hw_configpcipowersave(ah, 0, 0);
1216 ath9k_hw_htc_resetinit(ah);
1217 ret = ath9k_hw_reset(ah, init_channel, false);
1219 ath_print(common, ATH_DBG_FATAL,
1220 "Unable to reset hardware; reset status %d "
1221 "(freq %u MHz)\n", ret, curchan->center_freq);
1222 mutex_unlock(&priv->mutex);
1226 ath_update_txpow(priv);
1228 mode = ath9k_htc_get_curmode(priv, init_channel);
1229 htc_mode = cpu_to_be16(mode);
1230 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1231 WMI_CMD(WMI_ATH_INIT_CMDID);
1232 WMI_CMD(WMI_START_RECV_CMDID);
1234 ath9k_host_rx_init(priv);
1236 priv->op_flags &= ~OP_INVALID;
1237 htc_start(priv->htc);
1239 spin_lock_bh(&priv->tx_lock);
1240 priv->tx_queues_stop = false;
1241 spin_unlock_bh(&priv->tx_lock);
1243 ieee80211_wake_queues(hw);
1245 mutex_unlock(&priv->mutex);
1250 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1252 struct ath9k_htc_priv *priv = hw->priv;
1253 struct ath_hw *ah = priv->ah;
1254 struct ath_common *common = ath9k_hw_common(ah);
1258 mutex_lock(&priv->mutex);
1260 if (priv->op_flags & OP_INVALID) {
1261 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1262 mutex_unlock(&priv->mutex);
1266 /* Cancel all the running timers/work .. */
1267 cancel_work_sync(&priv->ps_work);
1268 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1269 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1270 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1271 ath9k_led_stop_brightness(priv);
1273 ath9k_htc_ps_wakeup(priv);
1274 htc_stop(priv->htc);
1275 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1276 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1277 WMI_CMD(WMI_STOP_RECV_CMDID);
1278 skb_queue_purge(&priv->tx_queue);
1280 /* Remove monitor interface here */
1281 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1282 if (ath9k_htc_remove_monitor_interface(priv))
1283 ath_print(common, ATH_DBG_FATAL,
1284 "Unable to remove monitor interface\n");
1286 ath_print(common, ATH_DBG_CONFIG,
1287 "Monitor interface removed\n");
1290 ath9k_hw_phy_disable(ah);
1291 ath9k_hw_disable(ah);
1292 ath9k_hw_configpcipowersave(ah, 1, 1);
1293 ath9k_htc_ps_restore(priv);
1294 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1296 priv->op_flags |= OP_INVALID;
1298 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1299 mutex_unlock(&priv->mutex);
1302 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1303 struct ieee80211_vif *vif)
1305 struct ath9k_htc_priv *priv = hw->priv;
1306 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1307 struct ath_common *common = ath9k_hw_common(priv->ah);
1308 struct ath9k_htc_target_vif hvif;
1312 mutex_lock(&priv->mutex);
1314 /* Only one interface for now */
1315 if (priv->nvifs > 0) {
1320 ath9k_htc_ps_wakeup(priv);
1321 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1322 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1324 switch (vif->type) {
1325 case NL80211_IFTYPE_STATION:
1326 hvif.opmode = cpu_to_be32(HTC_M_STA);
1328 case NL80211_IFTYPE_ADHOC:
1329 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1332 ath_print(common, ATH_DBG_FATAL,
1333 "Interface type %d not yet supported\n", vif->type);
1338 ath_print(common, ATH_DBG_CONFIG,
1339 "Attach a VIF of type: %d\n", vif->type);
1341 priv->ah->opmode = vif->type;
1343 /* Index starts from zero on the target */
1344 avp->index = hvif.index = priv->nvifs;
1345 hvif.rtsthreshold = cpu_to_be16(2304);
1346 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1353 * We need a node in target to tx mgmt frames
1354 * before association.
1356 ret = ath9k_htc_add_station(priv, vif, NULL);
1360 ret = ath9k_htc_update_cap_target(priv);
1362 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1363 " capability in target \n");
1367 ath9k_htc_ps_restore(priv);
1368 mutex_unlock(&priv->mutex);
1373 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1374 struct ieee80211_vif *vif)
1376 struct ath9k_htc_priv *priv = hw->priv;
1377 struct ath_common *common = ath9k_hw_common(priv->ah);
1378 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1379 struct ath9k_htc_target_vif hvif;
1383 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1385 mutex_lock(&priv->mutex);
1386 ath9k_htc_ps_wakeup(priv);
1388 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1389 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1390 hvif.index = avp->index;
1391 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1394 ath9k_htc_remove_station(priv, vif, NULL);
1397 ath9k_htc_ps_restore(priv);
1398 mutex_unlock(&priv->mutex);
1401 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1403 struct ath9k_htc_priv *priv = hw->priv;
1404 struct ath_common *common = ath9k_hw_common(priv->ah);
1405 struct ieee80211_conf *conf = &hw->conf;
1407 mutex_lock(&priv->mutex);
1409 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1410 bool enable_radio = false;
1411 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1413 mutex_lock(&priv->htc_pm_lock);
1414 if (!idle && priv->ps_idle)
1415 enable_radio = true;
1416 priv->ps_idle = idle;
1417 mutex_unlock(&priv->htc_pm_lock);
1420 ath_print(common, ATH_DBG_CONFIG,
1421 "not-idle: enabling radio\n");
1422 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1423 ath9k_htc_radio_enable(hw);
1427 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1428 struct ieee80211_channel *curchan = hw->conf.channel;
1429 int pos = curchan->hw_value;
1431 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1432 curchan->center_freq);
1434 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1436 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1437 ath_print(common, ATH_DBG_FATAL,
1438 "Unable to set channel\n");
1439 mutex_unlock(&priv->mutex);
1444 if (changed & IEEE80211_CONF_CHANGE_PS) {
1445 if (conf->flags & IEEE80211_CONF_PS) {
1446 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1447 priv->ps_enabled = true;
1449 priv->ps_enabled = false;
1450 cancel_work_sync(&priv->ps_work);
1451 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1455 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1456 if (conf->flags & IEEE80211_CONF_MONITOR) {
1457 if (ath9k_htc_add_monitor_interface(priv))
1458 ath_print(common, ATH_DBG_FATAL,
1459 "Failed to set monitor mode\n");
1461 ath_print(common, ATH_DBG_CONFIG,
1462 "HW opmode set to Monitor mode\n");
1466 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1467 mutex_lock(&priv->htc_pm_lock);
1468 if (!priv->ps_idle) {
1469 mutex_unlock(&priv->htc_pm_lock);
1472 mutex_unlock(&priv->htc_pm_lock);
1474 ath_print(common, ATH_DBG_CONFIG,
1475 "idle: disabling radio\n");
1476 ath9k_htc_radio_disable(hw);
1480 mutex_unlock(&priv->mutex);
1484 #define SUPPORTED_FILTERS \
1485 (FIF_PROMISC_IN_BSS | \
1490 FIF_BCN_PRBRESP_PROMISC | \
1493 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1494 unsigned int changed_flags,
1495 unsigned int *total_flags,
1498 struct ath9k_htc_priv *priv = hw->priv;
1501 mutex_lock(&priv->mutex);
1502 ath9k_htc_ps_wakeup(priv);
1504 changed_flags &= SUPPORTED_FILTERS;
1505 *total_flags &= SUPPORTED_FILTERS;
1507 priv->rxfilter = *total_flags;
1508 rfilt = ath9k_htc_calcrxfilter(priv);
1509 ath9k_hw_setrxfilter(priv->ah, rfilt);
1511 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1512 "Set HW RX filter: 0x%x\n", rfilt);
1514 ath9k_htc_ps_restore(priv);
1515 mutex_unlock(&priv->mutex);
1518 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1519 struct ieee80211_vif *vif,
1520 struct ieee80211_sta *sta)
1522 struct ath9k_htc_priv *priv = hw->priv;
1525 mutex_lock(&priv->mutex);
1526 ath9k_htc_ps_wakeup(priv);
1527 ret = ath9k_htc_add_station(priv, vif, sta);
1529 ath9k_htc_init_rate(priv, sta);
1530 ath9k_htc_ps_restore(priv);
1531 mutex_unlock(&priv->mutex);
1536 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1537 struct ieee80211_vif *vif,
1538 struct ieee80211_sta *sta)
1540 struct ath9k_htc_priv *priv = hw->priv;
1543 mutex_lock(&priv->mutex);
1544 ath9k_htc_ps_wakeup(priv);
1545 ret = ath9k_htc_remove_station(priv, vif, sta);
1546 ath9k_htc_ps_restore(priv);
1547 mutex_unlock(&priv->mutex);
1552 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1553 const struct ieee80211_tx_queue_params *params)
1555 struct ath9k_htc_priv *priv = hw->priv;
1556 struct ath_common *common = ath9k_hw_common(priv->ah);
1557 struct ath9k_tx_queue_info qi;
1560 if (queue >= WME_NUM_AC)
1563 mutex_lock(&priv->mutex);
1564 ath9k_htc_ps_wakeup(priv);
1566 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1568 qi.tqi_aifs = params->aifs;
1569 qi.tqi_cwmin = params->cw_min;
1570 qi.tqi_cwmax = params->cw_max;
1571 qi.tqi_burstTime = params->txop;
1573 qnum = get_hw_qnum(queue, priv->hwq_map);
1575 ath_print(common, ATH_DBG_CONFIG,
1576 "Configure tx [queue/hwq] [%d/%d], "
1577 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1578 queue, qnum, params->aifs, params->cw_min,
1579 params->cw_max, params->txop);
1581 ret = ath_htc_txq_update(priv, qnum, &qi);
1583 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1587 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1588 (qnum == priv->hwq_map[WME_AC_BE]))
1589 ath9k_htc_beaconq_config(priv);
1591 ath9k_htc_ps_restore(priv);
1592 mutex_unlock(&priv->mutex);
1597 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1598 enum set_key_cmd cmd,
1599 struct ieee80211_vif *vif,
1600 struct ieee80211_sta *sta,
1601 struct ieee80211_key_conf *key)
1603 struct ath9k_htc_priv *priv = hw->priv;
1604 struct ath_common *common = ath9k_hw_common(priv->ah);
1607 if (htc_modparam_nohwcrypt)
1610 mutex_lock(&priv->mutex);
1611 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1612 ath9k_htc_ps_wakeup(priv);
1616 ret = ath9k_cmn_key_config(common, vif, sta, key);
1618 key->hw_key_idx = ret;
1619 /* push IV and Michael MIC generation to stack */
1620 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1621 if (key->alg == ALG_TKIP)
1622 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1623 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1624 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1629 ath9k_cmn_key_delete(common, key);
1635 ath9k_htc_ps_restore(priv);
1636 mutex_unlock(&priv->mutex);
1641 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1642 struct ieee80211_vif *vif,
1643 struct ieee80211_bss_conf *bss_conf,
1646 struct ath9k_htc_priv *priv = hw->priv;
1647 struct ath_hw *ah = priv->ah;
1648 struct ath_common *common = ath9k_hw_common(ah);
1650 mutex_lock(&priv->mutex);
1651 ath9k_htc_ps_wakeup(priv);
1653 if (changed & BSS_CHANGED_ASSOC) {
1654 common->curaid = bss_conf->assoc ?
1656 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1659 if (bss_conf->assoc) {
1660 priv->op_flags |= OP_ASSOCIATED;
1661 ath_start_ani(priv);
1663 priv->op_flags &= ~OP_ASSOCIATED;
1664 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1668 if (changed & BSS_CHANGED_BSSID) {
1670 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1671 ath9k_hw_write_associd(ah);
1673 ath_print(common, ATH_DBG_CONFIG,
1674 "BSSID: %pM aid: 0x%x\n",
1675 common->curbssid, common->curaid);
1678 if ((changed & BSS_CHANGED_BEACON_INT) ||
1679 (changed & BSS_CHANGED_BEACON) ||
1680 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1681 bss_conf->enable_beacon)) {
1682 priv->op_flags |= OP_ENABLE_BEACON;
1683 ath9k_htc_beacon_config(priv, vif);
1686 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1687 !bss_conf->enable_beacon) {
1688 priv->op_flags &= ~OP_ENABLE_BEACON;
1689 ath9k_htc_beacon_config(priv, vif);
1692 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1693 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1694 bss_conf->use_short_preamble);
1695 if (bss_conf->use_short_preamble)
1696 priv->op_flags |= OP_PREAMBLE_SHORT;
1698 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1701 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1702 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1703 bss_conf->use_cts_prot);
1704 if (bss_conf->use_cts_prot &&
1705 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1706 priv->op_flags |= OP_PROTECT_ENABLE;
1708 priv->op_flags &= ~OP_PROTECT_ENABLE;
1711 if (changed & BSS_CHANGED_ERP_SLOT) {
1712 if (bss_conf->use_short_slot)
1717 ath9k_hw_init_global_settings(ah);
1720 if (changed & BSS_CHANGED_HT)
1721 ath9k_htc_update_rate(priv, vif, bss_conf);
1723 ath9k_htc_ps_restore(priv);
1724 mutex_unlock(&priv->mutex);
1727 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1729 struct ath9k_htc_priv *priv = hw->priv;
1732 mutex_lock(&priv->mutex);
1733 ath9k_htc_ps_wakeup(priv);
1734 tsf = ath9k_hw_gettsf64(priv->ah);
1735 ath9k_htc_ps_restore(priv);
1736 mutex_unlock(&priv->mutex);
1741 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1743 struct ath9k_htc_priv *priv = hw->priv;
1745 mutex_lock(&priv->mutex);
1746 ath9k_htc_ps_wakeup(priv);
1747 ath9k_hw_settsf64(priv->ah, tsf);
1748 ath9k_htc_ps_restore(priv);
1749 mutex_unlock(&priv->mutex);
1752 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1754 struct ath9k_htc_priv *priv = hw->priv;
1756 mutex_lock(&priv->mutex);
1757 ath9k_htc_ps_wakeup(priv);
1758 ath9k_hw_reset_tsf(priv->ah);
1759 ath9k_htc_ps_restore(priv);
1760 mutex_unlock(&priv->mutex);
1763 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1764 struct ieee80211_vif *vif,
1765 enum ieee80211_ampdu_mlme_action action,
1766 struct ieee80211_sta *sta,
1769 struct ath9k_htc_priv *priv = hw->priv;
1770 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1771 struct ath9k_htc_sta *ista;
1774 case IEEE80211_AMPDU_RX_START:
1776 case IEEE80211_AMPDU_RX_STOP:
1778 case IEEE80211_AMPDU_TX_START:
1779 case IEEE80211_AMPDU_TX_STOP:
1780 if (!(priv->op_flags & OP_TXAGGR))
1782 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1785 work->action = action;
1787 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1789 case IEEE80211_AMPDU_TX_OPERATIONAL:
1790 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1791 ista->tid_state[tid] = AGGR_OPERATIONAL;
1794 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1795 "Unknown AMPDU action\n");
1801 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1803 struct ath9k_htc_priv *priv = hw->priv;
1805 mutex_lock(&priv->mutex);
1806 spin_lock_bh(&priv->beacon_lock);
1807 priv->op_flags |= OP_SCANNING;
1808 spin_unlock_bh(&priv->beacon_lock);
1809 cancel_work_sync(&priv->ps_work);
1810 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1811 mutex_unlock(&priv->mutex);
1814 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1816 struct ath9k_htc_priv *priv = hw->priv;
1818 mutex_lock(&priv->mutex);
1819 ath9k_htc_ps_wakeup(priv);
1820 spin_lock_bh(&priv->beacon_lock);
1821 priv->op_flags &= ~OP_SCANNING;
1822 spin_unlock_bh(&priv->beacon_lock);
1823 priv->op_flags |= OP_FULL_RESET;
1824 if (priv->op_flags & OP_ASSOCIATED)
1825 ath9k_htc_beacon_config(priv, priv->vif);
1826 ath_start_ani(priv);
1827 ath9k_htc_ps_restore(priv);
1828 mutex_unlock(&priv->mutex);
1831 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1836 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1839 struct ath9k_htc_priv *priv = hw->priv;
1841 mutex_lock(&priv->mutex);
1842 ath9k_htc_ps_wakeup(priv);
1843 priv->ah->coverage_class = coverage_class;
1844 ath9k_hw_init_global_settings(priv->ah);
1845 ath9k_htc_ps_restore(priv);
1846 mutex_unlock(&priv->mutex);
1849 struct ieee80211_ops ath9k_htc_ops = {
1851 .start = ath9k_htc_start,
1852 .stop = ath9k_htc_stop,
1853 .add_interface = ath9k_htc_add_interface,
1854 .remove_interface = ath9k_htc_remove_interface,
1855 .config = ath9k_htc_config,
1856 .configure_filter = ath9k_htc_configure_filter,
1857 .sta_add = ath9k_htc_sta_add,
1858 .sta_remove = ath9k_htc_sta_remove,
1859 .conf_tx = ath9k_htc_conf_tx,
1860 .bss_info_changed = ath9k_htc_bss_info_changed,
1861 .set_key = ath9k_htc_set_key,
1862 .get_tsf = ath9k_htc_get_tsf,
1863 .set_tsf = ath9k_htc_set_tsf,
1864 .reset_tsf = ath9k_htc_reset_tsf,
1865 .ampdu_action = ath9k_htc_ampdu_action,
1866 .sw_scan_start = ath9k_htc_sw_scan_start,
1867 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1868 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1869 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1870 .set_coverage_class = ath9k_htc_set_coverage_class,