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;
935 priv->ah->led_pin = ATH_LED_PIN_DEF;
937 /* Configure gpio 1 for output */
938 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
939 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
940 /* LED off, active low */
941 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
943 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
945 trigger = ieee80211_get_radio_led_name(priv->hw);
946 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
947 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
948 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
949 priv->radio_led.led_type = ATH_LED_RADIO;
953 trigger = ieee80211_get_assoc_led_name(priv->hw);
954 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
955 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
956 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
957 priv->assoc_led.led_type = ATH_LED_ASSOC;
961 trigger = ieee80211_get_tx_led_name(priv->hw);
962 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
963 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
964 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
965 priv->tx_led.led_type = ATH_LED_TX;
969 trigger = ieee80211_get_rx_led_name(priv->hw);
970 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
971 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
972 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
973 priv->rx_led.led_type = ATH_LED_RX;
977 priv->op_flags &= ~OP_LED_DEINIT;
982 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
983 ath9k_deinit_leds(priv);
986 /*******************/
988 /*******************/
990 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
992 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
993 priv->ah->rfkill_polarity;
996 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
998 struct ath9k_htc_priv *priv = hw->priv;
999 bool blocked = !!ath_is_rfkill_set(priv);
1001 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1004 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1006 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1007 wiphy_rfkill_start_polling(priv->hw->wiphy);
1010 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1012 struct ath9k_htc_priv *priv = hw->priv;
1013 struct ath_hw *ah = priv->ah;
1014 struct ath_common *common = ath9k_hw_common(ah);
1019 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1022 ret = ath9k_hw_reset(ah, ah->curchan, false);
1024 ath_print(common, ATH_DBG_FATAL,
1025 "Unable to reset hardware; reset status %d "
1026 "(freq %u MHz)\n", ret, ah->curchan->channel);
1029 ath_update_txpow(priv);
1032 WMI_CMD(WMI_START_RECV_CMDID);
1033 ath9k_host_rx_init(priv);
1036 htc_start(priv->htc);
1037 spin_lock_bh(&priv->tx_lock);
1038 priv->tx_queues_stop = false;
1039 spin_unlock_bh(&priv->tx_lock);
1040 ieee80211_wake_queues(hw);
1042 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1045 ath9k_hw_cfg_output(ah, ah->led_pin,
1046 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1047 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1050 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1052 struct ath9k_htc_priv *priv = hw->priv;
1053 struct ath_hw *ah = priv->ah;
1054 struct ath_common *common = ath9k_hw_common(ah);
1058 ath9k_htc_ps_wakeup(priv);
1061 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1062 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1064 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1067 ieee80211_stop_queues(hw);
1068 htc_stop(priv->htc);
1069 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1070 skb_queue_purge(&priv->tx_queue);
1073 WMI_CMD(WMI_STOP_RECV_CMDID);
1076 * The MIB counters have to be disabled here,
1077 * since the target doesn't do it.
1079 ath9k_hw_disable_mib_counters(ah);
1082 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1085 ret = ath9k_hw_reset(ah, ah->curchan, false);
1087 ath_print(common, ATH_DBG_FATAL,
1088 "Unable to reset hardware; reset status %d "
1089 "(freq %u MHz)\n", ret, ah->curchan->channel);
1092 /* Disable the PHY */
1093 ath9k_hw_phy_disable(ah);
1095 ath9k_htc_ps_restore(priv);
1096 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1099 /**********************/
1100 /* mac80211 Callbacks */
1101 /**********************/
1103 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1105 struct ieee80211_hdr *hdr;
1106 struct ath9k_htc_priv *priv = hw->priv;
1107 int padpos, padsize, ret;
1109 hdr = (struct ieee80211_hdr *) skb->data;
1111 /* Add the padding after the header if this is not already done */
1112 padpos = ath9k_cmn_padpos(hdr->frame_control);
1113 padsize = padpos & 3;
1114 if (padsize && skb->len > padpos) {
1115 if (skb_headroom(skb) < padsize)
1117 skb_push(skb, padsize);
1118 memmove(skb->data, skb->data + padsize, padpos);
1121 ret = ath9k_htc_tx_start(priv, skb);
1123 if (ret == -ENOMEM) {
1124 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1125 "Stopping TX queues\n");
1126 ieee80211_stop_queues(hw);
1127 spin_lock_bh(&priv->tx_lock);
1128 priv->tx_queues_stop = true;
1129 spin_unlock_bh(&priv->tx_lock);
1131 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1140 dev_kfree_skb_any(skb);
1144 static int ath9k_htc_start(struct ieee80211_hw *hw)
1146 struct ath9k_htc_priv *priv = hw->priv;
1147 struct ath_hw *ah = priv->ah;
1148 struct ath_common *common = ath9k_hw_common(ah);
1149 struct ieee80211_channel *curchan = hw->conf.channel;
1150 struct ath9k_channel *init_channel;
1152 enum htc_phymode mode;
1156 mutex_lock(&priv->mutex);
1158 ath_print(common, ATH_DBG_CONFIG,
1159 "Starting driver with initial channel: %d MHz\n",
1160 curchan->center_freq);
1162 /* Ensure that HW is awake before flushing RX */
1163 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1164 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1166 /* setup initial channel */
1167 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1169 /* Reset SERDES registers */
1170 ath9k_hw_configpcipowersave(ah, 0, 0);
1172 ath9k_hw_htc_resetinit(ah);
1173 ret = ath9k_hw_reset(ah, init_channel, false);
1175 ath_print(common, ATH_DBG_FATAL,
1176 "Unable to reset hardware; reset status %d "
1177 "(freq %u MHz)\n", ret, curchan->center_freq);
1178 mutex_unlock(&priv->mutex);
1182 ath_update_txpow(priv);
1184 mode = ath9k_htc_get_curmode(priv, init_channel);
1185 htc_mode = cpu_to_be16(mode);
1186 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1187 WMI_CMD(WMI_ATH_INIT_CMDID);
1188 WMI_CMD(WMI_START_RECV_CMDID);
1190 ath9k_host_rx_init(priv);
1192 priv->op_flags &= ~OP_INVALID;
1193 htc_start(priv->htc);
1195 spin_lock_bh(&priv->tx_lock);
1196 priv->tx_queues_stop = false;
1197 spin_unlock_bh(&priv->tx_lock);
1199 ieee80211_wake_queues(hw);
1201 mutex_unlock(&priv->mutex);
1206 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1208 struct ath9k_htc_priv *priv = hw->priv;
1209 struct ath_hw *ah = priv->ah;
1210 struct ath_common *common = ath9k_hw_common(ah);
1214 mutex_lock(&priv->mutex);
1216 if (priv->op_flags & OP_INVALID) {
1217 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1218 mutex_unlock(&priv->mutex);
1222 /* Cancel all the running timers/work .. */
1223 cancel_work_sync(&priv->ps_work);
1224 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1225 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1226 ath9k_led_stop_brightness(priv);
1228 ath9k_htc_ps_wakeup(priv);
1229 htc_stop(priv->htc);
1230 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1231 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1232 WMI_CMD(WMI_STOP_RECV_CMDID);
1233 skb_queue_purge(&priv->tx_queue);
1235 /* Remove monitor interface here */
1236 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1237 if (ath9k_htc_remove_monitor_interface(priv))
1238 ath_print(common, ATH_DBG_FATAL,
1239 "Unable to remove monitor interface\n");
1241 ath_print(common, ATH_DBG_CONFIG,
1242 "Monitor interface removed\n");
1245 ath9k_hw_phy_disable(ah);
1246 ath9k_hw_disable(ah);
1247 ath9k_hw_configpcipowersave(ah, 1, 1);
1248 ath9k_htc_ps_restore(priv);
1249 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1251 priv->op_flags |= OP_INVALID;
1253 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1254 mutex_unlock(&priv->mutex);
1257 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1258 struct ieee80211_vif *vif)
1260 struct ath9k_htc_priv *priv = hw->priv;
1261 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1262 struct ath_common *common = ath9k_hw_common(priv->ah);
1263 struct ath9k_htc_target_vif hvif;
1267 mutex_lock(&priv->mutex);
1269 /* Only one interface for now */
1270 if (priv->nvifs > 0) {
1275 ath9k_htc_ps_wakeup(priv);
1276 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1277 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1279 switch (vif->type) {
1280 case NL80211_IFTYPE_STATION:
1281 hvif.opmode = cpu_to_be32(HTC_M_STA);
1283 case NL80211_IFTYPE_ADHOC:
1284 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1287 ath_print(common, ATH_DBG_FATAL,
1288 "Interface type %d not yet supported\n", vif->type);
1293 ath_print(common, ATH_DBG_CONFIG,
1294 "Attach a VIF of type: %d\n", vif->type);
1296 priv->ah->opmode = vif->type;
1298 /* Index starts from zero on the target */
1299 avp->index = hvif.index = priv->nvifs;
1300 hvif.rtsthreshold = cpu_to_be16(2304);
1301 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1308 * We need a node in target to tx mgmt frames
1309 * before association.
1311 ret = ath9k_htc_add_station(priv, vif, NULL);
1315 ret = ath9k_htc_update_cap_target(priv);
1317 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1318 " capability in target \n");
1322 ath9k_htc_ps_restore(priv);
1323 mutex_unlock(&priv->mutex);
1328 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1329 struct ieee80211_vif *vif)
1331 struct ath9k_htc_priv *priv = hw->priv;
1332 struct ath_common *common = ath9k_hw_common(priv->ah);
1333 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1334 struct ath9k_htc_target_vif hvif;
1338 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1340 mutex_lock(&priv->mutex);
1341 ath9k_htc_ps_wakeup(priv);
1343 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1344 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1345 hvif.index = avp->index;
1346 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1349 ath9k_htc_remove_station(priv, vif, NULL);
1352 ath9k_htc_ps_restore(priv);
1353 mutex_unlock(&priv->mutex);
1356 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1358 struct ath9k_htc_priv *priv = hw->priv;
1359 struct ath_common *common = ath9k_hw_common(priv->ah);
1360 struct ieee80211_conf *conf = &hw->conf;
1362 mutex_lock(&priv->mutex);
1364 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1365 bool enable_radio = false;
1366 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1368 mutex_lock(&priv->htc_pm_lock);
1369 if (!idle && priv->ps_idle)
1370 enable_radio = true;
1371 priv->ps_idle = idle;
1372 mutex_unlock(&priv->htc_pm_lock);
1375 ath_print(common, ATH_DBG_CONFIG,
1376 "not-idle: enabling radio\n");
1377 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1378 ath9k_htc_radio_enable(hw);
1382 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1383 struct ieee80211_channel *curchan = hw->conf.channel;
1384 int pos = curchan->hw_value;
1386 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1387 curchan->center_freq);
1389 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1391 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1392 ath_print(common, ATH_DBG_FATAL,
1393 "Unable to set channel\n");
1394 mutex_unlock(&priv->mutex);
1399 if (changed & IEEE80211_CONF_CHANGE_PS) {
1400 if (conf->flags & IEEE80211_CONF_PS) {
1401 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1402 priv->ps_enabled = true;
1404 priv->ps_enabled = false;
1405 cancel_work_sync(&priv->ps_work);
1406 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1410 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1411 if (conf->flags & IEEE80211_CONF_MONITOR) {
1412 if (ath9k_htc_add_monitor_interface(priv))
1413 ath_print(common, ATH_DBG_FATAL,
1414 "Failed to set monitor mode\n");
1416 ath_print(common, ATH_DBG_CONFIG,
1417 "HW opmode set to Monitor mode\n");
1421 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1422 mutex_lock(&priv->htc_pm_lock);
1423 if (!priv->ps_idle) {
1424 mutex_unlock(&priv->htc_pm_lock);
1427 mutex_unlock(&priv->htc_pm_lock);
1429 ath_print(common, ATH_DBG_CONFIG,
1430 "idle: disabling radio\n");
1431 ath9k_htc_radio_disable(hw);
1435 mutex_unlock(&priv->mutex);
1439 #define SUPPORTED_FILTERS \
1440 (FIF_PROMISC_IN_BSS | \
1445 FIF_BCN_PRBRESP_PROMISC | \
1448 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1449 unsigned int changed_flags,
1450 unsigned int *total_flags,
1453 struct ath9k_htc_priv *priv = hw->priv;
1456 mutex_lock(&priv->mutex);
1457 ath9k_htc_ps_wakeup(priv);
1459 changed_flags &= SUPPORTED_FILTERS;
1460 *total_flags &= SUPPORTED_FILTERS;
1462 priv->rxfilter = *total_flags;
1463 rfilt = ath9k_htc_calcrxfilter(priv);
1464 ath9k_hw_setrxfilter(priv->ah, rfilt);
1466 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1467 "Set HW RX filter: 0x%x\n", rfilt);
1469 ath9k_htc_ps_restore(priv);
1470 mutex_unlock(&priv->mutex);
1473 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1474 struct ieee80211_vif *vif,
1475 struct ieee80211_sta *sta)
1477 struct ath9k_htc_priv *priv = hw->priv;
1480 mutex_lock(&priv->mutex);
1481 ath9k_htc_ps_wakeup(priv);
1482 ret = ath9k_htc_add_station(priv, vif, sta);
1484 ath9k_htc_init_rate(priv, sta);
1485 ath9k_htc_ps_restore(priv);
1486 mutex_unlock(&priv->mutex);
1491 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1492 struct ieee80211_vif *vif,
1493 struct ieee80211_sta *sta)
1495 struct ath9k_htc_priv *priv = hw->priv;
1498 mutex_lock(&priv->mutex);
1499 ath9k_htc_ps_wakeup(priv);
1500 ret = ath9k_htc_remove_station(priv, vif, sta);
1501 ath9k_htc_ps_restore(priv);
1502 mutex_unlock(&priv->mutex);
1507 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1508 const struct ieee80211_tx_queue_params *params)
1510 struct ath9k_htc_priv *priv = hw->priv;
1511 struct ath_common *common = ath9k_hw_common(priv->ah);
1512 struct ath9k_tx_queue_info qi;
1515 if (queue >= WME_NUM_AC)
1518 mutex_lock(&priv->mutex);
1519 ath9k_htc_ps_wakeup(priv);
1521 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1523 qi.tqi_aifs = params->aifs;
1524 qi.tqi_cwmin = params->cw_min;
1525 qi.tqi_cwmax = params->cw_max;
1526 qi.tqi_burstTime = params->txop;
1528 qnum = get_hw_qnum(queue, priv->hwq_map);
1530 ath_print(common, ATH_DBG_CONFIG,
1531 "Configure tx [queue/hwq] [%d/%d], "
1532 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1533 queue, qnum, params->aifs, params->cw_min,
1534 params->cw_max, params->txop);
1536 ret = ath_htc_txq_update(priv, qnum, &qi);
1538 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1542 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1543 (qnum == priv->hwq_map[WME_AC_BE]))
1544 ath9k_htc_beaconq_config(priv);
1546 ath9k_htc_ps_restore(priv);
1547 mutex_unlock(&priv->mutex);
1552 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1553 enum set_key_cmd cmd,
1554 struct ieee80211_vif *vif,
1555 struct ieee80211_sta *sta,
1556 struct ieee80211_key_conf *key)
1558 struct ath9k_htc_priv *priv = hw->priv;
1559 struct ath_common *common = ath9k_hw_common(priv->ah);
1562 if (htc_modparam_nohwcrypt)
1565 mutex_lock(&priv->mutex);
1566 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1567 ath9k_htc_ps_wakeup(priv);
1571 ret = ath9k_cmn_key_config(common, vif, sta, key);
1573 key->hw_key_idx = ret;
1574 /* push IV and Michael MIC generation to stack */
1575 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1576 if (key->alg == ALG_TKIP)
1577 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1578 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1579 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1584 ath9k_cmn_key_delete(common, key);
1590 ath9k_htc_ps_restore(priv);
1591 mutex_unlock(&priv->mutex);
1596 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1597 struct ieee80211_vif *vif,
1598 struct ieee80211_bss_conf *bss_conf,
1601 struct ath9k_htc_priv *priv = hw->priv;
1602 struct ath_hw *ah = priv->ah;
1603 struct ath_common *common = ath9k_hw_common(ah);
1605 mutex_lock(&priv->mutex);
1606 ath9k_htc_ps_wakeup(priv);
1608 if (changed & BSS_CHANGED_ASSOC) {
1609 common->curaid = bss_conf->assoc ?
1611 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1614 if (bss_conf->assoc) {
1615 priv->op_flags |= OP_ASSOCIATED;
1616 ath_start_ani(priv);
1618 priv->op_flags &= ~OP_ASSOCIATED;
1619 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1623 if (changed & BSS_CHANGED_BSSID) {
1625 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1626 ath9k_hw_write_associd(ah);
1628 ath_print(common, ATH_DBG_CONFIG,
1629 "BSSID: %pM aid: 0x%x\n",
1630 common->curbssid, common->curaid);
1633 if ((changed & BSS_CHANGED_BEACON_INT) ||
1634 (changed & BSS_CHANGED_BEACON) ||
1635 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1636 bss_conf->enable_beacon)) {
1637 priv->op_flags |= OP_ENABLE_BEACON;
1638 ath9k_htc_beacon_config(priv, vif);
1641 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1642 !bss_conf->enable_beacon) {
1643 priv->op_flags &= ~OP_ENABLE_BEACON;
1644 ath9k_htc_beacon_config(priv, vif);
1647 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1648 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1649 bss_conf->use_short_preamble);
1650 if (bss_conf->use_short_preamble)
1651 priv->op_flags |= OP_PREAMBLE_SHORT;
1653 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1656 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1657 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1658 bss_conf->use_cts_prot);
1659 if (bss_conf->use_cts_prot &&
1660 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1661 priv->op_flags |= OP_PROTECT_ENABLE;
1663 priv->op_flags &= ~OP_PROTECT_ENABLE;
1666 if (changed & BSS_CHANGED_ERP_SLOT) {
1667 if (bss_conf->use_short_slot)
1672 ath9k_hw_init_global_settings(ah);
1675 if (changed & BSS_CHANGED_HT)
1676 ath9k_htc_update_rate(priv, vif, bss_conf);
1678 ath9k_htc_ps_restore(priv);
1679 mutex_unlock(&priv->mutex);
1682 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1684 struct ath9k_htc_priv *priv = hw->priv;
1687 mutex_lock(&priv->mutex);
1688 ath9k_htc_ps_wakeup(priv);
1689 tsf = ath9k_hw_gettsf64(priv->ah);
1690 ath9k_htc_ps_restore(priv);
1691 mutex_unlock(&priv->mutex);
1696 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1698 struct ath9k_htc_priv *priv = hw->priv;
1700 mutex_lock(&priv->mutex);
1701 ath9k_htc_ps_wakeup(priv);
1702 ath9k_hw_settsf64(priv->ah, tsf);
1703 ath9k_htc_ps_restore(priv);
1704 mutex_unlock(&priv->mutex);
1707 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1709 struct ath9k_htc_priv *priv = hw->priv;
1711 mutex_lock(&priv->mutex);
1712 ath9k_htc_ps_wakeup(priv);
1713 ath9k_hw_reset_tsf(priv->ah);
1714 ath9k_htc_ps_restore(priv);
1715 mutex_unlock(&priv->mutex);
1718 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1719 struct ieee80211_vif *vif,
1720 enum ieee80211_ampdu_mlme_action action,
1721 struct ieee80211_sta *sta,
1724 struct ath9k_htc_priv *priv = hw->priv;
1725 struct ath9k_htc_sta *ista;
1729 case IEEE80211_AMPDU_RX_START:
1731 case IEEE80211_AMPDU_RX_STOP:
1733 case IEEE80211_AMPDU_TX_START:
1734 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1736 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1738 case IEEE80211_AMPDU_TX_STOP:
1739 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1740 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1742 case IEEE80211_AMPDU_TX_OPERATIONAL:
1743 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1744 spin_lock_bh(&priv->tx_lock);
1745 ista->tid_state[tid] = AGGR_OPERATIONAL;
1746 spin_unlock_bh(&priv->tx_lock);
1749 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1750 "Unknown AMPDU action\n");
1756 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1758 struct ath9k_htc_priv *priv = hw->priv;
1760 mutex_lock(&priv->mutex);
1761 spin_lock_bh(&priv->beacon_lock);
1762 priv->op_flags |= OP_SCANNING;
1763 spin_unlock_bh(&priv->beacon_lock);
1764 cancel_work_sync(&priv->ps_work);
1765 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1766 mutex_unlock(&priv->mutex);
1769 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1771 struct ath9k_htc_priv *priv = hw->priv;
1773 mutex_lock(&priv->mutex);
1774 ath9k_htc_ps_wakeup(priv);
1775 spin_lock_bh(&priv->beacon_lock);
1776 priv->op_flags &= ~OP_SCANNING;
1777 spin_unlock_bh(&priv->beacon_lock);
1778 priv->op_flags |= OP_FULL_RESET;
1779 if (priv->op_flags & OP_ASSOCIATED)
1780 ath9k_htc_beacon_config(priv, priv->vif);
1781 ath_start_ani(priv);
1782 ath9k_htc_ps_restore(priv);
1783 mutex_unlock(&priv->mutex);
1786 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1791 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1794 struct ath9k_htc_priv *priv = hw->priv;
1796 mutex_lock(&priv->mutex);
1797 ath9k_htc_ps_wakeup(priv);
1798 priv->ah->coverage_class = coverage_class;
1799 ath9k_hw_init_global_settings(priv->ah);
1800 ath9k_htc_ps_restore(priv);
1801 mutex_unlock(&priv->mutex);
1804 struct ieee80211_ops ath9k_htc_ops = {
1806 .start = ath9k_htc_start,
1807 .stop = ath9k_htc_stop,
1808 .add_interface = ath9k_htc_add_interface,
1809 .remove_interface = ath9k_htc_remove_interface,
1810 .config = ath9k_htc_config,
1811 .configure_filter = ath9k_htc_configure_filter,
1812 .sta_add = ath9k_htc_sta_add,
1813 .sta_remove = ath9k_htc_sta_remove,
1814 .conf_tx = ath9k_htc_conf_tx,
1815 .bss_info_changed = ath9k_htc_bss_info_changed,
1816 .set_key = ath9k_htc_set_key,
1817 .get_tsf = ath9k_htc_get_tsf,
1818 .set_tsf = ath9k_htc_set_tsf,
1819 .reset_tsf = ath9k_htc_reset_tsf,
1820 .ampdu_action = ath9k_htc_ampdu_action,
1821 .sw_scan_start = ath9k_htc_sw_scan_start,
1822 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1823 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1824 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1825 .set_coverage_class = ath9k_htc_set_coverage_class,