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 ath9k_htc_ps_wakeup(priv);
1182 htc_stop(priv->htc);
1183 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1184 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1185 WMI_CMD(WMI_STOP_RECV_CMDID);
1186 ath9k_hw_phy_disable(ah);
1187 ath9k_hw_disable(ah);
1188 ath9k_hw_configpcipowersave(ah, 1, 1);
1189 ath9k_htc_ps_restore(priv);
1190 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1192 cancel_work_sync(&priv->ps_work);
1193 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1194 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1195 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1196 ath9k_led_stop_brightness(priv);
1197 skb_queue_purge(&priv->tx_queue);
1199 /* Remove monitor interface here */
1200 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1201 if (ath9k_htc_remove_monitor_interface(priv))
1202 ath_print(common, ATH_DBG_FATAL,
1203 "Unable to remove monitor interface\n");
1205 ath_print(common, ATH_DBG_CONFIG,
1206 "Monitor interface removed\n");
1209 priv->op_flags |= OP_INVALID;
1210 mutex_unlock(&priv->mutex);
1212 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1215 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1216 struct ieee80211_vif *vif)
1218 struct ath9k_htc_priv *priv = hw->priv;
1219 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1220 struct ath_common *common = ath9k_hw_common(priv->ah);
1221 struct ath9k_htc_target_vif hvif;
1225 mutex_lock(&priv->mutex);
1227 /* Only one interface for now */
1228 if (priv->nvifs > 0) {
1233 ath9k_htc_ps_wakeup(priv);
1234 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1235 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1237 switch (vif->type) {
1238 case NL80211_IFTYPE_STATION:
1239 hvif.opmode = cpu_to_be32(HTC_M_STA);
1241 case NL80211_IFTYPE_ADHOC:
1242 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1245 ath_print(common, ATH_DBG_FATAL,
1246 "Interface type %d not yet supported\n", vif->type);
1251 ath_print(common, ATH_DBG_CONFIG,
1252 "Attach a VIF of type: %d\n", vif->type);
1254 priv->ah->opmode = vif->type;
1256 /* Index starts from zero on the target */
1257 avp->index = hvif.index = priv->nvifs;
1258 hvif.rtsthreshold = cpu_to_be16(2304);
1259 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1266 * We need a node in target to tx mgmt frames
1267 * before association.
1269 ret = ath9k_htc_add_station(priv, vif, NULL);
1273 ret = ath9k_htc_update_cap_target(priv);
1275 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1276 " capability in target \n");
1280 ath9k_htc_ps_restore(priv);
1281 mutex_unlock(&priv->mutex);
1285 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1286 struct ieee80211_vif *vif)
1288 struct ath9k_htc_priv *priv = hw->priv;
1289 struct ath_common *common = ath9k_hw_common(priv->ah);
1290 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1291 struct ath9k_htc_target_vif hvif;
1295 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1297 mutex_lock(&priv->mutex);
1299 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1300 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1301 hvif.index = avp->index;
1302 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1305 ath9k_htc_remove_station(priv, vif, NULL);
1307 if (vif->type == NL80211_IFTYPE_ADHOC) {
1308 spin_lock_bh(&priv->beacon_lock);
1310 dev_kfree_skb_any(priv->beacon);
1311 priv->beacon = NULL;
1312 spin_unlock_bh(&priv->beacon_lock);
1317 mutex_unlock(&priv->mutex);
1320 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1322 struct ath9k_htc_priv *priv = hw->priv;
1323 struct ath_common *common = ath9k_hw_common(priv->ah);
1324 struct ieee80211_conf *conf = &hw->conf;
1326 mutex_lock(&priv->mutex);
1328 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1329 struct ieee80211_channel *curchan = hw->conf.channel;
1330 int pos = curchan->hw_value;
1331 bool is_cw40 = false;
1333 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1334 curchan->center_freq);
1336 if (check_rc_update(hw, &is_cw40))
1337 ath9k_htc_rc_update(priv, is_cw40);
1339 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1341 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1342 ath_print(common, ATH_DBG_FATAL,
1343 "Unable to set channel\n");
1344 mutex_unlock(&priv->mutex);
1349 if (changed & IEEE80211_CONF_CHANGE_PS) {
1350 if (conf->flags & IEEE80211_CONF_PS) {
1351 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1352 priv->ps_enabled = true;
1354 priv->ps_enabled = false;
1355 cancel_work_sync(&priv->ps_work);
1356 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1360 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1361 if (conf->flags & IEEE80211_CONF_MONITOR) {
1362 if (ath9k_htc_add_monitor_interface(priv))
1363 ath_print(common, ATH_DBG_FATAL,
1364 "Failed to set monitor mode\n");
1366 ath_print(common, ATH_DBG_CONFIG,
1367 "HW opmode set to Monitor mode\n");
1371 mutex_unlock(&priv->mutex);
1376 #define SUPPORTED_FILTERS \
1377 (FIF_PROMISC_IN_BSS | \
1382 FIF_BCN_PRBRESP_PROMISC | \
1385 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1386 unsigned int changed_flags,
1387 unsigned int *total_flags,
1390 struct ath9k_htc_priv *priv = hw->priv;
1393 mutex_lock(&priv->mutex);
1395 ath9k_htc_ps_wakeup(priv);
1396 changed_flags &= SUPPORTED_FILTERS;
1397 *total_flags &= SUPPORTED_FILTERS;
1399 priv->rxfilter = *total_flags;
1400 rfilt = ath9k_htc_calcrxfilter(priv);
1401 ath9k_hw_setrxfilter(priv->ah, rfilt);
1403 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1404 "Set HW RX filter: 0x%x\n", rfilt);
1406 ath9k_htc_ps_restore(priv);
1407 mutex_unlock(&priv->mutex);
1410 static void ath9k_htc_sta_notify(struct ieee80211_hw *hw,
1411 struct ieee80211_vif *vif,
1412 enum sta_notify_cmd cmd,
1413 struct ieee80211_sta *sta)
1415 struct ath9k_htc_priv *priv = hw->priv;
1419 case STA_NOTIFY_ADD:
1420 ret = ath9k_htc_add_station(priv, vif, sta);
1422 ath9k_htc_init_rate(priv, vif, sta);
1424 case STA_NOTIFY_REMOVE:
1425 ath9k_htc_remove_station(priv, vif, sta);
1432 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1433 const struct ieee80211_tx_queue_params *params)
1435 struct ath9k_htc_priv *priv = hw->priv;
1436 struct ath_common *common = ath9k_hw_common(priv->ah);
1437 struct ath9k_tx_queue_info qi;
1440 if (queue >= WME_NUM_AC)
1443 mutex_lock(&priv->mutex);
1445 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1447 qi.tqi_aifs = params->aifs;
1448 qi.tqi_cwmin = params->cw_min;
1449 qi.tqi_cwmax = params->cw_max;
1450 qi.tqi_burstTime = params->txop;
1452 qnum = get_hw_qnum(queue, priv->hwq_map);
1454 ath_print(common, ATH_DBG_CONFIG,
1455 "Configure tx [queue/hwq] [%d/%d], "
1456 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1457 queue, qnum, params->aifs, params->cw_min,
1458 params->cw_max, params->txop);
1460 ret = ath_htc_txq_update(priv, qnum, &qi);
1462 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1464 mutex_unlock(&priv->mutex);
1469 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1470 enum set_key_cmd cmd,
1471 struct ieee80211_vif *vif,
1472 struct ieee80211_sta *sta,
1473 struct ieee80211_key_conf *key)
1475 struct ath9k_htc_priv *priv = hw->priv;
1476 struct ath_common *common = ath9k_hw_common(priv->ah);
1479 if (htc_modparam_nohwcrypt)
1482 mutex_lock(&priv->mutex);
1483 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1484 ath9k_htc_ps_wakeup(priv);
1488 ret = ath9k_cmn_key_config(common, vif, sta, key);
1490 key->hw_key_idx = ret;
1491 /* push IV and Michael MIC generation to stack */
1492 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1493 if (key->alg == ALG_TKIP)
1494 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1495 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1496 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1501 ath9k_cmn_key_delete(common, key);
1507 ath9k_htc_ps_restore(priv);
1508 mutex_unlock(&priv->mutex);
1513 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1514 struct ieee80211_vif *vif,
1515 struct ieee80211_bss_conf *bss_conf,
1518 struct ath9k_htc_priv *priv = hw->priv;
1519 struct ath_hw *ah = priv->ah;
1520 struct ath_common *common = ath9k_hw_common(ah);
1522 mutex_lock(&priv->mutex);
1523 ath9k_htc_ps_wakeup(priv);
1525 if (changed & BSS_CHANGED_ASSOC) {
1526 common->curaid = bss_conf->assoc ?
1528 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1531 if (bss_conf->assoc) {
1532 priv->op_flags |= OP_ASSOCIATED;
1533 ath_start_ani(priv);
1535 priv->op_flags &= ~OP_ASSOCIATED;
1536 cancel_work_sync(&priv->ps_work);
1537 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1541 if (changed & BSS_CHANGED_BSSID) {
1543 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1544 ath9k_hw_write_associd(ah);
1546 ath_print(common, ATH_DBG_CONFIG,
1547 "BSSID: %pM aid: 0x%x\n",
1548 common->curbssid, common->curaid);
1551 if ((changed & BSS_CHANGED_BEACON_INT) ||
1552 (changed & BSS_CHANGED_BEACON) ||
1553 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1554 bss_conf->enable_beacon)) {
1555 priv->op_flags |= OP_ENABLE_BEACON;
1556 ath9k_htc_beacon_config(priv, vif);
1559 if (changed & BSS_CHANGED_BEACON)
1560 ath9k_htc_beacon_update(priv, vif);
1562 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1563 !bss_conf->enable_beacon) {
1564 priv->op_flags &= ~OP_ENABLE_BEACON;
1565 ath9k_htc_beacon_config(priv, vif);
1568 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1569 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1570 bss_conf->use_short_preamble);
1571 if (bss_conf->use_short_preamble)
1572 priv->op_flags |= OP_PREAMBLE_SHORT;
1574 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1577 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1578 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1579 bss_conf->use_cts_prot);
1580 if (bss_conf->use_cts_prot &&
1581 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1582 priv->op_flags |= OP_PROTECT_ENABLE;
1584 priv->op_flags &= ~OP_PROTECT_ENABLE;
1587 if (changed & BSS_CHANGED_ERP_SLOT) {
1588 if (bss_conf->use_short_slot)
1593 ath9k_hw_init_global_settings(ah);
1596 ath9k_htc_ps_restore(priv);
1597 mutex_unlock(&priv->mutex);
1600 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1602 struct ath9k_htc_priv *priv = hw->priv;
1605 mutex_lock(&priv->mutex);
1606 tsf = ath9k_hw_gettsf64(priv->ah);
1607 mutex_unlock(&priv->mutex);
1612 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1614 struct ath9k_htc_priv *priv = hw->priv;
1616 mutex_lock(&priv->mutex);
1617 ath9k_hw_settsf64(priv->ah, tsf);
1618 mutex_unlock(&priv->mutex);
1621 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1623 struct ath9k_htc_priv *priv = hw->priv;
1625 ath9k_htc_ps_wakeup(priv);
1626 mutex_lock(&priv->mutex);
1627 ath9k_hw_reset_tsf(priv->ah);
1628 mutex_unlock(&priv->mutex);
1629 ath9k_htc_ps_restore(priv);
1632 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1633 struct ieee80211_vif *vif,
1634 enum ieee80211_ampdu_mlme_action action,
1635 struct ieee80211_sta *sta,
1638 struct ath9k_htc_priv *priv = hw->priv;
1639 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1640 struct ath9k_htc_sta *ista;
1643 case IEEE80211_AMPDU_RX_START:
1645 case IEEE80211_AMPDU_RX_STOP:
1647 case IEEE80211_AMPDU_TX_START:
1648 case IEEE80211_AMPDU_TX_STOP:
1649 if (!(priv->op_flags & OP_TXAGGR))
1651 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1654 work->action = action;
1656 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1658 case IEEE80211_AMPDU_TX_OPERATIONAL:
1659 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1660 ista->tid_state[tid] = AGGR_OPERATIONAL;
1663 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1664 "Unknown AMPDU action\n");
1670 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1672 struct ath9k_htc_priv *priv = hw->priv;
1674 mutex_lock(&priv->mutex);
1675 spin_lock_bh(&priv->beacon_lock);
1676 priv->op_flags |= OP_SCANNING;
1677 spin_unlock_bh(&priv->beacon_lock);
1678 cancel_work_sync(&priv->ps_work);
1679 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1680 mutex_unlock(&priv->mutex);
1683 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1685 struct ath9k_htc_priv *priv = hw->priv;
1687 ath9k_htc_ps_wakeup(priv);
1688 mutex_lock(&priv->mutex);
1689 spin_lock_bh(&priv->beacon_lock);
1690 priv->op_flags &= ~OP_SCANNING;
1691 spin_unlock_bh(&priv->beacon_lock);
1692 priv->op_flags |= OP_FULL_RESET;
1693 if (priv->op_flags & OP_ASSOCIATED)
1694 ath9k_htc_beacon_config(priv, priv->vif);
1695 ath_start_ani(priv);
1696 mutex_unlock(&priv->mutex);
1697 ath9k_htc_ps_restore(priv);
1700 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1705 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1708 struct ath9k_htc_priv *priv = hw->priv;
1710 mutex_lock(&priv->mutex);
1711 priv->ah->coverage_class = coverage_class;
1712 ath9k_hw_init_global_settings(priv->ah);
1713 mutex_unlock(&priv->mutex);
1716 struct ieee80211_ops ath9k_htc_ops = {
1718 .start = ath9k_htc_start,
1719 .stop = ath9k_htc_stop,
1720 .add_interface = ath9k_htc_add_interface,
1721 .remove_interface = ath9k_htc_remove_interface,
1722 .config = ath9k_htc_config,
1723 .configure_filter = ath9k_htc_configure_filter,
1724 .sta_notify = ath9k_htc_sta_notify,
1725 .conf_tx = ath9k_htc_conf_tx,
1726 .bss_info_changed = ath9k_htc_bss_info_changed,
1727 .set_key = ath9k_htc_set_key,
1728 .get_tsf = ath9k_htc_get_tsf,
1729 .set_tsf = ath9k_htc_set_tsf,
1730 .reset_tsf = ath9k_htc_reset_tsf,
1731 .ampdu_action = ath9k_htc_ampdu_action,
1732 .sw_scan_start = ath9k_htc_sw_scan_start,
1733 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1734 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1735 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1736 .set_coverage_class = ath9k_htc_set_coverage_class,