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 struct ath9k_hw_cal_data *caldata;
129 enum htc_phymode mode;
134 if (priv->op_flags & OP_INVALID)
137 if (priv->op_flags & OP_FULL_RESET)
140 ath9k_htc_ps_wakeup(priv);
142 WMI_CMD(WMI_DISABLE_INTR_CMDID);
143 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
144 WMI_CMD(WMI_STOP_RECV_CMDID);
146 ath_print(common, ATH_DBG_CONFIG,
147 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
148 priv->ah->curchan->channel,
149 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
152 caldata = &priv->caldata[channel->hw_value];
153 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
155 ath_print(common, ATH_DBG_FATAL,
156 "Unable to reset channel (%u Mhz) "
157 "reset status %d\n", channel->center_freq, ret);
161 ath_update_txpow(priv);
163 WMI_CMD(WMI_START_RECV_CMDID);
167 ath9k_host_rx_init(priv);
169 mode = ath9k_htc_get_curmode(priv, hchan);
170 htc_mode = cpu_to_be16(mode);
171 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
175 WMI_CMD(WMI_ENABLE_INTR_CMDID);
179 htc_start(priv->htc);
181 priv->op_flags &= ~OP_FULL_RESET;
183 ath9k_htc_ps_restore(priv);
187 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
189 struct ath_common *common = ath9k_hw_common(priv->ah);
190 struct ath9k_htc_target_vif hvif;
197 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
198 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
200 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
201 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
202 hvif.index = priv->nvifs;
204 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
212 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
214 struct ath_common *common = ath9k_hw_common(priv->ah);
215 struct ath9k_htc_target_vif hvif;
219 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
220 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
221 hvif.index = 0; /* Should do for now */
222 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
228 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
229 struct ieee80211_vif *vif,
230 struct ieee80211_sta *sta)
232 struct ath_common *common = ath9k_hw_common(priv->ah);
233 struct ath9k_htc_target_sta tsta;
234 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
235 struct ath9k_htc_sta *ista;
239 if (priv->nstations >= ATH9K_HTC_MAX_STA)
242 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
245 ista = (struct ath9k_htc_sta *) sta->drv_priv;
246 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
247 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
248 tsta.associd = common->curaid;
251 ista->index = priv->nstations;
253 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
257 tsta.sta_index = priv->nstations;
258 tsta.vif_index = avp->index;
259 tsta.maxampdu = 0xffff;
260 if (sta && sta->ht_cap.ht_supported)
261 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
263 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
266 ath_print(common, ATH_DBG_FATAL,
267 "Unable to add station entry for: %pM\n", sta->addr);
272 ath_print(common, ATH_DBG_CONFIG,
273 "Added a station entry for: %pM (idx: %d)\n",
274 sta->addr, tsta.sta_index);
280 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
281 struct ieee80211_vif *vif,
282 struct ieee80211_sta *sta)
284 struct ath_common *common = ath9k_hw_common(priv->ah);
285 struct ath9k_htc_sta *ista;
290 ista = (struct ath9k_htc_sta *) sta->drv_priv;
291 sta_idx = ista->index;
296 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
299 ath_print(common, ATH_DBG_FATAL,
300 "Unable to remove station entry for: %pM\n",
306 ath_print(common, ATH_DBG_CONFIG,
307 "Removed a station entry for: %pM (idx: %d)\n",
314 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
316 struct ath9k_htc_cap_target tcap;
320 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
322 /* FIXME: Values are hardcoded */
323 tcap.flags = 0x240c40;
324 tcap.flags_ext = 0x80601000;
325 tcap.ampdu_limit = 0xffff0000;
326 tcap.ampdu_subframes = 20;
327 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
329 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
331 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
336 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
337 struct ieee80211_sta *sta,
338 struct ath9k_htc_target_rate *trate)
340 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
341 struct ieee80211_supported_band *sband;
345 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
347 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
348 if (sta->supp_rates[sband->band] & BIT(i)) {
349 trate->rates.legacy_rates.rs_rates[j]
350 = (sband->bitrates[i].bitrate * 2) / 10;
354 trate->rates.legacy_rates.rs_nrates = j;
356 if (sta->ht_cap.ht_supported) {
357 for (i = 0, j = 0; i < 77; i++) {
358 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
359 trate->rates.ht_rates.rs_rates[j++] = i;
360 if (j == ATH_HTC_RATE_MAX)
363 trate->rates.ht_rates.rs_nrates = j;
365 caps = WLAN_RC_HT_FLAG;
366 if (sta->ht_cap.mcs.rx_mask[1])
367 caps |= WLAN_RC_DS_FLAG;
368 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
369 (conf_is_ht40(&priv->hw->conf)))
370 caps |= WLAN_RC_40_FLAG;
371 if (conf_is_ht40(&priv->hw->conf) &&
372 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
373 caps |= WLAN_RC_SGI_FLAG;
374 else if (conf_is_ht20(&priv->hw->conf) &&
375 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
376 caps |= WLAN_RC_SGI_FLAG;
379 trate->sta_index = ista->index;
381 trate->capflags = cpu_to_be32(caps);
384 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
385 struct ath9k_htc_target_rate *trate)
387 struct ath_common *common = ath9k_hw_common(priv->ah);
391 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
393 ath_print(common, ATH_DBG_FATAL,
394 "Unable to initialize Rate information on target\n");
400 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
401 struct ieee80211_sta *sta)
403 struct ath_common *common = ath9k_hw_common(priv->ah);
404 struct ath9k_htc_target_rate trate;
407 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
408 ath9k_htc_setup_rate(priv, sta, &trate);
409 ret = ath9k_htc_send_rate_cmd(priv, &trate);
411 ath_print(common, ATH_DBG_CONFIG,
412 "Updated target sta: %pM, rate caps: 0x%X\n",
413 sta->addr, be32_to_cpu(trate.capflags));
416 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
417 struct ieee80211_vif *vif,
418 struct ieee80211_bss_conf *bss_conf)
420 struct ath_common *common = ath9k_hw_common(priv->ah);
421 struct ath9k_htc_target_rate trate;
422 struct ieee80211_sta *sta;
425 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
428 sta = ieee80211_find_sta(vif, bss_conf->bssid);
433 ath9k_htc_setup_rate(priv, sta, &trate);
436 ret = ath9k_htc_send_rate_cmd(priv, &trate);
438 ath_print(common, ATH_DBG_CONFIG,
439 "Updated target sta: %pM, rate caps: 0x%X\n",
440 bss_conf->bssid, be32_to_cpu(trate.capflags));
443 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
444 struct ieee80211_vif *vif,
445 struct ieee80211_sta *sta,
446 enum ieee80211_ampdu_mlme_action action,
449 struct ath_common *common = ath9k_hw_common(priv->ah);
450 struct ath9k_htc_target_aggr aggr;
451 struct ath9k_htc_sta *ista;
455 if (tid >= ATH9K_HTC_MAX_TID)
458 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
459 ista = (struct ath9k_htc_sta *) sta->drv_priv;
461 aggr.sta_index = ista->index;
462 aggr.tidno = tid & 0xf;
463 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
465 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
467 ath_print(common, ATH_DBG_CONFIG,
468 "Unable to %s TX aggregation for (%pM, %d)\n",
469 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
471 ath_print(common, ATH_DBG_CONFIG,
472 "%s TX aggregation for (%pM, %d)\n",
473 (aggr.aggr_enable) ? "Starting" : "Stopping",
476 spin_lock_bh(&priv->tx_lock);
477 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
478 spin_unlock_bh(&priv->tx_lock);
487 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
489 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
491 file->private_data = inode->i_private;
495 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
496 size_t count, loff_t *ppos)
498 struct ath9k_htc_priv *priv = file->private_data;
499 struct ath9k_htc_target_stats cmd_rsp;
501 unsigned int len = 0;
504 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
506 WMI_CMD(WMI_TGT_STATS_CMDID);
511 len += snprintf(buf + len, sizeof(buf) - len,
512 "%19s : %10u\n", "TX Short Retries",
513 be32_to_cpu(cmd_rsp.tx_shortretry));
514 len += snprintf(buf + len, sizeof(buf) - len,
515 "%19s : %10u\n", "TX Long Retries",
516 be32_to_cpu(cmd_rsp.tx_longretry));
517 len += snprintf(buf + len, sizeof(buf) - len,
518 "%19s : %10u\n", "TX Xretries",
519 be32_to_cpu(cmd_rsp.tx_xretries));
520 len += snprintf(buf + len, sizeof(buf) - len,
521 "%19s : %10u\n", "TX Unaggr. Xretries",
522 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
523 len += snprintf(buf + len, sizeof(buf) - len,
524 "%19s : %10u\n", "TX Xretries (HT)",
525 be32_to_cpu(cmd_rsp.ht_tx_xretries));
526 len += snprintf(buf + len, sizeof(buf) - len,
527 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
529 if (len > sizeof(buf))
532 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
535 static const struct file_operations fops_tgt_stats = {
536 .read = read_file_tgt_stats,
537 .open = ath9k_debugfs_open,
541 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
542 size_t count, loff_t *ppos)
544 struct ath9k_htc_priv *priv = file->private_data;
546 unsigned int len = 0;
548 len += snprintf(buf + len, sizeof(buf) - len,
549 "%20s : %10u\n", "Buffers queued",
550 priv->debug.tx_stats.buf_queued);
551 len += snprintf(buf + len, sizeof(buf) - len,
552 "%20s : %10u\n", "Buffers completed",
553 priv->debug.tx_stats.buf_completed);
554 len += snprintf(buf + len, sizeof(buf) - len,
555 "%20s : %10u\n", "SKBs queued",
556 priv->debug.tx_stats.skb_queued);
557 len += snprintf(buf + len, sizeof(buf) - len,
558 "%20s : %10u\n", "SKBs completed",
559 priv->debug.tx_stats.skb_completed);
560 len += snprintf(buf + len, sizeof(buf) - len,
561 "%20s : %10u\n", "SKBs dropped",
562 priv->debug.tx_stats.skb_dropped);
564 len += snprintf(buf + len, sizeof(buf) - len,
565 "%20s : %10u\n", "BE queued",
566 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
567 len += snprintf(buf + len, sizeof(buf) - len,
568 "%20s : %10u\n", "BK queued",
569 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
570 len += snprintf(buf + len, sizeof(buf) - len,
571 "%20s : %10u\n", "VI queued",
572 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
573 len += snprintf(buf + len, sizeof(buf) - len,
574 "%20s : %10u\n", "VO queued",
575 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
577 if (len > sizeof(buf))
580 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
583 static const struct file_operations fops_xmit = {
584 .read = read_file_xmit,
585 .open = ath9k_debugfs_open,
589 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
590 size_t count, loff_t *ppos)
592 struct ath9k_htc_priv *priv = file->private_data;
594 unsigned int len = 0;
596 len += snprintf(buf + len, sizeof(buf) - len,
597 "%20s : %10u\n", "SKBs allocated",
598 priv->debug.rx_stats.skb_allocated);
599 len += snprintf(buf + len, sizeof(buf) - len,
600 "%20s : %10u\n", "SKBs completed",
601 priv->debug.rx_stats.skb_completed);
602 len += snprintf(buf + len, sizeof(buf) - len,
603 "%20s : %10u\n", "SKBs Dropped",
604 priv->debug.rx_stats.skb_dropped);
606 if (len > sizeof(buf))
609 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
612 static const struct file_operations fops_recv = {
613 .read = read_file_recv,
614 .open = ath9k_debugfs_open,
618 int ath9k_htc_init_debug(struct ath_hw *ah)
620 struct ath_common *common = ath9k_hw_common(ah);
621 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
623 if (!ath9k_debugfs_root)
626 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
628 if (!priv->debug.debugfs_phy)
631 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
632 priv->debug.debugfs_phy,
633 priv, &fops_tgt_stats);
634 if (!priv->debug.debugfs_tgt_stats)
638 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
639 priv->debug.debugfs_phy,
641 if (!priv->debug.debugfs_xmit)
644 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
645 priv->debug.debugfs_phy,
647 if (!priv->debug.debugfs_recv)
653 ath9k_htc_exit_debug(ah);
657 void ath9k_htc_exit_debug(struct ath_hw *ah)
659 struct ath_common *common = ath9k_hw_common(ah);
660 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
662 debugfs_remove(priv->debug.debugfs_recv);
663 debugfs_remove(priv->debug.debugfs_xmit);
664 debugfs_remove(priv->debug.debugfs_tgt_stats);
665 debugfs_remove(priv->debug.debugfs_phy);
668 int ath9k_htc_debug_create_root(void)
670 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
671 if (!ath9k_debugfs_root)
677 void ath9k_htc_debug_remove_root(void)
679 debugfs_remove(ath9k_debugfs_root);
680 ath9k_debugfs_root = NULL;
683 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
689 static void ath_start_ani(struct ath9k_htc_priv *priv)
691 struct ath_common *common = ath9k_hw_common(priv->ah);
692 unsigned long timestamp = jiffies_to_msecs(jiffies);
694 common->ani.longcal_timer = timestamp;
695 common->ani.shortcal_timer = timestamp;
696 common->ani.checkani_timer = timestamp;
698 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
699 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
702 void ath9k_ani_work(struct work_struct *work)
704 struct ath9k_htc_priv *priv =
705 container_of(work, struct ath9k_htc_priv,
706 ath9k_ani_work.work);
707 struct ath_hw *ah = priv->ah;
708 struct ath_common *common = ath9k_hw_common(ah);
709 bool longcal = false;
710 bool shortcal = false;
711 bool aniflag = false;
712 unsigned int timestamp = jiffies_to_msecs(jiffies);
713 u32 cal_interval, short_cal_interval;
715 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
717 /* Only calibrate if awake */
718 if (ah->power_mode != ATH9K_PM_AWAKE)
721 /* Long calibration runs independently of short calibration. */
722 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
724 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
725 common->ani.longcal_timer = timestamp;
728 /* Short calibration applies only while caldone is false */
729 if (!common->ani.caldone) {
730 if ((timestamp - common->ani.shortcal_timer) >=
731 short_cal_interval) {
733 ath_print(common, ATH_DBG_ANI,
734 "shortcal @%lu\n", jiffies);
735 common->ani.shortcal_timer = timestamp;
736 common->ani.resetcal_timer = timestamp;
739 if ((timestamp - common->ani.resetcal_timer) >=
740 ATH_RESTART_CALINTERVAL) {
741 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
742 if (common->ani.caldone)
743 common->ani.resetcal_timer = timestamp;
747 /* Verify whether we must check ANI */
748 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
750 common->ani.checkani_timer = timestamp;
753 /* Skip all processing if there's nothing to do. */
754 if (longcal || shortcal || aniflag) {
756 ath9k_htc_ps_wakeup(priv);
758 /* Call ANI routine if necessary */
760 ath9k_hw_ani_monitor(ah, ah->curchan);
762 /* Perform calibration if necessary */
763 if (longcal || shortcal) {
764 common->ani.caldone =
765 ath9k_hw_calibrate(ah, ah->curchan,
766 common->rx_chainmask,
770 common->ani.noise_floor =
771 ath9k_hw_getchan_noise(ah, ah->curchan);
773 ath_print(common, ATH_DBG_ANI,
774 " calibrate chan %u/%x nf: %d\n",
775 ah->curchan->channel,
776 ah->curchan->channelFlags,
777 common->ani.noise_floor);
780 ath9k_htc_ps_restore(priv);
785 * Set timer interval based on previous results.
786 * The interval must be the shortest necessary to satisfy ANI,
787 * short calibration and long calibration.
789 cal_interval = ATH_LONG_CALINTERVAL;
790 if (priv->ah->config.enable_ani)
791 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
792 if (!common->ani.caldone)
793 cal_interval = min(cal_interval, (u32)short_cal_interval);
795 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
796 msecs_to_jiffies(cal_interval));
803 static void ath9k_led_blink_work(struct work_struct *work)
805 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
806 ath9k_led_blink_work.work);
808 if (!(priv->op_flags & OP_LED_ASSOCIATED))
811 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
812 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
813 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
815 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
816 (priv->op_flags & OP_LED_ON) ? 1 : 0);
818 ieee80211_queue_delayed_work(priv->hw,
819 &priv->ath9k_led_blink_work,
820 (priv->op_flags & OP_LED_ON) ?
821 msecs_to_jiffies(priv->led_off_duration) :
822 msecs_to_jiffies(priv->led_on_duration));
824 priv->led_on_duration = priv->led_on_cnt ?
825 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
826 ATH_LED_ON_DURATION_IDLE;
827 priv->led_off_duration = priv->led_off_cnt ?
828 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
829 ATH_LED_OFF_DURATION_IDLE;
830 priv->led_on_cnt = priv->led_off_cnt = 0;
832 if (priv->op_flags & OP_LED_ON)
833 priv->op_flags &= ~OP_LED_ON;
835 priv->op_flags |= OP_LED_ON;
838 static void ath9k_led_brightness_work(struct work_struct *work)
840 struct ath_led *led = container_of(work, struct ath_led,
841 brightness_work.work);
842 struct ath9k_htc_priv *priv = led->priv;
844 switch (led->brightness) {
846 if (led->led_type == ATH_LED_ASSOC ||
847 led->led_type == ATH_LED_RADIO) {
848 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
849 (led->led_type == ATH_LED_RADIO));
850 priv->op_flags &= ~OP_LED_ASSOCIATED;
851 if (led->led_type == ATH_LED_RADIO)
852 priv->op_flags &= ~OP_LED_ON;
858 if (led->led_type == ATH_LED_ASSOC) {
859 priv->op_flags |= OP_LED_ASSOCIATED;
860 ieee80211_queue_delayed_work(priv->hw,
861 &priv->ath9k_led_blink_work, 0);
862 } else if (led->led_type == ATH_LED_RADIO) {
863 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
864 priv->op_flags |= OP_LED_ON;
874 static void ath9k_led_brightness(struct led_classdev *led_cdev,
875 enum led_brightness brightness)
877 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
878 struct ath9k_htc_priv *priv = led->priv;
880 led->brightness = brightness;
881 if (!(priv->op_flags & OP_LED_DEINIT))
882 ieee80211_queue_delayed_work(priv->hw,
883 &led->brightness_work, 0);
886 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
888 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
889 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
890 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
891 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
894 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
900 led->led_cdev.name = led->name;
901 led->led_cdev.default_trigger = trigger;
902 led->led_cdev.brightness_set = ath9k_led_brightness;
904 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
906 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
907 "Failed to register led:%s", led->name);
911 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
916 static void ath9k_unregister_led(struct ath_led *led)
918 if (led->registered) {
919 led_classdev_unregister(&led->led_cdev);
924 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
926 priv->op_flags |= OP_LED_DEINIT;
927 ath9k_unregister_led(&priv->assoc_led);
928 priv->op_flags &= ~OP_LED_ASSOCIATED;
929 ath9k_unregister_led(&priv->tx_led);
930 ath9k_unregister_led(&priv->rx_led);
931 ath9k_unregister_led(&priv->radio_led);
934 void ath9k_init_leds(struct ath9k_htc_priv *priv)
939 if (AR_SREV_9287(priv->ah))
940 priv->ah->led_pin = ATH_LED_PIN_9287;
941 else if (AR_SREV_9271(priv->ah))
942 priv->ah->led_pin = ATH_LED_PIN_9271;
943 else if (AR_DEVID_7010(priv->ah))
944 priv->ah->led_pin = ATH_LED_PIN_7010;
946 priv->ah->led_pin = ATH_LED_PIN_DEF;
948 /* Configure gpio 1 for output */
949 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
950 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
951 /* LED off, active low */
952 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
954 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
956 trigger = ieee80211_get_radio_led_name(priv->hw);
957 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
958 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
959 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
960 priv->radio_led.led_type = ATH_LED_RADIO;
964 trigger = ieee80211_get_assoc_led_name(priv->hw);
965 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
966 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
967 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
968 priv->assoc_led.led_type = ATH_LED_ASSOC;
972 trigger = ieee80211_get_tx_led_name(priv->hw);
973 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
974 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
975 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
976 priv->tx_led.led_type = ATH_LED_TX;
980 trigger = ieee80211_get_rx_led_name(priv->hw);
981 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
982 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
983 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
984 priv->rx_led.led_type = ATH_LED_RX;
988 priv->op_flags &= ~OP_LED_DEINIT;
993 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
994 ath9k_deinit_leds(priv);
997 /*******************/
999 /*******************/
1001 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1003 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1004 priv->ah->rfkill_polarity;
1007 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1009 struct ath9k_htc_priv *priv = hw->priv;
1010 bool blocked = !!ath_is_rfkill_set(priv);
1012 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1015 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1017 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1018 wiphy_rfkill_start_polling(priv->hw->wiphy);
1021 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1023 struct ath9k_htc_priv *priv = hw->priv;
1024 struct ath_hw *ah = priv->ah;
1025 struct ath_common *common = ath9k_hw_common(ah);
1030 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1033 ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
1035 ath_print(common, ATH_DBG_FATAL,
1036 "Unable to reset hardware; reset status %d "
1037 "(freq %u MHz)\n", ret, ah->curchan->channel);
1040 ath_update_txpow(priv);
1043 WMI_CMD(WMI_START_RECV_CMDID);
1044 ath9k_host_rx_init(priv);
1047 htc_start(priv->htc);
1048 spin_lock_bh(&priv->tx_lock);
1049 priv->tx_queues_stop = false;
1050 spin_unlock_bh(&priv->tx_lock);
1051 ieee80211_wake_queues(hw);
1053 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1056 ath9k_hw_cfg_output(ah, ah->led_pin,
1057 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1058 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1061 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1063 struct ath9k_htc_priv *priv = hw->priv;
1064 struct ath_hw *ah = priv->ah;
1065 struct ath_common *common = ath9k_hw_common(ah);
1069 ath9k_htc_ps_wakeup(priv);
1072 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1073 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1075 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1078 ieee80211_stop_queues(hw);
1079 htc_stop(priv->htc);
1080 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1081 skb_queue_purge(&priv->tx_queue);
1084 WMI_CMD(WMI_STOP_RECV_CMDID);
1087 * The MIB counters have to be disabled here,
1088 * since the target doesn't do it.
1090 ath9k_hw_disable_mib_counters(ah);
1093 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1096 ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
1098 ath_print(common, ATH_DBG_FATAL,
1099 "Unable to reset hardware; reset status %d "
1100 "(freq %u MHz)\n", ret, ah->curchan->channel);
1103 /* Disable the PHY */
1104 ath9k_hw_phy_disable(ah);
1106 ath9k_htc_ps_restore(priv);
1107 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1110 /**********************/
1111 /* mac80211 Callbacks */
1112 /**********************/
1114 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1116 struct ieee80211_hdr *hdr;
1117 struct ath9k_htc_priv *priv = hw->priv;
1118 int padpos, padsize, ret;
1120 hdr = (struct ieee80211_hdr *) skb->data;
1122 /* Add the padding after the header if this is not already done */
1123 padpos = ath9k_cmn_padpos(hdr->frame_control);
1124 padsize = padpos & 3;
1125 if (padsize && skb->len > padpos) {
1126 if (skb_headroom(skb) < padsize)
1128 skb_push(skb, padsize);
1129 memmove(skb->data, skb->data + padsize, padpos);
1132 ret = ath9k_htc_tx_start(priv, skb);
1134 if (ret == -ENOMEM) {
1135 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1136 "Stopping TX queues\n");
1137 ieee80211_stop_queues(hw);
1138 spin_lock_bh(&priv->tx_lock);
1139 priv->tx_queues_stop = true;
1140 spin_unlock_bh(&priv->tx_lock);
1142 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1151 dev_kfree_skb_any(skb);
1155 static int ath9k_htc_start(struct ieee80211_hw *hw)
1157 struct ath9k_htc_priv *priv = hw->priv;
1158 struct ath_hw *ah = priv->ah;
1159 struct ath_common *common = ath9k_hw_common(ah);
1160 struct ieee80211_channel *curchan = hw->conf.channel;
1161 struct ath9k_channel *init_channel;
1163 enum htc_phymode mode;
1167 mutex_lock(&priv->mutex);
1169 ath_print(common, ATH_DBG_CONFIG,
1170 "Starting driver with initial channel: %d MHz\n",
1171 curchan->center_freq);
1173 /* Ensure that HW is awake before flushing RX */
1174 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1175 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1177 /* setup initial channel */
1178 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1180 /* Reset SERDES registers */
1181 ath9k_hw_configpcipowersave(ah, 0, 0);
1183 ath9k_hw_htc_resetinit(ah);
1184 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
1186 ath_print(common, ATH_DBG_FATAL,
1187 "Unable to reset hardware; reset status %d "
1188 "(freq %u MHz)\n", ret, curchan->center_freq);
1189 mutex_unlock(&priv->mutex);
1193 ath_update_txpow(priv);
1195 mode = ath9k_htc_get_curmode(priv, init_channel);
1196 htc_mode = cpu_to_be16(mode);
1197 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1198 WMI_CMD(WMI_ATH_INIT_CMDID);
1199 WMI_CMD(WMI_START_RECV_CMDID);
1201 ath9k_host_rx_init(priv);
1203 priv->op_flags &= ~OP_INVALID;
1204 htc_start(priv->htc);
1206 spin_lock_bh(&priv->tx_lock);
1207 priv->tx_queues_stop = false;
1208 spin_unlock_bh(&priv->tx_lock);
1210 ieee80211_wake_queues(hw);
1212 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
1213 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1214 AR_STOMP_LOW_WLAN_WGHT);
1215 ath9k_hw_btcoex_enable(ah);
1216 ath_htc_resume_btcoex_work(priv);
1218 mutex_unlock(&priv->mutex);
1223 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1225 struct ath9k_htc_priv *priv = hw->priv;
1226 struct ath_hw *ah = priv->ah;
1227 struct ath_common *common = ath9k_hw_common(ah);
1231 mutex_lock(&priv->mutex);
1233 if (priv->op_flags & OP_INVALID) {
1234 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1235 mutex_unlock(&priv->mutex);
1239 /* Cancel all the running timers/work .. */
1240 cancel_work_sync(&priv->ps_work);
1241 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1242 ath9k_led_stop_brightness(priv);
1244 ath9k_htc_ps_wakeup(priv);
1245 htc_stop(priv->htc);
1246 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1247 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1248 WMI_CMD(WMI_STOP_RECV_CMDID);
1249 skb_queue_purge(&priv->tx_queue);
1251 /* Remove monitor interface here */
1252 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1253 if (ath9k_htc_remove_monitor_interface(priv))
1254 ath_print(common, ATH_DBG_FATAL,
1255 "Unable to remove monitor interface\n");
1257 ath_print(common, ATH_DBG_CONFIG,
1258 "Monitor interface removed\n");
1261 if (ah->btcoex_hw.enabled) {
1262 ath9k_hw_btcoex_disable(ah);
1263 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
1264 ath_htc_cancel_btcoex_work(priv);
1267 ath9k_hw_phy_disable(ah);
1268 ath9k_hw_disable(ah);
1269 ath9k_hw_configpcipowersave(ah, 1, 1);
1270 ath9k_htc_ps_restore(priv);
1271 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1273 priv->op_flags |= OP_INVALID;
1275 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1276 mutex_unlock(&priv->mutex);
1279 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1280 struct ieee80211_vif *vif)
1282 struct ath9k_htc_priv *priv = hw->priv;
1283 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1284 struct ath_common *common = ath9k_hw_common(priv->ah);
1285 struct ath9k_htc_target_vif hvif;
1289 mutex_lock(&priv->mutex);
1291 /* Only one interface for now */
1292 if (priv->nvifs > 0) {
1297 ath9k_htc_ps_wakeup(priv);
1298 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1299 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1301 switch (vif->type) {
1302 case NL80211_IFTYPE_STATION:
1303 hvif.opmode = cpu_to_be32(HTC_M_STA);
1305 case NL80211_IFTYPE_ADHOC:
1306 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1309 ath_print(common, ATH_DBG_FATAL,
1310 "Interface type %d not yet supported\n", vif->type);
1315 ath_print(common, ATH_DBG_CONFIG,
1316 "Attach a VIF of type: %d\n", vif->type);
1318 priv->ah->opmode = vif->type;
1320 /* Index starts from zero on the target */
1321 avp->index = hvif.index = priv->nvifs;
1322 hvif.rtsthreshold = cpu_to_be16(2304);
1323 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1330 * We need a node in target to tx mgmt frames
1331 * before association.
1333 ret = ath9k_htc_add_station(priv, vif, NULL);
1337 ret = ath9k_htc_update_cap_target(priv);
1339 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1340 " capability in target \n");
1344 ath9k_htc_ps_restore(priv);
1345 mutex_unlock(&priv->mutex);
1350 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1351 struct ieee80211_vif *vif)
1353 struct ath9k_htc_priv *priv = hw->priv;
1354 struct ath_common *common = ath9k_hw_common(priv->ah);
1355 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1356 struct ath9k_htc_target_vif hvif;
1360 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1362 mutex_lock(&priv->mutex);
1363 ath9k_htc_ps_wakeup(priv);
1365 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1366 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1367 hvif.index = avp->index;
1368 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1371 ath9k_htc_remove_station(priv, vif, NULL);
1374 ath9k_htc_ps_restore(priv);
1375 mutex_unlock(&priv->mutex);
1378 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1380 struct ath9k_htc_priv *priv = hw->priv;
1381 struct ath_common *common = ath9k_hw_common(priv->ah);
1382 struct ieee80211_conf *conf = &hw->conf;
1384 mutex_lock(&priv->mutex);
1386 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1387 bool enable_radio = false;
1388 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1390 mutex_lock(&priv->htc_pm_lock);
1391 if (!idle && priv->ps_idle)
1392 enable_radio = true;
1393 priv->ps_idle = idle;
1394 mutex_unlock(&priv->htc_pm_lock);
1397 ath_print(common, ATH_DBG_CONFIG,
1398 "not-idle: enabling radio\n");
1399 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1400 ath9k_htc_radio_enable(hw);
1404 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1405 struct ieee80211_channel *curchan = hw->conf.channel;
1406 int pos = curchan->hw_value;
1408 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1409 curchan->center_freq);
1411 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1413 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1414 ath_print(common, ATH_DBG_FATAL,
1415 "Unable to set channel\n");
1416 mutex_unlock(&priv->mutex);
1421 if (changed & IEEE80211_CONF_CHANGE_PS) {
1422 if (conf->flags & IEEE80211_CONF_PS) {
1423 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1424 priv->ps_enabled = true;
1426 priv->ps_enabled = false;
1427 cancel_work_sync(&priv->ps_work);
1428 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1432 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1433 if (conf->flags & IEEE80211_CONF_MONITOR) {
1434 if (ath9k_htc_add_monitor_interface(priv))
1435 ath_print(common, ATH_DBG_FATAL,
1436 "Failed to set monitor mode\n");
1438 ath_print(common, ATH_DBG_CONFIG,
1439 "HW opmode set to Monitor mode\n");
1443 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1444 mutex_lock(&priv->htc_pm_lock);
1445 if (!priv->ps_idle) {
1446 mutex_unlock(&priv->htc_pm_lock);
1449 mutex_unlock(&priv->htc_pm_lock);
1451 ath_print(common, ATH_DBG_CONFIG,
1452 "idle: disabling radio\n");
1453 ath9k_htc_radio_disable(hw);
1457 mutex_unlock(&priv->mutex);
1461 #define SUPPORTED_FILTERS \
1462 (FIF_PROMISC_IN_BSS | \
1467 FIF_BCN_PRBRESP_PROMISC | \
1470 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1471 unsigned int changed_flags,
1472 unsigned int *total_flags,
1475 struct ath9k_htc_priv *priv = hw->priv;
1478 mutex_lock(&priv->mutex);
1479 ath9k_htc_ps_wakeup(priv);
1481 changed_flags &= SUPPORTED_FILTERS;
1482 *total_flags &= SUPPORTED_FILTERS;
1484 priv->rxfilter = *total_flags;
1485 rfilt = ath9k_htc_calcrxfilter(priv);
1486 ath9k_hw_setrxfilter(priv->ah, rfilt);
1488 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1489 "Set HW RX filter: 0x%x\n", rfilt);
1491 ath9k_htc_ps_restore(priv);
1492 mutex_unlock(&priv->mutex);
1495 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1496 struct ieee80211_vif *vif,
1497 struct ieee80211_sta *sta)
1499 struct ath9k_htc_priv *priv = hw->priv;
1502 mutex_lock(&priv->mutex);
1503 ath9k_htc_ps_wakeup(priv);
1504 ret = ath9k_htc_add_station(priv, vif, sta);
1506 ath9k_htc_init_rate(priv, sta);
1507 ath9k_htc_ps_restore(priv);
1508 mutex_unlock(&priv->mutex);
1513 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1514 struct ieee80211_vif *vif,
1515 struct ieee80211_sta *sta)
1517 struct ath9k_htc_priv *priv = hw->priv;
1520 mutex_lock(&priv->mutex);
1521 ath9k_htc_ps_wakeup(priv);
1522 ret = ath9k_htc_remove_station(priv, vif, sta);
1523 ath9k_htc_ps_restore(priv);
1524 mutex_unlock(&priv->mutex);
1529 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1530 const struct ieee80211_tx_queue_params *params)
1532 struct ath9k_htc_priv *priv = hw->priv;
1533 struct ath_common *common = ath9k_hw_common(priv->ah);
1534 struct ath9k_tx_queue_info qi;
1537 if (queue >= WME_NUM_AC)
1540 mutex_lock(&priv->mutex);
1541 ath9k_htc_ps_wakeup(priv);
1543 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1545 qi.tqi_aifs = params->aifs;
1546 qi.tqi_cwmin = params->cw_min;
1547 qi.tqi_cwmax = params->cw_max;
1548 qi.tqi_burstTime = params->txop;
1550 qnum = get_hw_qnum(queue, priv->hwq_map);
1552 ath_print(common, ATH_DBG_CONFIG,
1553 "Configure tx [queue/hwq] [%d/%d], "
1554 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1555 queue, qnum, params->aifs, params->cw_min,
1556 params->cw_max, params->txop);
1558 ret = ath_htc_txq_update(priv, qnum, &qi);
1560 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1564 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1565 (qnum == priv->hwq_map[WME_AC_BE]))
1566 ath9k_htc_beaconq_config(priv);
1568 ath9k_htc_ps_restore(priv);
1569 mutex_unlock(&priv->mutex);
1574 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1575 enum set_key_cmd cmd,
1576 struct ieee80211_vif *vif,
1577 struct ieee80211_sta *sta,
1578 struct ieee80211_key_conf *key)
1580 struct ath9k_htc_priv *priv = hw->priv;
1581 struct ath_common *common = ath9k_hw_common(priv->ah);
1584 if (htc_modparam_nohwcrypt)
1587 mutex_lock(&priv->mutex);
1588 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1589 ath9k_htc_ps_wakeup(priv);
1593 ret = ath9k_cmn_key_config(common, vif, sta, key);
1595 key->hw_key_idx = ret;
1596 /* push IV and Michael MIC generation to stack */
1597 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1598 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1599 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1600 if (priv->ah->sw_mgmt_crypto &&
1601 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1602 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1607 ath9k_cmn_key_delete(common, key);
1613 ath9k_htc_ps_restore(priv);
1614 mutex_unlock(&priv->mutex);
1619 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1620 struct ieee80211_vif *vif,
1621 struct ieee80211_bss_conf *bss_conf,
1624 struct ath9k_htc_priv *priv = hw->priv;
1625 struct ath_hw *ah = priv->ah;
1626 struct ath_common *common = ath9k_hw_common(ah);
1628 mutex_lock(&priv->mutex);
1629 ath9k_htc_ps_wakeup(priv);
1631 if (changed & BSS_CHANGED_ASSOC) {
1632 common->curaid = bss_conf->assoc ?
1634 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1637 if (bss_conf->assoc) {
1638 priv->op_flags |= OP_ASSOCIATED;
1639 ath_start_ani(priv);
1641 priv->op_flags &= ~OP_ASSOCIATED;
1642 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1646 if (changed & BSS_CHANGED_BSSID) {
1648 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1649 ath9k_hw_write_associd(ah);
1651 ath_print(common, ATH_DBG_CONFIG,
1652 "BSSID: %pM aid: 0x%x\n",
1653 common->curbssid, common->curaid);
1656 if ((changed & BSS_CHANGED_BEACON_INT) ||
1657 (changed & BSS_CHANGED_BEACON) ||
1658 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1659 bss_conf->enable_beacon)) {
1660 priv->op_flags |= OP_ENABLE_BEACON;
1661 ath9k_htc_beacon_config(priv, vif);
1664 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1665 !bss_conf->enable_beacon) {
1666 priv->op_flags &= ~OP_ENABLE_BEACON;
1667 ath9k_htc_beacon_config(priv, vif);
1670 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1671 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1672 bss_conf->use_short_preamble);
1673 if (bss_conf->use_short_preamble)
1674 priv->op_flags |= OP_PREAMBLE_SHORT;
1676 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1679 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1680 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1681 bss_conf->use_cts_prot);
1682 if (bss_conf->use_cts_prot &&
1683 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1684 priv->op_flags |= OP_PROTECT_ENABLE;
1686 priv->op_flags &= ~OP_PROTECT_ENABLE;
1689 if (changed & BSS_CHANGED_ERP_SLOT) {
1690 if (bss_conf->use_short_slot)
1695 ath9k_hw_init_global_settings(ah);
1698 if (changed & BSS_CHANGED_HT)
1699 ath9k_htc_update_rate(priv, vif, bss_conf);
1701 ath9k_htc_ps_restore(priv);
1702 mutex_unlock(&priv->mutex);
1705 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1707 struct ath9k_htc_priv *priv = hw->priv;
1710 mutex_lock(&priv->mutex);
1711 ath9k_htc_ps_wakeup(priv);
1712 tsf = ath9k_hw_gettsf64(priv->ah);
1713 ath9k_htc_ps_restore(priv);
1714 mutex_unlock(&priv->mutex);
1719 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1721 struct ath9k_htc_priv *priv = hw->priv;
1723 mutex_lock(&priv->mutex);
1724 ath9k_htc_ps_wakeup(priv);
1725 ath9k_hw_settsf64(priv->ah, tsf);
1726 ath9k_htc_ps_restore(priv);
1727 mutex_unlock(&priv->mutex);
1730 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1732 struct ath9k_htc_priv *priv = hw->priv;
1734 mutex_lock(&priv->mutex);
1735 ath9k_htc_ps_wakeup(priv);
1736 ath9k_hw_reset_tsf(priv->ah);
1737 ath9k_htc_ps_restore(priv);
1738 mutex_unlock(&priv->mutex);
1741 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1742 struct ieee80211_vif *vif,
1743 enum ieee80211_ampdu_mlme_action action,
1744 struct ieee80211_sta *sta,
1747 struct ath9k_htc_priv *priv = hw->priv;
1748 struct ath9k_htc_sta *ista;
1752 case IEEE80211_AMPDU_RX_START:
1754 case IEEE80211_AMPDU_RX_STOP:
1756 case IEEE80211_AMPDU_TX_START:
1757 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1759 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1761 case IEEE80211_AMPDU_TX_STOP:
1762 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1763 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1765 case IEEE80211_AMPDU_TX_OPERATIONAL:
1766 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1767 spin_lock_bh(&priv->tx_lock);
1768 ista->tid_state[tid] = AGGR_OPERATIONAL;
1769 spin_unlock_bh(&priv->tx_lock);
1772 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1773 "Unknown AMPDU action\n");
1779 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1781 struct ath9k_htc_priv *priv = hw->priv;
1783 mutex_lock(&priv->mutex);
1784 spin_lock_bh(&priv->beacon_lock);
1785 priv->op_flags |= OP_SCANNING;
1786 spin_unlock_bh(&priv->beacon_lock);
1787 cancel_work_sync(&priv->ps_work);
1788 if (priv->op_flags & OP_ASSOCIATED)
1789 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1790 mutex_unlock(&priv->mutex);
1793 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1795 struct ath9k_htc_priv *priv = hw->priv;
1797 mutex_lock(&priv->mutex);
1798 ath9k_htc_ps_wakeup(priv);
1799 spin_lock_bh(&priv->beacon_lock);
1800 priv->op_flags &= ~OP_SCANNING;
1801 spin_unlock_bh(&priv->beacon_lock);
1802 priv->op_flags |= OP_FULL_RESET;
1803 if (priv->op_flags & OP_ASSOCIATED) {
1804 ath9k_htc_beacon_config(priv, priv->vif);
1805 ath_start_ani(priv);
1807 ath9k_htc_ps_restore(priv);
1808 mutex_unlock(&priv->mutex);
1811 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1816 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1819 struct ath9k_htc_priv *priv = hw->priv;
1821 mutex_lock(&priv->mutex);
1822 ath9k_htc_ps_wakeup(priv);
1823 priv->ah->coverage_class = coverage_class;
1824 ath9k_hw_init_global_settings(priv->ah);
1825 ath9k_htc_ps_restore(priv);
1826 mutex_unlock(&priv->mutex);
1829 struct ieee80211_ops ath9k_htc_ops = {
1831 .start = ath9k_htc_start,
1832 .stop = ath9k_htc_stop,
1833 .add_interface = ath9k_htc_add_interface,
1834 .remove_interface = ath9k_htc_remove_interface,
1835 .config = ath9k_htc_config,
1836 .configure_filter = ath9k_htc_configure_filter,
1837 .sta_add = ath9k_htc_sta_add,
1838 .sta_remove = ath9k_htc_sta_remove,
1839 .conf_tx = ath9k_htc_conf_tx,
1840 .bss_info_changed = ath9k_htc_bss_info_changed,
1841 .set_key = ath9k_htc_set_key,
1842 .get_tsf = ath9k_htc_get_tsf,
1843 .set_tsf = ath9k_htc_set_tsf,
1844 .reset_tsf = ath9k_htc_reset_tsf,
1845 .ampdu_action = ath9k_htc_ampdu_action,
1846 .sw_scan_start = ath9k_htc_sw_scan_start,
1847 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1848 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1849 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1850 .set_coverage_class = ath9k_htc_set_coverage_class,