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, 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 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_dbg(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);
156 "Unable to reset channel (%u Mhz) reset status %d\n",
157 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);
267 "Unable to add station entry for: %pM\n",
273 ath_dbg(common, ATH_DBG_CONFIG,
274 "Added a station entry for: %pM (idx: %d)\n",
275 sta->addr, tsta.sta_index);
281 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
282 struct ieee80211_vif *vif,
283 struct ieee80211_sta *sta)
285 struct ath_common *common = ath9k_hw_common(priv->ah);
286 struct ath9k_htc_sta *ista;
291 ista = (struct ath9k_htc_sta *) sta->drv_priv;
292 sta_idx = ista->index;
297 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
301 "Unable to remove station entry for: %pM\n",
307 ath_dbg(common, ATH_DBG_CONFIG,
308 "Removed a station entry for: %pM (idx: %d)\n",
315 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
317 struct ath9k_htc_cap_target tcap;
321 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
323 /* FIXME: Values are hardcoded */
324 tcap.flags = 0x240c40;
325 tcap.flags_ext = 0x80601000;
326 tcap.ampdu_limit = 0xffff0000;
327 tcap.ampdu_subframes = 20;
328 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
330 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
332 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
337 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
338 struct ieee80211_sta *sta,
339 struct ath9k_htc_target_rate *trate)
341 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
342 struct ieee80211_supported_band *sband;
346 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
348 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
349 if (sta->supp_rates[sband->band] & BIT(i)) {
350 trate->rates.legacy_rates.rs_rates[j]
351 = (sband->bitrates[i].bitrate * 2) / 10;
355 trate->rates.legacy_rates.rs_nrates = j;
357 if (sta->ht_cap.ht_supported) {
358 for (i = 0, j = 0; i < 77; i++) {
359 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
360 trate->rates.ht_rates.rs_rates[j++] = i;
361 if (j == ATH_HTC_RATE_MAX)
364 trate->rates.ht_rates.rs_nrates = j;
366 caps = WLAN_RC_HT_FLAG;
367 if (sta->ht_cap.mcs.rx_mask[1])
368 caps |= WLAN_RC_DS_FLAG;
369 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
370 (conf_is_ht40(&priv->hw->conf)))
371 caps |= WLAN_RC_40_FLAG;
372 if (conf_is_ht40(&priv->hw->conf) &&
373 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
374 caps |= WLAN_RC_SGI_FLAG;
375 else if (conf_is_ht20(&priv->hw->conf) &&
376 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
377 caps |= WLAN_RC_SGI_FLAG;
380 trate->sta_index = ista->index;
382 trate->capflags = cpu_to_be32(caps);
385 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
386 struct ath9k_htc_target_rate *trate)
388 struct ath_common *common = ath9k_hw_common(priv->ah);
392 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
395 "Unable to initialize Rate information on target\n");
401 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
402 struct ieee80211_sta *sta)
404 struct ath_common *common = ath9k_hw_common(priv->ah);
405 struct ath9k_htc_target_rate trate;
408 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
409 ath9k_htc_setup_rate(priv, sta, &trate);
410 ret = ath9k_htc_send_rate_cmd(priv, &trate);
412 ath_dbg(common, ATH_DBG_CONFIG,
413 "Updated target sta: %pM, rate caps: 0x%X\n",
414 sta->addr, be32_to_cpu(trate.capflags));
417 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
418 struct ieee80211_vif *vif,
419 struct ieee80211_bss_conf *bss_conf)
421 struct ath_common *common = ath9k_hw_common(priv->ah);
422 struct ath9k_htc_target_rate trate;
423 struct ieee80211_sta *sta;
426 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
429 sta = ieee80211_find_sta(vif, bss_conf->bssid);
434 ath9k_htc_setup_rate(priv, sta, &trate);
437 ret = ath9k_htc_send_rate_cmd(priv, &trate);
439 ath_dbg(common, ATH_DBG_CONFIG,
440 "Updated target sta: %pM, rate caps: 0x%X\n",
441 bss_conf->bssid, be32_to_cpu(trate.capflags));
444 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
445 struct ieee80211_vif *vif,
446 struct ieee80211_sta *sta,
447 enum ieee80211_ampdu_mlme_action action,
450 struct ath_common *common = ath9k_hw_common(priv->ah);
451 struct ath9k_htc_target_aggr aggr;
452 struct ath9k_htc_sta *ista;
456 if (tid >= ATH9K_HTC_MAX_TID)
459 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
460 ista = (struct ath9k_htc_sta *) sta->drv_priv;
462 aggr.sta_index = ista->index;
463 aggr.tidno = tid & 0xf;
464 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
466 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
468 ath_dbg(common, ATH_DBG_CONFIG,
469 "Unable to %s TX aggregation for (%pM, %d)\n",
470 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
472 ath_dbg(common, ATH_DBG_CONFIG,
473 "%s TX aggregation for (%pM, %d)\n",
474 (aggr.aggr_enable) ? "Starting" : "Stopping",
477 spin_lock_bh(&priv->tx_lock);
478 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
479 spin_unlock_bh(&priv->tx_lock);
488 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
490 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
492 file->private_data = inode->i_private;
496 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
497 size_t count, loff_t *ppos)
499 struct ath9k_htc_priv *priv = file->private_data;
500 struct ath9k_htc_target_stats cmd_rsp;
502 unsigned int len = 0;
505 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
507 WMI_CMD(WMI_TGT_STATS_CMDID);
512 len += snprintf(buf + len, sizeof(buf) - len,
513 "%19s : %10u\n", "TX Short Retries",
514 be32_to_cpu(cmd_rsp.tx_shortretry));
515 len += snprintf(buf + len, sizeof(buf) - len,
516 "%19s : %10u\n", "TX Long Retries",
517 be32_to_cpu(cmd_rsp.tx_longretry));
518 len += snprintf(buf + len, sizeof(buf) - len,
519 "%19s : %10u\n", "TX Xretries",
520 be32_to_cpu(cmd_rsp.tx_xretries));
521 len += snprintf(buf + len, sizeof(buf) - len,
522 "%19s : %10u\n", "TX Unaggr. Xretries",
523 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
524 len += snprintf(buf + len, sizeof(buf) - len,
525 "%19s : %10u\n", "TX Xretries (HT)",
526 be32_to_cpu(cmd_rsp.ht_tx_xretries));
527 len += snprintf(buf + len, sizeof(buf) - len,
528 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
530 if (len > sizeof(buf))
533 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
536 static const struct file_operations fops_tgt_stats = {
537 .read = read_file_tgt_stats,
538 .open = ath9k_debugfs_open,
539 .owner = THIS_MODULE,
540 .llseek = default_llseek,
543 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
544 size_t count, loff_t *ppos)
546 struct ath9k_htc_priv *priv = file->private_data;
548 unsigned int len = 0;
550 len += snprintf(buf + len, sizeof(buf) - len,
551 "%20s : %10u\n", "Buffers queued",
552 priv->debug.tx_stats.buf_queued);
553 len += snprintf(buf + len, sizeof(buf) - len,
554 "%20s : %10u\n", "Buffers completed",
555 priv->debug.tx_stats.buf_completed);
556 len += snprintf(buf + len, sizeof(buf) - len,
557 "%20s : %10u\n", "SKBs queued",
558 priv->debug.tx_stats.skb_queued);
559 len += snprintf(buf + len, sizeof(buf) - len,
560 "%20s : %10u\n", "SKBs completed",
561 priv->debug.tx_stats.skb_completed);
562 len += snprintf(buf + len, sizeof(buf) - len,
563 "%20s : %10u\n", "SKBs dropped",
564 priv->debug.tx_stats.skb_dropped);
566 len += snprintf(buf + len, sizeof(buf) - len,
567 "%20s : %10u\n", "BE queued",
568 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
569 len += snprintf(buf + len, sizeof(buf) - len,
570 "%20s : %10u\n", "BK queued",
571 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
572 len += snprintf(buf + len, sizeof(buf) - len,
573 "%20s : %10u\n", "VI queued",
574 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
575 len += snprintf(buf + len, sizeof(buf) - len,
576 "%20s : %10u\n", "VO queued",
577 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
579 if (len > sizeof(buf))
582 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
585 static const struct file_operations fops_xmit = {
586 .read = read_file_xmit,
587 .open = ath9k_debugfs_open,
588 .owner = THIS_MODULE,
589 .llseek = default_llseek,
592 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
593 size_t count, loff_t *ppos)
595 struct ath9k_htc_priv *priv = file->private_data;
597 unsigned int len = 0;
599 len += snprintf(buf + len, sizeof(buf) - len,
600 "%20s : %10u\n", "SKBs allocated",
601 priv->debug.rx_stats.skb_allocated);
602 len += snprintf(buf + len, sizeof(buf) - len,
603 "%20s : %10u\n", "SKBs completed",
604 priv->debug.rx_stats.skb_completed);
605 len += snprintf(buf + len, sizeof(buf) - len,
606 "%20s : %10u\n", "SKBs Dropped",
607 priv->debug.rx_stats.skb_dropped);
609 if (len > sizeof(buf))
612 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
615 static const struct file_operations fops_recv = {
616 .read = read_file_recv,
617 .open = ath9k_debugfs_open,
618 .owner = THIS_MODULE,
619 .llseek = default_llseek,
622 int ath9k_htc_init_debug(struct ath_hw *ah)
624 struct ath_common *common = ath9k_hw_common(ah);
625 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
627 if (!ath9k_debugfs_root)
630 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
632 if (!priv->debug.debugfs_phy)
635 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
636 priv->debug.debugfs_phy,
637 priv, &fops_tgt_stats);
638 if (!priv->debug.debugfs_tgt_stats)
642 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
643 priv->debug.debugfs_phy,
645 if (!priv->debug.debugfs_xmit)
648 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
649 priv->debug.debugfs_phy,
651 if (!priv->debug.debugfs_recv)
657 ath9k_htc_exit_debug(ah);
661 void ath9k_htc_exit_debug(struct ath_hw *ah)
663 struct ath_common *common = ath9k_hw_common(ah);
664 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
666 debugfs_remove(priv->debug.debugfs_recv);
667 debugfs_remove(priv->debug.debugfs_xmit);
668 debugfs_remove(priv->debug.debugfs_tgt_stats);
669 debugfs_remove(priv->debug.debugfs_phy);
672 int ath9k_htc_debug_create_root(void)
674 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
675 if (!ath9k_debugfs_root)
681 void ath9k_htc_debug_remove_root(void)
683 debugfs_remove(ath9k_debugfs_root);
684 ath9k_debugfs_root = NULL;
687 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
693 static void ath_start_ani(struct ath9k_htc_priv *priv)
695 struct ath_common *common = ath9k_hw_common(priv->ah);
696 unsigned long timestamp = jiffies_to_msecs(jiffies);
698 common->ani.longcal_timer = timestamp;
699 common->ani.shortcal_timer = timestamp;
700 common->ani.checkani_timer = timestamp;
702 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
703 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
706 void ath9k_ani_work(struct work_struct *work)
708 struct ath9k_htc_priv *priv =
709 container_of(work, struct ath9k_htc_priv,
710 ath9k_ani_work.work);
711 struct ath_hw *ah = priv->ah;
712 struct ath_common *common = ath9k_hw_common(ah);
713 bool longcal = false;
714 bool shortcal = false;
715 bool aniflag = false;
716 unsigned int timestamp = jiffies_to_msecs(jiffies);
717 u32 cal_interval, short_cal_interval;
719 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
721 /* Only calibrate if awake */
722 if (ah->power_mode != ATH9K_PM_AWAKE)
725 /* Long calibration runs independently of short calibration. */
726 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
728 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
729 common->ani.longcal_timer = timestamp;
732 /* Short calibration applies only while caldone is false */
733 if (!common->ani.caldone) {
734 if ((timestamp - common->ani.shortcal_timer) >=
735 short_cal_interval) {
737 ath_dbg(common, ATH_DBG_ANI,
738 "shortcal @%lu\n", jiffies);
739 common->ani.shortcal_timer = timestamp;
740 common->ani.resetcal_timer = timestamp;
743 if ((timestamp - common->ani.resetcal_timer) >=
744 ATH_RESTART_CALINTERVAL) {
745 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
746 if (common->ani.caldone)
747 common->ani.resetcal_timer = timestamp;
751 /* Verify whether we must check ANI */
752 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
754 common->ani.checkani_timer = timestamp;
757 /* Skip all processing if there's nothing to do. */
758 if (longcal || shortcal || aniflag) {
760 ath9k_htc_ps_wakeup(priv);
762 /* Call ANI routine if necessary */
764 ath9k_hw_ani_monitor(ah, ah->curchan);
766 /* Perform calibration if necessary */
767 if (longcal || shortcal)
768 common->ani.caldone =
769 ath9k_hw_calibrate(ah, ah->curchan,
770 common->rx_chainmask,
773 ath9k_htc_ps_restore(priv);
778 * Set timer interval based on previous results.
779 * The interval must be the shortest necessary to satisfy ANI,
780 * short calibration and long calibration.
782 cal_interval = ATH_LONG_CALINTERVAL;
783 if (priv->ah->config.enable_ani)
784 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
785 if (!common->ani.caldone)
786 cal_interval = min(cal_interval, (u32)short_cal_interval);
788 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
789 msecs_to_jiffies(cal_interval));
796 static void ath9k_led_blink_work(struct work_struct *work)
798 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
799 ath9k_led_blink_work.work);
801 if (!(priv->op_flags & OP_LED_ASSOCIATED))
804 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
805 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
806 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
808 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
809 (priv->op_flags & OP_LED_ON) ? 1 : 0);
811 ieee80211_queue_delayed_work(priv->hw,
812 &priv->ath9k_led_blink_work,
813 (priv->op_flags & OP_LED_ON) ?
814 msecs_to_jiffies(priv->led_off_duration) :
815 msecs_to_jiffies(priv->led_on_duration));
817 priv->led_on_duration = priv->led_on_cnt ?
818 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
819 ATH_LED_ON_DURATION_IDLE;
820 priv->led_off_duration = priv->led_off_cnt ?
821 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
822 ATH_LED_OFF_DURATION_IDLE;
823 priv->led_on_cnt = priv->led_off_cnt = 0;
825 if (priv->op_flags & OP_LED_ON)
826 priv->op_flags &= ~OP_LED_ON;
828 priv->op_flags |= OP_LED_ON;
831 static void ath9k_led_brightness_work(struct work_struct *work)
833 struct ath_led *led = container_of(work, struct ath_led,
834 brightness_work.work);
835 struct ath9k_htc_priv *priv = led->priv;
837 switch (led->brightness) {
839 if (led->led_type == ATH_LED_ASSOC ||
840 led->led_type == ATH_LED_RADIO) {
841 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
842 (led->led_type == ATH_LED_RADIO));
843 priv->op_flags &= ~OP_LED_ASSOCIATED;
844 if (led->led_type == ATH_LED_RADIO)
845 priv->op_flags &= ~OP_LED_ON;
851 if (led->led_type == ATH_LED_ASSOC) {
852 priv->op_flags |= OP_LED_ASSOCIATED;
853 ieee80211_queue_delayed_work(priv->hw,
854 &priv->ath9k_led_blink_work, 0);
855 } else if (led->led_type == ATH_LED_RADIO) {
856 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
857 priv->op_flags |= OP_LED_ON;
867 static void ath9k_led_brightness(struct led_classdev *led_cdev,
868 enum led_brightness brightness)
870 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
871 struct ath9k_htc_priv *priv = led->priv;
873 led->brightness = brightness;
874 if (!(priv->op_flags & OP_LED_DEINIT))
875 ieee80211_queue_delayed_work(priv->hw,
876 &led->brightness_work, 0);
879 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
881 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
882 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
883 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
884 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
887 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
893 led->led_cdev.name = led->name;
894 led->led_cdev.default_trigger = trigger;
895 led->led_cdev.brightness_set = ath9k_led_brightness;
897 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
899 ath_err(ath9k_hw_common(priv->ah),
900 "Failed to register led:%s", led->name);
904 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
909 static void ath9k_unregister_led(struct ath_led *led)
911 if (led->registered) {
912 led_classdev_unregister(&led->led_cdev);
917 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
919 priv->op_flags |= OP_LED_DEINIT;
920 ath9k_unregister_led(&priv->assoc_led);
921 priv->op_flags &= ~OP_LED_ASSOCIATED;
922 ath9k_unregister_led(&priv->tx_led);
923 ath9k_unregister_led(&priv->rx_led);
924 ath9k_unregister_led(&priv->radio_led);
927 void ath9k_init_leds(struct ath9k_htc_priv *priv)
932 if (AR_SREV_9287(priv->ah))
933 priv->ah->led_pin = ATH_LED_PIN_9287;
934 else if (AR_SREV_9271(priv->ah))
935 priv->ah->led_pin = ATH_LED_PIN_9271;
936 else if (AR_DEVID_7010(priv->ah))
937 priv->ah->led_pin = ATH_LED_PIN_7010;
939 priv->ah->led_pin = ATH_LED_PIN_DEF;
941 /* Configure gpio 1 for output */
942 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
943 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
944 /* LED off, active low */
945 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
947 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
949 trigger = ieee80211_get_radio_led_name(priv->hw);
950 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
951 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
952 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
953 priv->radio_led.led_type = ATH_LED_RADIO;
957 trigger = ieee80211_get_assoc_led_name(priv->hw);
958 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
959 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
960 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
961 priv->assoc_led.led_type = ATH_LED_ASSOC;
965 trigger = ieee80211_get_tx_led_name(priv->hw);
966 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
967 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
968 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
969 priv->tx_led.led_type = ATH_LED_TX;
973 trigger = ieee80211_get_rx_led_name(priv->hw);
974 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
975 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
976 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
977 priv->rx_led.led_type = ATH_LED_RX;
981 priv->op_flags &= ~OP_LED_DEINIT;
986 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
987 ath9k_deinit_leds(priv);
990 /*******************/
992 /*******************/
994 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
996 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
997 priv->ah->rfkill_polarity;
1000 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1002 struct ath9k_htc_priv *priv = hw->priv;
1003 bool blocked = !!ath_is_rfkill_set(priv);
1005 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1008 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1010 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1011 wiphy_rfkill_start_polling(priv->hw->wiphy);
1014 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1016 struct ath9k_htc_priv *priv = hw->priv;
1017 struct ath_hw *ah = priv->ah;
1018 struct ath_common *common = ath9k_hw_common(ah);
1023 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1026 ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
1029 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
1030 ret, ah->curchan->channel);
1033 ath_update_txpow(priv);
1036 WMI_CMD(WMI_START_RECV_CMDID);
1037 ath9k_host_rx_init(priv);
1040 htc_start(priv->htc);
1041 spin_lock_bh(&priv->tx_lock);
1042 priv->tx_queues_stop = false;
1043 spin_unlock_bh(&priv->tx_lock);
1044 ieee80211_wake_queues(hw);
1046 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1049 ath9k_hw_cfg_output(ah, ah->led_pin,
1050 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1051 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1054 static void ath9k_htc_radio_disable(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);
1062 ath9k_htc_ps_wakeup(priv);
1065 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1066 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1068 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1071 ieee80211_stop_queues(hw);
1072 htc_stop(priv->htc);
1073 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1074 skb_queue_purge(&priv->tx_queue);
1077 WMI_CMD(WMI_STOP_RECV_CMDID);
1080 * The MIB counters have to be disabled here,
1081 * since the target doesn't do it.
1083 ath9k_hw_disable_mib_counters(ah);
1086 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1089 ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
1092 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
1093 ret, ah->curchan->channel);
1096 /* Disable the PHY */
1097 ath9k_hw_phy_disable(ah);
1099 ath9k_htc_ps_restore(priv);
1100 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1103 /**********************/
1104 /* mac80211 Callbacks */
1105 /**********************/
1107 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1109 struct ieee80211_hdr *hdr;
1110 struct ath9k_htc_priv *priv = hw->priv;
1111 int padpos, padsize, ret;
1113 hdr = (struct ieee80211_hdr *) skb->data;
1115 /* Add the padding after the header if this is not already done */
1116 padpos = ath9k_cmn_padpos(hdr->frame_control);
1117 padsize = padpos & 3;
1118 if (padsize && skb->len > padpos) {
1119 if (skb_headroom(skb) < padsize)
1121 skb_push(skb, padsize);
1122 memmove(skb->data, skb->data + padsize, padpos);
1125 ret = ath9k_htc_tx_start(priv, skb);
1127 if (ret == -ENOMEM) {
1128 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1129 "Stopping TX queues\n");
1130 ieee80211_stop_queues(hw);
1131 spin_lock_bh(&priv->tx_lock);
1132 priv->tx_queues_stop = true;
1133 spin_unlock_bh(&priv->tx_lock);
1135 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1144 dev_kfree_skb_any(skb);
1148 static int ath9k_htc_start(struct ieee80211_hw *hw)
1150 struct ath9k_htc_priv *priv = hw->priv;
1151 struct ath_hw *ah = priv->ah;
1152 struct ath_common *common = ath9k_hw_common(ah);
1153 struct ieee80211_channel *curchan = hw->conf.channel;
1154 struct ath9k_channel *init_channel;
1156 enum htc_phymode mode;
1160 mutex_lock(&priv->mutex);
1162 ath_dbg(common, ATH_DBG_CONFIG,
1163 "Starting driver with initial channel: %d MHz\n",
1164 curchan->center_freq);
1166 /* Ensure that HW is awake before flushing RX */
1167 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1168 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1170 /* setup initial channel */
1171 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1173 /* Reset SERDES registers */
1174 ath9k_hw_configpcipowersave(ah, 0, 0);
1176 ath9k_hw_htc_resetinit(ah);
1177 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
1180 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
1181 ret, curchan->center_freq);
1182 mutex_unlock(&priv->mutex);
1186 ath_update_txpow(priv);
1188 mode = ath9k_htc_get_curmode(priv, init_channel);
1189 htc_mode = cpu_to_be16(mode);
1190 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1191 WMI_CMD(WMI_ATH_INIT_CMDID);
1192 WMI_CMD(WMI_START_RECV_CMDID);
1194 ath9k_host_rx_init(priv);
1196 priv->op_flags &= ~OP_INVALID;
1197 htc_start(priv->htc);
1199 spin_lock_bh(&priv->tx_lock);
1200 priv->tx_queues_stop = false;
1201 spin_unlock_bh(&priv->tx_lock);
1203 ieee80211_wake_queues(hw);
1205 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
1206 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1207 AR_STOMP_LOW_WLAN_WGHT);
1208 ath9k_hw_btcoex_enable(ah);
1209 ath_htc_resume_btcoex_work(priv);
1211 mutex_unlock(&priv->mutex);
1216 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1218 struct ath9k_htc_priv *priv = hw->priv;
1219 struct ath_hw *ah = priv->ah;
1220 struct ath_common *common = ath9k_hw_common(ah);
1224 mutex_lock(&priv->mutex);
1226 if (priv->op_flags & OP_INVALID) {
1227 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
1228 mutex_unlock(&priv->mutex);
1232 /* Cancel all the running timers/work .. */
1233 cancel_work_sync(&priv->ps_work);
1234 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1235 ath9k_led_stop_brightness(priv);
1237 ath9k_htc_ps_wakeup(priv);
1238 htc_stop(priv->htc);
1239 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1240 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1241 WMI_CMD(WMI_STOP_RECV_CMDID);
1242 skb_queue_purge(&priv->tx_queue);
1244 /* Remove monitor interface here */
1245 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1246 if (ath9k_htc_remove_monitor_interface(priv))
1247 ath_err(common, "Unable to remove monitor interface\n");
1249 ath_dbg(common, ATH_DBG_CONFIG,
1250 "Monitor interface removed\n");
1253 if (ah->btcoex_hw.enabled) {
1254 ath9k_hw_btcoex_disable(ah);
1255 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
1256 ath_htc_cancel_btcoex_work(priv);
1259 ath9k_hw_phy_disable(ah);
1260 ath9k_hw_disable(ah);
1261 ath9k_hw_configpcipowersave(ah, 1, 1);
1262 ath9k_htc_ps_restore(priv);
1263 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1265 priv->op_flags |= OP_INVALID;
1267 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1268 mutex_unlock(&priv->mutex);
1271 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1272 struct ieee80211_vif *vif)
1274 struct ath9k_htc_priv *priv = hw->priv;
1275 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1276 struct ath_common *common = ath9k_hw_common(priv->ah);
1277 struct ath9k_htc_target_vif hvif;
1281 mutex_lock(&priv->mutex);
1283 /* Only one interface for now */
1284 if (priv->nvifs > 0) {
1289 ath9k_htc_ps_wakeup(priv);
1290 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1291 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1293 switch (vif->type) {
1294 case NL80211_IFTYPE_STATION:
1295 hvif.opmode = cpu_to_be32(HTC_M_STA);
1297 case NL80211_IFTYPE_ADHOC:
1298 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1302 "Interface type %d not yet supported\n", vif->type);
1307 ath_dbg(common, ATH_DBG_CONFIG,
1308 "Attach a VIF of type: %d\n", vif->type);
1310 priv->ah->opmode = vif->type;
1312 /* Index starts from zero on the target */
1313 avp->index = hvif.index = priv->nvifs;
1314 hvif.rtsthreshold = cpu_to_be16(2304);
1315 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1322 * We need a node in target to tx mgmt frames
1323 * before association.
1325 ret = ath9k_htc_add_station(priv, vif, NULL);
1329 ret = ath9k_htc_update_cap_target(priv);
1331 ath_dbg(common, ATH_DBG_CONFIG,
1332 "Failed to update capability in target\n");
1336 ath9k_htc_ps_restore(priv);
1337 mutex_unlock(&priv->mutex);
1342 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1343 struct ieee80211_vif *vif)
1345 struct ath9k_htc_priv *priv = hw->priv;
1346 struct ath_common *common = ath9k_hw_common(priv->ah);
1347 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1348 struct ath9k_htc_target_vif hvif;
1352 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface\n");
1354 mutex_lock(&priv->mutex);
1355 ath9k_htc_ps_wakeup(priv);
1357 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1358 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1359 hvif.index = avp->index;
1360 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1363 ath9k_htc_remove_station(priv, vif, NULL);
1366 ath9k_htc_ps_restore(priv);
1367 mutex_unlock(&priv->mutex);
1370 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1372 struct ath9k_htc_priv *priv = hw->priv;
1373 struct ath_common *common = ath9k_hw_common(priv->ah);
1374 struct ieee80211_conf *conf = &hw->conf;
1376 mutex_lock(&priv->mutex);
1378 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1379 bool enable_radio = false;
1380 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1382 mutex_lock(&priv->htc_pm_lock);
1383 if (!idle && priv->ps_idle)
1384 enable_radio = true;
1385 priv->ps_idle = idle;
1386 mutex_unlock(&priv->htc_pm_lock);
1389 ath_dbg(common, ATH_DBG_CONFIG,
1390 "not-idle: enabling radio\n");
1391 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1392 ath9k_htc_radio_enable(hw);
1396 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1397 struct ieee80211_channel *curchan = hw->conf.channel;
1398 int pos = curchan->hw_value;
1400 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1401 curchan->center_freq);
1403 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1405 hw->conf.channel_type);
1407 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1408 ath_err(common, "Unable to set channel\n");
1409 mutex_unlock(&priv->mutex);
1415 if (changed & IEEE80211_CONF_CHANGE_PS) {
1416 if (conf->flags & IEEE80211_CONF_PS) {
1417 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1418 priv->ps_enabled = true;
1420 priv->ps_enabled = false;
1421 cancel_work_sync(&priv->ps_work);
1422 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1426 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1427 priv->txpowlimit = 2 * conf->power_level;
1428 ath_update_txpow(priv);
1431 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1432 if (conf->flags & IEEE80211_CONF_MONITOR) {
1433 if (ath9k_htc_add_monitor_interface(priv))
1434 ath_err(common, "Failed to set monitor mode\n");
1436 ath_dbg(common, ATH_DBG_CONFIG,
1437 "HW opmode set to Monitor mode\n");
1441 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1442 mutex_lock(&priv->htc_pm_lock);
1443 if (!priv->ps_idle) {
1444 mutex_unlock(&priv->htc_pm_lock);
1447 mutex_unlock(&priv->htc_pm_lock);
1449 ath_dbg(common, ATH_DBG_CONFIG,
1450 "idle: disabling radio\n");
1451 ath9k_htc_radio_disable(hw);
1455 mutex_unlock(&priv->mutex);
1459 #define SUPPORTED_FILTERS \
1460 (FIF_PROMISC_IN_BSS | \
1465 FIF_BCN_PRBRESP_PROMISC | \
1469 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1470 unsigned int changed_flags,
1471 unsigned int *total_flags,
1474 struct ath9k_htc_priv *priv = hw->priv;
1477 mutex_lock(&priv->mutex);
1478 ath9k_htc_ps_wakeup(priv);
1480 changed_flags &= SUPPORTED_FILTERS;
1481 *total_flags &= SUPPORTED_FILTERS;
1483 priv->rxfilter = *total_flags;
1484 rfilt = ath9k_htc_calcrxfilter(priv);
1485 ath9k_hw_setrxfilter(priv->ah, rfilt);
1487 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1488 "Set HW RX filter: 0x%x\n", rfilt);
1490 ath9k_htc_ps_restore(priv);
1491 mutex_unlock(&priv->mutex);
1494 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1495 struct ieee80211_vif *vif,
1496 struct ieee80211_sta *sta)
1498 struct ath9k_htc_priv *priv = hw->priv;
1501 mutex_lock(&priv->mutex);
1502 ath9k_htc_ps_wakeup(priv);
1503 ret = ath9k_htc_add_station(priv, vif, sta);
1505 ath9k_htc_init_rate(priv, sta);
1506 ath9k_htc_ps_restore(priv);
1507 mutex_unlock(&priv->mutex);
1512 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1513 struct ieee80211_vif *vif,
1514 struct ieee80211_sta *sta)
1516 struct ath9k_htc_priv *priv = hw->priv;
1519 mutex_lock(&priv->mutex);
1520 ath9k_htc_ps_wakeup(priv);
1521 ret = ath9k_htc_remove_station(priv, vif, sta);
1522 ath9k_htc_ps_restore(priv);
1523 mutex_unlock(&priv->mutex);
1528 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1529 const struct ieee80211_tx_queue_params *params)
1531 struct ath9k_htc_priv *priv = hw->priv;
1532 struct ath_common *common = ath9k_hw_common(priv->ah);
1533 struct ath9k_tx_queue_info qi;
1536 if (queue >= WME_NUM_AC)
1539 mutex_lock(&priv->mutex);
1540 ath9k_htc_ps_wakeup(priv);
1542 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1544 qi.tqi_aifs = params->aifs;
1545 qi.tqi_cwmin = params->cw_min;
1546 qi.tqi_cwmax = params->cw_max;
1547 qi.tqi_burstTime = params->txop;
1549 qnum = get_hw_qnum(queue, priv->hwq_map);
1551 ath_dbg(common, ATH_DBG_CONFIG,
1552 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1553 queue, qnum, params->aifs, params->cw_min,
1554 params->cw_max, params->txop);
1556 ret = ath_htc_txq_update(priv, qnum, &qi);
1558 ath_err(common, "TXQ Update failed\n");
1562 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1563 (qnum == priv->hwq_map[WME_AC_BE]))
1564 ath9k_htc_beaconq_config(priv);
1566 ath9k_htc_ps_restore(priv);
1567 mutex_unlock(&priv->mutex);
1572 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1573 enum set_key_cmd cmd,
1574 struct ieee80211_vif *vif,
1575 struct ieee80211_sta *sta,
1576 struct ieee80211_key_conf *key)
1578 struct ath9k_htc_priv *priv = hw->priv;
1579 struct ath_common *common = ath9k_hw_common(priv->ah);
1582 if (htc_modparam_nohwcrypt)
1585 mutex_lock(&priv->mutex);
1586 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1587 ath9k_htc_ps_wakeup(priv);
1591 ret = ath_key_config(common, vif, sta, key);
1593 key->hw_key_idx = ret;
1594 /* push IV and Michael MIC generation to stack */
1595 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1596 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1597 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1598 if (priv->ah->sw_mgmt_crypto &&
1599 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1600 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1605 ath_key_delete(common, key);
1611 ath9k_htc_ps_restore(priv);
1612 mutex_unlock(&priv->mutex);
1617 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1618 struct ieee80211_vif *vif,
1619 struct ieee80211_bss_conf *bss_conf,
1622 struct ath9k_htc_priv *priv = hw->priv;
1623 struct ath_hw *ah = priv->ah;
1624 struct ath_common *common = ath9k_hw_common(ah);
1626 mutex_lock(&priv->mutex);
1627 ath9k_htc_ps_wakeup(priv);
1629 if (changed & BSS_CHANGED_ASSOC) {
1630 common->curaid = bss_conf->assoc ?
1632 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1635 if (bss_conf->assoc) {
1636 priv->op_flags |= OP_ASSOCIATED;
1637 ath_start_ani(priv);
1639 priv->op_flags &= ~OP_ASSOCIATED;
1640 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1644 if (changed & BSS_CHANGED_BSSID) {
1646 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1647 ath9k_hw_write_associd(ah);
1649 ath_dbg(common, ATH_DBG_CONFIG,
1650 "BSSID: %pM aid: 0x%x\n",
1651 common->curbssid, common->curaid);
1654 if ((changed & BSS_CHANGED_BEACON_INT) ||
1655 (changed & BSS_CHANGED_BEACON) ||
1656 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1657 bss_conf->enable_beacon)) {
1658 priv->op_flags |= OP_ENABLE_BEACON;
1659 ath9k_htc_beacon_config(priv, vif);
1662 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1663 !bss_conf->enable_beacon) {
1664 priv->op_flags &= ~OP_ENABLE_BEACON;
1665 ath9k_htc_beacon_config(priv, vif);
1668 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1669 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1670 bss_conf->use_short_preamble);
1671 if (bss_conf->use_short_preamble)
1672 priv->op_flags |= OP_PREAMBLE_SHORT;
1674 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1677 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1678 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1679 bss_conf->use_cts_prot);
1680 if (bss_conf->use_cts_prot &&
1681 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1682 priv->op_flags |= OP_PROTECT_ENABLE;
1684 priv->op_flags &= ~OP_PROTECT_ENABLE;
1687 if (changed & BSS_CHANGED_ERP_SLOT) {
1688 if (bss_conf->use_short_slot)
1693 ath9k_hw_init_global_settings(ah);
1696 if (changed & BSS_CHANGED_HT)
1697 ath9k_htc_update_rate(priv, vif, bss_conf);
1699 ath9k_htc_ps_restore(priv);
1700 mutex_unlock(&priv->mutex);
1703 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1705 struct ath9k_htc_priv *priv = hw->priv;
1708 mutex_lock(&priv->mutex);
1709 ath9k_htc_ps_wakeup(priv);
1710 tsf = ath9k_hw_gettsf64(priv->ah);
1711 ath9k_htc_ps_restore(priv);
1712 mutex_unlock(&priv->mutex);
1717 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1719 struct ath9k_htc_priv *priv = hw->priv;
1721 mutex_lock(&priv->mutex);
1722 ath9k_htc_ps_wakeup(priv);
1723 ath9k_hw_settsf64(priv->ah, tsf);
1724 ath9k_htc_ps_restore(priv);
1725 mutex_unlock(&priv->mutex);
1728 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1730 struct ath9k_htc_priv *priv = hw->priv;
1732 mutex_lock(&priv->mutex);
1733 ath9k_htc_ps_wakeup(priv);
1734 ath9k_hw_reset_tsf(priv->ah);
1735 ath9k_htc_ps_restore(priv);
1736 mutex_unlock(&priv->mutex);
1739 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1740 struct ieee80211_vif *vif,
1741 enum ieee80211_ampdu_mlme_action action,
1742 struct ieee80211_sta *sta,
1745 struct ath9k_htc_priv *priv = hw->priv;
1746 struct ath9k_htc_sta *ista;
1750 case IEEE80211_AMPDU_RX_START:
1752 case IEEE80211_AMPDU_RX_STOP:
1754 case IEEE80211_AMPDU_TX_START:
1755 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1757 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1759 case IEEE80211_AMPDU_TX_STOP:
1760 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1761 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1763 case IEEE80211_AMPDU_TX_OPERATIONAL:
1764 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1765 spin_lock_bh(&priv->tx_lock);
1766 ista->tid_state[tid] = AGGR_OPERATIONAL;
1767 spin_unlock_bh(&priv->tx_lock);
1770 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1776 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1778 struct ath9k_htc_priv *priv = hw->priv;
1780 mutex_lock(&priv->mutex);
1781 spin_lock_bh(&priv->beacon_lock);
1782 priv->op_flags |= OP_SCANNING;
1783 spin_unlock_bh(&priv->beacon_lock);
1784 cancel_work_sync(&priv->ps_work);
1785 if (priv->op_flags & OP_ASSOCIATED)
1786 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1787 mutex_unlock(&priv->mutex);
1790 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1792 struct ath9k_htc_priv *priv = hw->priv;
1794 mutex_lock(&priv->mutex);
1795 ath9k_htc_ps_wakeup(priv);
1796 spin_lock_bh(&priv->beacon_lock);
1797 priv->op_flags &= ~OP_SCANNING;
1798 spin_unlock_bh(&priv->beacon_lock);
1799 priv->op_flags |= OP_FULL_RESET;
1800 if (priv->op_flags & OP_ASSOCIATED) {
1801 ath9k_htc_beacon_config(priv, priv->vif);
1802 ath_start_ani(priv);
1804 ath9k_htc_ps_restore(priv);
1805 mutex_unlock(&priv->mutex);
1808 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1813 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1816 struct ath9k_htc_priv *priv = hw->priv;
1818 mutex_lock(&priv->mutex);
1819 ath9k_htc_ps_wakeup(priv);
1820 priv->ah->coverage_class = coverage_class;
1821 ath9k_hw_init_global_settings(priv->ah);
1822 ath9k_htc_ps_restore(priv);
1823 mutex_unlock(&priv->mutex);
1826 struct ieee80211_ops ath9k_htc_ops = {
1828 .start = ath9k_htc_start,
1829 .stop = ath9k_htc_stop,
1830 .add_interface = ath9k_htc_add_interface,
1831 .remove_interface = ath9k_htc_remove_interface,
1832 .config = ath9k_htc_config,
1833 .configure_filter = ath9k_htc_configure_filter,
1834 .sta_add = ath9k_htc_sta_add,
1835 .sta_remove = ath9k_htc_sta_remove,
1836 .conf_tx = ath9k_htc_conf_tx,
1837 .bss_info_changed = ath9k_htc_bss_info_changed,
1838 .set_key = ath9k_htc_set_key,
1839 .get_tsf = ath9k_htc_get_tsf,
1840 .set_tsf = ath9k_htc_set_tsf,
1841 .reset_tsf = ath9k_htc_reset_tsf,
1842 .ampdu_action = ath9k_htc_ampdu_action,
1843 .sw_scan_start = ath9k_htc_sw_scan_start,
1844 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1845 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1846 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1847 .set_coverage_class = ath9k_htc_set_coverage_class,