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 = 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);
431 memset(&trate, 0, sizeof(trate));
433 trate = priv->tgt_rate;
436 priv->tgt_rate.capflags |= WLAN_RC_40_FLAG;
438 priv->tgt_rate.capflags &= ~WLAN_RC_40_FLAG;
440 trate.capflags = cpu_to_be32(priv->tgt_rate.capflags);
442 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, &trate);
444 ath_print(common, ATH_DBG_FATAL,
445 "Unable to update Rate information on target\n");
449 ath_print(common, ATH_DBG_CONFIG, "Rate control updated with "
450 "caps:0x%x on target\n", priv->tgt_rate.capflags);
453 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv *priv,
454 struct ieee80211_vif *vif,
455 u8 *sta_addr, u8 tid, bool oper)
457 struct ath_common *common = ath9k_hw_common(priv->ah);
458 struct ath9k_htc_target_aggr aggr;
459 struct ieee80211_sta *sta = NULL;
460 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
464 if (tid > ATH9K_HTC_MAX_TID)
467 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
471 /* Check if we are able to retrieve the station */
472 sta = ieee80211_find_sta(vif, sta_addr);
478 ista = (struct ath9k_htc_sta *) sta->drv_priv;
481 ista->tid_state[tid] = AGGR_START;
483 ista->tid_state[tid] = AGGR_STOP;
485 aggr.sta_index = ista->index;
490 aggr.aggr_enable = oper;
492 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
494 ath_print(common, ATH_DBG_CONFIG,
495 "Unable to %s TX aggregation for (%pM, %d)\n",
496 (oper) ? "start" : "stop", sta->addr, tid);
498 ath_print(common, ATH_DBG_CONFIG,
499 "%s aggregation for (%pM, %d)\n",
500 (oper) ? "Starting" : "Stopping", sta->addr, tid);
505 void ath9k_htc_aggr_work(struct work_struct *work)
508 struct ath9k_htc_priv *priv =
509 container_of(work, struct ath9k_htc_priv,
510 ath9k_aggr_work.work);
511 struct ath9k_htc_aggr_work *wk = &priv->aggr_work;
513 mutex_lock(&wk->mutex);
515 switch (wk->action) {
516 case IEEE80211_AMPDU_TX_START:
517 ret = ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
520 ieee80211_start_tx_ba_cb(wk->vif, wk->sta_addr,
523 case IEEE80211_AMPDU_TX_STOP:
524 ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
526 ieee80211_stop_tx_ba_cb(wk->vif, wk->sta_addr, wk->tid);
529 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
530 "Unknown AMPDU action\n");
533 mutex_unlock(&wk->mutex);
540 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
542 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
544 file->private_data = inode->i_private;
548 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
549 size_t count, loff_t *ppos)
551 struct ath9k_htc_priv *priv =
552 (struct ath9k_htc_priv *) file->private_data;
553 struct ath9k_htc_target_stats cmd_rsp;
555 unsigned int len = 0;
558 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
560 WMI_CMD(WMI_TGT_STATS_CMDID);
565 len += snprintf(buf + len, sizeof(buf) - len,
566 "%19s : %10u\n", "TX Short Retries",
567 be32_to_cpu(cmd_rsp.tx_shortretry));
568 len += snprintf(buf + len, sizeof(buf) - len,
569 "%19s : %10u\n", "TX Long Retries",
570 be32_to_cpu(cmd_rsp.tx_longretry));
571 len += snprintf(buf + len, sizeof(buf) - len,
572 "%19s : %10u\n", "TX Xretries",
573 be32_to_cpu(cmd_rsp.tx_xretries));
574 len += snprintf(buf + len, sizeof(buf) - len,
575 "%19s : %10u\n", "TX Unaggr. Xretries",
576 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
577 len += snprintf(buf + len, sizeof(buf) - len,
578 "%19s : %10u\n", "TX Xretries (HT)",
579 be32_to_cpu(cmd_rsp.ht_tx_xretries));
580 len += snprintf(buf + len, sizeof(buf) - len,
581 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
583 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
586 static const struct file_operations fops_tgt_stats = {
587 .read = read_file_tgt_stats,
588 .open = ath9k_debugfs_open,
592 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
593 size_t count, loff_t *ppos)
595 struct ath9k_htc_priv *priv =
596 (struct ath9k_htc_priv *) file->private_data;
598 unsigned int len = 0;
600 len += snprintf(buf + len, sizeof(buf) - len,
601 "%20s : %10u\n", "Buffers queued",
602 priv->debug.tx_stats.buf_queued);
603 len += snprintf(buf + len, sizeof(buf) - len,
604 "%20s : %10u\n", "Buffers completed",
605 priv->debug.tx_stats.buf_completed);
606 len += snprintf(buf + len, sizeof(buf) - len,
607 "%20s : %10u\n", "SKBs queued",
608 priv->debug.tx_stats.skb_queued);
609 len += snprintf(buf + len, sizeof(buf) - len,
610 "%20s : %10u\n", "SKBs completed",
611 priv->debug.tx_stats.skb_completed);
613 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
616 static const struct file_operations fops_xmit = {
617 .read = read_file_xmit,
618 .open = ath9k_debugfs_open,
622 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
623 size_t count, loff_t *ppos)
625 struct ath9k_htc_priv *priv =
626 (struct ath9k_htc_priv *) file->private_data;
628 unsigned int len = 0;
630 len += snprintf(buf + len, sizeof(buf) - len,
631 "%20s : %10u\n", "SKBs allocated",
632 priv->debug.rx_stats.skb_allocated);
633 len += snprintf(buf + len, sizeof(buf) - len,
634 "%20s : %10u\n", "SKBs completed",
635 priv->debug.rx_stats.skb_completed);
636 len += snprintf(buf + len, sizeof(buf) - len,
637 "%20s : %10u\n", "SKBs Dropped",
638 priv->debug.rx_stats.skb_dropped);
640 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
643 static const struct file_operations fops_recv = {
644 .read = read_file_recv,
645 .open = ath9k_debugfs_open,
649 int ath9k_htc_init_debug(struct ath_hw *ah)
651 struct ath_common *common = ath9k_hw_common(ah);
652 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
654 if (!ath9k_debugfs_root)
657 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
659 if (!priv->debug.debugfs_phy)
662 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
663 priv->debug.debugfs_phy,
664 priv, &fops_tgt_stats);
665 if (!priv->debug.debugfs_tgt_stats)
669 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
670 priv->debug.debugfs_phy,
672 if (!priv->debug.debugfs_xmit)
675 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
676 priv->debug.debugfs_phy,
678 if (!priv->debug.debugfs_recv)
684 ath9k_htc_exit_debug(ah);
688 void ath9k_htc_exit_debug(struct ath_hw *ah)
690 struct ath_common *common = ath9k_hw_common(ah);
691 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
693 debugfs_remove(priv->debug.debugfs_recv);
694 debugfs_remove(priv->debug.debugfs_xmit);
695 debugfs_remove(priv->debug.debugfs_tgt_stats);
696 debugfs_remove(priv->debug.debugfs_phy);
699 int ath9k_htc_debug_create_root(void)
701 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
702 if (!ath9k_debugfs_root)
708 void ath9k_htc_debug_remove_root(void)
710 debugfs_remove(ath9k_debugfs_root);
711 ath9k_debugfs_root = NULL;
714 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
720 static void ath_start_ani(struct ath9k_htc_priv *priv)
722 struct ath_common *common = ath9k_hw_common(priv->ah);
723 unsigned long timestamp = jiffies_to_msecs(jiffies);
725 common->ani.longcal_timer = timestamp;
726 common->ani.shortcal_timer = timestamp;
727 common->ani.checkani_timer = timestamp;
729 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
730 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
733 void ath9k_ani_work(struct work_struct *work)
735 struct ath9k_htc_priv *priv =
736 container_of(work, struct ath9k_htc_priv,
737 ath9k_ani_work.work);
738 struct ath_hw *ah = priv->ah;
739 struct ath_common *common = ath9k_hw_common(ah);
740 bool longcal = false;
741 bool shortcal = false;
742 bool aniflag = false;
743 unsigned int timestamp = jiffies_to_msecs(jiffies);
744 u32 cal_interval, short_cal_interval;
746 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
748 /* Only calibrate if awake */
749 if (ah->power_mode != ATH9K_PM_AWAKE)
752 /* Long calibration runs independently of short calibration. */
753 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
755 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
756 common->ani.longcal_timer = timestamp;
759 /* Short calibration applies only while caldone is false */
760 if (!common->ani.caldone) {
761 if ((timestamp - common->ani.shortcal_timer) >=
762 short_cal_interval) {
764 ath_print(common, ATH_DBG_ANI,
765 "shortcal @%lu\n", jiffies);
766 common->ani.shortcal_timer = timestamp;
767 common->ani.resetcal_timer = timestamp;
770 if ((timestamp - common->ani.resetcal_timer) >=
771 ATH_RESTART_CALINTERVAL) {
772 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
773 if (common->ani.caldone)
774 common->ani.resetcal_timer = timestamp;
778 /* Verify whether we must check ANI */
779 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
781 common->ani.checkani_timer = timestamp;
784 /* Skip all processing if there's nothing to do. */
785 if (longcal || shortcal || aniflag) {
787 ath9k_htc_ps_wakeup(priv);
789 /* Call ANI routine if necessary */
791 ath9k_hw_ani_monitor(ah, ah->curchan);
793 /* Perform calibration if necessary */
794 if (longcal || shortcal) {
795 common->ani.caldone =
796 ath9k_hw_calibrate(ah, ah->curchan,
797 common->rx_chainmask,
801 common->ani.noise_floor =
802 ath9k_hw_getchan_noise(ah, ah->curchan);
804 ath_print(common, ATH_DBG_ANI,
805 " calibrate chan %u/%x nf: %d\n",
806 ah->curchan->channel,
807 ah->curchan->channelFlags,
808 common->ani.noise_floor);
811 ath9k_htc_ps_restore(priv);
816 * Set timer interval based on previous results.
817 * The interval must be the shortest necessary to satisfy ANI,
818 * short calibration and long calibration.
820 cal_interval = ATH_LONG_CALINTERVAL;
821 if (priv->ah->config.enable_ani)
822 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
823 if (!common->ani.caldone)
824 cal_interval = min(cal_interval, (u32)short_cal_interval);
826 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
827 msecs_to_jiffies(cal_interval));
834 static void ath9k_led_blink_work(struct work_struct *work)
836 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
837 ath9k_led_blink_work.work);
839 if (!(priv->op_flags & OP_LED_ASSOCIATED))
842 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
843 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
844 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
846 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
847 (priv->op_flags & OP_LED_ON) ? 1 : 0);
849 ieee80211_queue_delayed_work(priv->hw,
850 &priv->ath9k_led_blink_work,
851 (priv->op_flags & OP_LED_ON) ?
852 msecs_to_jiffies(priv->led_off_duration) :
853 msecs_to_jiffies(priv->led_on_duration));
855 priv->led_on_duration = priv->led_on_cnt ?
856 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
857 ATH_LED_ON_DURATION_IDLE;
858 priv->led_off_duration = priv->led_off_cnt ?
859 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
860 ATH_LED_OFF_DURATION_IDLE;
861 priv->led_on_cnt = priv->led_off_cnt = 0;
863 if (priv->op_flags & OP_LED_ON)
864 priv->op_flags &= ~OP_LED_ON;
866 priv->op_flags |= OP_LED_ON;
869 static void ath9k_led_brightness_work(struct work_struct *work)
871 struct ath_led *led = container_of(work, struct ath_led,
872 brightness_work.work);
873 struct ath9k_htc_priv *priv = led->priv;
875 switch (led->brightness) {
877 if (led->led_type == ATH_LED_ASSOC ||
878 led->led_type == ATH_LED_RADIO) {
879 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
880 (led->led_type == ATH_LED_RADIO));
881 priv->op_flags &= ~OP_LED_ASSOCIATED;
882 if (led->led_type == ATH_LED_RADIO)
883 priv->op_flags &= ~OP_LED_ON;
889 if (led->led_type == ATH_LED_ASSOC) {
890 priv->op_flags |= OP_LED_ASSOCIATED;
891 ieee80211_queue_delayed_work(priv->hw,
892 &priv->ath9k_led_blink_work, 0);
893 } else if (led->led_type == ATH_LED_RADIO) {
894 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
895 priv->op_flags |= OP_LED_ON;
905 static void ath9k_led_brightness(struct led_classdev *led_cdev,
906 enum led_brightness brightness)
908 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
909 struct ath9k_htc_priv *priv = led->priv;
911 led->brightness = brightness;
912 if (!(priv->op_flags & OP_LED_DEINIT))
913 ieee80211_queue_delayed_work(priv->hw,
914 &led->brightness_work, 0);
917 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
919 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
920 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
921 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
922 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
925 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
931 led->led_cdev.name = led->name;
932 led->led_cdev.default_trigger = trigger;
933 led->led_cdev.brightness_set = ath9k_led_brightness;
935 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
937 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
938 "Failed to register led:%s", led->name);
942 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
947 static void ath9k_unregister_led(struct ath_led *led)
949 if (led->registered) {
950 led_classdev_unregister(&led->led_cdev);
955 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
957 priv->op_flags |= OP_LED_DEINIT;
958 ath9k_unregister_led(&priv->assoc_led);
959 priv->op_flags &= ~OP_LED_ASSOCIATED;
960 ath9k_unregister_led(&priv->tx_led);
961 ath9k_unregister_led(&priv->rx_led);
962 ath9k_unregister_led(&priv->radio_led);
965 void ath9k_init_leds(struct ath9k_htc_priv *priv)
970 if (AR_SREV_9287(priv->ah))
971 priv->ah->led_pin = ATH_LED_PIN_9287;
972 else if (AR_SREV_9271(priv->ah))
973 priv->ah->led_pin = ATH_LED_PIN_9271;
975 priv->ah->led_pin = ATH_LED_PIN_DEF;
977 /* Configure gpio 1 for output */
978 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
979 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
980 /* LED off, active low */
981 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
983 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
985 trigger = ieee80211_get_radio_led_name(priv->hw);
986 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
987 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
988 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
989 priv->radio_led.led_type = ATH_LED_RADIO;
993 trigger = ieee80211_get_assoc_led_name(priv->hw);
994 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
995 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
996 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
997 priv->assoc_led.led_type = ATH_LED_ASSOC;
1001 trigger = ieee80211_get_tx_led_name(priv->hw);
1002 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
1003 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
1004 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
1005 priv->tx_led.led_type = ATH_LED_TX;
1009 trigger = ieee80211_get_rx_led_name(priv->hw);
1010 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
1011 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
1012 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
1013 priv->rx_led.led_type = ATH_LED_RX;
1017 priv->op_flags &= ~OP_LED_DEINIT;
1022 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1023 ath9k_deinit_leds(priv);
1026 /*******************/
1028 /*******************/
1030 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1032 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1033 priv->ah->rfkill_polarity;
1036 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1038 struct ath9k_htc_priv *priv = hw->priv;
1039 bool blocked = !!ath_is_rfkill_set(priv);
1041 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1044 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1046 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1047 wiphy_rfkill_start_polling(priv->hw->wiphy);
1050 /**********************/
1051 /* mac80211 Callbacks */
1052 /**********************/
1054 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1056 struct ieee80211_hdr *hdr;
1057 struct ath9k_htc_priv *priv = hw->priv;
1058 int padpos, padsize, ret;
1060 hdr = (struct ieee80211_hdr *) skb->data;
1062 /* Add the padding after the header if this is not already done */
1063 padpos = ath9k_cmn_padpos(hdr->frame_control);
1064 padsize = padpos & 3;
1065 if (padsize && skb->len > padpos) {
1066 if (skb_headroom(skb) < padsize)
1068 skb_push(skb, padsize);
1069 memmove(skb->data, skb->data + padsize, padpos);
1072 ret = ath9k_htc_tx_start(priv, skb);
1074 if (ret == -ENOMEM) {
1075 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1076 "Stopping TX queues\n");
1077 ieee80211_stop_queues(hw);
1078 spin_lock_bh(&priv->tx_lock);
1079 priv->tx_queues_stop = true;
1080 spin_unlock_bh(&priv->tx_lock);
1082 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1091 dev_kfree_skb_any(skb);
1095 static int ath9k_htc_start(struct ieee80211_hw *hw)
1097 struct ath9k_htc_priv *priv = hw->priv;
1098 struct ath_hw *ah = priv->ah;
1099 struct ath_common *common = ath9k_hw_common(ah);
1100 struct ieee80211_channel *curchan = hw->conf.channel;
1101 struct ath9k_channel *init_channel;
1103 enum htc_phymode mode;
1107 ath_print(common, ATH_DBG_CONFIG,
1108 "Starting driver with initial channel: %d MHz\n",
1109 curchan->center_freq);
1111 mutex_lock(&priv->mutex);
1113 /* setup initial channel */
1114 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1116 /* Reset SERDES registers */
1117 ath9k_hw_configpcipowersave(ah, 0, 0);
1119 ath9k_hw_htc_resetinit(ah);
1120 ret = ath9k_hw_reset(ah, init_channel, false);
1122 ath_print(common, ATH_DBG_FATAL,
1123 "Unable to reset hardware; reset status %d "
1124 "(freq %u MHz)\n", ret, curchan->center_freq);
1128 ath_update_txpow(priv);
1130 mode = ath9k_htc_get_curmode(priv, init_channel);
1131 htc_mode = cpu_to_be16(mode);
1132 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1136 WMI_CMD(WMI_ATH_INIT_CMDID);
1140 WMI_CMD(WMI_START_RECV_CMDID);
1144 ath9k_host_rx_init(priv);
1146 priv->op_flags &= ~OP_INVALID;
1147 htc_start(priv->htc);
1149 spin_lock_bh(&priv->tx_lock);
1150 priv->tx_queues_stop = false;
1151 spin_unlock_bh(&priv->tx_lock);
1153 ieee80211_wake_queues(hw);
1156 mutex_unlock(&priv->mutex);
1160 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1162 struct ath9k_htc_priv *priv = hw->priv;
1163 struct ath_hw *ah = priv->ah;
1164 struct ath_common *common = ath9k_hw_common(ah);
1168 mutex_lock(&priv->mutex);
1170 if (priv->op_flags & OP_INVALID) {
1171 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1172 mutex_unlock(&priv->mutex);
1176 ath9k_htc_ps_wakeup(priv);
1177 htc_stop(priv->htc);
1178 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1179 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1180 WMI_CMD(WMI_STOP_RECV_CMDID);
1181 ath9k_hw_phy_disable(ah);
1182 ath9k_hw_disable(ah);
1183 ath9k_hw_configpcipowersave(ah, 1, 1);
1184 ath9k_htc_ps_restore(priv);
1185 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1187 cancel_work_sync(&priv->ps_work);
1188 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1189 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1190 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1191 ath9k_led_stop_brightness(priv);
1192 skb_queue_purge(&priv->tx_queue);
1194 /* Remove monitor interface here */
1195 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1196 if (ath9k_htc_remove_monitor_interface(priv))
1197 ath_print(common, ATH_DBG_FATAL,
1198 "Unable to remove monitor interface\n");
1200 ath_print(common, ATH_DBG_CONFIG,
1201 "Monitor interface removed\n");
1204 priv->op_flags |= OP_INVALID;
1205 mutex_unlock(&priv->mutex);
1207 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1210 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1211 struct ieee80211_vif *vif)
1213 struct ath9k_htc_priv *priv = hw->priv;
1214 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1215 struct ath_common *common = ath9k_hw_common(priv->ah);
1216 struct ath9k_htc_target_vif hvif;
1220 mutex_lock(&priv->mutex);
1222 /* Only one interface for now */
1223 if (priv->nvifs > 0) {
1228 ath9k_htc_ps_wakeup(priv);
1229 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1230 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1232 switch (vif->type) {
1233 case NL80211_IFTYPE_STATION:
1234 hvif.opmode = cpu_to_be32(HTC_M_STA);
1236 case NL80211_IFTYPE_ADHOC:
1237 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1240 ath_print(common, ATH_DBG_FATAL,
1241 "Interface type %d not yet supported\n", vif->type);
1246 ath_print(common, ATH_DBG_CONFIG,
1247 "Attach a VIF of type: %d\n", vif->type);
1249 priv->ah->opmode = vif->type;
1251 /* Index starts from zero on the target */
1252 avp->index = hvif.index = priv->nvifs;
1253 hvif.rtsthreshold = cpu_to_be16(2304);
1254 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1261 * We need a node in target to tx mgmt frames
1262 * before association.
1264 ret = ath9k_htc_add_station(priv, vif, NULL);
1268 ret = ath9k_htc_update_cap_target(priv);
1270 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1271 " capability in target \n");
1275 ath9k_htc_ps_restore(priv);
1276 mutex_unlock(&priv->mutex);
1280 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1281 struct ieee80211_vif *vif)
1283 struct ath9k_htc_priv *priv = hw->priv;
1284 struct ath_common *common = ath9k_hw_common(priv->ah);
1285 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1286 struct ath9k_htc_target_vif hvif;
1290 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1292 mutex_lock(&priv->mutex);
1294 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1295 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1296 hvif.index = avp->index;
1297 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1300 ath9k_htc_remove_station(priv, vif, NULL);
1302 if (vif->type == NL80211_IFTYPE_ADHOC) {
1303 spin_lock_bh(&priv->beacon_lock);
1305 dev_kfree_skb_any(priv->beacon);
1306 priv->beacon = NULL;
1307 spin_unlock_bh(&priv->beacon_lock);
1312 mutex_unlock(&priv->mutex);
1315 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1317 struct ath9k_htc_priv *priv = hw->priv;
1318 struct ath_common *common = ath9k_hw_common(priv->ah);
1319 struct ieee80211_conf *conf = &hw->conf;
1321 mutex_lock(&priv->mutex);
1323 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1324 struct ieee80211_channel *curchan = hw->conf.channel;
1325 int pos = curchan->hw_value;
1326 bool is_cw40 = false;
1328 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1329 curchan->center_freq);
1331 if (check_rc_update(hw, &is_cw40))
1332 ath9k_htc_rc_update(priv, is_cw40);
1334 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1336 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1337 ath_print(common, ATH_DBG_FATAL,
1338 "Unable to set channel\n");
1339 mutex_unlock(&priv->mutex);
1344 if (changed & IEEE80211_CONF_CHANGE_PS) {
1345 if (conf->flags & IEEE80211_CONF_PS) {
1346 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1347 priv->ps_enabled = true;
1349 priv->ps_enabled = false;
1350 cancel_work_sync(&priv->ps_work);
1351 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1355 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1356 if (conf->flags & IEEE80211_CONF_MONITOR) {
1357 if (ath9k_htc_add_monitor_interface(priv))
1358 ath_print(common, ATH_DBG_FATAL,
1359 "Failed to set monitor mode\n");
1361 ath_print(common, ATH_DBG_CONFIG,
1362 "HW opmode set to Monitor mode\n");
1366 mutex_unlock(&priv->mutex);
1371 #define SUPPORTED_FILTERS \
1372 (FIF_PROMISC_IN_BSS | \
1377 FIF_BCN_PRBRESP_PROMISC | \
1380 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1381 unsigned int changed_flags,
1382 unsigned int *total_flags,
1385 struct ath9k_htc_priv *priv = hw->priv;
1388 mutex_lock(&priv->mutex);
1390 ath9k_htc_ps_wakeup(priv);
1391 changed_flags &= SUPPORTED_FILTERS;
1392 *total_flags &= SUPPORTED_FILTERS;
1394 priv->rxfilter = *total_flags;
1395 rfilt = ath9k_htc_calcrxfilter(priv);
1396 ath9k_hw_setrxfilter(priv->ah, rfilt);
1398 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1399 "Set HW RX filter: 0x%x\n", rfilt);
1401 ath9k_htc_ps_restore(priv);
1402 mutex_unlock(&priv->mutex);
1405 static void ath9k_htc_sta_notify(struct ieee80211_hw *hw,
1406 struct ieee80211_vif *vif,
1407 enum sta_notify_cmd cmd,
1408 struct ieee80211_sta *sta)
1410 struct ath9k_htc_priv *priv = hw->priv;
1414 case STA_NOTIFY_ADD:
1415 ret = ath9k_htc_add_station(priv, vif, sta);
1417 ath9k_htc_init_rate(priv, vif, sta);
1419 case STA_NOTIFY_REMOVE:
1420 ath9k_htc_remove_station(priv, vif, sta);
1427 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1428 const struct ieee80211_tx_queue_params *params)
1430 struct ath9k_htc_priv *priv = hw->priv;
1431 struct ath_common *common = ath9k_hw_common(priv->ah);
1432 struct ath9k_tx_queue_info qi;
1435 if (queue >= WME_NUM_AC)
1438 mutex_lock(&priv->mutex);
1440 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1442 qi.tqi_aifs = params->aifs;
1443 qi.tqi_cwmin = params->cw_min;
1444 qi.tqi_cwmax = params->cw_max;
1445 qi.tqi_burstTime = params->txop;
1447 qnum = get_hw_qnum(queue, priv->hwq_map);
1449 ath_print(common, ATH_DBG_CONFIG,
1450 "Configure tx [queue/hwq] [%d/%d], "
1451 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1452 queue, qnum, params->aifs, params->cw_min,
1453 params->cw_max, params->txop);
1455 ret = ath_htc_txq_update(priv, qnum, &qi);
1457 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1459 mutex_unlock(&priv->mutex);
1464 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1465 enum set_key_cmd cmd,
1466 struct ieee80211_vif *vif,
1467 struct ieee80211_sta *sta,
1468 struct ieee80211_key_conf *key)
1470 struct ath9k_htc_priv *priv = hw->priv;
1471 struct ath_common *common = ath9k_hw_common(priv->ah);
1474 if (htc_modparam_nohwcrypt)
1477 mutex_lock(&priv->mutex);
1478 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1479 ath9k_htc_ps_wakeup(priv);
1483 ret = ath9k_cmn_key_config(common, vif, sta, key);
1485 key->hw_key_idx = ret;
1486 /* push IV and Michael MIC generation to stack */
1487 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1488 if (key->alg == ALG_TKIP)
1489 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1490 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1491 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1496 ath9k_cmn_key_delete(common, key);
1502 ath9k_htc_ps_restore(priv);
1503 mutex_unlock(&priv->mutex);
1508 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1509 struct ieee80211_vif *vif,
1510 struct ieee80211_bss_conf *bss_conf,
1513 struct ath9k_htc_priv *priv = hw->priv;
1514 struct ath_hw *ah = priv->ah;
1515 struct ath_common *common = ath9k_hw_common(ah);
1517 mutex_lock(&priv->mutex);
1518 ath9k_htc_ps_wakeup(priv);
1520 if (changed & BSS_CHANGED_ASSOC) {
1521 common->curaid = bss_conf->assoc ?
1523 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1526 if (bss_conf->assoc) {
1527 priv->op_flags |= OP_ASSOCIATED;
1528 ath_start_ani(priv);
1530 priv->op_flags &= ~OP_ASSOCIATED;
1531 cancel_work_sync(&priv->ps_work);
1532 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1536 if (changed & BSS_CHANGED_BSSID) {
1538 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1539 ath9k_hw_write_associd(ah);
1541 ath_print(common, ATH_DBG_CONFIG,
1542 "BSSID: %pM aid: 0x%x\n",
1543 common->curbssid, common->curaid);
1546 if ((changed & BSS_CHANGED_BEACON_INT) ||
1547 (changed & BSS_CHANGED_BEACON) ||
1548 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1549 bss_conf->enable_beacon)) {
1550 priv->op_flags |= OP_ENABLE_BEACON;
1551 ath9k_htc_beacon_config(priv, vif);
1554 if (changed & BSS_CHANGED_BEACON)
1555 ath9k_htc_beacon_update(priv, vif);
1557 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1558 !bss_conf->enable_beacon) {
1559 priv->op_flags &= ~OP_ENABLE_BEACON;
1560 ath9k_htc_beacon_config(priv, vif);
1563 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1564 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1565 bss_conf->use_short_preamble);
1566 if (bss_conf->use_short_preamble)
1567 priv->op_flags |= OP_PREAMBLE_SHORT;
1569 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1572 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1573 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1574 bss_conf->use_cts_prot);
1575 if (bss_conf->use_cts_prot &&
1576 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1577 priv->op_flags |= OP_PROTECT_ENABLE;
1579 priv->op_flags &= ~OP_PROTECT_ENABLE;
1582 if (changed & BSS_CHANGED_ERP_SLOT) {
1583 if (bss_conf->use_short_slot)
1588 ath9k_hw_init_global_settings(ah);
1591 ath9k_htc_ps_restore(priv);
1592 mutex_unlock(&priv->mutex);
1595 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1597 struct ath9k_htc_priv *priv = hw->priv;
1600 mutex_lock(&priv->mutex);
1601 tsf = ath9k_hw_gettsf64(priv->ah);
1602 mutex_unlock(&priv->mutex);
1607 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1609 struct ath9k_htc_priv *priv = hw->priv;
1611 mutex_lock(&priv->mutex);
1612 ath9k_hw_settsf64(priv->ah, tsf);
1613 mutex_unlock(&priv->mutex);
1616 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1618 struct ath9k_htc_priv *priv = hw->priv;
1620 ath9k_htc_ps_wakeup(priv);
1621 mutex_lock(&priv->mutex);
1622 ath9k_hw_reset_tsf(priv->ah);
1623 mutex_unlock(&priv->mutex);
1624 ath9k_htc_ps_restore(priv);
1627 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1628 struct ieee80211_vif *vif,
1629 enum ieee80211_ampdu_mlme_action action,
1630 struct ieee80211_sta *sta,
1633 struct ath9k_htc_priv *priv = hw->priv;
1634 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1635 struct ath9k_htc_sta *ista;
1638 case IEEE80211_AMPDU_RX_START:
1640 case IEEE80211_AMPDU_RX_STOP:
1642 case IEEE80211_AMPDU_TX_START:
1643 case IEEE80211_AMPDU_TX_STOP:
1644 if (!(priv->op_flags & OP_TXAGGR))
1646 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1649 work->action = action;
1651 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1653 case IEEE80211_AMPDU_TX_OPERATIONAL:
1654 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1655 ista->tid_state[tid] = AGGR_OPERATIONAL;
1658 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1659 "Unknown AMPDU action\n");
1665 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1667 struct ath9k_htc_priv *priv = hw->priv;
1669 mutex_lock(&priv->mutex);
1670 spin_lock_bh(&priv->beacon_lock);
1671 priv->op_flags |= OP_SCANNING;
1672 spin_unlock_bh(&priv->beacon_lock);
1673 cancel_work_sync(&priv->ps_work);
1674 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1675 mutex_unlock(&priv->mutex);
1678 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1680 struct ath9k_htc_priv *priv = hw->priv;
1682 ath9k_htc_ps_wakeup(priv);
1683 mutex_lock(&priv->mutex);
1684 spin_lock_bh(&priv->beacon_lock);
1685 priv->op_flags &= ~OP_SCANNING;
1686 spin_unlock_bh(&priv->beacon_lock);
1687 priv->op_flags |= OP_FULL_RESET;
1688 if (priv->op_flags & OP_ASSOCIATED)
1689 ath9k_htc_beacon_config(priv, priv->vif);
1690 ath_start_ani(priv);
1691 mutex_unlock(&priv->mutex);
1692 ath9k_htc_ps_restore(priv);
1695 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1700 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1703 struct ath9k_htc_priv *priv = hw->priv;
1705 mutex_lock(&priv->mutex);
1706 priv->ah->coverage_class = coverage_class;
1707 ath9k_hw_init_global_settings(priv->ah);
1708 mutex_unlock(&priv->mutex);
1711 struct ieee80211_ops ath9k_htc_ops = {
1713 .start = ath9k_htc_start,
1714 .stop = ath9k_htc_stop,
1715 .add_interface = ath9k_htc_add_interface,
1716 .remove_interface = ath9k_htc_remove_interface,
1717 .config = ath9k_htc_config,
1718 .configure_filter = ath9k_htc_configure_filter,
1719 .sta_notify = ath9k_htc_sta_notify,
1720 .conf_tx = ath9k_htc_conf_tx,
1721 .bss_info_changed = ath9k_htc_bss_info_changed,
1722 .set_key = ath9k_htc_set_key,
1723 .get_tsf = ath9k_htc_get_tsf,
1724 .set_tsf = ath9k_htc_set_tsf,
1725 .reset_tsf = ath9k_htc_reset_tsf,
1726 .ampdu_action = ath9k_htc_ampdu_action,
1727 .sw_scan_start = ath9k_htc_sw_scan_start,
1728 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1729 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1730 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1731 .set_coverage_class = ath9k_htc_set_coverage_class,