2 * Copyright (c) 2010 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
20 static struct dentry *ath9k_debugfs_root;
27 static void ath_update_txpow(struct ath9k_htc_priv *priv)
29 struct ath_hw *ah = priv->ah;
31 if (priv->curtxpow != priv->txpowlimit) {
32 ath9k_hw_set_txpowerlimit(ah, priv->txpowlimit);
33 /* read back in case value is clamped */
34 priv->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
38 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
39 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
40 struct ath9k_channel *ichan)
42 enum htc_phymode mode;
46 switch (ichan->chanmode) {
49 case CHANNEL_G_HT40PLUS:
50 case CHANNEL_G_HT40MINUS:
55 case CHANNEL_A_HT40PLUS:
56 case CHANNEL_A_HT40MINUS:
66 static bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
67 enum ath9k_power_mode mode)
71 mutex_lock(&priv->htc_pm_lock);
72 ret = ath9k_hw_setpower(priv->ah, mode);
73 mutex_unlock(&priv->htc_pm_lock);
78 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
80 mutex_lock(&priv->htc_pm_lock);
81 if (++priv->ps_usecount != 1)
83 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
86 mutex_unlock(&priv->htc_pm_lock);
89 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
91 mutex_lock(&priv->htc_pm_lock);
92 if (--priv->ps_usecount != 0)
96 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
97 else if (priv->ps_enabled)
98 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
101 mutex_unlock(&priv->htc_pm_lock);
104 void ath9k_ps_work(struct work_struct *work)
106 struct ath9k_htc_priv *priv =
107 container_of(work, struct ath9k_htc_priv,
109 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
111 /* The chip wakes up after receiving the first beacon
112 while network sleep is enabled. For the driver to
113 be in sync with the hw, set the chip to awake and
114 only then set it to sleep.
116 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
119 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
120 struct ieee80211_hw *hw,
121 struct ath9k_channel *hchan)
123 struct ath_hw *ah = priv->ah;
124 struct ath_common *common = ath9k_hw_common(ah);
125 struct ieee80211_conf *conf = &common->hw->conf;
127 struct ieee80211_channel *channel = hw->conf.channel;
128 enum htc_phymode mode;
133 if (priv->op_flags & OP_INVALID)
136 if (priv->op_flags & OP_FULL_RESET)
139 /* Fiddle around with fastcc later on, for now just use full reset */
141 ath9k_htc_ps_wakeup(priv);
143 WMI_CMD(WMI_DISABLE_INTR_CMDID);
144 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
145 WMI_CMD(WMI_STOP_RECV_CMDID);
147 ath_print(common, ATH_DBG_CONFIG,
148 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d\n",
149 priv->ah->curchan->channel,
150 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
152 ret = ath9k_hw_reset(ah, hchan, fastcc);
154 ath_print(common, ATH_DBG_FATAL,
155 "Unable to reset channel (%u Mhz) "
156 "reset status %d\n", channel->center_freq, ret);
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 = priv->ah->caps.tx_chainmask;
328 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
330 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
335 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
336 struct ieee80211_sta *sta,
337 struct ath9k_htc_target_rate *trate)
339 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
340 struct ieee80211_supported_band *sband;
344 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
346 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
347 if (sta->supp_rates[sband->band] & BIT(i)) {
348 trate->rates.legacy_rates.rs_rates[j]
349 = (sband->bitrates[i].bitrate * 2) / 10;
353 trate->rates.legacy_rates.rs_nrates = j;
355 if (sta->ht_cap.ht_supported) {
356 for (i = 0, j = 0; i < 77; i++) {
357 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
358 trate->rates.ht_rates.rs_rates[j++] = i;
359 if (j == ATH_HTC_RATE_MAX)
362 trate->rates.ht_rates.rs_nrates = j;
364 caps = WLAN_RC_HT_FLAG;
365 if (sta->ht_cap.mcs.rx_mask[1])
366 caps |= WLAN_RC_DS_FLAG;
367 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
368 caps |= WLAN_RC_40_FLAG;
369 if (conf_is_ht40(&priv->hw->conf) &&
370 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
371 caps |= WLAN_RC_SGI_FLAG;
372 else if (conf_is_ht20(&priv->hw->conf) &&
373 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
374 caps |= WLAN_RC_SGI_FLAG;
377 trate->sta_index = ista->index;
379 trate->capflags = cpu_to_be32(caps);
382 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
383 struct ath9k_htc_target_rate *trate)
385 struct ath_common *common = ath9k_hw_common(priv->ah);
389 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
391 ath_print(common, ATH_DBG_FATAL,
392 "Unable to initialize Rate information on target\n");
398 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
399 struct ieee80211_sta *sta)
401 struct ath_common *common = ath9k_hw_common(priv->ah);
402 struct ath9k_htc_target_rate trate;
405 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
406 ath9k_htc_setup_rate(priv, sta, &trate);
407 ret = ath9k_htc_send_rate_cmd(priv, &trate);
409 ath_print(common, ATH_DBG_CONFIG,
410 "Updated target sta: %pM, rate caps: 0x%X\n",
411 sta->addr, be32_to_cpu(trate.capflags));
414 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
415 struct ieee80211_vif *vif,
416 struct ieee80211_bss_conf *bss_conf)
418 struct ath_common *common = ath9k_hw_common(priv->ah);
419 struct ath9k_htc_target_rate trate;
420 struct ieee80211_sta *sta;
423 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
426 sta = ieee80211_find_sta(vif, bss_conf->bssid);
431 ath9k_htc_setup_rate(priv, sta, &trate);
434 ret = ath9k_htc_send_rate_cmd(priv, &trate);
436 ath_print(common, ATH_DBG_CONFIG,
437 "Updated target sta: %pM, rate caps: 0x%X\n",
438 bss_conf->bssid, be32_to_cpu(trate.capflags));
441 int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
442 struct ieee80211_vif *vif,
443 struct ieee80211_sta *sta,
444 enum ieee80211_ampdu_mlme_action action, u16 tid)
446 struct ath_common *common = ath9k_hw_common(priv->ah);
447 struct ath9k_htc_target_aggr aggr;
448 struct ath9k_htc_sta *ista;
452 if (tid >= ATH9K_HTC_MAX_TID)
455 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
456 ista = (struct ath9k_htc_sta *) sta->drv_priv;
458 aggr.sta_index = ista->index;
459 aggr.tidno = tid & 0xf;
460 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
462 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
464 ath_print(common, ATH_DBG_CONFIG,
465 "Unable to %s TX aggregation for (%pM, %d)\n",
466 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
468 ath_print(common, ATH_DBG_CONFIG,
469 "%s TX aggregation for (%pM, %d)\n",
470 (aggr.aggr_enable) ? "Starting" : "Stopping",
473 spin_lock_bh(&priv->tx_lock);
474 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
475 spin_unlock_bh(&priv->tx_lock);
484 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
486 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
488 file->private_data = inode->i_private;
492 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
493 size_t count, loff_t *ppos)
495 struct ath9k_htc_priv *priv = file->private_data;
496 struct ath9k_htc_target_stats cmd_rsp;
498 unsigned int len = 0;
501 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
503 WMI_CMD(WMI_TGT_STATS_CMDID);
508 len += snprintf(buf + len, sizeof(buf) - len,
509 "%19s : %10u\n", "TX Short Retries",
510 be32_to_cpu(cmd_rsp.tx_shortretry));
511 len += snprintf(buf + len, sizeof(buf) - len,
512 "%19s : %10u\n", "TX Long Retries",
513 be32_to_cpu(cmd_rsp.tx_longretry));
514 len += snprintf(buf + len, sizeof(buf) - len,
515 "%19s : %10u\n", "TX Xretries",
516 be32_to_cpu(cmd_rsp.tx_xretries));
517 len += snprintf(buf + len, sizeof(buf) - len,
518 "%19s : %10u\n", "TX Unaggr. Xretries",
519 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
520 len += snprintf(buf + len, sizeof(buf) - len,
521 "%19s : %10u\n", "TX Xretries (HT)",
522 be32_to_cpu(cmd_rsp.ht_tx_xretries));
523 len += snprintf(buf + len, sizeof(buf) - len,
524 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
526 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
529 static const struct file_operations fops_tgt_stats = {
530 .read = read_file_tgt_stats,
531 .open = ath9k_debugfs_open,
535 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
536 size_t count, loff_t *ppos)
538 struct ath9k_htc_priv *priv = file->private_data;
540 unsigned int len = 0;
542 len += snprintf(buf + len, sizeof(buf) - len,
543 "%20s : %10u\n", "Buffers queued",
544 priv->debug.tx_stats.buf_queued);
545 len += snprintf(buf + len, sizeof(buf) - len,
546 "%20s : %10u\n", "Buffers completed",
547 priv->debug.tx_stats.buf_completed);
548 len += snprintf(buf + len, sizeof(buf) - len,
549 "%20s : %10u\n", "SKBs queued",
550 priv->debug.tx_stats.skb_queued);
551 len += snprintf(buf + len, sizeof(buf) - len,
552 "%20s : %10u\n", "SKBs completed",
553 priv->debug.tx_stats.skb_completed);
554 len += snprintf(buf + len, sizeof(buf) - len,
555 "%20s : %10u\n", "SKBs dropped",
556 priv->debug.tx_stats.skb_dropped);
558 len += snprintf(buf + len, sizeof(buf) - len,
559 "%20s : %10u\n", "BE queued",
560 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
561 len += snprintf(buf + len, sizeof(buf) - len,
562 "%20s : %10u\n", "BK queued",
563 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
564 len += snprintf(buf + len, sizeof(buf) - len,
565 "%20s : %10u\n", "VI queued",
566 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
567 len += snprintf(buf + len, sizeof(buf) - len,
568 "%20s : %10u\n", "VO queued",
569 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
571 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
574 static const struct file_operations fops_xmit = {
575 .read = read_file_xmit,
576 .open = ath9k_debugfs_open,
580 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
581 size_t count, loff_t *ppos)
583 struct ath9k_htc_priv *priv = file->private_data;
585 unsigned int len = 0;
587 len += snprintf(buf + len, sizeof(buf) - len,
588 "%20s : %10u\n", "SKBs allocated",
589 priv->debug.rx_stats.skb_allocated);
590 len += snprintf(buf + len, sizeof(buf) - len,
591 "%20s : %10u\n", "SKBs completed",
592 priv->debug.rx_stats.skb_completed);
593 len += snprintf(buf + len, sizeof(buf) - len,
594 "%20s : %10u\n", "SKBs Dropped",
595 priv->debug.rx_stats.skb_dropped);
597 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
600 static const struct file_operations fops_recv = {
601 .read = read_file_recv,
602 .open = ath9k_debugfs_open,
606 int ath9k_htc_init_debug(struct ath_hw *ah)
608 struct ath_common *common = ath9k_hw_common(ah);
609 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
611 if (!ath9k_debugfs_root)
614 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
616 if (!priv->debug.debugfs_phy)
619 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
620 priv->debug.debugfs_phy,
621 priv, &fops_tgt_stats);
622 if (!priv->debug.debugfs_tgt_stats)
626 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
627 priv->debug.debugfs_phy,
629 if (!priv->debug.debugfs_xmit)
632 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
633 priv->debug.debugfs_phy,
635 if (!priv->debug.debugfs_recv)
641 ath9k_htc_exit_debug(ah);
645 void ath9k_htc_exit_debug(struct ath_hw *ah)
647 struct ath_common *common = ath9k_hw_common(ah);
648 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
650 debugfs_remove(priv->debug.debugfs_recv);
651 debugfs_remove(priv->debug.debugfs_xmit);
652 debugfs_remove(priv->debug.debugfs_tgt_stats);
653 debugfs_remove(priv->debug.debugfs_phy);
656 int ath9k_htc_debug_create_root(void)
658 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
659 if (!ath9k_debugfs_root)
665 void ath9k_htc_debug_remove_root(void)
667 debugfs_remove(ath9k_debugfs_root);
668 ath9k_debugfs_root = NULL;
671 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
677 static void ath_start_ani(struct ath9k_htc_priv *priv)
679 struct ath_common *common = ath9k_hw_common(priv->ah);
680 unsigned long timestamp = jiffies_to_msecs(jiffies);
682 common->ani.longcal_timer = timestamp;
683 common->ani.shortcal_timer = timestamp;
684 common->ani.checkani_timer = timestamp;
686 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
687 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
690 void ath9k_ani_work(struct work_struct *work)
692 struct ath9k_htc_priv *priv =
693 container_of(work, struct ath9k_htc_priv,
694 ath9k_ani_work.work);
695 struct ath_hw *ah = priv->ah;
696 struct ath_common *common = ath9k_hw_common(ah);
697 bool longcal = false;
698 bool shortcal = false;
699 bool aniflag = false;
700 unsigned int timestamp = jiffies_to_msecs(jiffies);
701 u32 cal_interval, short_cal_interval;
703 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
705 /* Only calibrate if awake */
706 if (ah->power_mode != ATH9K_PM_AWAKE)
709 /* Long calibration runs independently of short calibration. */
710 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
712 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
713 common->ani.longcal_timer = timestamp;
716 /* Short calibration applies only while caldone is false */
717 if (!common->ani.caldone) {
718 if ((timestamp - common->ani.shortcal_timer) >=
719 short_cal_interval) {
721 ath_print(common, ATH_DBG_ANI,
722 "shortcal @%lu\n", jiffies);
723 common->ani.shortcal_timer = timestamp;
724 common->ani.resetcal_timer = timestamp;
727 if ((timestamp - common->ani.resetcal_timer) >=
728 ATH_RESTART_CALINTERVAL) {
729 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
730 if (common->ani.caldone)
731 common->ani.resetcal_timer = timestamp;
735 /* Verify whether we must check ANI */
736 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
738 common->ani.checkani_timer = timestamp;
741 /* Skip all processing if there's nothing to do. */
742 if (longcal || shortcal || aniflag) {
744 ath9k_htc_ps_wakeup(priv);
746 /* Call ANI routine if necessary */
748 ath9k_hw_ani_monitor(ah, ah->curchan);
750 /* Perform calibration if necessary */
751 if (longcal || shortcal) {
752 common->ani.caldone =
753 ath9k_hw_calibrate(ah, ah->curchan,
754 common->rx_chainmask,
758 common->ani.noise_floor =
759 ath9k_hw_getchan_noise(ah, ah->curchan);
761 ath_print(common, ATH_DBG_ANI,
762 " calibrate chan %u/%x nf: %d\n",
763 ah->curchan->channel,
764 ah->curchan->channelFlags,
765 common->ani.noise_floor);
768 ath9k_htc_ps_restore(priv);
773 * Set timer interval based on previous results.
774 * The interval must be the shortest necessary to satisfy ANI,
775 * short calibration and long calibration.
777 cal_interval = ATH_LONG_CALINTERVAL;
778 if (priv->ah->config.enable_ani)
779 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
780 if (!common->ani.caldone)
781 cal_interval = min(cal_interval, (u32)short_cal_interval);
783 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
784 msecs_to_jiffies(cal_interval));
791 static void ath9k_led_blink_work(struct work_struct *work)
793 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
794 ath9k_led_blink_work.work);
796 if (!(priv->op_flags & OP_LED_ASSOCIATED))
799 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
800 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
801 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
803 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
804 (priv->op_flags & OP_LED_ON) ? 1 : 0);
806 ieee80211_queue_delayed_work(priv->hw,
807 &priv->ath9k_led_blink_work,
808 (priv->op_flags & OP_LED_ON) ?
809 msecs_to_jiffies(priv->led_off_duration) :
810 msecs_to_jiffies(priv->led_on_duration));
812 priv->led_on_duration = priv->led_on_cnt ?
813 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
814 ATH_LED_ON_DURATION_IDLE;
815 priv->led_off_duration = priv->led_off_cnt ?
816 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
817 ATH_LED_OFF_DURATION_IDLE;
818 priv->led_on_cnt = priv->led_off_cnt = 0;
820 if (priv->op_flags & OP_LED_ON)
821 priv->op_flags &= ~OP_LED_ON;
823 priv->op_flags |= OP_LED_ON;
826 static void ath9k_led_brightness_work(struct work_struct *work)
828 struct ath_led *led = container_of(work, struct ath_led,
829 brightness_work.work);
830 struct ath9k_htc_priv *priv = led->priv;
832 switch (led->brightness) {
834 if (led->led_type == ATH_LED_ASSOC ||
835 led->led_type == ATH_LED_RADIO) {
836 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
837 (led->led_type == ATH_LED_RADIO));
838 priv->op_flags &= ~OP_LED_ASSOCIATED;
839 if (led->led_type == ATH_LED_RADIO)
840 priv->op_flags &= ~OP_LED_ON;
846 if (led->led_type == ATH_LED_ASSOC) {
847 priv->op_flags |= OP_LED_ASSOCIATED;
848 ieee80211_queue_delayed_work(priv->hw,
849 &priv->ath9k_led_blink_work, 0);
850 } else if (led->led_type == ATH_LED_RADIO) {
851 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
852 priv->op_flags |= OP_LED_ON;
862 static void ath9k_led_brightness(struct led_classdev *led_cdev,
863 enum led_brightness brightness)
865 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
866 struct ath9k_htc_priv *priv = led->priv;
868 led->brightness = brightness;
869 if (!(priv->op_flags & OP_LED_DEINIT))
870 ieee80211_queue_delayed_work(priv->hw,
871 &led->brightness_work, 0);
874 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
876 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
877 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
878 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
879 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
882 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
888 led->led_cdev.name = led->name;
889 led->led_cdev.default_trigger = trigger;
890 led->led_cdev.brightness_set = ath9k_led_brightness;
892 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
894 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
895 "Failed to register led:%s", led->name);
899 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
904 static void ath9k_unregister_led(struct ath_led *led)
906 if (led->registered) {
907 led_classdev_unregister(&led->led_cdev);
912 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
914 priv->op_flags |= OP_LED_DEINIT;
915 ath9k_unregister_led(&priv->assoc_led);
916 priv->op_flags &= ~OP_LED_ASSOCIATED;
917 ath9k_unregister_led(&priv->tx_led);
918 ath9k_unregister_led(&priv->rx_led);
919 ath9k_unregister_led(&priv->radio_led);
922 void ath9k_init_leds(struct ath9k_htc_priv *priv)
927 if (AR_SREV_9287(priv->ah))
928 priv->ah->led_pin = ATH_LED_PIN_9287;
929 else if (AR_SREV_9271(priv->ah))
930 priv->ah->led_pin = ATH_LED_PIN_9271;
931 else if (AR_DEVID_7010(priv->ah))
932 priv->ah->led_pin = ATH_LED_PIN_7010;
934 priv->ah->led_pin = ATH_LED_PIN_DEF;
936 /* Configure gpio 1 for output */
937 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
938 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
939 /* LED off, active low */
940 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
942 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
944 trigger = ieee80211_get_radio_led_name(priv->hw);
945 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
946 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
947 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
948 priv->radio_led.led_type = ATH_LED_RADIO;
952 trigger = ieee80211_get_assoc_led_name(priv->hw);
953 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
954 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
955 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
956 priv->assoc_led.led_type = ATH_LED_ASSOC;
960 trigger = ieee80211_get_tx_led_name(priv->hw);
961 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
962 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
963 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
964 priv->tx_led.led_type = ATH_LED_TX;
968 trigger = ieee80211_get_rx_led_name(priv->hw);
969 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
970 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
971 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
972 priv->rx_led.led_type = ATH_LED_RX;
976 priv->op_flags &= ~OP_LED_DEINIT;
981 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
982 ath9k_deinit_leds(priv);
985 /*******************/
987 /*******************/
989 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
991 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
992 priv->ah->rfkill_polarity;
995 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
997 struct ath9k_htc_priv *priv = hw->priv;
998 bool blocked = !!ath_is_rfkill_set(priv);
1000 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1003 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1005 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1006 wiphy_rfkill_start_polling(priv->hw->wiphy);
1009 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1011 struct ath9k_htc_priv *priv = hw->priv;
1012 struct ath_hw *ah = priv->ah;
1013 struct ath_common *common = ath9k_hw_common(ah);
1018 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1021 ret = ath9k_hw_reset(ah, ah->curchan, false);
1023 ath_print(common, ATH_DBG_FATAL,
1024 "Unable to reset hardware; reset status %d "
1025 "(freq %u MHz)\n", ret, ah->curchan->channel);
1028 ath_update_txpow(priv);
1031 WMI_CMD(WMI_START_RECV_CMDID);
1032 ath9k_host_rx_init(priv);
1035 htc_start(priv->htc);
1036 spin_lock_bh(&priv->tx_lock);
1037 priv->tx_queues_stop = false;
1038 spin_unlock_bh(&priv->tx_lock);
1039 ieee80211_wake_queues(hw);
1041 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1044 ath9k_hw_cfg_output(ah, ah->led_pin,
1045 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1046 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1049 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1051 struct ath9k_htc_priv *priv = hw->priv;
1052 struct ath_hw *ah = priv->ah;
1053 struct ath_common *common = ath9k_hw_common(ah);
1057 ath9k_htc_ps_wakeup(priv);
1060 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1061 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1063 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1066 ieee80211_stop_queues(hw);
1067 htc_stop(priv->htc);
1068 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1069 skb_queue_purge(&priv->tx_queue);
1072 WMI_CMD(WMI_STOP_RECV_CMDID);
1075 * The MIB counters have to be disabled here,
1076 * since the target doesn't do it.
1078 ath9k_hw_disable_mib_counters(ah);
1081 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1084 ret = ath9k_hw_reset(ah, ah->curchan, false);
1086 ath_print(common, ATH_DBG_FATAL,
1087 "Unable to reset hardware; reset status %d "
1088 "(freq %u MHz)\n", ret, ah->curchan->channel);
1091 /* Disable the PHY */
1092 ath9k_hw_phy_disable(ah);
1094 ath9k_htc_ps_restore(priv);
1095 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1098 /**********************/
1099 /* mac80211 Callbacks */
1100 /**********************/
1102 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1104 struct ieee80211_hdr *hdr;
1105 struct ath9k_htc_priv *priv = hw->priv;
1106 int padpos, padsize, ret;
1108 hdr = (struct ieee80211_hdr *) skb->data;
1110 /* Add the padding after the header if this is not already done */
1111 padpos = ath9k_cmn_padpos(hdr->frame_control);
1112 padsize = padpos & 3;
1113 if (padsize && skb->len > padpos) {
1114 if (skb_headroom(skb) < padsize)
1116 skb_push(skb, padsize);
1117 memmove(skb->data, skb->data + padsize, padpos);
1120 ret = ath9k_htc_tx_start(priv, skb);
1122 if (ret == -ENOMEM) {
1123 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1124 "Stopping TX queues\n");
1125 ieee80211_stop_queues(hw);
1126 spin_lock_bh(&priv->tx_lock);
1127 priv->tx_queues_stop = true;
1128 spin_unlock_bh(&priv->tx_lock);
1130 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1139 dev_kfree_skb_any(skb);
1143 static int ath9k_htc_start(struct ieee80211_hw *hw)
1145 struct ath9k_htc_priv *priv = hw->priv;
1146 struct ath_hw *ah = priv->ah;
1147 struct ath_common *common = ath9k_hw_common(ah);
1148 struct ieee80211_channel *curchan = hw->conf.channel;
1149 struct ath9k_channel *init_channel;
1151 enum htc_phymode mode;
1155 mutex_lock(&priv->mutex);
1157 ath_print(common, ATH_DBG_CONFIG,
1158 "Starting driver with initial channel: %d MHz\n",
1159 curchan->center_freq);
1161 /* Ensure that HW is awake before flushing RX */
1162 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1163 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1165 /* setup initial channel */
1166 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1168 /* Reset SERDES registers */
1169 ath9k_hw_configpcipowersave(ah, 0, 0);
1171 ath9k_hw_htc_resetinit(ah);
1172 ret = ath9k_hw_reset(ah, init_channel, false);
1174 ath_print(common, ATH_DBG_FATAL,
1175 "Unable to reset hardware; reset status %d "
1176 "(freq %u MHz)\n", ret, curchan->center_freq);
1177 mutex_unlock(&priv->mutex);
1181 ath_update_txpow(priv);
1183 mode = ath9k_htc_get_curmode(priv, init_channel);
1184 htc_mode = cpu_to_be16(mode);
1185 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1186 WMI_CMD(WMI_ATH_INIT_CMDID);
1187 WMI_CMD(WMI_START_RECV_CMDID);
1189 ath9k_host_rx_init(priv);
1191 priv->op_flags &= ~OP_INVALID;
1192 htc_start(priv->htc);
1194 spin_lock_bh(&priv->tx_lock);
1195 priv->tx_queues_stop = false;
1196 spin_unlock_bh(&priv->tx_lock);
1198 ieee80211_wake_queues(hw);
1200 mutex_unlock(&priv->mutex);
1205 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1207 struct ath9k_htc_priv *priv = hw->priv;
1208 struct ath_hw *ah = priv->ah;
1209 struct ath_common *common = ath9k_hw_common(ah);
1213 mutex_lock(&priv->mutex);
1215 if (priv->op_flags & OP_INVALID) {
1216 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1217 mutex_unlock(&priv->mutex);
1221 /* Cancel all the running timers/work .. */
1222 cancel_work_sync(&priv->ps_work);
1223 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1224 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1225 ath9k_led_stop_brightness(priv);
1227 ath9k_htc_ps_wakeup(priv);
1228 htc_stop(priv->htc);
1229 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1230 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1231 WMI_CMD(WMI_STOP_RECV_CMDID);
1232 skb_queue_purge(&priv->tx_queue);
1234 /* Remove monitor interface here */
1235 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1236 if (ath9k_htc_remove_monitor_interface(priv))
1237 ath_print(common, ATH_DBG_FATAL,
1238 "Unable to remove monitor interface\n");
1240 ath_print(common, ATH_DBG_CONFIG,
1241 "Monitor interface removed\n");
1244 ath9k_hw_phy_disable(ah);
1245 ath9k_hw_disable(ah);
1246 ath9k_hw_configpcipowersave(ah, 1, 1);
1247 ath9k_htc_ps_restore(priv);
1248 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1250 priv->op_flags |= OP_INVALID;
1252 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1253 mutex_unlock(&priv->mutex);
1256 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1257 struct ieee80211_vif *vif)
1259 struct ath9k_htc_priv *priv = hw->priv;
1260 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1261 struct ath_common *common = ath9k_hw_common(priv->ah);
1262 struct ath9k_htc_target_vif hvif;
1266 mutex_lock(&priv->mutex);
1268 /* Only one interface for now */
1269 if (priv->nvifs > 0) {
1274 ath9k_htc_ps_wakeup(priv);
1275 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1276 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1278 switch (vif->type) {
1279 case NL80211_IFTYPE_STATION:
1280 hvif.opmode = cpu_to_be32(HTC_M_STA);
1282 case NL80211_IFTYPE_ADHOC:
1283 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1286 ath_print(common, ATH_DBG_FATAL,
1287 "Interface type %d not yet supported\n", vif->type);
1292 ath_print(common, ATH_DBG_CONFIG,
1293 "Attach a VIF of type: %d\n", vif->type);
1295 priv->ah->opmode = vif->type;
1297 /* Index starts from zero on the target */
1298 avp->index = hvif.index = priv->nvifs;
1299 hvif.rtsthreshold = cpu_to_be16(2304);
1300 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1307 * We need a node in target to tx mgmt frames
1308 * before association.
1310 ret = ath9k_htc_add_station(priv, vif, NULL);
1314 ret = ath9k_htc_update_cap_target(priv);
1316 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1317 " capability in target \n");
1321 ath9k_htc_ps_restore(priv);
1322 mutex_unlock(&priv->mutex);
1327 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1328 struct ieee80211_vif *vif)
1330 struct ath9k_htc_priv *priv = hw->priv;
1331 struct ath_common *common = ath9k_hw_common(priv->ah);
1332 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1333 struct ath9k_htc_target_vif hvif;
1337 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1339 mutex_lock(&priv->mutex);
1340 ath9k_htc_ps_wakeup(priv);
1342 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1343 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1344 hvif.index = avp->index;
1345 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1348 ath9k_htc_remove_station(priv, vif, NULL);
1351 ath9k_htc_ps_restore(priv);
1352 mutex_unlock(&priv->mutex);
1355 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1357 struct ath9k_htc_priv *priv = hw->priv;
1358 struct ath_common *common = ath9k_hw_common(priv->ah);
1359 struct ieee80211_conf *conf = &hw->conf;
1361 mutex_lock(&priv->mutex);
1363 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1364 bool enable_radio = false;
1365 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1367 mutex_lock(&priv->htc_pm_lock);
1368 if (!idle && priv->ps_idle)
1369 enable_radio = true;
1370 priv->ps_idle = idle;
1371 mutex_unlock(&priv->htc_pm_lock);
1374 ath_print(common, ATH_DBG_CONFIG,
1375 "not-idle: enabling radio\n");
1376 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1377 ath9k_htc_radio_enable(hw);
1381 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1382 struct ieee80211_channel *curchan = hw->conf.channel;
1383 int pos = curchan->hw_value;
1385 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1386 curchan->center_freq);
1388 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1390 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1391 ath_print(common, ATH_DBG_FATAL,
1392 "Unable to set channel\n");
1393 mutex_unlock(&priv->mutex);
1398 if (changed & IEEE80211_CONF_CHANGE_PS) {
1399 if (conf->flags & IEEE80211_CONF_PS) {
1400 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1401 priv->ps_enabled = true;
1403 priv->ps_enabled = false;
1404 cancel_work_sync(&priv->ps_work);
1405 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1409 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1410 if (conf->flags & IEEE80211_CONF_MONITOR) {
1411 if (ath9k_htc_add_monitor_interface(priv))
1412 ath_print(common, ATH_DBG_FATAL,
1413 "Failed to set monitor mode\n");
1415 ath_print(common, ATH_DBG_CONFIG,
1416 "HW opmode set to Monitor mode\n");
1420 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1421 mutex_lock(&priv->htc_pm_lock);
1422 if (!priv->ps_idle) {
1423 mutex_unlock(&priv->htc_pm_lock);
1426 mutex_unlock(&priv->htc_pm_lock);
1428 ath_print(common, ATH_DBG_CONFIG,
1429 "idle: disabling radio\n");
1430 ath9k_htc_radio_disable(hw);
1434 mutex_unlock(&priv->mutex);
1438 #define SUPPORTED_FILTERS \
1439 (FIF_PROMISC_IN_BSS | \
1444 FIF_BCN_PRBRESP_PROMISC | \
1447 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1448 unsigned int changed_flags,
1449 unsigned int *total_flags,
1452 struct ath9k_htc_priv *priv = hw->priv;
1455 mutex_lock(&priv->mutex);
1456 ath9k_htc_ps_wakeup(priv);
1458 changed_flags &= SUPPORTED_FILTERS;
1459 *total_flags &= SUPPORTED_FILTERS;
1461 priv->rxfilter = *total_flags;
1462 rfilt = ath9k_htc_calcrxfilter(priv);
1463 ath9k_hw_setrxfilter(priv->ah, rfilt);
1465 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1466 "Set HW RX filter: 0x%x\n", rfilt);
1468 ath9k_htc_ps_restore(priv);
1469 mutex_unlock(&priv->mutex);
1472 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1473 struct ieee80211_vif *vif,
1474 struct ieee80211_sta *sta)
1476 struct ath9k_htc_priv *priv = hw->priv;
1479 mutex_lock(&priv->mutex);
1480 ath9k_htc_ps_wakeup(priv);
1481 ret = ath9k_htc_add_station(priv, vif, sta);
1483 ath9k_htc_init_rate(priv, sta);
1484 ath9k_htc_ps_restore(priv);
1485 mutex_unlock(&priv->mutex);
1490 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1491 struct ieee80211_vif *vif,
1492 struct ieee80211_sta *sta)
1494 struct ath9k_htc_priv *priv = hw->priv;
1497 mutex_lock(&priv->mutex);
1498 ath9k_htc_ps_wakeup(priv);
1499 ret = ath9k_htc_remove_station(priv, vif, sta);
1500 ath9k_htc_ps_restore(priv);
1501 mutex_unlock(&priv->mutex);
1506 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1507 const struct ieee80211_tx_queue_params *params)
1509 struct ath9k_htc_priv *priv = hw->priv;
1510 struct ath_common *common = ath9k_hw_common(priv->ah);
1511 struct ath9k_tx_queue_info qi;
1514 if (queue >= WME_NUM_AC)
1517 mutex_lock(&priv->mutex);
1518 ath9k_htc_ps_wakeup(priv);
1520 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1522 qi.tqi_aifs = params->aifs;
1523 qi.tqi_cwmin = params->cw_min;
1524 qi.tqi_cwmax = params->cw_max;
1525 qi.tqi_burstTime = params->txop;
1527 qnum = get_hw_qnum(queue, priv->hwq_map);
1529 ath_print(common, ATH_DBG_CONFIG,
1530 "Configure tx [queue/hwq] [%d/%d], "
1531 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1532 queue, qnum, params->aifs, params->cw_min,
1533 params->cw_max, params->txop);
1535 ret = ath_htc_txq_update(priv, qnum, &qi);
1537 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1541 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1542 (qnum == priv->hwq_map[WME_AC_BE]))
1543 ath9k_htc_beaconq_config(priv);
1545 ath9k_htc_ps_restore(priv);
1546 mutex_unlock(&priv->mutex);
1551 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1552 enum set_key_cmd cmd,
1553 struct ieee80211_vif *vif,
1554 struct ieee80211_sta *sta,
1555 struct ieee80211_key_conf *key)
1557 struct ath9k_htc_priv *priv = hw->priv;
1558 struct ath_common *common = ath9k_hw_common(priv->ah);
1561 if (htc_modparam_nohwcrypt)
1564 mutex_lock(&priv->mutex);
1565 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1566 ath9k_htc_ps_wakeup(priv);
1570 ret = ath9k_cmn_key_config(common, vif, sta, key);
1572 key->hw_key_idx = ret;
1573 /* push IV and Michael MIC generation to stack */
1574 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1575 if (key->alg == ALG_TKIP)
1576 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1577 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1578 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1583 ath9k_cmn_key_delete(common, key);
1589 ath9k_htc_ps_restore(priv);
1590 mutex_unlock(&priv->mutex);
1595 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1596 struct ieee80211_vif *vif,
1597 struct ieee80211_bss_conf *bss_conf,
1600 struct ath9k_htc_priv *priv = hw->priv;
1601 struct ath_hw *ah = priv->ah;
1602 struct ath_common *common = ath9k_hw_common(ah);
1604 mutex_lock(&priv->mutex);
1605 ath9k_htc_ps_wakeup(priv);
1607 if (changed & BSS_CHANGED_ASSOC) {
1608 common->curaid = bss_conf->assoc ?
1610 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1613 if (bss_conf->assoc) {
1614 priv->op_flags |= OP_ASSOCIATED;
1615 ath_start_ani(priv);
1617 priv->op_flags &= ~OP_ASSOCIATED;
1618 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1622 if (changed & BSS_CHANGED_BSSID) {
1624 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1625 ath9k_hw_write_associd(ah);
1627 ath_print(common, ATH_DBG_CONFIG,
1628 "BSSID: %pM aid: 0x%x\n",
1629 common->curbssid, common->curaid);
1632 if ((changed & BSS_CHANGED_BEACON_INT) ||
1633 (changed & BSS_CHANGED_BEACON) ||
1634 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1635 bss_conf->enable_beacon)) {
1636 priv->op_flags |= OP_ENABLE_BEACON;
1637 ath9k_htc_beacon_config(priv, vif);
1640 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1641 !bss_conf->enable_beacon) {
1642 priv->op_flags &= ~OP_ENABLE_BEACON;
1643 ath9k_htc_beacon_config(priv, vif);
1646 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1647 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1648 bss_conf->use_short_preamble);
1649 if (bss_conf->use_short_preamble)
1650 priv->op_flags |= OP_PREAMBLE_SHORT;
1652 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1655 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1656 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1657 bss_conf->use_cts_prot);
1658 if (bss_conf->use_cts_prot &&
1659 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1660 priv->op_flags |= OP_PROTECT_ENABLE;
1662 priv->op_flags &= ~OP_PROTECT_ENABLE;
1665 if (changed & BSS_CHANGED_ERP_SLOT) {
1666 if (bss_conf->use_short_slot)
1671 ath9k_hw_init_global_settings(ah);
1674 if (changed & BSS_CHANGED_HT)
1675 ath9k_htc_update_rate(priv, vif, bss_conf);
1677 ath9k_htc_ps_restore(priv);
1678 mutex_unlock(&priv->mutex);
1681 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1683 struct ath9k_htc_priv *priv = hw->priv;
1686 mutex_lock(&priv->mutex);
1687 ath9k_htc_ps_wakeup(priv);
1688 tsf = ath9k_hw_gettsf64(priv->ah);
1689 ath9k_htc_ps_restore(priv);
1690 mutex_unlock(&priv->mutex);
1695 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1697 struct ath9k_htc_priv *priv = hw->priv;
1699 mutex_lock(&priv->mutex);
1700 ath9k_htc_ps_wakeup(priv);
1701 ath9k_hw_settsf64(priv->ah, tsf);
1702 ath9k_htc_ps_restore(priv);
1703 mutex_unlock(&priv->mutex);
1706 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1708 struct ath9k_htc_priv *priv = hw->priv;
1710 mutex_lock(&priv->mutex);
1711 ath9k_htc_ps_wakeup(priv);
1712 ath9k_hw_reset_tsf(priv->ah);
1713 ath9k_htc_ps_restore(priv);
1714 mutex_unlock(&priv->mutex);
1717 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1718 struct ieee80211_vif *vif,
1719 enum ieee80211_ampdu_mlme_action action,
1720 struct ieee80211_sta *sta,
1723 struct ath9k_htc_priv *priv = hw->priv;
1724 struct ath9k_htc_sta *ista;
1728 case IEEE80211_AMPDU_RX_START:
1730 case IEEE80211_AMPDU_RX_STOP:
1732 case IEEE80211_AMPDU_TX_START:
1733 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1735 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1737 case IEEE80211_AMPDU_TX_STOP:
1738 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1739 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1741 case IEEE80211_AMPDU_TX_OPERATIONAL:
1742 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1743 spin_lock_bh(&priv->tx_lock);
1744 ista->tid_state[tid] = AGGR_OPERATIONAL;
1745 spin_unlock_bh(&priv->tx_lock);
1748 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1749 "Unknown AMPDU action\n");
1755 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1757 struct ath9k_htc_priv *priv = hw->priv;
1759 mutex_lock(&priv->mutex);
1760 spin_lock_bh(&priv->beacon_lock);
1761 priv->op_flags |= OP_SCANNING;
1762 spin_unlock_bh(&priv->beacon_lock);
1763 cancel_work_sync(&priv->ps_work);
1764 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1765 mutex_unlock(&priv->mutex);
1768 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1770 struct ath9k_htc_priv *priv = hw->priv;
1772 mutex_lock(&priv->mutex);
1773 ath9k_htc_ps_wakeup(priv);
1774 spin_lock_bh(&priv->beacon_lock);
1775 priv->op_flags &= ~OP_SCANNING;
1776 spin_unlock_bh(&priv->beacon_lock);
1777 priv->op_flags |= OP_FULL_RESET;
1778 if (priv->op_flags & OP_ASSOCIATED)
1779 ath9k_htc_beacon_config(priv, priv->vif);
1780 ath_start_ani(priv);
1781 ath9k_htc_ps_restore(priv);
1782 mutex_unlock(&priv->mutex);
1785 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1790 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1793 struct ath9k_htc_priv *priv = hw->priv;
1795 mutex_lock(&priv->mutex);
1796 ath9k_htc_ps_wakeup(priv);
1797 priv->ah->coverage_class = coverage_class;
1798 ath9k_hw_init_global_settings(priv->ah);
1799 ath9k_htc_ps_restore(priv);
1800 mutex_unlock(&priv->mutex);
1803 struct ieee80211_ops ath9k_htc_ops = {
1805 .start = ath9k_htc_start,
1806 .stop = ath9k_htc_stop,
1807 .add_interface = ath9k_htc_add_interface,
1808 .remove_interface = ath9k_htc_remove_interface,
1809 .config = ath9k_htc_config,
1810 .configure_filter = ath9k_htc_configure_filter,
1811 .sta_add = ath9k_htc_sta_add,
1812 .sta_remove = ath9k_htc_sta_remove,
1813 .conf_tx = ath9k_htc_conf_tx,
1814 .bss_info_changed = ath9k_htc_bss_info_changed,
1815 .set_key = ath9k_htc_set_key,
1816 .get_tsf = ath9k_htc_get_tsf,
1817 .set_tsf = ath9k_htc_set_tsf,
1818 .reset_tsf = ath9k_htc_reset_tsf,
1819 .ampdu_action = ath9k_htc_ampdu_action,
1820 .sw_scan_start = ath9k_htc_sw_scan_start,
1821 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1822 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1823 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1824 .set_coverage_class = ath9k_htc_set_coverage_class,