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 =
496 (struct ath9k_htc_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 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
530 static const struct file_operations fops_tgt_stats = {
531 .read = read_file_tgt_stats,
532 .open = ath9k_debugfs_open,
536 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
537 size_t count, loff_t *ppos)
539 struct ath9k_htc_priv *priv =
540 (struct ath9k_htc_priv *) file->private_data;
542 unsigned int len = 0;
544 len += snprintf(buf + len, sizeof(buf) - len,
545 "%20s : %10u\n", "Buffers queued",
546 priv->debug.tx_stats.buf_queued);
547 len += snprintf(buf + len, sizeof(buf) - len,
548 "%20s : %10u\n", "Buffers completed",
549 priv->debug.tx_stats.buf_completed);
550 len += snprintf(buf + len, sizeof(buf) - len,
551 "%20s : %10u\n", "SKBs queued",
552 priv->debug.tx_stats.skb_queued);
553 len += snprintf(buf + len, sizeof(buf) - len,
554 "%20s : %10u\n", "SKBs completed",
555 priv->debug.tx_stats.skb_completed);
556 len += snprintf(buf + len, sizeof(buf) - len,
557 "%20s : %10u\n", "SKBs dropped",
558 priv->debug.tx_stats.skb_dropped);
560 len += snprintf(buf + len, sizeof(buf) - len,
561 "%20s : %10u\n", "BE queued",
562 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
563 len += snprintf(buf + len, sizeof(buf) - len,
564 "%20s : %10u\n", "BK queued",
565 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
566 len += snprintf(buf + len, sizeof(buf) - len,
567 "%20s : %10u\n", "VI queued",
568 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
569 len += snprintf(buf + len, sizeof(buf) - len,
570 "%20s : %10u\n", "VO queued",
571 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
573 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
576 static const struct file_operations fops_xmit = {
577 .read = read_file_xmit,
578 .open = ath9k_debugfs_open,
582 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
583 size_t count, loff_t *ppos)
585 struct ath9k_htc_priv *priv =
586 (struct ath9k_htc_priv *) file->private_data;
588 unsigned int len = 0;
590 len += snprintf(buf + len, sizeof(buf) - len,
591 "%20s : %10u\n", "SKBs allocated",
592 priv->debug.rx_stats.skb_allocated);
593 len += snprintf(buf + len, sizeof(buf) - len,
594 "%20s : %10u\n", "SKBs completed",
595 priv->debug.rx_stats.skb_completed);
596 len += snprintf(buf + len, sizeof(buf) - len,
597 "%20s : %10u\n", "SKBs Dropped",
598 priv->debug.rx_stats.skb_dropped);
600 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
603 static const struct file_operations fops_recv = {
604 .read = read_file_recv,
605 .open = ath9k_debugfs_open,
609 int ath9k_htc_init_debug(struct ath_hw *ah)
611 struct ath_common *common = ath9k_hw_common(ah);
612 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
614 if (!ath9k_debugfs_root)
617 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
619 if (!priv->debug.debugfs_phy)
622 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
623 priv->debug.debugfs_phy,
624 priv, &fops_tgt_stats);
625 if (!priv->debug.debugfs_tgt_stats)
629 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
630 priv->debug.debugfs_phy,
632 if (!priv->debug.debugfs_xmit)
635 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
636 priv->debug.debugfs_phy,
638 if (!priv->debug.debugfs_recv)
644 ath9k_htc_exit_debug(ah);
648 void ath9k_htc_exit_debug(struct ath_hw *ah)
650 struct ath_common *common = ath9k_hw_common(ah);
651 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
653 debugfs_remove(priv->debug.debugfs_recv);
654 debugfs_remove(priv->debug.debugfs_xmit);
655 debugfs_remove(priv->debug.debugfs_tgt_stats);
656 debugfs_remove(priv->debug.debugfs_phy);
659 int ath9k_htc_debug_create_root(void)
661 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
662 if (!ath9k_debugfs_root)
668 void ath9k_htc_debug_remove_root(void)
670 debugfs_remove(ath9k_debugfs_root);
671 ath9k_debugfs_root = NULL;
674 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
680 static void ath_start_ani(struct ath9k_htc_priv *priv)
682 struct ath_common *common = ath9k_hw_common(priv->ah);
683 unsigned long timestamp = jiffies_to_msecs(jiffies);
685 common->ani.longcal_timer = timestamp;
686 common->ani.shortcal_timer = timestamp;
687 common->ani.checkani_timer = timestamp;
689 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
690 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
693 void ath9k_ani_work(struct work_struct *work)
695 struct ath9k_htc_priv *priv =
696 container_of(work, struct ath9k_htc_priv,
697 ath9k_ani_work.work);
698 struct ath_hw *ah = priv->ah;
699 struct ath_common *common = ath9k_hw_common(ah);
700 bool longcal = false;
701 bool shortcal = false;
702 bool aniflag = false;
703 unsigned int timestamp = jiffies_to_msecs(jiffies);
704 u32 cal_interval, short_cal_interval;
706 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
708 /* Only calibrate if awake */
709 if (ah->power_mode != ATH9K_PM_AWAKE)
712 /* Long calibration runs independently of short calibration. */
713 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
715 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
716 common->ani.longcal_timer = timestamp;
719 /* Short calibration applies only while caldone is false */
720 if (!common->ani.caldone) {
721 if ((timestamp - common->ani.shortcal_timer) >=
722 short_cal_interval) {
724 ath_print(common, ATH_DBG_ANI,
725 "shortcal @%lu\n", jiffies);
726 common->ani.shortcal_timer = timestamp;
727 common->ani.resetcal_timer = timestamp;
730 if ((timestamp - common->ani.resetcal_timer) >=
731 ATH_RESTART_CALINTERVAL) {
732 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
733 if (common->ani.caldone)
734 common->ani.resetcal_timer = timestamp;
738 /* Verify whether we must check ANI */
739 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
741 common->ani.checkani_timer = timestamp;
744 /* Skip all processing if there's nothing to do. */
745 if (longcal || shortcal || aniflag) {
747 ath9k_htc_ps_wakeup(priv);
749 /* Call ANI routine if necessary */
751 ath9k_hw_ani_monitor(ah, ah->curchan);
753 /* Perform calibration if necessary */
754 if (longcal || shortcal) {
755 common->ani.caldone =
756 ath9k_hw_calibrate(ah, ah->curchan,
757 common->rx_chainmask,
761 common->ani.noise_floor =
762 ath9k_hw_getchan_noise(ah, ah->curchan);
764 ath_print(common, ATH_DBG_ANI,
765 " calibrate chan %u/%x nf: %d\n",
766 ah->curchan->channel,
767 ah->curchan->channelFlags,
768 common->ani.noise_floor);
771 ath9k_htc_ps_restore(priv);
776 * Set timer interval based on previous results.
777 * The interval must be the shortest necessary to satisfy ANI,
778 * short calibration and long calibration.
780 cal_interval = ATH_LONG_CALINTERVAL;
781 if (priv->ah->config.enable_ani)
782 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
783 if (!common->ani.caldone)
784 cal_interval = min(cal_interval, (u32)short_cal_interval);
786 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
787 msecs_to_jiffies(cal_interval));
794 static void ath9k_led_blink_work(struct work_struct *work)
796 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
797 ath9k_led_blink_work.work);
799 if (!(priv->op_flags & OP_LED_ASSOCIATED))
802 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
803 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
804 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
806 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
807 (priv->op_flags & OP_LED_ON) ? 1 : 0);
809 ieee80211_queue_delayed_work(priv->hw,
810 &priv->ath9k_led_blink_work,
811 (priv->op_flags & OP_LED_ON) ?
812 msecs_to_jiffies(priv->led_off_duration) :
813 msecs_to_jiffies(priv->led_on_duration));
815 priv->led_on_duration = priv->led_on_cnt ?
816 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
817 ATH_LED_ON_DURATION_IDLE;
818 priv->led_off_duration = priv->led_off_cnt ?
819 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
820 ATH_LED_OFF_DURATION_IDLE;
821 priv->led_on_cnt = priv->led_off_cnt = 0;
823 if (priv->op_flags & OP_LED_ON)
824 priv->op_flags &= ~OP_LED_ON;
826 priv->op_flags |= OP_LED_ON;
829 static void ath9k_led_brightness_work(struct work_struct *work)
831 struct ath_led *led = container_of(work, struct ath_led,
832 brightness_work.work);
833 struct ath9k_htc_priv *priv = led->priv;
835 switch (led->brightness) {
837 if (led->led_type == ATH_LED_ASSOC ||
838 led->led_type == ATH_LED_RADIO) {
839 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
840 (led->led_type == ATH_LED_RADIO));
841 priv->op_flags &= ~OP_LED_ASSOCIATED;
842 if (led->led_type == ATH_LED_RADIO)
843 priv->op_flags &= ~OP_LED_ON;
849 if (led->led_type == ATH_LED_ASSOC) {
850 priv->op_flags |= OP_LED_ASSOCIATED;
851 ieee80211_queue_delayed_work(priv->hw,
852 &priv->ath9k_led_blink_work, 0);
853 } else if (led->led_type == ATH_LED_RADIO) {
854 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
855 priv->op_flags |= OP_LED_ON;
865 static void ath9k_led_brightness(struct led_classdev *led_cdev,
866 enum led_brightness brightness)
868 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
869 struct ath9k_htc_priv *priv = led->priv;
871 led->brightness = brightness;
872 if (!(priv->op_flags & OP_LED_DEINIT))
873 ieee80211_queue_delayed_work(priv->hw,
874 &led->brightness_work, 0);
877 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
879 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
880 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
881 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
882 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
885 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
891 led->led_cdev.name = led->name;
892 led->led_cdev.default_trigger = trigger;
893 led->led_cdev.brightness_set = ath9k_led_brightness;
895 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
897 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
898 "Failed to register led:%s", led->name);
902 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
907 static void ath9k_unregister_led(struct ath_led *led)
909 if (led->registered) {
910 led_classdev_unregister(&led->led_cdev);
915 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
917 priv->op_flags |= OP_LED_DEINIT;
918 ath9k_unregister_led(&priv->assoc_led);
919 priv->op_flags &= ~OP_LED_ASSOCIATED;
920 ath9k_unregister_led(&priv->tx_led);
921 ath9k_unregister_led(&priv->rx_led);
922 ath9k_unregister_led(&priv->radio_led);
925 void ath9k_init_leds(struct ath9k_htc_priv *priv)
930 if (AR_SREV_9287(priv->ah))
931 priv->ah->led_pin = ATH_LED_PIN_9287;
932 else if (AR_SREV_9271(priv->ah))
933 priv->ah->led_pin = ATH_LED_PIN_9271;
934 else if (AR_DEVID_7010(priv->ah))
935 priv->ah->led_pin = ATH_LED_PIN_7010;
937 priv->ah->led_pin = ATH_LED_PIN_DEF;
939 /* Configure gpio 1 for output */
940 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
941 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
942 /* LED off, active low */
943 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
945 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
947 trigger = ieee80211_get_radio_led_name(priv->hw);
948 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
949 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
950 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
951 priv->radio_led.led_type = ATH_LED_RADIO;
955 trigger = ieee80211_get_assoc_led_name(priv->hw);
956 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
957 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
958 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
959 priv->assoc_led.led_type = ATH_LED_ASSOC;
963 trigger = ieee80211_get_tx_led_name(priv->hw);
964 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
965 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
966 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
967 priv->tx_led.led_type = ATH_LED_TX;
971 trigger = ieee80211_get_rx_led_name(priv->hw);
972 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
973 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
974 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
975 priv->rx_led.led_type = ATH_LED_RX;
979 priv->op_flags &= ~OP_LED_DEINIT;
984 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
985 ath9k_deinit_leds(priv);
988 /*******************/
990 /*******************/
992 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
994 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
995 priv->ah->rfkill_polarity;
998 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1000 struct ath9k_htc_priv *priv = hw->priv;
1001 bool blocked = !!ath_is_rfkill_set(priv);
1003 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1006 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1008 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1009 wiphy_rfkill_start_polling(priv->hw->wiphy);
1012 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1014 struct ath9k_htc_priv *priv = hw->priv;
1015 struct ath_hw *ah = priv->ah;
1016 struct ath_common *common = ath9k_hw_common(ah);
1021 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1024 ret = ath9k_hw_reset(ah, ah->curchan, false);
1026 ath_print(common, ATH_DBG_FATAL,
1027 "Unable to reset hardware; reset status %d "
1028 "(freq %u MHz)\n", ret, ah->curchan->channel);
1031 ath_update_txpow(priv);
1034 WMI_CMD(WMI_START_RECV_CMDID);
1035 ath9k_host_rx_init(priv);
1038 htc_start(priv->htc);
1039 spin_lock_bh(&priv->tx_lock);
1040 priv->tx_queues_stop = false;
1041 spin_unlock_bh(&priv->tx_lock);
1042 ieee80211_wake_queues(hw);
1044 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1047 ath9k_hw_cfg_output(ah, ah->led_pin,
1048 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1049 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1052 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1054 struct ath9k_htc_priv *priv = hw->priv;
1055 struct ath_hw *ah = priv->ah;
1056 struct ath_common *common = ath9k_hw_common(ah);
1060 ath9k_htc_ps_wakeup(priv);
1063 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1064 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1066 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1069 ieee80211_stop_queues(hw);
1070 htc_stop(priv->htc);
1071 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1072 skb_queue_purge(&priv->tx_queue);
1075 WMI_CMD(WMI_STOP_RECV_CMDID);
1078 * The MIB counters have to be disabled here,
1079 * since the target doesn't do it.
1081 ath9k_hw_disable_mib_counters(ah);
1084 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1087 ret = ath9k_hw_reset(ah, ah->curchan, false);
1089 ath_print(common, ATH_DBG_FATAL,
1090 "Unable to reset hardware; reset status %d "
1091 "(freq %u MHz)\n", ret, ah->curchan->channel);
1094 /* Disable the PHY */
1095 ath9k_hw_phy_disable(ah);
1097 ath9k_htc_ps_restore(priv);
1098 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1101 /**********************/
1102 /* mac80211 Callbacks */
1103 /**********************/
1105 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1107 struct ieee80211_hdr *hdr;
1108 struct ath9k_htc_priv *priv = hw->priv;
1109 int padpos, padsize, ret;
1111 hdr = (struct ieee80211_hdr *) skb->data;
1113 /* Add the padding after the header if this is not already done */
1114 padpos = ath9k_cmn_padpos(hdr->frame_control);
1115 padsize = padpos & 3;
1116 if (padsize && skb->len > padpos) {
1117 if (skb_headroom(skb) < padsize)
1119 skb_push(skb, padsize);
1120 memmove(skb->data, skb->data + padsize, padpos);
1123 ret = ath9k_htc_tx_start(priv, skb);
1125 if (ret == -ENOMEM) {
1126 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1127 "Stopping TX queues\n");
1128 ieee80211_stop_queues(hw);
1129 spin_lock_bh(&priv->tx_lock);
1130 priv->tx_queues_stop = true;
1131 spin_unlock_bh(&priv->tx_lock);
1133 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1142 dev_kfree_skb_any(skb);
1146 static int ath9k_htc_start(struct ieee80211_hw *hw)
1148 struct ath9k_htc_priv *priv = hw->priv;
1149 struct ath_hw *ah = priv->ah;
1150 struct ath_common *common = ath9k_hw_common(ah);
1151 struct ieee80211_channel *curchan = hw->conf.channel;
1152 struct ath9k_channel *init_channel;
1154 enum htc_phymode mode;
1158 mutex_lock(&priv->mutex);
1160 ath_print(common, ATH_DBG_CONFIG,
1161 "Starting driver with initial channel: %d MHz\n",
1162 curchan->center_freq);
1164 /* Ensure that HW is awake before flushing RX */
1165 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1166 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1168 /* setup initial channel */
1169 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1171 /* Reset SERDES registers */
1172 ath9k_hw_configpcipowersave(ah, 0, 0);
1174 ath9k_hw_htc_resetinit(ah);
1175 ret = ath9k_hw_reset(ah, init_channel, false);
1177 ath_print(common, ATH_DBG_FATAL,
1178 "Unable to reset hardware; reset status %d "
1179 "(freq %u MHz)\n", ret, curchan->center_freq);
1180 mutex_unlock(&priv->mutex);
1184 ath_update_txpow(priv);
1186 mode = ath9k_htc_get_curmode(priv, init_channel);
1187 htc_mode = cpu_to_be16(mode);
1188 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1189 WMI_CMD(WMI_ATH_INIT_CMDID);
1190 WMI_CMD(WMI_START_RECV_CMDID);
1192 ath9k_host_rx_init(priv);
1194 priv->op_flags &= ~OP_INVALID;
1195 htc_start(priv->htc);
1197 spin_lock_bh(&priv->tx_lock);
1198 priv->tx_queues_stop = false;
1199 spin_unlock_bh(&priv->tx_lock);
1201 ieee80211_wake_queues(hw);
1203 mutex_unlock(&priv->mutex);
1208 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1210 struct ath9k_htc_priv *priv = hw->priv;
1211 struct ath_hw *ah = priv->ah;
1212 struct ath_common *common = ath9k_hw_common(ah);
1216 mutex_lock(&priv->mutex);
1218 if (priv->op_flags & OP_INVALID) {
1219 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1220 mutex_unlock(&priv->mutex);
1224 /* Cancel all the running timers/work .. */
1225 cancel_work_sync(&priv->ps_work);
1226 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1227 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1228 ath9k_led_stop_brightness(priv);
1230 ath9k_htc_ps_wakeup(priv);
1231 htc_stop(priv->htc);
1232 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1233 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1234 WMI_CMD(WMI_STOP_RECV_CMDID);
1235 skb_queue_purge(&priv->tx_queue);
1237 /* Remove monitor interface here */
1238 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1239 if (ath9k_htc_remove_monitor_interface(priv))
1240 ath_print(common, ATH_DBG_FATAL,
1241 "Unable to remove monitor interface\n");
1243 ath_print(common, ATH_DBG_CONFIG,
1244 "Monitor interface removed\n");
1247 ath9k_hw_phy_disable(ah);
1248 ath9k_hw_disable(ah);
1249 ath9k_hw_configpcipowersave(ah, 1, 1);
1250 ath9k_htc_ps_restore(priv);
1251 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1253 priv->op_flags |= OP_INVALID;
1255 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1256 mutex_unlock(&priv->mutex);
1259 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1260 struct ieee80211_vif *vif)
1262 struct ath9k_htc_priv *priv = hw->priv;
1263 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1264 struct ath_common *common = ath9k_hw_common(priv->ah);
1265 struct ath9k_htc_target_vif hvif;
1269 mutex_lock(&priv->mutex);
1271 /* Only one interface for now */
1272 if (priv->nvifs > 0) {
1277 ath9k_htc_ps_wakeup(priv);
1278 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1279 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1281 switch (vif->type) {
1282 case NL80211_IFTYPE_STATION:
1283 hvif.opmode = cpu_to_be32(HTC_M_STA);
1285 case NL80211_IFTYPE_ADHOC:
1286 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1289 ath_print(common, ATH_DBG_FATAL,
1290 "Interface type %d not yet supported\n", vif->type);
1295 ath_print(common, ATH_DBG_CONFIG,
1296 "Attach a VIF of type: %d\n", vif->type);
1298 priv->ah->opmode = vif->type;
1300 /* Index starts from zero on the target */
1301 avp->index = hvif.index = priv->nvifs;
1302 hvif.rtsthreshold = cpu_to_be16(2304);
1303 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1310 * We need a node in target to tx mgmt frames
1311 * before association.
1313 ret = ath9k_htc_add_station(priv, vif, NULL);
1317 ret = ath9k_htc_update_cap_target(priv);
1319 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1320 " capability in target \n");
1324 ath9k_htc_ps_restore(priv);
1325 mutex_unlock(&priv->mutex);
1330 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1331 struct ieee80211_vif *vif)
1333 struct ath9k_htc_priv *priv = hw->priv;
1334 struct ath_common *common = ath9k_hw_common(priv->ah);
1335 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1336 struct ath9k_htc_target_vif hvif;
1340 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1342 mutex_lock(&priv->mutex);
1343 ath9k_htc_ps_wakeup(priv);
1345 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1346 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1347 hvif.index = avp->index;
1348 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1351 ath9k_htc_remove_station(priv, vif, NULL);
1354 ath9k_htc_ps_restore(priv);
1355 mutex_unlock(&priv->mutex);
1358 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1360 struct ath9k_htc_priv *priv = hw->priv;
1361 struct ath_common *common = ath9k_hw_common(priv->ah);
1362 struct ieee80211_conf *conf = &hw->conf;
1364 mutex_lock(&priv->mutex);
1366 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1367 bool enable_radio = false;
1368 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1370 mutex_lock(&priv->htc_pm_lock);
1371 if (!idle && priv->ps_idle)
1372 enable_radio = true;
1373 priv->ps_idle = idle;
1374 mutex_unlock(&priv->htc_pm_lock);
1377 ath_print(common, ATH_DBG_CONFIG,
1378 "not-idle: enabling radio\n");
1379 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1380 ath9k_htc_radio_enable(hw);
1384 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1385 struct ieee80211_channel *curchan = hw->conf.channel;
1386 int pos = curchan->hw_value;
1388 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1389 curchan->center_freq);
1391 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1393 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1394 ath_print(common, ATH_DBG_FATAL,
1395 "Unable to set channel\n");
1396 mutex_unlock(&priv->mutex);
1401 if (changed & IEEE80211_CONF_CHANGE_PS) {
1402 if (conf->flags & IEEE80211_CONF_PS) {
1403 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1404 priv->ps_enabled = true;
1406 priv->ps_enabled = false;
1407 cancel_work_sync(&priv->ps_work);
1408 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1412 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1413 if (conf->flags & IEEE80211_CONF_MONITOR) {
1414 if (ath9k_htc_add_monitor_interface(priv))
1415 ath_print(common, ATH_DBG_FATAL,
1416 "Failed to set monitor mode\n");
1418 ath_print(common, ATH_DBG_CONFIG,
1419 "HW opmode set to Monitor mode\n");
1423 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1424 mutex_lock(&priv->htc_pm_lock);
1425 if (!priv->ps_idle) {
1426 mutex_unlock(&priv->htc_pm_lock);
1429 mutex_unlock(&priv->htc_pm_lock);
1431 ath_print(common, ATH_DBG_CONFIG,
1432 "idle: disabling radio\n");
1433 ath9k_htc_radio_disable(hw);
1437 mutex_unlock(&priv->mutex);
1441 #define SUPPORTED_FILTERS \
1442 (FIF_PROMISC_IN_BSS | \
1447 FIF_BCN_PRBRESP_PROMISC | \
1450 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1451 unsigned int changed_flags,
1452 unsigned int *total_flags,
1455 struct ath9k_htc_priv *priv = hw->priv;
1458 mutex_lock(&priv->mutex);
1459 ath9k_htc_ps_wakeup(priv);
1461 changed_flags &= SUPPORTED_FILTERS;
1462 *total_flags &= SUPPORTED_FILTERS;
1464 priv->rxfilter = *total_flags;
1465 rfilt = ath9k_htc_calcrxfilter(priv);
1466 ath9k_hw_setrxfilter(priv->ah, rfilt);
1468 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1469 "Set HW RX filter: 0x%x\n", rfilt);
1471 ath9k_htc_ps_restore(priv);
1472 mutex_unlock(&priv->mutex);
1475 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1476 struct ieee80211_vif *vif,
1477 struct ieee80211_sta *sta)
1479 struct ath9k_htc_priv *priv = hw->priv;
1482 mutex_lock(&priv->mutex);
1483 ath9k_htc_ps_wakeup(priv);
1484 ret = ath9k_htc_add_station(priv, vif, sta);
1486 ath9k_htc_init_rate(priv, sta);
1487 ath9k_htc_ps_restore(priv);
1488 mutex_unlock(&priv->mutex);
1493 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1494 struct ieee80211_vif *vif,
1495 struct ieee80211_sta *sta)
1497 struct ath9k_htc_priv *priv = hw->priv;
1500 mutex_lock(&priv->mutex);
1501 ath9k_htc_ps_wakeup(priv);
1502 ret = ath9k_htc_remove_station(priv, vif, sta);
1503 ath9k_htc_ps_restore(priv);
1504 mutex_unlock(&priv->mutex);
1509 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1510 const struct ieee80211_tx_queue_params *params)
1512 struct ath9k_htc_priv *priv = hw->priv;
1513 struct ath_common *common = ath9k_hw_common(priv->ah);
1514 struct ath9k_tx_queue_info qi;
1517 if (queue >= WME_NUM_AC)
1520 mutex_lock(&priv->mutex);
1521 ath9k_htc_ps_wakeup(priv);
1523 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1525 qi.tqi_aifs = params->aifs;
1526 qi.tqi_cwmin = params->cw_min;
1527 qi.tqi_cwmax = params->cw_max;
1528 qi.tqi_burstTime = params->txop;
1530 qnum = get_hw_qnum(queue, priv->hwq_map);
1532 ath_print(common, ATH_DBG_CONFIG,
1533 "Configure tx [queue/hwq] [%d/%d], "
1534 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1535 queue, qnum, params->aifs, params->cw_min,
1536 params->cw_max, params->txop);
1538 ret = ath_htc_txq_update(priv, qnum, &qi);
1540 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1544 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1545 (qnum == priv->hwq_map[WME_AC_BE]))
1546 ath9k_htc_beaconq_config(priv);
1548 ath9k_htc_ps_restore(priv);
1549 mutex_unlock(&priv->mutex);
1554 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1555 enum set_key_cmd cmd,
1556 struct ieee80211_vif *vif,
1557 struct ieee80211_sta *sta,
1558 struct ieee80211_key_conf *key)
1560 struct ath9k_htc_priv *priv = hw->priv;
1561 struct ath_common *common = ath9k_hw_common(priv->ah);
1564 if (htc_modparam_nohwcrypt)
1567 mutex_lock(&priv->mutex);
1568 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1569 ath9k_htc_ps_wakeup(priv);
1573 ret = ath9k_cmn_key_config(common, vif, sta, key);
1575 key->hw_key_idx = ret;
1576 /* push IV and Michael MIC generation to stack */
1577 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1578 if (key->alg == ALG_TKIP)
1579 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1580 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1581 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1586 ath9k_cmn_key_delete(common, key);
1592 ath9k_htc_ps_restore(priv);
1593 mutex_unlock(&priv->mutex);
1598 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1599 struct ieee80211_vif *vif,
1600 struct ieee80211_bss_conf *bss_conf,
1603 struct ath9k_htc_priv *priv = hw->priv;
1604 struct ath_hw *ah = priv->ah;
1605 struct ath_common *common = ath9k_hw_common(ah);
1607 mutex_lock(&priv->mutex);
1608 ath9k_htc_ps_wakeup(priv);
1610 if (changed & BSS_CHANGED_ASSOC) {
1611 common->curaid = bss_conf->assoc ?
1613 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1616 if (bss_conf->assoc) {
1617 priv->op_flags |= OP_ASSOCIATED;
1618 ath_start_ani(priv);
1620 priv->op_flags &= ~OP_ASSOCIATED;
1621 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1625 if (changed & BSS_CHANGED_BSSID) {
1627 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1628 ath9k_hw_write_associd(ah);
1630 ath_print(common, ATH_DBG_CONFIG,
1631 "BSSID: %pM aid: 0x%x\n",
1632 common->curbssid, common->curaid);
1635 if ((changed & BSS_CHANGED_BEACON_INT) ||
1636 (changed & BSS_CHANGED_BEACON) ||
1637 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1638 bss_conf->enable_beacon)) {
1639 priv->op_flags |= OP_ENABLE_BEACON;
1640 ath9k_htc_beacon_config(priv, vif);
1643 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1644 !bss_conf->enable_beacon) {
1645 priv->op_flags &= ~OP_ENABLE_BEACON;
1646 ath9k_htc_beacon_config(priv, vif);
1649 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1650 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1651 bss_conf->use_short_preamble);
1652 if (bss_conf->use_short_preamble)
1653 priv->op_flags |= OP_PREAMBLE_SHORT;
1655 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1658 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1659 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1660 bss_conf->use_cts_prot);
1661 if (bss_conf->use_cts_prot &&
1662 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1663 priv->op_flags |= OP_PROTECT_ENABLE;
1665 priv->op_flags &= ~OP_PROTECT_ENABLE;
1668 if (changed & BSS_CHANGED_ERP_SLOT) {
1669 if (bss_conf->use_short_slot)
1674 ath9k_hw_init_global_settings(ah);
1677 if (changed & BSS_CHANGED_HT)
1678 ath9k_htc_update_rate(priv, vif, bss_conf);
1680 ath9k_htc_ps_restore(priv);
1681 mutex_unlock(&priv->mutex);
1684 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1686 struct ath9k_htc_priv *priv = hw->priv;
1689 mutex_lock(&priv->mutex);
1690 ath9k_htc_ps_wakeup(priv);
1691 tsf = ath9k_hw_gettsf64(priv->ah);
1692 ath9k_htc_ps_restore(priv);
1693 mutex_unlock(&priv->mutex);
1698 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1700 struct ath9k_htc_priv *priv = hw->priv;
1702 mutex_lock(&priv->mutex);
1703 ath9k_htc_ps_wakeup(priv);
1704 ath9k_hw_settsf64(priv->ah, tsf);
1705 ath9k_htc_ps_restore(priv);
1706 mutex_unlock(&priv->mutex);
1709 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1711 struct ath9k_htc_priv *priv = hw->priv;
1713 mutex_lock(&priv->mutex);
1714 ath9k_htc_ps_wakeup(priv);
1715 ath9k_hw_reset_tsf(priv->ah);
1716 ath9k_htc_ps_restore(priv);
1717 mutex_unlock(&priv->mutex);
1720 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1721 struct ieee80211_vif *vif,
1722 enum ieee80211_ampdu_mlme_action action,
1723 struct ieee80211_sta *sta,
1726 struct ath9k_htc_priv *priv = hw->priv;
1727 struct ath9k_htc_sta *ista;
1731 case IEEE80211_AMPDU_RX_START:
1733 case IEEE80211_AMPDU_RX_STOP:
1735 case IEEE80211_AMPDU_TX_START:
1736 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1738 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1740 case IEEE80211_AMPDU_TX_STOP:
1741 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1742 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1744 case IEEE80211_AMPDU_TX_OPERATIONAL:
1745 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1746 spin_lock_bh(&priv->tx_lock);
1747 ista->tid_state[tid] = AGGR_OPERATIONAL;
1748 spin_unlock_bh(&priv->tx_lock);
1751 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1752 "Unknown AMPDU action\n");
1758 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1760 struct ath9k_htc_priv *priv = hw->priv;
1762 mutex_lock(&priv->mutex);
1763 spin_lock_bh(&priv->beacon_lock);
1764 priv->op_flags |= OP_SCANNING;
1765 spin_unlock_bh(&priv->beacon_lock);
1766 cancel_work_sync(&priv->ps_work);
1767 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1768 mutex_unlock(&priv->mutex);
1771 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1773 struct ath9k_htc_priv *priv = hw->priv;
1775 mutex_lock(&priv->mutex);
1776 ath9k_htc_ps_wakeup(priv);
1777 spin_lock_bh(&priv->beacon_lock);
1778 priv->op_flags &= ~OP_SCANNING;
1779 spin_unlock_bh(&priv->beacon_lock);
1780 priv->op_flags |= OP_FULL_RESET;
1781 if (priv->op_flags & OP_ASSOCIATED)
1782 ath9k_htc_beacon_config(priv, priv->vif);
1783 ath_start_ani(priv);
1784 ath9k_htc_ps_restore(priv);
1785 mutex_unlock(&priv->mutex);
1788 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1793 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1796 struct ath9k_htc_priv *priv = hw->priv;
1798 mutex_lock(&priv->mutex);
1799 ath9k_htc_ps_wakeup(priv);
1800 priv->ah->coverage_class = coverage_class;
1801 ath9k_hw_init_global_settings(priv->ah);
1802 ath9k_htc_ps_restore(priv);
1803 mutex_unlock(&priv->mutex);
1806 struct ieee80211_ops ath9k_htc_ops = {
1808 .start = ath9k_htc_start,
1809 .stop = ath9k_htc_stop,
1810 .add_interface = ath9k_htc_add_interface,
1811 .remove_interface = ath9k_htc_remove_interface,
1812 .config = ath9k_htc_config,
1813 .configure_filter = ath9k_htc_configure_filter,
1814 .sta_add = ath9k_htc_sta_add,
1815 .sta_remove = ath9k_htc_sta_remove,
1816 .conf_tx = ath9k_htc_conf_tx,
1817 .bss_info_changed = ath9k_htc_bss_info_changed,
1818 .set_key = ath9k_htc_set_key,
1819 .get_tsf = ath9k_htc_get_tsf,
1820 .set_tsf = ath9k_htc_set_tsf,
1821 .reset_tsf = ath9k_htc_reset_tsf,
1822 .ampdu_action = ath9k_htc_ampdu_action,
1823 .sw_scan_start = ath9k_htc_sw_scan_start,
1824 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1825 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1826 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1827 .set_coverage_class = ath9k_htc_set_coverage_class,