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 static 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,
447 struct ath_common *common = ath9k_hw_common(priv->ah);
448 struct ath9k_htc_target_aggr aggr;
449 struct ath9k_htc_sta *ista;
453 if (tid >= ATH9K_HTC_MAX_TID)
456 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
457 ista = (struct ath9k_htc_sta *) sta->drv_priv;
459 aggr.sta_index = ista->index;
460 aggr.tidno = tid & 0xf;
461 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
463 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
465 ath_print(common, ATH_DBG_CONFIG,
466 "Unable to %s TX aggregation for (%pM, %d)\n",
467 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
469 ath_print(common, ATH_DBG_CONFIG,
470 "%s TX aggregation for (%pM, %d)\n",
471 (aggr.aggr_enable) ? "Starting" : "Stopping",
474 spin_lock_bh(&priv->tx_lock);
475 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
476 spin_unlock_bh(&priv->tx_lock);
485 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
487 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
489 file->private_data = inode->i_private;
493 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
494 size_t count, loff_t *ppos)
496 struct ath9k_htc_priv *priv = file->private_data;
497 struct ath9k_htc_target_stats cmd_rsp;
499 unsigned int len = 0;
502 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
504 WMI_CMD(WMI_TGT_STATS_CMDID);
509 len += snprintf(buf + len, sizeof(buf) - len,
510 "%19s : %10u\n", "TX Short Retries",
511 be32_to_cpu(cmd_rsp.tx_shortretry));
512 len += snprintf(buf + len, sizeof(buf) - len,
513 "%19s : %10u\n", "TX Long Retries",
514 be32_to_cpu(cmd_rsp.tx_longretry));
515 len += snprintf(buf + len, sizeof(buf) - len,
516 "%19s : %10u\n", "TX Xretries",
517 be32_to_cpu(cmd_rsp.tx_xretries));
518 len += snprintf(buf + len, sizeof(buf) - len,
519 "%19s : %10u\n", "TX Unaggr. Xretries",
520 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
521 len += snprintf(buf + len, sizeof(buf) - len,
522 "%19s : %10u\n", "TX Xretries (HT)",
523 be32_to_cpu(cmd_rsp.ht_tx_xretries));
524 len += snprintf(buf + len, sizeof(buf) - len,
525 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
527 if (len > sizeof(buf))
530 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
533 static const struct file_operations fops_tgt_stats = {
534 .read = read_file_tgt_stats,
535 .open = ath9k_debugfs_open,
539 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
540 size_t count, loff_t *ppos)
542 struct ath9k_htc_priv *priv = file->private_data;
544 unsigned int len = 0;
546 len += snprintf(buf + len, sizeof(buf) - len,
547 "%20s : %10u\n", "Buffers queued",
548 priv->debug.tx_stats.buf_queued);
549 len += snprintf(buf + len, sizeof(buf) - len,
550 "%20s : %10u\n", "Buffers completed",
551 priv->debug.tx_stats.buf_completed);
552 len += snprintf(buf + len, sizeof(buf) - len,
553 "%20s : %10u\n", "SKBs queued",
554 priv->debug.tx_stats.skb_queued);
555 len += snprintf(buf + len, sizeof(buf) - len,
556 "%20s : %10u\n", "SKBs completed",
557 priv->debug.tx_stats.skb_completed);
558 len += snprintf(buf + len, sizeof(buf) - len,
559 "%20s : %10u\n", "SKBs dropped",
560 priv->debug.tx_stats.skb_dropped);
562 len += snprintf(buf + len, sizeof(buf) - len,
563 "%20s : %10u\n", "BE queued",
564 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
565 len += snprintf(buf + len, sizeof(buf) - len,
566 "%20s : %10u\n", "BK queued",
567 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
568 len += snprintf(buf + len, sizeof(buf) - len,
569 "%20s : %10u\n", "VI queued",
570 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
571 len += snprintf(buf + len, sizeof(buf) - len,
572 "%20s : %10u\n", "VO queued",
573 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
575 if (len > sizeof(buf))
578 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
581 static const struct file_operations fops_xmit = {
582 .read = read_file_xmit,
583 .open = ath9k_debugfs_open,
587 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
588 size_t count, loff_t *ppos)
590 struct ath9k_htc_priv *priv = file->private_data;
592 unsigned int len = 0;
594 len += snprintf(buf + len, sizeof(buf) - len,
595 "%20s : %10u\n", "SKBs allocated",
596 priv->debug.rx_stats.skb_allocated);
597 len += snprintf(buf + len, sizeof(buf) - len,
598 "%20s : %10u\n", "SKBs completed",
599 priv->debug.rx_stats.skb_completed);
600 len += snprintf(buf + len, sizeof(buf) - len,
601 "%20s : %10u\n", "SKBs Dropped",
602 priv->debug.rx_stats.skb_dropped);
604 if (len > sizeof(buf))
607 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
610 static const struct file_operations fops_recv = {
611 .read = read_file_recv,
612 .open = ath9k_debugfs_open,
616 int ath9k_htc_init_debug(struct ath_hw *ah)
618 struct ath_common *common = ath9k_hw_common(ah);
619 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
621 if (!ath9k_debugfs_root)
624 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
626 if (!priv->debug.debugfs_phy)
629 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
630 priv->debug.debugfs_phy,
631 priv, &fops_tgt_stats);
632 if (!priv->debug.debugfs_tgt_stats)
636 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
637 priv->debug.debugfs_phy,
639 if (!priv->debug.debugfs_xmit)
642 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
643 priv->debug.debugfs_phy,
645 if (!priv->debug.debugfs_recv)
651 ath9k_htc_exit_debug(ah);
655 void ath9k_htc_exit_debug(struct ath_hw *ah)
657 struct ath_common *common = ath9k_hw_common(ah);
658 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
660 debugfs_remove(priv->debug.debugfs_recv);
661 debugfs_remove(priv->debug.debugfs_xmit);
662 debugfs_remove(priv->debug.debugfs_tgt_stats);
663 debugfs_remove(priv->debug.debugfs_phy);
666 int ath9k_htc_debug_create_root(void)
668 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
669 if (!ath9k_debugfs_root)
675 void ath9k_htc_debug_remove_root(void)
677 debugfs_remove(ath9k_debugfs_root);
678 ath9k_debugfs_root = NULL;
681 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
687 static void ath_start_ani(struct ath9k_htc_priv *priv)
689 struct ath_common *common = ath9k_hw_common(priv->ah);
690 unsigned long timestamp = jiffies_to_msecs(jiffies);
692 common->ani.longcal_timer = timestamp;
693 common->ani.shortcal_timer = timestamp;
694 common->ani.checkani_timer = timestamp;
696 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
697 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
700 void ath9k_ani_work(struct work_struct *work)
702 struct ath9k_htc_priv *priv =
703 container_of(work, struct ath9k_htc_priv,
704 ath9k_ani_work.work);
705 struct ath_hw *ah = priv->ah;
706 struct ath_common *common = ath9k_hw_common(ah);
707 bool longcal = false;
708 bool shortcal = false;
709 bool aniflag = false;
710 unsigned int timestamp = jiffies_to_msecs(jiffies);
711 u32 cal_interval, short_cal_interval;
713 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
715 /* Only calibrate if awake */
716 if (ah->power_mode != ATH9K_PM_AWAKE)
719 /* Long calibration runs independently of short calibration. */
720 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
722 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
723 common->ani.longcal_timer = timestamp;
726 /* Short calibration applies only while caldone is false */
727 if (!common->ani.caldone) {
728 if ((timestamp - common->ani.shortcal_timer) >=
729 short_cal_interval) {
731 ath_print(common, ATH_DBG_ANI,
732 "shortcal @%lu\n", jiffies);
733 common->ani.shortcal_timer = timestamp;
734 common->ani.resetcal_timer = timestamp;
737 if ((timestamp - common->ani.resetcal_timer) >=
738 ATH_RESTART_CALINTERVAL) {
739 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
740 if (common->ani.caldone)
741 common->ani.resetcal_timer = timestamp;
745 /* Verify whether we must check ANI */
746 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
748 common->ani.checkani_timer = timestamp;
751 /* Skip all processing if there's nothing to do. */
752 if (longcal || shortcal || aniflag) {
754 ath9k_htc_ps_wakeup(priv);
756 /* Call ANI routine if necessary */
758 ath9k_hw_ani_monitor(ah, ah->curchan);
760 /* Perform calibration if necessary */
761 if (longcal || shortcal) {
762 common->ani.caldone =
763 ath9k_hw_calibrate(ah, ah->curchan,
764 common->rx_chainmask,
768 common->ani.noise_floor =
769 ath9k_hw_getchan_noise(ah, ah->curchan);
771 ath_print(common, ATH_DBG_ANI,
772 " calibrate chan %u/%x nf: %d\n",
773 ah->curchan->channel,
774 ah->curchan->channelFlags,
775 common->ani.noise_floor);
778 ath9k_htc_ps_restore(priv);
783 * Set timer interval based on previous results.
784 * The interval must be the shortest necessary to satisfy ANI,
785 * short calibration and long calibration.
787 cal_interval = ATH_LONG_CALINTERVAL;
788 if (priv->ah->config.enable_ani)
789 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
790 if (!common->ani.caldone)
791 cal_interval = min(cal_interval, (u32)short_cal_interval);
793 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
794 msecs_to_jiffies(cal_interval));
801 static void ath9k_led_blink_work(struct work_struct *work)
803 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
804 ath9k_led_blink_work.work);
806 if (!(priv->op_flags & OP_LED_ASSOCIATED))
809 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
810 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
811 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
813 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
814 (priv->op_flags & OP_LED_ON) ? 1 : 0);
816 ieee80211_queue_delayed_work(priv->hw,
817 &priv->ath9k_led_blink_work,
818 (priv->op_flags & OP_LED_ON) ?
819 msecs_to_jiffies(priv->led_off_duration) :
820 msecs_to_jiffies(priv->led_on_duration));
822 priv->led_on_duration = priv->led_on_cnt ?
823 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
824 ATH_LED_ON_DURATION_IDLE;
825 priv->led_off_duration = priv->led_off_cnt ?
826 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
827 ATH_LED_OFF_DURATION_IDLE;
828 priv->led_on_cnt = priv->led_off_cnt = 0;
830 if (priv->op_flags & OP_LED_ON)
831 priv->op_flags &= ~OP_LED_ON;
833 priv->op_flags |= OP_LED_ON;
836 static void ath9k_led_brightness_work(struct work_struct *work)
838 struct ath_led *led = container_of(work, struct ath_led,
839 brightness_work.work);
840 struct ath9k_htc_priv *priv = led->priv;
842 switch (led->brightness) {
844 if (led->led_type == ATH_LED_ASSOC ||
845 led->led_type == ATH_LED_RADIO) {
846 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
847 (led->led_type == ATH_LED_RADIO));
848 priv->op_flags &= ~OP_LED_ASSOCIATED;
849 if (led->led_type == ATH_LED_RADIO)
850 priv->op_flags &= ~OP_LED_ON;
856 if (led->led_type == ATH_LED_ASSOC) {
857 priv->op_flags |= OP_LED_ASSOCIATED;
858 ieee80211_queue_delayed_work(priv->hw,
859 &priv->ath9k_led_blink_work, 0);
860 } else if (led->led_type == ATH_LED_RADIO) {
861 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
862 priv->op_flags |= OP_LED_ON;
872 static void ath9k_led_brightness(struct led_classdev *led_cdev,
873 enum led_brightness brightness)
875 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
876 struct ath9k_htc_priv *priv = led->priv;
878 led->brightness = brightness;
879 if (!(priv->op_flags & OP_LED_DEINIT))
880 ieee80211_queue_delayed_work(priv->hw,
881 &led->brightness_work, 0);
884 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
886 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
887 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
888 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
889 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
892 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
898 led->led_cdev.name = led->name;
899 led->led_cdev.default_trigger = trigger;
900 led->led_cdev.brightness_set = ath9k_led_brightness;
902 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
904 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
905 "Failed to register led:%s", led->name);
909 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
914 static void ath9k_unregister_led(struct ath_led *led)
916 if (led->registered) {
917 led_classdev_unregister(&led->led_cdev);
922 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
924 priv->op_flags |= OP_LED_DEINIT;
925 ath9k_unregister_led(&priv->assoc_led);
926 priv->op_flags &= ~OP_LED_ASSOCIATED;
927 ath9k_unregister_led(&priv->tx_led);
928 ath9k_unregister_led(&priv->rx_led);
929 ath9k_unregister_led(&priv->radio_led);
932 void ath9k_init_leds(struct ath9k_htc_priv *priv)
937 if (AR_SREV_9287(priv->ah))
938 priv->ah->led_pin = ATH_LED_PIN_9287;
939 else if (AR_SREV_9271(priv->ah))
940 priv->ah->led_pin = ATH_LED_PIN_9271;
941 else if (AR_DEVID_7010(priv->ah))
942 priv->ah->led_pin = ATH_LED_PIN_7010;
944 priv->ah->led_pin = ATH_LED_PIN_DEF;
946 /* Configure gpio 1 for output */
947 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
948 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
949 /* LED off, active low */
950 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
952 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
954 trigger = ieee80211_get_radio_led_name(priv->hw);
955 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
956 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
957 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
958 priv->radio_led.led_type = ATH_LED_RADIO;
962 trigger = ieee80211_get_assoc_led_name(priv->hw);
963 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
964 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
965 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
966 priv->assoc_led.led_type = ATH_LED_ASSOC;
970 trigger = ieee80211_get_tx_led_name(priv->hw);
971 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
972 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
973 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
974 priv->tx_led.led_type = ATH_LED_TX;
978 trigger = ieee80211_get_rx_led_name(priv->hw);
979 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
980 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
981 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
982 priv->rx_led.led_type = ATH_LED_RX;
986 priv->op_flags &= ~OP_LED_DEINIT;
991 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
992 ath9k_deinit_leds(priv);
995 /*******************/
997 /*******************/
999 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1001 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1002 priv->ah->rfkill_polarity;
1005 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1007 struct ath9k_htc_priv *priv = hw->priv;
1008 bool blocked = !!ath_is_rfkill_set(priv);
1010 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1013 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1015 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1016 wiphy_rfkill_start_polling(priv->hw->wiphy);
1019 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1021 struct ath9k_htc_priv *priv = hw->priv;
1022 struct ath_hw *ah = priv->ah;
1023 struct ath_common *common = ath9k_hw_common(ah);
1028 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1031 ret = ath9k_hw_reset(ah, ah->curchan, false);
1033 ath_print(common, ATH_DBG_FATAL,
1034 "Unable to reset hardware; reset status %d "
1035 "(freq %u MHz)\n", ret, ah->curchan->channel);
1038 ath_update_txpow(priv);
1041 WMI_CMD(WMI_START_RECV_CMDID);
1042 ath9k_host_rx_init(priv);
1045 htc_start(priv->htc);
1046 spin_lock_bh(&priv->tx_lock);
1047 priv->tx_queues_stop = false;
1048 spin_unlock_bh(&priv->tx_lock);
1049 ieee80211_wake_queues(hw);
1051 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1054 ath9k_hw_cfg_output(ah, ah->led_pin,
1055 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1056 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1059 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1061 struct ath9k_htc_priv *priv = hw->priv;
1062 struct ath_hw *ah = priv->ah;
1063 struct ath_common *common = ath9k_hw_common(ah);
1067 ath9k_htc_ps_wakeup(priv);
1070 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1071 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1073 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1076 ieee80211_stop_queues(hw);
1077 htc_stop(priv->htc);
1078 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1079 skb_queue_purge(&priv->tx_queue);
1082 WMI_CMD(WMI_STOP_RECV_CMDID);
1085 * The MIB counters have to be disabled here,
1086 * since the target doesn't do it.
1088 ath9k_hw_disable_mib_counters(ah);
1091 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1094 ret = ath9k_hw_reset(ah, ah->curchan, false);
1096 ath_print(common, ATH_DBG_FATAL,
1097 "Unable to reset hardware; reset status %d "
1098 "(freq %u MHz)\n", ret, ah->curchan->channel);
1101 /* Disable the PHY */
1102 ath9k_hw_phy_disable(ah);
1104 ath9k_htc_ps_restore(priv);
1105 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1108 /**********************/
1109 /* mac80211 Callbacks */
1110 /**********************/
1112 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1114 struct ieee80211_hdr *hdr;
1115 struct ath9k_htc_priv *priv = hw->priv;
1116 int padpos, padsize, ret;
1118 hdr = (struct ieee80211_hdr *) skb->data;
1120 /* Add the padding after the header if this is not already done */
1121 padpos = ath9k_cmn_padpos(hdr->frame_control);
1122 padsize = padpos & 3;
1123 if (padsize && skb->len > padpos) {
1124 if (skb_headroom(skb) < padsize)
1126 skb_push(skb, padsize);
1127 memmove(skb->data, skb->data + padsize, padpos);
1130 ret = ath9k_htc_tx_start(priv, skb);
1132 if (ret == -ENOMEM) {
1133 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1134 "Stopping TX queues\n");
1135 ieee80211_stop_queues(hw);
1136 spin_lock_bh(&priv->tx_lock);
1137 priv->tx_queues_stop = true;
1138 spin_unlock_bh(&priv->tx_lock);
1140 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1149 dev_kfree_skb_any(skb);
1153 static int ath9k_htc_start(struct ieee80211_hw *hw)
1155 struct ath9k_htc_priv *priv = hw->priv;
1156 struct ath_hw *ah = priv->ah;
1157 struct ath_common *common = ath9k_hw_common(ah);
1158 struct ieee80211_channel *curchan = hw->conf.channel;
1159 struct ath9k_channel *init_channel;
1161 enum htc_phymode mode;
1165 mutex_lock(&priv->mutex);
1167 ath_print(common, ATH_DBG_CONFIG,
1168 "Starting driver with initial channel: %d MHz\n",
1169 curchan->center_freq);
1171 /* Ensure that HW is awake before flushing RX */
1172 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1173 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1175 /* setup initial channel */
1176 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1178 /* Reset SERDES registers */
1179 ath9k_hw_configpcipowersave(ah, 0, 0);
1181 ath9k_hw_htc_resetinit(ah);
1182 ret = ath9k_hw_reset(ah, init_channel, false);
1184 ath_print(common, ATH_DBG_FATAL,
1185 "Unable to reset hardware; reset status %d "
1186 "(freq %u MHz)\n", ret, curchan->center_freq);
1187 mutex_unlock(&priv->mutex);
1191 ath_update_txpow(priv);
1193 mode = ath9k_htc_get_curmode(priv, init_channel);
1194 htc_mode = cpu_to_be16(mode);
1195 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1196 WMI_CMD(WMI_ATH_INIT_CMDID);
1197 WMI_CMD(WMI_START_RECV_CMDID);
1199 ath9k_host_rx_init(priv);
1201 priv->op_flags &= ~OP_INVALID;
1202 htc_start(priv->htc);
1204 spin_lock_bh(&priv->tx_lock);
1205 priv->tx_queues_stop = false;
1206 spin_unlock_bh(&priv->tx_lock);
1208 ieee80211_wake_queues(hw);
1210 mutex_unlock(&priv->mutex);
1215 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1217 struct ath9k_htc_priv *priv = hw->priv;
1218 struct ath_hw *ah = priv->ah;
1219 struct ath_common *common = ath9k_hw_common(ah);
1223 mutex_lock(&priv->mutex);
1225 if (priv->op_flags & OP_INVALID) {
1226 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1227 mutex_unlock(&priv->mutex);
1231 /* Cancel all the running timers/work .. */
1232 cancel_work_sync(&priv->ps_work);
1233 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1234 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1235 ath9k_led_stop_brightness(priv);
1237 ath9k_htc_ps_wakeup(priv);
1238 htc_stop(priv->htc);
1239 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1240 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1241 WMI_CMD(WMI_STOP_RECV_CMDID);
1242 skb_queue_purge(&priv->tx_queue);
1244 /* Remove monitor interface here */
1245 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1246 if (ath9k_htc_remove_monitor_interface(priv))
1247 ath_print(common, ATH_DBG_FATAL,
1248 "Unable to remove monitor interface\n");
1250 ath_print(common, ATH_DBG_CONFIG,
1251 "Monitor interface removed\n");
1254 ath9k_hw_phy_disable(ah);
1255 ath9k_hw_disable(ah);
1256 ath9k_hw_configpcipowersave(ah, 1, 1);
1257 ath9k_htc_ps_restore(priv);
1258 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1260 priv->op_flags |= OP_INVALID;
1262 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1263 mutex_unlock(&priv->mutex);
1266 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1267 struct ieee80211_vif *vif)
1269 struct ath9k_htc_priv *priv = hw->priv;
1270 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1271 struct ath_common *common = ath9k_hw_common(priv->ah);
1272 struct ath9k_htc_target_vif hvif;
1276 mutex_lock(&priv->mutex);
1278 /* Only one interface for now */
1279 if (priv->nvifs > 0) {
1284 ath9k_htc_ps_wakeup(priv);
1285 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1286 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1288 switch (vif->type) {
1289 case NL80211_IFTYPE_STATION:
1290 hvif.opmode = cpu_to_be32(HTC_M_STA);
1292 case NL80211_IFTYPE_ADHOC:
1293 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1296 ath_print(common, ATH_DBG_FATAL,
1297 "Interface type %d not yet supported\n", vif->type);
1302 ath_print(common, ATH_DBG_CONFIG,
1303 "Attach a VIF of type: %d\n", vif->type);
1305 priv->ah->opmode = vif->type;
1307 /* Index starts from zero on the target */
1308 avp->index = hvif.index = priv->nvifs;
1309 hvif.rtsthreshold = cpu_to_be16(2304);
1310 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1317 * We need a node in target to tx mgmt frames
1318 * before association.
1320 ret = ath9k_htc_add_station(priv, vif, NULL);
1324 ret = ath9k_htc_update_cap_target(priv);
1326 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1327 " capability in target \n");
1331 ath9k_htc_ps_restore(priv);
1332 mutex_unlock(&priv->mutex);
1337 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1338 struct ieee80211_vif *vif)
1340 struct ath9k_htc_priv *priv = hw->priv;
1341 struct ath_common *common = ath9k_hw_common(priv->ah);
1342 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1343 struct ath9k_htc_target_vif hvif;
1347 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1349 mutex_lock(&priv->mutex);
1350 ath9k_htc_ps_wakeup(priv);
1352 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1353 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1354 hvif.index = avp->index;
1355 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1358 ath9k_htc_remove_station(priv, vif, NULL);
1361 ath9k_htc_ps_restore(priv);
1362 mutex_unlock(&priv->mutex);
1365 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1367 struct ath9k_htc_priv *priv = hw->priv;
1368 struct ath_common *common = ath9k_hw_common(priv->ah);
1369 struct ieee80211_conf *conf = &hw->conf;
1371 mutex_lock(&priv->mutex);
1373 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1374 bool enable_radio = false;
1375 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1377 mutex_lock(&priv->htc_pm_lock);
1378 if (!idle && priv->ps_idle)
1379 enable_radio = true;
1380 priv->ps_idle = idle;
1381 mutex_unlock(&priv->htc_pm_lock);
1384 ath_print(common, ATH_DBG_CONFIG,
1385 "not-idle: enabling radio\n");
1386 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1387 ath9k_htc_radio_enable(hw);
1391 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1392 struct ieee80211_channel *curchan = hw->conf.channel;
1393 int pos = curchan->hw_value;
1395 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1396 curchan->center_freq);
1398 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1400 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1401 ath_print(common, ATH_DBG_FATAL,
1402 "Unable to set channel\n");
1403 mutex_unlock(&priv->mutex);
1408 if (changed & IEEE80211_CONF_CHANGE_PS) {
1409 if (conf->flags & IEEE80211_CONF_PS) {
1410 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1411 priv->ps_enabled = true;
1413 priv->ps_enabled = false;
1414 cancel_work_sync(&priv->ps_work);
1415 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1419 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1420 if (conf->flags & IEEE80211_CONF_MONITOR) {
1421 if (ath9k_htc_add_monitor_interface(priv))
1422 ath_print(common, ATH_DBG_FATAL,
1423 "Failed to set monitor mode\n");
1425 ath_print(common, ATH_DBG_CONFIG,
1426 "HW opmode set to Monitor mode\n");
1430 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1431 mutex_lock(&priv->htc_pm_lock);
1432 if (!priv->ps_idle) {
1433 mutex_unlock(&priv->htc_pm_lock);
1436 mutex_unlock(&priv->htc_pm_lock);
1438 ath_print(common, ATH_DBG_CONFIG,
1439 "idle: disabling radio\n");
1440 ath9k_htc_radio_disable(hw);
1444 mutex_unlock(&priv->mutex);
1448 #define SUPPORTED_FILTERS \
1449 (FIF_PROMISC_IN_BSS | \
1454 FIF_BCN_PRBRESP_PROMISC | \
1457 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1458 unsigned int changed_flags,
1459 unsigned int *total_flags,
1462 struct ath9k_htc_priv *priv = hw->priv;
1465 mutex_lock(&priv->mutex);
1466 ath9k_htc_ps_wakeup(priv);
1468 changed_flags &= SUPPORTED_FILTERS;
1469 *total_flags &= SUPPORTED_FILTERS;
1471 priv->rxfilter = *total_flags;
1472 rfilt = ath9k_htc_calcrxfilter(priv);
1473 ath9k_hw_setrxfilter(priv->ah, rfilt);
1475 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1476 "Set HW RX filter: 0x%x\n", rfilt);
1478 ath9k_htc_ps_restore(priv);
1479 mutex_unlock(&priv->mutex);
1482 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1483 struct ieee80211_vif *vif,
1484 struct ieee80211_sta *sta)
1486 struct ath9k_htc_priv *priv = hw->priv;
1489 mutex_lock(&priv->mutex);
1490 ath9k_htc_ps_wakeup(priv);
1491 ret = ath9k_htc_add_station(priv, vif, sta);
1493 ath9k_htc_init_rate(priv, sta);
1494 ath9k_htc_ps_restore(priv);
1495 mutex_unlock(&priv->mutex);
1500 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1501 struct ieee80211_vif *vif,
1502 struct ieee80211_sta *sta)
1504 struct ath9k_htc_priv *priv = hw->priv;
1507 mutex_lock(&priv->mutex);
1508 ath9k_htc_ps_wakeup(priv);
1509 ret = ath9k_htc_remove_station(priv, vif, sta);
1510 ath9k_htc_ps_restore(priv);
1511 mutex_unlock(&priv->mutex);
1516 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1517 const struct ieee80211_tx_queue_params *params)
1519 struct ath9k_htc_priv *priv = hw->priv;
1520 struct ath_common *common = ath9k_hw_common(priv->ah);
1521 struct ath9k_tx_queue_info qi;
1524 if (queue >= WME_NUM_AC)
1527 mutex_lock(&priv->mutex);
1528 ath9k_htc_ps_wakeup(priv);
1530 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1532 qi.tqi_aifs = params->aifs;
1533 qi.tqi_cwmin = params->cw_min;
1534 qi.tqi_cwmax = params->cw_max;
1535 qi.tqi_burstTime = params->txop;
1537 qnum = get_hw_qnum(queue, priv->hwq_map);
1539 ath_print(common, ATH_DBG_CONFIG,
1540 "Configure tx [queue/hwq] [%d/%d], "
1541 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1542 queue, qnum, params->aifs, params->cw_min,
1543 params->cw_max, params->txop);
1545 ret = ath_htc_txq_update(priv, qnum, &qi);
1547 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1551 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1552 (qnum == priv->hwq_map[WME_AC_BE]))
1553 ath9k_htc_beaconq_config(priv);
1555 ath9k_htc_ps_restore(priv);
1556 mutex_unlock(&priv->mutex);
1561 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1562 enum set_key_cmd cmd,
1563 struct ieee80211_vif *vif,
1564 struct ieee80211_sta *sta,
1565 struct ieee80211_key_conf *key)
1567 struct ath9k_htc_priv *priv = hw->priv;
1568 struct ath_common *common = ath9k_hw_common(priv->ah);
1571 if (htc_modparam_nohwcrypt)
1574 mutex_lock(&priv->mutex);
1575 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1576 ath9k_htc_ps_wakeup(priv);
1580 ret = ath9k_cmn_key_config(common, vif, sta, key);
1582 key->hw_key_idx = ret;
1583 /* push IV and Michael MIC generation to stack */
1584 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1585 if (key->alg == ALG_TKIP)
1586 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1587 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1588 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1593 ath9k_cmn_key_delete(common, key);
1599 ath9k_htc_ps_restore(priv);
1600 mutex_unlock(&priv->mutex);
1605 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1606 struct ieee80211_vif *vif,
1607 struct ieee80211_bss_conf *bss_conf,
1610 struct ath9k_htc_priv *priv = hw->priv;
1611 struct ath_hw *ah = priv->ah;
1612 struct ath_common *common = ath9k_hw_common(ah);
1614 mutex_lock(&priv->mutex);
1615 ath9k_htc_ps_wakeup(priv);
1617 if (changed & BSS_CHANGED_ASSOC) {
1618 common->curaid = bss_conf->assoc ?
1620 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1623 if (bss_conf->assoc) {
1624 priv->op_flags |= OP_ASSOCIATED;
1625 ath_start_ani(priv);
1627 priv->op_flags &= ~OP_ASSOCIATED;
1628 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1632 if (changed & BSS_CHANGED_BSSID) {
1634 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1635 ath9k_hw_write_associd(ah);
1637 ath_print(common, ATH_DBG_CONFIG,
1638 "BSSID: %pM aid: 0x%x\n",
1639 common->curbssid, common->curaid);
1642 if ((changed & BSS_CHANGED_BEACON_INT) ||
1643 (changed & BSS_CHANGED_BEACON) ||
1644 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1645 bss_conf->enable_beacon)) {
1646 priv->op_flags |= OP_ENABLE_BEACON;
1647 ath9k_htc_beacon_config(priv, vif);
1650 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1651 !bss_conf->enable_beacon) {
1652 priv->op_flags &= ~OP_ENABLE_BEACON;
1653 ath9k_htc_beacon_config(priv, vif);
1656 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1657 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1658 bss_conf->use_short_preamble);
1659 if (bss_conf->use_short_preamble)
1660 priv->op_flags |= OP_PREAMBLE_SHORT;
1662 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1665 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1666 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1667 bss_conf->use_cts_prot);
1668 if (bss_conf->use_cts_prot &&
1669 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1670 priv->op_flags |= OP_PROTECT_ENABLE;
1672 priv->op_flags &= ~OP_PROTECT_ENABLE;
1675 if (changed & BSS_CHANGED_ERP_SLOT) {
1676 if (bss_conf->use_short_slot)
1681 ath9k_hw_init_global_settings(ah);
1684 if (changed & BSS_CHANGED_HT)
1685 ath9k_htc_update_rate(priv, vif, bss_conf);
1687 ath9k_htc_ps_restore(priv);
1688 mutex_unlock(&priv->mutex);
1691 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1693 struct ath9k_htc_priv *priv = hw->priv;
1696 mutex_lock(&priv->mutex);
1697 ath9k_htc_ps_wakeup(priv);
1698 tsf = ath9k_hw_gettsf64(priv->ah);
1699 ath9k_htc_ps_restore(priv);
1700 mutex_unlock(&priv->mutex);
1705 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1707 struct ath9k_htc_priv *priv = hw->priv;
1709 mutex_lock(&priv->mutex);
1710 ath9k_htc_ps_wakeup(priv);
1711 ath9k_hw_settsf64(priv->ah, tsf);
1712 ath9k_htc_ps_restore(priv);
1713 mutex_unlock(&priv->mutex);
1716 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1718 struct ath9k_htc_priv *priv = hw->priv;
1720 mutex_lock(&priv->mutex);
1721 ath9k_htc_ps_wakeup(priv);
1722 ath9k_hw_reset_tsf(priv->ah);
1723 ath9k_htc_ps_restore(priv);
1724 mutex_unlock(&priv->mutex);
1727 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1728 struct ieee80211_vif *vif,
1729 enum ieee80211_ampdu_mlme_action action,
1730 struct ieee80211_sta *sta,
1733 struct ath9k_htc_priv *priv = hw->priv;
1734 struct ath9k_htc_sta *ista;
1738 case IEEE80211_AMPDU_RX_START:
1740 case IEEE80211_AMPDU_RX_STOP:
1742 case IEEE80211_AMPDU_TX_START:
1743 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1745 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1747 case IEEE80211_AMPDU_TX_STOP:
1748 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1749 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1751 case IEEE80211_AMPDU_TX_OPERATIONAL:
1752 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1753 spin_lock_bh(&priv->tx_lock);
1754 ista->tid_state[tid] = AGGR_OPERATIONAL;
1755 spin_unlock_bh(&priv->tx_lock);
1758 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1759 "Unknown AMPDU action\n");
1765 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1767 struct ath9k_htc_priv *priv = hw->priv;
1769 mutex_lock(&priv->mutex);
1770 spin_lock_bh(&priv->beacon_lock);
1771 priv->op_flags |= OP_SCANNING;
1772 spin_unlock_bh(&priv->beacon_lock);
1773 cancel_work_sync(&priv->ps_work);
1774 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1775 mutex_unlock(&priv->mutex);
1778 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1780 struct ath9k_htc_priv *priv = hw->priv;
1782 mutex_lock(&priv->mutex);
1783 ath9k_htc_ps_wakeup(priv);
1784 spin_lock_bh(&priv->beacon_lock);
1785 priv->op_flags &= ~OP_SCANNING;
1786 spin_unlock_bh(&priv->beacon_lock);
1787 priv->op_flags |= OP_FULL_RESET;
1788 if (priv->op_flags & OP_ASSOCIATED)
1789 ath9k_htc_beacon_config(priv, priv->vif);
1790 ath_start_ani(priv);
1791 ath9k_htc_ps_restore(priv);
1792 mutex_unlock(&priv->mutex);
1795 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1800 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1803 struct ath9k_htc_priv *priv = hw->priv;
1805 mutex_lock(&priv->mutex);
1806 ath9k_htc_ps_wakeup(priv);
1807 priv->ah->coverage_class = coverage_class;
1808 ath9k_hw_init_global_settings(priv->ah);
1809 ath9k_htc_ps_restore(priv);
1810 mutex_unlock(&priv->mutex);
1813 struct ieee80211_ops ath9k_htc_ops = {
1815 .start = ath9k_htc_start,
1816 .stop = ath9k_htc_stop,
1817 .add_interface = ath9k_htc_add_interface,
1818 .remove_interface = ath9k_htc_remove_interface,
1819 .config = ath9k_htc_config,
1820 .configure_filter = ath9k_htc_configure_filter,
1821 .sta_add = ath9k_htc_sta_add,
1822 .sta_remove = ath9k_htc_sta_remove,
1823 .conf_tx = ath9k_htc_conf_tx,
1824 .bss_info_changed = ath9k_htc_bss_info_changed,
1825 .set_key = ath9k_htc_set_key,
1826 .get_tsf = ath9k_htc_get_tsf,
1827 .set_tsf = ath9k_htc_set_tsf,
1828 .reset_tsf = ath9k_htc_reset_tsf,
1829 .ampdu_action = ath9k_htc_ampdu_action,
1830 .sw_scan_start = ath9k_htc_sw_scan_start,
1831 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1832 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1833 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1834 .set_coverage_class = ath9k_htc_set_coverage_class,