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);
963 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
966 void ath9k_init_leds(struct ath9k_htc_priv *priv)
971 if (AR_SREV_9287(priv->ah))
972 priv->ah->led_pin = ATH_LED_PIN_9287;
973 else if (AR_SREV_9271(priv->ah))
974 priv->ah->led_pin = ATH_LED_PIN_9271;
976 priv->ah->led_pin = ATH_LED_PIN_DEF;
978 /* Configure gpio 1 for output */
979 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
980 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
981 /* LED off, active low */
982 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
984 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
986 trigger = ieee80211_get_radio_led_name(priv->hw);
987 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
988 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
989 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
990 priv->radio_led.led_type = ATH_LED_RADIO;
994 trigger = ieee80211_get_assoc_led_name(priv->hw);
995 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
996 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
997 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
998 priv->assoc_led.led_type = ATH_LED_ASSOC;
1002 trigger = ieee80211_get_tx_led_name(priv->hw);
1003 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
1004 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
1005 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
1006 priv->tx_led.led_type = ATH_LED_TX;
1010 trigger = ieee80211_get_rx_led_name(priv->hw);
1011 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
1012 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
1013 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
1014 priv->rx_led.led_type = ATH_LED_RX;
1018 priv->op_flags &= ~OP_LED_DEINIT;
1023 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1024 ath9k_deinit_leds(priv);
1027 /*******************/
1029 /*******************/
1031 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1033 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1034 priv->ah->rfkill_polarity;
1037 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1039 struct ath9k_htc_priv *priv = hw->priv;
1040 bool blocked = !!ath_is_rfkill_set(priv);
1042 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1045 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1047 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1048 wiphy_rfkill_start_polling(priv->hw->wiphy);
1051 /**********************/
1052 /* mac80211 Callbacks */
1053 /**********************/
1055 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1057 struct ieee80211_hdr *hdr;
1058 struct ath9k_htc_priv *priv = hw->priv;
1059 int padpos, padsize, ret;
1061 hdr = (struct ieee80211_hdr *) skb->data;
1063 /* Add the padding after the header if this is not already done */
1064 padpos = ath9k_cmn_padpos(hdr->frame_control);
1065 padsize = padpos & 3;
1066 if (padsize && skb->len > padpos) {
1067 if (skb_headroom(skb) < padsize)
1069 skb_push(skb, padsize);
1070 memmove(skb->data, skb->data + padsize, padpos);
1073 ret = ath9k_htc_tx_start(priv, skb);
1075 if (ret == -ENOMEM) {
1076 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1077 "Stopping TX queues\n");
1078 ieee80211_stop_queues(hw);
1079 spin_lock_bh(&priv->tx_lock);
1080 priv->tx_queues_stop = true;
1081 spin_unlock_bh(&priv->tx_lock);
1083 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1092 dev_kfree_skb_any(skb);
1096 static int ath9k_htc_start(struct ieee80211_hw *hw)
1098 struct ath9k_htc_priv *priv = hw->priv;
1099 struct ath_hw *ah = priv->ah;
1100 struct ath_common *common = ath9k_hw_common(ah);
1101 struct ieee80211_channel *curchan = hw->conf.channel;
1102 struct ath9k_channel *init_channel;
1104 enum htc_phymode mode;
1108 ath_print(common, ATH_DBG_CONFIG,
1109 "Starting driver with initial channel: %d MHz\n",
1110 curchan->center_freq);
1112 mutex_lock(&priv->mutex);
1114 /* setup initial channel */
1115 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1117 /* Reset SERDES registers */
1118 ath9k_hw_configpcipowersave(ah, 0, 0);
1120 ath9k_hw_htc_resetinit(ah);
1121 ret = ath9k_hw_reset(ah, init_channel, false);
1123 ath_print(common, ATH_DBG_FATAL,
1124 "Unable to reset hardware; reset status %d "
1125 "(freq %u MHz)\n", ret, curchan->center_freq);
1129 ath_update_txpow(priv);
1131 mode = ath9k_htc_get_curmode(priv, init_channel);
1132 htc_mode = cpu_to_be16(mode);
1133 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1137 WMI_CMD(WMI_ATH_INIT_CMDID);
1141 WMI_CMD(WMI_START_RECV_CMDID);
1145 ath9k_host_rx_init(priv);
1147 priv->op_flags &= ~OP_INVALID;
1148 htc_start(priv->htc);
1150 spin_lock_bh(&priv->tx_lock);
1151 priv->tx_queues_stop = false;
1152 spin_unlock_bh(&priv->tx_lock);
1154 ieee80211_wake_queues(hw);
1157 mutex_unlock(&priv->mutex);
1161 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1163 struct ath9k_htc_priv *priv = hw->priv;
1164 struct ath_hw *ah = priv->ah;
1165 struct ath_common *common = ath9k_hw_common(ah);
1169 mutex_lock(&priv->mutex);
1171 if (priv->op_flags & OP_INVALID) {
1172 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1173 mutex_unlock(&priv->mutex);
1177 ath9k_htc_ps_wakeup(priv);
1178 htc_stop(priv->htc);
1179 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1180 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1181 WMI_CMD(WMI_STOP_RECV_CMDID);
1182 ath9k_hw_phy_disable(ah);
1183 ath9k_hw_disable(ah);
1184 ath9k_hw_configpcipowersave(ah, 1, 1);
1185 ath9k_htc_ps_restore(priv);
1186 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1188 cancel_work_sync(&priv->ps_work);
1189 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1190 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1191 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1192 ath9k_led_stop_brightness(priv);
1193 skb_queue_purge(&priv->tx_queue);
1195 /* Remove monitor interface here */
1196 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1197 if (ath9k_htc_remove_monitor_interface(priv))
1198 ath_print(common, ATH_DBG_FATAL,
1199 "Unable to remove monitor interface\n");
1201 ath_print(common, ATH_DBG_CONFIG,
1202 "Monitor interface removed\n");
1205 priv->op_flags |= OP_INVALID;
1206 mutex_unlock(&priv->mutex);
1208 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1211 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1212 struct ieee80211_vif *vif)
1214 struct ath9k_htc_priv *priv = hw->priv;
1215 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1216 struct ath_common *common = ath9k_hw_common(priv->ah);
1217 struct ath9k_htc_target_vif hvif;
1221 mutex_lock(&priv->mutex);
1223 /* Only one interface for now */
1224 if (priv->nvifs > 0) {
1229 ath9k_htc_ps_wakeup(priv);
1230 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1231 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1233 switch (vif->type) {
1234 case NL80211_IFTYPE_STATION:
1235 hvif.opmode = cpu_to_be32(HTC_M_STA);
1237 case NL80211_IFTYPE_ADHOC:
1238 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1241 ath_print(common, ATH_DBG_FATAL,
1242 "Interface type %d not yet supported\n", vif->type);
1247 ath_print(common, ATH_DBG_CONFIG,
1248 "Attach a VIF of type: %d\n", vif->type);
1250 priv->ah->opmode = vif->type;
1252 /* Index starts from zero on the target */
1253 avp->index = hvif.index = priv->nvifs;
1254 hvif.rtsthreshold = cpu_to_be16(2304);
1255 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1262 * We need a node in target to tx mgmt frames
1263 * before association.
1265 ret = ath9k_htc_add_station(priv, vif, NULL);
1269 ret = ath9k_htc_update_cap_target(priv);
1271 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1272 " capability in target \n");
1276 ath9k_htc_ps_restore(priv);
1277 mutex_unlock(&priv->mutex);
1281 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1282 struct ieee80211_vif *vif)
1284 struct ath9k_htc_priv *priv = hw->priv;
1285 struct ath_common *common = ath9k_hw_common(priv->ah);
1286 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1287 struct ath9k_htc_target_vif hvif;
1291 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1293 mutex_lock(&priv->mutex);
1295 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1296 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1297 hvif.index = avp->index;
1298 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1301 ath9k_htc_remove_station(priv, vif, NULL);
1303 if (vif->type == NL80211_IFTYPE_ADHOC) {
1304 spin_lock_bh(&priv->beacon_lock);
1306 dev_kfree_skb_any(priv->beacon);
1307 priv->beacon = NULL;
1308 spin_unlock_bh(&priv->beacon_lock);
1313 mutex_unlock(&priv->mutex);
1316 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1318 struct ath9k_htc_priv *priv = hw->priv;
1319 struct ath_common *common = ath9k_hw_common(priv->ah);
1320 struct ieee80211_conf *conf = &hw->conf;
1322 mutex_lock(&priv->mutex);
1324 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1325 struct ieee80211_channel *curchan = hw->conf.channel;
1326 int pos = curchan->hw_value;
1327 bool is_cw40 = false;
1329 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1330 curchan->center_freq);
1332 if (check_rc_update(hw, &is_cw40))
1333 ath9k_htc_rc_update(priv, is_cw40);
1335 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1337 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1338 ath_print(common, ATH_DBG_FATAL,
1339 "Unable to set channel\n");
1340 mutex_unlock(&priv->mutex);
1345 if (changed & IEEE80211_CONF_CHANGE_PS) {
1346 if (conf->flags & IEEE80211_CONF_PS) {
1347 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1348 priv->ps_enabled = true;
1350 priv->ps_enabled = false;
1351 cancel_work_sync(&priv->ps_work);
1352 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1356 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1357 if (conf->flags & IEEE80211_CONF_MONITOR) {
1358 if (ath9k_htc_add_monitor_interface(priv))
1359 ath_print(common, ATH_DBG_FATAL,
1360 "Failed to set monitor mode\n");
1362 ath_print(common, ATH_DBG_CONFIG,
1363 "HW opmode set to Monitor mode\n");
1367 mutex_unlock(&priv->mutex);
1372 #define SUPPORTED_FILTERS \
1373 (FIF_PROMISC_IN_BSS | \
1378 FIF_BCN_PRBRESP_PROMISC | \
1381 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1382 unsigned int changed_flags,
1383 unsigned int *total_flags,
1386 struct ath9k_htc_priv *priv = hw->priv;
1389 mutex_lock(&priv->mutex);
1391 ath9k_htc_ps_wakeup(priv);
1392 changed_flags &= SUPPORTED_FILTERS;
1393 *total_flags &= SUPPORTED_FILTERS;
1395 priv->rxfilter = *total_flags;
1396 rfilt = ath9k_htc_calcrxfilter(priv);
1397 ath9k_hw_setrxfilter(priv->ah, rfilt);
1399 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1400 "Set HW RX filter: 0x%x\n", rfilt);
1402 ath9k_htc_ps_restore(priv);
1403 mutex_unlock(&priv->mutex);
1406 static void ath9k_htc_sta_notify(struct ieee80211_hw *hw,
1407 struct ieee80211_vif *vif,
1408 enum sta_notify_cmd cmd,
1409 struct ieee80211_sta *sta)
1411 struct ath9k_htc_priv *priv = hw->priv;
1415 case STA_NOTIFY_ADD:
1416 ret = ath9k_htc_add_station(priv, vif, sta);
1418 ath9k_htc_init_rate(priv, vif, sta);
1420 case STA_NOTIFY_REMOVE:
1421 ath9k_htc_remove_station(priv, vif, sta);
1428 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1429 const struct ieee80211_tx_queue_params *params)
1431 struct ath9k_htc_priv *priv = hw->priv;
1432 struct ath_common *common = ath9k_hw_common(priv->ah);
1433 struct ath9k_tx_queue_info qi;
1436 if (queue >= WME_NUM_AC)
1439 mutex_lock(&priv->mutex);
1441 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1443 qi.tqi_aifs = params->aifs;
1444 qi.tqi_cwmin = params->cw_min;
1445 qi.tqi_cwmax = params->cw_max;
1446 qi.tqi_burstTime = params->txop;
1448 qnum = get_hw_qnum(queue, priv->hwq_map);
1450 ath_print(common, ATH_DBG_CONFIG,
1451 "Configure tx [queue/hwq] [%d/%d], "
1452 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1453 queue, qnum, params->aifs, params->cw_min,
1454 params->cw_max, params->txop);
1456 ret = ath_htc_txq_update(priv, qnum, &qi);
1458 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1460 mutex_unlock(&priv->mutex);
1465 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1466 enum set_key_cmd cmd,
1467 struct ieee80211_vif *vif,
1468 struct ieee80211_sta *sta,
1469 struct ieee80211_key_conf *key)
1471 struct ath9k_htc_priv *priv = hw->priv;
1472 struct ath_common *common = ath9k_hw_common(priv->ah);
1475 if (htc_modparam_nohwcrypt)
1478 mutex_lock(&priv->mutex);
1479 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1480 ath9k_htc_ps_wakeup(priv);
1484 ret = ath9k_cmn_key_config(common, vif, sta, key);
1486 key->hw_key_idx = ret;
1487 /* push IV and Michael MIC generation to stack */
1488 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1489 if (key->alg == ALG_TKIP)
1490 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1491 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1492 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1497 ath9k_cmn_key_delete(common, key);
1503 ath9k_htc_ps_restore(priv);
1504 mutex_unlock(&priv->mutex);
1509 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1510 struct ieee80211_vif *vif,
1511 struct ieee80211_bss_conf *bss_conf,
1514 struct ath9k_htc_priv *priv = hw->priv;
1515 struct ath_hw *ah = priv->ah;
1516 struct ath_common *common = ath9k_hw_common(ah);
1518 mutex_lock(&priv->mutex);
1519 ath9k_htc_ps_wakeup(priv);
1521 if (changed & BSS_CHANGED_ASSOC) {
1522 common->curaid = bss_conf->assoc ?
1524 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1527 if (bss_conf->assoc) {
1528 priv->op_flags |= OP_ASSOCIATED;
1529 ath_start_ani(priv);
1531 priv->op_flags &= ~OP_ASSOCIATED;
1532 cancel_work_sync(&priv->ps_work);
1533 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1537 if (changed & BSS_CHANGED_BSSID) {
1539 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1540 ath9k_hw_write_associd(ah);
1542 ath_print(common, ATH_DBG_CONFIG,
1543 "BSSID: %pM aid: 0x%x\n",
1544 common->curbssid, common->curaid);
1547 if ((changed & BSS_CHANGED_BEACON_INT) ||
1548 (changed & BSS_CHANGED_BEACON) ||
1549 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1550 bss_conf->enable_beacon)) {
1551 priv->op_flags |= OP_ENABLE_BEACON;
1552 ath9k_htc_beacon_config(priv, vif, bss_conf);
1555 if (changed & BSS_CHANGED_BEACON)
1556 ath9k_htc_beacon_update(priv, vif);
1558 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1559 !bss_conf->enable_beacon) {
1560 priv->op_flags &= ~OP_ENABLE_BEACON;
1561 ath9k_htc_beacon_config(priv, vif, bss_conf);
1564 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1565 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1566 bss_conf->use_short_preamble);
1567 if (bss_conf->use_short_preamble)
1568 priv->op_flags |= OP_PREAMBLE_SHORT;
1570 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1573 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1574 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1575 bss_conf->use_cts_prot);
1576 if (bss_conf->use_cts_prot &&
1577 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1578 priv->op_flags |= OP_PROTECT_ENABLE;
1580 priv->op_flags &= ~OP_PROTECT_ENABLE;
1583 if (changed & BSS_CHANGED_ERP_SLOT) {
1584 if (bss_conf->use_short_slot)
1589 ath9k_hw_init_global_settings(ah);
1592 ath9k_htc_ps_restore(priv);
1593 mutex_unlock(&priv->mutex);
1596 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1598 struct ath9k_htc_priv *priv = hw->priv;
1601 mutex_lock(&priv->mutex);
1602 tsf = ath9k_hw_gettsf64(priv->ah);
1603 mutex_unlock(&priv->mutex);
1608 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1610 struct ath9k_htc_priv *priv = hw->priv;
1612 mutex_lock(&priv->mutex);
1613 ath9k_hw_settsf64(priv->ah, tsf);
1614 mutex_unlock(&priv->mutex);
1617 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1619 struct ath9k_htc_priv *priv = hw->priv;
1621 ath9k_htc_ps_wakeup(priv);
1622 mutex_lock(&priv->mutex);
1623 ath9k_hw_reset_tsf(priv->ah);
1624 mutex_unlock(&priv->mutex);
1625 ath9k_htc_ps_restore(priv);
1628 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1629 struct ieee80211_vif *vif,
1630 enum ieee80211_ampdu_mlme_action action,
1631 struct ieee80211_sta *sta,
1634 struct ath9k_htc_priv *priv = hw->priv;
1635 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1636 struct ath9k_htc_sta *ista;
1639 case IEEE80211_AMPDU_RX_START:
1641 case IEEE80211_AMPDU_RX_STOP:
1643 case IEEE80211_AMPDU_TX_START:
1644 case IEEE80211_AMPDU_TX_STOP:
1645 if (!(priv->op_flags & OP_TXAGGR))
1647 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1650 work->action = action;
1652 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1654 case IEEE80211_AMPDU_TX_OPERATIONAL:
1655 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1656 ista->tid_state[tid] = AGGR_OPERATIONAL;
1659 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1660 "Unknown AMPDU action\n");
1666 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1668 struct ath9k_htc_priv *priv = hw->priv;
1670 mutex_lock(&priv->mutex);
1671 spin_lock_bh(&priv->beacon_lock);
1672 priv->op_flags |= OP_SCANNING;
1673 spin_unlock_bh(&priv->beacon_lock);
1674 cancel_work_sync(&priv->ps_work);
1675 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1676 mutex_unlock(&priv->mutex);
1679 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1681 struct ath9k_htc_priv *priv = hw->priv;
1683 ath9k_htc_ps_wakeup(priv);
1684 mutex_lock(&priv->mutex);
1685 spin_lock_bh(&priv->beacon_lock);
1686 priv->op_flags &= ~OP_SCANNING;
1687 spin_unlock_bh(&priv->beacon_lock);
1688 priv->op_flags |= OP_FULL_RESET;
1689 ath_start_ani(priv);
1690 mutex_unlock(&priv->mutex);
1691 ath9k_htc_ps_restore(priv);
1694 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1699 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1702 struct ath9k_htc_priv *priv = hw->priv;
1704 mutex_lock(&priv->mutex);
1705 priv->ah->coverage_class = coverage_class;
1706 ath9k_hw_init_global_settings(priv->ah);
1707 mutex_unlock(&priv->mutex);
1710 struct ieee80211_ops ath9k_htc_ops = {
1712 .start = ath9k_htc_start,
1713 .stop = ath9k_htc_stop,
1714 .add_interface = ath9k_htc_add_interface,
1715 .remove_interface = ath9k_htc_remove_interface,
1716 .config = ath9k_htc_config,
1717 .configure_filter = ath9k_htc_configure_filter,
1718 .sta_notify = ath9k_htc_sta_notify,
1719 .conf_tx = ath9k_htc_conf_tx,
1720 .bss_info_changed = ath9k_htc_bss_info_changed,
1721 .set_key = ath9k_htc_set_key,
1722 .get_tsf = ath9k_htc_get_tsf,
1723 .set_tsf = ath9k_htc_set_tsf,
1724 .reset_tsf = ath9k_htc_reset_tsf,
1725 .ampdu_action = ath9k_htc_ampdu_action,
1726 .sw_scan_start = ath9k_htc_sw_scan_start,
1727 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1728 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1729 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1730 .set_coverage_class = ath9k_htc_set_coverage_class,