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;
32 if (priv->curtxpow != priv->txpowlimit) {
33 ath9k_hw_set_txpowerlimit(ah, priv->txpowlimit);
34 /* read back in case value is clamped */
35 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
36 priv->curtxpow = txpow;
40 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
41 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
42 struct ath9k_channel *ichan)
44 enum htc_phymode mode;
48 switch (ichan->chanmode) {
51 case CHANNEL_G_HT40PLUS:
52 case CHANNEL_G_HT40MINUS:
57 case CHANNEL_A_HT40PLUS:
58 case CHANNEL_A_HT40MINUS:
68 static bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
69 enum ath9k_power_mode mode)
73 mutex_lock(&priv->htc_pm_lock);
74 ret = ath9k_hw_setpower(priv->ah, mode);
75 mutex_unlock(&priv->htc_pm_lock);
80 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
82 mutex_lock(&priv->htc_pm_lock);
83 if (++priv->ps_usecount != 1)
85 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
88 mutex_unlock(&priv->htc_pm_lock);
91 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
93 mutex_lock(&priv->htc_pm_lock);
94 if (--priv->ps_usecount != 0)
98 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
100 mutex_unlock(&priv->htc_pm_lock);
103 void ath9k_ps_work(struct work_struct *work)
105 struct ath9k_htc_priv *priv =
106 container_of(work, struct ath9k_htc_priv,
108 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
110 /* The chip wakes up after receiving the first beacon
111 while network sleep is enabled. For the driver to
112 be in sync with the hw, set the chip to awake and
113 only then set it to sleep.
115 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
118 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
119 struct ieee80211_hw *hw,
120 struct ath9k_channel *hchan)
122 struct ath_hw *ah = priv->ah;
123 struct ath_common *common = ath9k_hw_common(ah);
124 struct ieee80211_conf *conf = &common->hw->conf;
126 struct ieee80211_channel *channel = hw->conf.channel;
127 enum htc_phymode mode;
132 if (priv->op_flags & OP_INVALID)
135 if (priv->op_flags & OP_FULL_RESET)
138 /* Fiddle around with fastcc later on, for now just use 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\n",
148 priv->ah->curchan->channel,
149 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
151 ret = ath9k_hw_reset(ah, hchan, fastcc);
153 ath_print(common, ATH_DBG_FATAL,
154 "Unable to reset channel (%u Mhz) "
155 "reset status %d\n", channel->center_freq, ret);
156 ath9k_htc_ps_restore(priv);
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 = 1;
328 tcap.tx_chainmask = 1;
330 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
335 static int ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
336 struct ieee80211_vif *vif,
337 struct ieee80211_sta *sta)
339 struct ath_common *common = ath9k_hw_common(priv->ah);
340 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
341 struct ieee80211_supported_band *sband;
342 struct ath9k_htc_target_rate trate;
347 memset(&trate, 0, sizeof(trate));
349 /* Only 2GHz is supported */
350 sband = priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ];
352 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
353 if (sta->supp_rates[sband->band] & BIT(i)) {
354 priv->tgt_rate.rates.legacy_rates.rs_rates[j]
355 = (sband->bitrates[i].bitrate * 2) / 10;
359 priv->tgt_rate.rates.legacy_rates.rs_nrates = j;
361 if (sta->ht_cap.ht_supported) {
362 for (i = 0, j = 0; i < 77; i++) {
363 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
364 priv->tgt_rate.rates.ht_rates.rs_rates[j++] = i;
365 if (j == ATH_HTC_RATE_MAX)
368 priv->tgt_rate.rates.ht_rates.rs_nrates = j;
370 caps = WLAN_RC_HT_FLAG;
371 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
372 caps |= WLAN_RC_40_FLAG;
373 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)
374 caps |= WLAN_RC_SGI_FLAG;
378 priv->tgt_rate.sta_index = ista->index;
379 priv->tgt_rate.isnew = 1;
380 trate = priv->tgt_rate;
381 priv->tgt_rate.capflags = cpu_to_be32(caps);
382 trate.capflags = cpu_to_be32(caps);
384 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, &trate);
386 ath_print(common, ATH_DBG_FATAL,
387 "Unable to initialize Rate information on target\n");
391 ath_print(common, ATH_DBG_CONFIG,
392 "Updated target STA: %pM (caps: 0x%x)\n", sta->addr, caps);
396 static bool check_rc_update(struct ieee80211_hw *hw, bool *cw40)
398 struct ath9k_htc_priv *priv = hw->priv;
399 struct ieee80211_conf *conf = &hw->conf;
401 if (!conf_is_ht(conf))
404 if (!(priv->op_flags & OP_ASSOCIATED) ||
405 (priv->op_flags & OP_SCANNING))
408 if (conf_is_ht40(conf)) {
409 if (priv->ah->curchan->chanmode &
410 (CHANNEL_HT40PLUS | CHANNEL_HT40MINUS)) {
417 if (priv->ah->curchan->chanmode & CHANNEL_HT20)
424 static void ath9k_htc_rc_update(struct ath9k_htc_priv *priv, bool is_cw40)
426 struct ath9k_htc_target_rate trate;
427 struct ath_common *common = ath9k_hw_common(priv->ah);
429 u32 caps = be32_to_cpu(priv->tgt_rate.capflags);
432 memset(&trate, 0, sizeof(trate));
434 trate = priv->tgt_rate;
437 caps |= WLAN_RC_40_FLAG;
439 caps &= ~WLAN_RC_40_FLAG;
441 priv->tgt_rate.capflags = cpu_to_be32(caps);
442 trate.capflags = cpu_to_be32(caps);
444 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, &trate);
446 ath_print(common, ATH_DBG_FATAL,
447 "Unable to update Rate information on target\n");
451 ath_print(common, ATH_DBG_CONFIG, "Rate control updated with "
452 "caps:0x%x on target\n", priv->tgt_rate.capflags);
455 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv *priv,
456 struct ieee80211_vif *vif,
457 u8 *sta_addr, u8 tid, bool oper)
459 struct ath_common *common = ath9k_hw_common(priv->ah);
460 struct ath9k_htc_target_aggr aggr;
461 struct ieee80211_sta *sta = NULL;
462 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
466 if (tid > ATH9K_HTC_MAX_TID)
469 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
473 /* Check if we are able to retrieve the station */
474 sta = ieee80211_find_sta(vif, sta_addr);
480 ista = (struct ath9k_htc_sta *) sta->drv_priv;
483 ista->tid_state[tid] = AGGR_START;
485 ista->tid_state[tid] = AGGR_STOP;
487 aggr.sta_index = ista->index;
492 aggr.aggr_enable = oper;
494 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
496 ath_print(common, ATH_DBG_CONFIG,
497 "Unable to %s TX aggregation for (%pM, %d)\n",
498 (oper) ? "start" : "stop", sta->addr, tid);
500 ath_print(common, ATH_DBG_CONFIG,
501 "%s aggregation for (%pM, %d)\n",
502 (oper) ? "Starting" : "Stopping", sta->addr, tid);
507 void ath9k_htc_aggr_work(struct work_struct *work)
510 struct ath9k_htc_priv *priv =
511 container_of(work, struct ath9k_htc_priv,
512 ath9k_aggr_work.work);
513 struct ath9k_htc_aggr_work *wk = &priv->aggr_work;
515 mutex_lock(&wk->mutex);
517 switch (wk->action) {
518 case IEEE80211_AMPDU_TX_START:
519 ret = ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
522 ieee80211_start_tx_ba_cb(wk->vif, wk->sta_addr,
525 case IEEE80211_AMPDU_TX_STOP:
526 ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
528 ieee80211_stop_tx_ba_cb(wk->vif, wk->sta_addr, wk->tid);
531 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
532 "Unknown AMPDU action\n");
535 mutex_unlock(&wk->mutex);
542 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
544 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
546 file->private_data = inode->i_private;
550 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
551 size_t count, loff_t *ppos)
553 struct ath9k_htc_priv *priv =
554 (struct ath9k_htc_priv *) file->private_data;
555 struct ath9k_htc_target_stats cmd_rsp;
557 unsigned int len = 0;
560 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
562 WMI_CMD(WMI_TGT_STATS_CMDID);
567 len += snprintf(buf + len, sizeof(buf) - len,
568 "%19s : %10u\n", "TX Short Retries",
569 be32_to_cpu(cmd_rsp.tx_shortretry));
570 len += snprintf(buf + len, sizeof(buf) - len,
571 "%19s : %10u\n", "TX Long Retries",
572 be32_to_cpu(cmd_rsp.tx_longretry));
573 len += snprintf(buf + len, sizeof(buf) - len,
574 "%19s : %10u\n", "TX Xretries",
575 be32_to_cpu(cmd_rsp.tx_xretries));
576 len += snprintf(buf + len, sizeof(buf) - len,
577 "%19s : %10u\n", "TX Unaggr. Xretries",
578 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
579 len += snprintf(buf + len, sizeof(buf) - len,
580 "%19s : %10u\n", "TX Xretries (HT)",
581 be32_to_cpu(cmd_rsp.ht_tx_xretries));
582 len += snprintf(buf + len, sizeof(buf) - len,
583 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
585 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
588 static const struct file_operations fops_tgt_stats = {
589 .read = read_file_tgt_stats,
590 .open = ath9k_debugfs_open,
594 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
595 size_t count, loff_t *ppos)
597 struct ath9k_htc_priv *priv =
598 (struct ath9k_htc_priv *) file->private_data;
600 unsigned int len = 0;
602 len += snprintf(buf + len, sizeof(buf) - len,
603 "%20s : %10u\n", "Buffers queued",
604 priv->debug.tx_stats.buf_queued);
605 len += snprintf(buf + len, sizeof(buf) - len,
606 "%20s : %10u\n", "Buffers completed",
607 priv->debug.tx_stats.buf_completed);
608 len += snprintf(buf + len, sizeof(buf) - len,
609 "%20s : %10u\n", "SKBs queued",
610 priv->debug.tx_stats.skb_queued);
611 len += snprintf(buf + len, sizeof(buf) - len,
612 "%20s : %10u\n", "SKBs completed",
613 priv->debug.tx_stats.skb_completed);
614 len += snprintf(buf + len, sizeof(buf) - len,
615 "%20s : %10u\n", "SKBs dropped",
616 priv->debug.tx_stats.skb_dropped);
618 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
621 static const struct file_operations fops_xmit = {
622 .read = read_file_xmit,
623 .open = ath9k_debugfs_open,
627 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
628 size_t count, loff_t *ppos)
630 struct ath9k_htc_priv *priv =
631 (struct ath9k_htc_priv *) file->private_data;
633 unsigned int len = 0;
635 len += snprintf(buf + len, sizeof(buf) - len,
636 "%20s : %10u\n", "SKBs allocated",
637 priv->debug.rx_stats.skb_allocated);
638 len += snprintf(buf + len, sizeof(buf) - len,
639 "%20s : %10u\n", "SKBs completed",
640 priv->debug.rx_stats.skb_completed);
641 len += snprintf(buf + len, sizeof(buf) - len,
642 "%20s : %10u\n", "SKBs Dropped",
643 priv->debug.rx_stats.skb_dropped);
645 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
648 static const struct file_operations fops_recv = {
649 .read = read_file_recv,
650 .open = ath9k_debugfs_open,
654 int ath9k_htc_init_debug(struct ath_hw *ah)
656 struct ath_common *common = ath9k_hw_common(ah);
657 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
659 if (!ath9k_debugfs_root)
662 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
664 if (!priv->debug.debugfs_phy)
667 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
668 priv->debug.debugfs_phy,
669 priv, &fops_tgt_stats);
670 if (!priv->debug.debugfs_tgt_stats)
674 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
675 priv->debug.debugfs_phy,
677 if (!priv->debug.debugfs_xmit)
680 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
681 priv->debug.debugfs_phy,
683 if (!priv->debug.debugfs_recv)
689 ath9k_htc_exit_debug(ah);
693 void ath9k_htc_exit_debug(struct ath_hw *ah)
695 struct ath_common *common = ath9k_hw_common(ah);
696 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
698 debugfs_remove(priv->debug.debugfs_recv);
699 debugfs_remove(priv->debug.debugfs_xmit);
700 debugfs_remove(priv->debug.debugfs_tgt_stats);
701 debugfs_remove(priv->debug.debugfs_phy);
704 int ath9k_htc_debug_create_root(void)
706 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
707 if (!ath9k_debugfs_root)
713 void ath9k_htc_debug_remove_root(void)
715 debugfs_remove(ath9k_debugfs_root);
716 ath9k_debugfs_root = NULL;
719 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
725 static void ath_start_ani(struct ath9k_htc_priv *priv)
727 struct ath_common *common = ath9k_hw_common(priv->ah);
728 unsigned long timestamp = jiffies_to_msecs(jiffies);
730 common->ani.longcal_timer = timestamp;
731 common->ani.shortcal_timer = timestamp;
732 common->ani.checkani_timer = timestamp;
734 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
735 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
738 void ath9k_ani_work(struct work_struct *work)
740 struct ath9k_htc_priv *priv =
741 container_of(work, struct ath9k_htc_priv,
742 ath9k_ani_work.work);
743 struct ath_hw *ah = priv->ah;
744 struct ath_common *common = ath9k_hw_common(ah);
745 bool longcal = false;
746 bool shortcal = false;
747 bool aniflag = false;
748 unsigned int timestamp = jiffies_to_msecs(jiffies);
749 u32 cal_interval, short_cal_interval;
751 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
753 /* Only calibrate if awake */
754 if (ah->power_mode != ATH9K_PM_AWAKE)
757 /* Long calibration runs independently of short calibration. */
758 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
760 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
761 common->ani.longcal_timer = timestamp;
764 /* Short calibration applies only while caldone is false */
765 if (!common->ani.caldone) {
766 if ((timestamp - common->ani.shortcal_timer) >=
767 short_cal_interval) {
769 ath_print(common, ATH_DBG_ANI,
770 "shortcal @%lu\n", jiffies);
771 common->ani.shortcal_timer = timestamp;
772 common->ani.resetcal_timer = timestamp;
775 if ((timestamp - common->ani.resetcal_timer) >=
776 ATH_RESTART_CALINTERVAL) {
777 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
778 if (common->ani.caldone)
779 common->ani.resetcal_timer = timestamp;
783 /* Verify whether we must check ANI */
784 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
786 common->ani.checkani_timer = timestamp;
789 /* Skip all processing if there's nothing to do. */
790 if (longcal || shortcal || aniflag) {
792 ath9k_htc_ps_wakeup(priv);
794 /* Call ANI routine if necessary */
796 ath9k_hw_ani_monitor(ah, ah->curchan);
798 /* Perform calibration if necessary */
799 if (longcal || shortcal) {
800 common->ani.caldone =
801 ath9k_hw_calibrate(ah, ah->curchan,
802 common->rx_chainmask,
806 common->ani.noise_floor =
807 ath9k_hw_getchan_noise(ah, ah->curchan);
809 ath_print(common, ATH_DBG_ANI,
810 " calibrate chan %u/%x nf: %d\n",
811 ah->curchan->channel,
812 ah->curchan->channelFlags,
813 common->ani.noise_floor);
816 ath9k_htc_ps_restore(priv);
821 * Set timer interval based on previous results.
822 * The interval must be the shortest necessary to satisfy ANI,
823 * short calibration and long calibration.
825 cal_interval = ATH_LONG_CALINTERVAL;
826 if (priv->ah->config.enable_ani)
827 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
828 if (!common->ani.caldone)
829 cal_interval = min(cal_interval, (u32)short_cal_interval);
831 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
832 msecs_to_jiffies(cal_interval));
839 static void ath9k_led_blink_work(struct work_struct *work)
841 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
842 ath9k_led_blink_work.work);
844 if (!(priv->op_flags & OP_LED_ASSOCIATED))
847 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
848 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
849 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
851 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
852 (priv->op_flags & OP_LED_ON) ? 1 : 0);
854 ieee80211_queue_delayed_work(priv->hw,
855 &priv->ath9k_led_blink_work,
856 (priv->op_flags & OP_LED_ON) ?
857 msecs_to_jiffies(priv->led_off_duration) :
858 msecs_to_jiffies(priv->led_on_duration));
860 priv->led_on_duration = priv->led_on_cnt ?
861 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
862 ATH_LED_ON_DURATION_IDLE;
863 priv->led_off_duration = priv->led_off_cnt ?
864 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
865 ATH_LED_OFF_DURATION_IDLE;
866 priv->led_on_cnt = priv->led_off_cnt = 0;
868 if (priv->op_flags & OP_LED_ON)
869 priv->op_flags &= ~OP_LED_ON;
871 priv->op_flags |= OP_LED_ON;
874 static void ath9k_led_brightness_work(struct work_struct *work)
876 struct ath_led *led = container_of(work, struct ath_led,
877 brightness_work.work);
878 struct ath9k_htc_priv *priv = led->priv;
880 switch (led->brightness) {
882 if (led->led_type == ATH_LED_ASSOC ||
883 led->led_type == ATH_LED_RADIO) {
884 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
885 (led->led_type == ATH_LED_RADIO));
886 priv->op_flags &= ~OP_LED_ASSOCIATED;
887 if (led->led_type == ATH_LED_RADIO)
888 priv->op_flags &= ~OP_LED_ON;
894 if (led->led_type == ATH_LED_ASSOC) {
895 priv->op_flags |= OP_LED_ASSOCIATED;
896 ieee80211_queue_delayed_work(priv->hw,
897 &priv->ath9k_led_blink_work, 0);
898 } else if (led->led_type == ATH_LED_RADIO) {
899 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
900 priv->op_flags |= OP_LED_ON;
910 static void ath9k_led_brightness(struct led_classdev *led_cdev,
911 enum led_brightness brightness)
913 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
914 struct ath9k_htc_priv *priv = led->priv;
916 led->brightness = brightness;
917 if (!(priv->op_flags & OP_LED_DEINIT))
918 ieee80211_queue_delayed_work(priv->hw,
919 &led->brightness_work, 0);
922 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
924 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
925 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
926 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
927 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
930 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
936 led->led_cdev.name = led->name;
937 led->led_cdev.default_trigger = trigger;
938 led->led_cdev.brightness_set = ath9k_led_brightness;
940 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
942 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
943 "Failed to register led:%s", led->name);
947 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
952 static void ath9k_unregister_led(struct ath_led *led)
954 if (led->registered) {
955 led_classdev_unregister(&led->led_cdev);
960 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
962 priv->op_flags |= OP_LED_DEINIT;
963 ath9k_unregister_led(&priv->assoc_led);
964 priv->op_flags &= ~OP_LED_ASSOCIATED;
965 ath9k_unregister_led(&priv->tx_led);
966 ath9k_unregister_led(&priv->rx_led);
967 ath9k_unregister_led(&priv->radio_led);
970 void ath9k_init_leds(struct ath9k_htc_priv *priv)
975 if (AR_SREV_9287(priv->ah))
976 priv->ah->led_pin = ATH_LED_PIN_9287;
977 else if (AR_SREV_9271(priv->ah))
978 priv->ah->led_pin = ATH_LED_PIN_9271;
980 priv->ah->led_pin = ATH_LED_PIN_DEF;
982 /* Configure gpio 1 for output */
983 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
984 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
985 /* LED off, active low */
986 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
988 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
990 trigger = ieee80211_get_radio_led_name(priv->hw);
991 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
992 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
993 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
994 priv->radio_led.led_type = ATH_LED_RADIO;
998 trigger = ieee80211_get_assoc_led_name(priv->hw);
999 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
1000 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
1001 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
1002 priv->assoc_led.led_type = ATH_LED_ASSOC;
1006 trigger = ieee80211_get_tx_led_name(priv->hw);
1007 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
1008 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
1009 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
1010 priv->tx_led.led_type = ATH_LED_TX;
1014 trigger = ieee80211_get_rx_led_name(priv->hw);
1015 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
1016 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
1017 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
1018 priv->rx_led.led_type = ATH_LED_RX;
1022 priv->op_flags &= ~OP_LED_DEINIT;
1027 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1028 ath9k_deinit_leds(priv);
1031 /*******************/
1033 /*******************/
1035 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1037 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1038 priv->ah->rfkill_polarity;
1041 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1043 struct ath9k_htc_priv *priv = hw->priv;
1044 bool blocked = !!ath_is_rfkill_set(priv);
1046 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1049 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1051 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1052 wiphy_rfkill_start_polling(priv->hw->wiphy);
1055 /**********************/
1056 /* mac80211 Callbacks */
1057 /**********************/
1059 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1061 struct ieee80211_hdr *hdr;
1062 struct ath9k_htc_priv *priv = hw->priv;
1063 int padpos, padsize, ret;
1065 hdr = (struct ieee80211_hdr *) skb->data;
1067 /* Add the padding after the header if this is not already done */
1068 padpos = ath9k_cmn_padpos(hdr->frame_control);
1069 padsize = padpos & 3;
1070 if (padsize && skb->len > padpos) {
1071 if (skb_headroom(skb) < padsize)
1073 skb_push(skb, padsize);
1074 memmove(skb->data, skb->data + padsize, padpos);
1077 ret = ath9k_htc_tx_start(priv, skb);
1079 if (ret == -ENOMEM) {
1080 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1081 "Stopping TX queues\n");
1082 ieee80211_stop_queues(hw);
1083 spin_lock_bh(&priv->tx_lock);
1084 priv->tx_queues_stop = true;
1085 spin_unlock_bh(&priv->tx_lock);
1087 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1096 dev_kfree_skb_any(skb);
1100 static int ath9k_htc_start(struct ieee80211_hw *hw)
1102 struct ath9k_htc_priv *priv = hw->priv;
1103 struct ath_hw *ah = priv->ah;
1104 struct ath_common *common = ath9k_hw_common(ah);
1105 struct ieee80211_channel *curchan = hw->conf.channel;
1106 struct ath9k_channel *init_channel;
1108 enum htc_phymode mode;
1112 ath_print(common, ATH_DBG_CONFIG,
1113 "Starting driver with initial channel: %d MHz\n",
1114 curchan->center_freq);
1116 mutex_lock(&priv->mutex);
1118 /* setup initial channel */
1119 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1121 /* Reset SERDES registers */
1122 ath9k_hw_configpcipowersave(ah, 0, 0);
1124 ath9k_hw_htc_resetinit(ah);
1125 ret = ath9k_hw_reset(ah, init_channel, false);
1127 ath_print(common, ATH_DBG_FATAL,
1128 "Unable to reset hardware; reset status %d "
1129 "(freq %u MHz)\n", ret, curchan->center_freq);
1133 ath_update_txpow(priv);
1135 mode = ath9k_htc_get_curmode(priv, init_channel);
1136 htc_mode = cpu_to_be16(mode);
1137 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1141 WMI_CMD(WMI_ATH_INIT_CMDID);
1145 WMI_CMD(WMI_START_RECV_CMDID);
1149 ath9k_host_rx_init(priv);
1151 priv->op_flags &= ~OP_INVALID;
1152 htc_start(priv->htc);
1154 spin_lock_bh(&priv->tx_lock);
1155 priv->tx_queues_stop = false;
1156 spin_unlock_bh(&priv->tx_lock);
1158 ieee80211_wake_queues(hw);
1161 mutex_unlock(&priv->mutex);
1165 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1167 struct ath9k_htc_priv *priv = hw->priv;
1168 struct ath_hw *ah = priv->ah;
1169 struct ath_common *common = ath9k_hw_common(ah);
1173 mutex_lock(&priv->mutex);
1175 if (priv->op_flags & OP_INVALID) {
1176 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1177 mutex_unlock(&priv->mutex);
1181 /* Cancel all the running timers/work .. */
1182 cancel_work_sync(&priv->ps_work);
1183 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1184 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1185 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1186 ath9k_led_stop_brightness(priv);
1188 ath9k_htc_ps_wakeup(priv);
1189 htc_stop(priv->htc);
1190 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1191 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1192 WMI_CMD(WMI_STOP_RECV_CMDID);
1193 ath9k_hw_phy_disable(ah);
1194 ath9k_hw_disable(ah);
1195 ath9k_hw_configpcipowersave(ah, 1, 1);
1196 ath9k_htc_ps_restore(priv);
1197 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1199 skb_queue_purge(&priv->tx_queue);
1201 /* Remove monitor interface here */
1202 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1203 if (ath9k_htc_remove_monitor_interface(priv))
1204 ath_print(common, ATH_DBG_FATAL,
1205 "Unable to remove monitor interface\n");
1207 ath_print(common, ATH_DBG_CONFIG,
1208 "Monitor interface removed\n");
1211 priv->op_flags |= OP_INVALID;
1212 mutex_unlock(&priv->mutex);
1214 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1217 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1218 struct ieee80211_vif *vif)
1220 struct ath9k_htc_priv *priv = hw->priv;
1221 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1222 struct ath_common *common = ath9k_hw_common(priv->ah);
1223 struct ath9k_htc_target_vif hvif;
1227 mutex_lock(&priv->mutex);
1229 /* Only one interface for now */
1230 if (priv->nvifs > 0) {
1235 ath9k_htc_ps_wakeup(priv);
1236 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1237 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1239 switch (vif->type) {
1240 case NL80211_IFTYPE_STATION:
1241 hvif.opmode = cpu_to_be32(HTC_M_STA);
1243 case NL80211_IFTYPE_ADHOC:
1244 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1247 ath_print(common, ATH_DBG_FATAL,
1248 "Interface type %d not yet supported\n", vif->type);
1253 ath_print(common, ATH_DBG_CONFIG,
1254 "Attach a VIF of type: %d\n", vif->type);
1256 priv->ah->opmode = vif->type;
1258 /* Index starts from zero on the target */
1259 avp->index = hvif.index = priv->nvifs;
1260 hvif.rtsthreshold = cpu_to_be16(2304);
1261 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1268 * We need a node in target to tx mgmt frames
1269 * before association.
1271 ret = ath9k_htc_add_station(priv, vif, NULL);
1275 ret = ath9k_htc_update_cap_target(priv);
1277 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1278 " capability in target \n");
1282 ath9k_htc_ps_restore(priv);
1283 mutex_unlock(&priv->mutex);
1287 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1288 struct ieee80211_vif *vif)
1290 struct ath9k_htc_priv *priv = hw->priv;
1291 struct ath_common *common = ath9k_hw_common(priv->ah);
1292 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1293 struct ath9k_htc_target_vif hvif;
1297 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1299 mutex_lock(&priv->mutex);
1301 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1302 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1303 hvif.index = avp->index;
1304 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1307 ath9k_htc_remove_station(priv, vif, NULL);
1309 if (vif->type == NL80211_IFTYPE_ADHOC) {
1310 spin_lock_bh(&priv->beacon_lock);
1312 dev_kfree_skb_any(priv->beacon);
1313 priv->beacon = NULL;
1314 spin_unlock_bh(&priv->beacon_lock);
1319 mutex_unlock(&priv->mutex);
1322 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1324 struct ath9k_htc_priv *priv = hw->priv;
1325 struct ath_common *common = ath9k_hw_common(priv->ah);
1326 struct ieee80211_conf *conf = &hw->conf;
1328 mutex_lock(&priv->mutex);
1330 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1331 struct ieee80211_channel *curchan = hw->conf.channel;
1332 int pos = curchan->hw_value;
1333 bool is_cw40 = false;
1335 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1336 curchan->center_freq);
1338 if (check_rc_update(hw, &is_cw40))
1339 ath9k_htc_rc_update(priv, is_cw40);
1341 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1343 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1344 ath_print(common, ATH_DBG_FATAL,
1345 "Unable to set channel\n");
1346 mutex_unlock(&priv->mutex);
1351 if (changed & IEEE80211_CONF_CHANGE_PS) {
1352 if (conf->flags & IEEE80211_CONF_PS) {
1353 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1354 priv->ps_enabled = true;
1356 priv->ps_enabled = false;
1357 cancel_work_sync(&priv->ps_work);
1358 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1362 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1363 if (conf->flags & IEEE80211_CONF_MONITOR) {
1364 if (ath9k_htc_add_monitor_interface(priv))
1365 ath_print(common, ATH_DBG_FATAL,
1366 "Failed to set monitor mode\n");
1368 ath_print(common, ATH_DBG_CONFIG,
1369 "HW opmode set to Monitor mode\n");
1373 mutex_unlock(&priv->mutex);
1378 #define SUPPORTED_FILTERS \
1379 (FIF_PROMISC_IN_BSS | \
1384 FIF_BCN_PRBRESP_PROMISC | \
1387 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1388 unsigned int changed_flags,
1389 unsigned int *total_flags,
1392 struct ath9k_htc_priv *priv = hw->priv;
1395 mutex_lock(&priv->mutex);
1397 ath9k_htc_ps_wakeup(priv);
1398 changed_flags &= SUPPORTED_FILTERS;
1399 *total_flags &= SUPPORTED_FILTERS;
1401 priv->rxfilter = *total_flags;
1402 rfilt = ath9k_htc_calcrxfilter(priv);
1403 ath9k_hw_setrxfilter(priv->ah, rfilt);
1405 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1406 "Set HW RX filter: 0x%x\n", rfilt);
1408 ath9k_htc_ps_restore(priv);
1409 mutex_unlock(&priv->mutex);
1412 static void ath9k_htc_sta_notify(struct ieee80211_hw *hw,
1413 struct ieee80211_vif *vif,
1414 enum sta_notify_cmd cmd,
1415 struct ieee80211_sta *sta)
1417 struct ath9k_htc_priv *priv = hw->priv;
1421 case STA_NOTIFY_ADD:
1422 ret = ath9k_htc_add_station(priv, vif, sta);
1424 ath9k_htc_init_rate(priv, vif, sta);
1426 case STA_NOTIFY_REMOVE:
1427 ath9k_htc_remove_station(priv, vif, sta);
1434 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1435 const struct ieee80211_tx_queue_params *params)
1437 struct ath9k_htc_priv *priv = hw->priv;
1438 struct ath_common *common = ath9k_hw_common(priv->ah);
1439 struct ath9k_tx_queue_info qi;
1442 if (queue >= WME_NUM_AC)
1445 mutex_lock(&priv->mutex);
1447 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1449 qi.tqi_aifs = params->aifs;
1450 qi.tqi_cwmin = params->cw_min;
1451 qi.tqi_cwmax = params->cw_max;
1452 qi.tqi_burstTime = params->txop;
1454 qnum = get_hw_qnum(queue, priv->hwq_map);
1456 ath_print(common, ATH_DBG_CONFIG,
1457 "Configure tx [queue/hwq] [%d/%d], "
1458 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1459 queue, qnum, params->aifs, params->cw_min,
1460 params->cw_max, params->txop);
1462 ret = ath_htc_txq_update(priv, qnum, &qi);
1464 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1466 mutex_unlock(&priv->mutex);
1471 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1472 enum set_key_cmd cmd,
1473 struct ieee80211_vif *vif,
1474 struct ieee80211_sta *sta,
1475 struct ieee80211_key_conf *key)
1477 struct ath9k_htc_priv *priv = hw->priv;
1478 struct ath_common *common = ath9k_hw_common(priv->ah);
1481 if (htc_modparam_nohwcrypt)
1484 mutex_lock(&priv->mutex);
1485 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1486 ath9k_htc_ps_wakeup(priv);
1490 ret = ath9k_cmn_key_config(common, vif, sta, key);
1492 key->hw_key_idx = ret;
1493 /* push IV and Michael MIC generation to stack */
1494 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1495 if (key->alg == ALG_TKIP)
1496 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1497 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1498 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1503 ath9k_cmn_key_delete(common, key);
1509 ath9k_htc_ps_restore(priv);
1510 mutex_unlock(&priv->mutex);
1515 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1516 struct ieee80211_vif *vif,
1517 struct ieee80211_bss_conf *bss_conf,
1520 struct ath9k_htc_priv *priv = hw->priv;
1521 struct ath_hw *ah = priv->ah;
1522 struct ath_common *common = ath9k_hw_common(ah);
1524 mutex_lock(&priv->mutex);
1525 ath9k_htc_ps_wakeup(priv);
1527 if (changed & BSS_CHANGED_ASSOC) {
1528 common->curaid = bss_conf->assoc ?
1530 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1533 if (bss_conf->assoc) {
1534 priv->op_flags |= OP_ASSOCIATED;
1535 ath_start_ani(priv);
1537 priv->op_flags &= ~OP_ASSOCIATED;
1538 cancel_work_sync(&priv->ps_work);
1539 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1543 if (changed & BSS_CHANGED_BSSID) {
1545 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1546 ath9k_hw_write_associd(ah);
1548 ath_print(common, ATH_DBG_CONFIG,
1549 "BSSID: %pM aid: 0x%x\n",
1550 common->curbssid, common->curaid);
1553 if ((changed & BSS_CHANGED_BEACON_INT) ||
1554 (changed & BSS_CHANGED_BEACON) ||
1555 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1556 bss_conf->enable_beacon)) {
1557 priv->op_flags |= OP_ENABLE_BEACON;
1558 ath9k_htc_beacon_config(priv, vif);
1561 if (changed & BSS_CHANGED_BEACON)
1562 ath9k_htc_beacon_update(priv, vif);
1564 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1565 !bss_conf->enable_beacon) {
1566 priv->op_flags &= ~OP_ENABLE_BEACON;
1567 ath9k_htc_beacon_config(priv, vif);
1570 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1571 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1572 bss_conf->use_short_preamble);
1573 if (bss_conf->use_short_preamble)
1574 priv->op_flags |= OP_PREAMBLE_SHORT;
1576 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1579 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1580 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1581 bss_conf->use_cts_prot);
1582 if (bss_conf->use_cts_prot &&
1583 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1584 priv->op_flags |= OP_PROTECT_ENABLE;
1586 priv->op_flags &= ~OP_PROTECT_ENABLE;
1589 if (changed & BSS_CHANGED_ERP_SLOT) {
1590 if (bss_conf->use_short_slot)
1595 ath9k_hw_init_global_settings(ah);
1598 ath9k_htc_ps_restore(priv);
1599 mutex_unlock(&priv->mutex);
1602 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1604 struct ath9k_htc_priv *priv = hw->priv;
1607 mutex_lock(&priv->mutex);
1608 tsf = ath9k_hw_gettsf64(priv->ah);
1609 mutex_unlock(&priv->mutex);
1614 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1616 struct ath9k_htc_priv *priv = hw->priv;
1618 mutex_lock(&priv->mutex);
1619 ath9k_hw_settsf64(priv->ah, tsf);
1620 mutex_unlock(&priv->mutex);
1623 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1625 struct ath9k_htc_priv *priv = hw->priv;
1627 ath9k_htc_ps_wakeup(priv);
1628 mutex_lock(&priv->mutex);
1629 ath9k_hw_reset_tsf(priv->ah);
1630 mutex_unlock(&priv->mutex);
1631 ath9k_htc_ps_restore(priv);
1634 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1635 struct ieee80211_vif *vif,
1636 enum ieee80211_ampdu_mlme_action action,
1637 struct ieee80211_sta *sta,
1640 struct ath9k_htc_priv *priv = hw->priv;
1641 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1642 struct ath9k_htc_sta *ista;
1645 case IEEE80211_AMPDU_RX_START:
1647 case IEEE80211_AMPDU_RX_STOP:
1649 case IEEE80211_AMPDU_TX_START:
1650 case IEEE80211_AMPDU_TX_STOP:
1651 if (!(priv->op_flags & OP_TXAGGR))
1653 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1656 work->action = action;
1658 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1660 case IEEE80211_AMPDU_TX_OPERATIONAL:
1661 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1662 ista->tid_state[tid] = AGGR_OPERATIONAL;
1665 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1666 "Unknown AMPDU action\n");
1672 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1674 struct ath9k_htc_priv *priv = hw->priv;
1676 mutex_lock(&priv->mutex);
1677 spin_lock_bh(&priv->beacon_lock);
1678 priv->op_flags |= OP_SCANNING;
1679 spin_unlock_bh(&priv->beacon_lock);
1680 cancel_work_sync(&priv->ps_work);
1681 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1682 mutex_unlock(&priv->mutex);
1685 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1687 struct ath9k_htc_priv *priv = hw->priv;
1689 ath9k_htc_ps_wakeup(priv);
1690 mutex_lock(&priv->mutex);
1691 spin_lock_bh(&priv->beacon_lock);
1692 priv->op_flags &= ~OP_SCANNING;
1693 spin_unlock_bh(&priv->beacon_lock);
1694 priv->op_flags |= OP_FULL_RESET;
1695 if (priv->op_flags & OP_ASSOCIATED)
1696 ath9k_htc_beacon_config(priv, priv->vif);
1697 ath_start_ani(priv);
1698 mutex_unlock(&priv->mutex);
1699 ath9k_htc_ps_restore(priv);
1702 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1707 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1710 struct ath9k_htc_priv *priv = hw->priv;
1712 mutex_lock(&priv->mutex);
1713 priv->ah->coverage_class = coverage_class;
1714 ath9k_hw_init_global_settings(priv->ah);
1715 mutex_unlock(&priv->mutex);
1718 struct ieee80211_ops ath9k_htc_ops = {
1720 .start = ath9k_htc_start,
1721 .stop = ath9k_htc_stop,
1722 .add_interface = ath9k_htc_add_interface,
1723 .remove_interface = ath9k_htc_remove_interface,
1724 .config = ath9k_htc_config,
1725 .configure_filter = ath9k_htc_configure_filter,
1726 .sta_notify = ath9k_htc_sta_notify,
1727 .conf_tx = ath9k_htc_conf_tx,
1728 .bss_info_changed = ath9k_htc_bss_info_changed,
1729 .set_key = ath9k_htc_set_key,
1730 .get_tsf = ath9k_htc_get_tsf,
1731 .set_tsf = ath9k_htc_set_tsf,
1732 .reset_tsf = ath9k_htc_reset_tsf,
1733 .ampdu_action = ath9k_htc_ampdu_action,
1734 .sw_scan_start = ath9k_htc_sw_scan_start,
1735 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1736 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1737 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1738 .set_coverage_class = ath9k_htc_set_coverage_class,