2 * Copyright (c) 2010 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
20 static struct dentry *ath9k_debugfs_root;
27 static void ath_update_txpow(struct ath9k_htc_priv *priv)
29 struct ath_hw *ah = priv->ah;
32 if (priv->curtxpow != priv->txpowlimit) {
33 ath9k_hw_set_txpowerlimit(ah, priv->txpowlimit);
34 /* read back in case value is clamped */
35 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
36 priv->curtxpow = txpow;
40 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
41 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
42 struct ath9k_channel *ichan)
44 enum htc_phymode mode;
48 switch (ichan->chanmode) {
51 case CHANNEL_G_HT40PLUS:
52 case CHANNEL_G_HT40MINUS:
57 case CHANNEL_A_HT40PLUS:
58 case CHANNEL_A_HT40MINUS:
68 static bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
69 enum ath9k_power_mode mode)
73 mutex_lock(&priv->htc_pm_lock);
74 ret = ath9k_hw_setpower(priv->ah, mode);
75 mutex_unlock(&priv->htc_pm_lock);
80 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
82 mutex_lock(&priv->htc_pm_lock);
83 if (++priv->ps_usecount != 1)
85 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
88 mutex_unlock(&priv->htc_pm_lock);
91 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
93 mutex_lock(&priv->htc_pm_lock);
94 if (--priv->ps_usecount != 0)
98 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
99 else if (priv->ps_enabled)
100 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
103 mutex_unlock(&priv->htc_pm_lock);
106 void ath9k_ps_work(struct work_struct *work)
108 struct ath9k_htc_priv *priv =
109 container_of(work, struct ath9k_htc_priv,
111 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
113 /* The chip wakes up after receiving the first beacon
114 while network sleep is enabled. For the driver to
115 be in sync with the hw, set the chip to awake and
116 only then set it to sleep.
118 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
121 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
122 struct ieee80211_hw *hw,
123 struct ath9k_channel *hchan)
125 struct ath_hw *ah = priv->ah;
126 struct ath_common *common = ath9k_hw_common(ah);
127 struct ieee80211_conf *conf = &common->hw->conf;
129 struct ieee80211_channel *channel = hw->conf.channel;
130 enum htc_phymode mode;
135 if (priv->op_flags & OP_INVALID)
138 if (priv->op_flags & OP_FULL_RESET)
141 /* Fiddle around with fastcc later on, for now just use full reset */
143 ath9k_htc_ps_wakeup(priv);
145 WMI_CMD(WMI_DISABLE_INTR_CMDID);
146 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
147 WMI_CMD(WMI_STOP_RECV_CMDID);
149 ath_print(common, ATH_DBG_CONFIG,
150 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d\n",
151 priv->ah->curchan->channel,
152 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
154 ret = ath9k_hw_reset(ah, hchan, fastcc);
156 ath_print(common, ATH_DBG_FATAL,
157 "Unable to reset channel (%u Mhz) "
158 "reset status %d\n", channel->center_freq, ret);
162 ath_update_txpow(priv);
164 WMI_CMD(WMI_START_RECV_CMDID);
168 ath9k_host_rx_init(priv);
170 mode = ath9k_htc_get_curmode(priv, hchan);
171 htc_mode = cpu_to_be16(mode);
172 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
176 WMI_CMD(WMI_ENABLE_INTR_CMDID);
180 htc_start(priv->htc);
182 priv->op_flags &= ~OP_FULL_RESET;
184 ath9k_htc_ps_restore(priv);
188 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
190 struct ath_common *common = ath9k_hw_common(priv->ah);
191 struct ath9k_htc_target_vif hvif;
198 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
199 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
201 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
202 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
203 hvif.index = priv->nvifs;
205 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
213 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
215 struct ath_common *common = ath9k_hw_common(priv->ah);
216 struct ath9k_htc_target_vif hvif;
220 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
221 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
222 hvif.index = 0; /* Should do for now */
223 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
229 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
230 struct ieee80211_vif *vif,
231 struct ieee80211_sta *sta)
233 struct ath_common *common = ath9k_hw_common(priv->ah);
234 struct ath9k_htc_target_sta tsta;
235 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
236 struct ath9k_htc_sta *ista;
240 if (priv->nstations >= ATH9K_HTC_MAX_STA)
243 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
246 ista = (struct ath9k_htc_sta *) sta->drv_priv;
247 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
248 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
249 tsta.associd = common->curaid;
252 ista->index = priv->nstations;
254 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
258 tsta.sta_index = priv->nstations;
259 tsta.vif_index = avp->index;
260 tsta.maxampdu = 0xffff;
261 if (sta && sta->ht_cap.ht_supported)
262 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
264 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
267 ath_print(common, ATH_DBG_FATAL,
268 "Unable to add station entry for: %pM\n", sta->addr);
273 ath_print(common, ATH_DBG_CONFIG,
274 "Added a station entry for: %pM (idx: %d)\n",
275 sta->addr, tsta.sta_index);
281 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
282 struct ieee80211_vif *vif,
283 struct ieee80211_sta *sta)
285 struct ath_common *common = ath9k_hw_common(priv->ah);
286 struct ath9k_htc_sta *ista;
291 ista = (struct ath9k_htc_sta *) sta->drv_priv;
292 sta_idx = ista->index;
297 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
300 ath_print(common, ATH_DBG_FATAL,
301 "Unable to remove station entry for: %pM\n",
307 ath_print(common, ATH_DBG_CONFIG,
308 "Removed a station entry for: %pM (idx: %d)\n",
315 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
317 struct ath9k_htc_cap_target tcap;
321 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
323 /* FIXME: Values are hardcoded */
324 tcap.flags = 0x240c40;
325 tcap.flags_ext = 0x80601000;
326 tcap.ampdu_limit = 0xffff0000;
327 tcap.ampdu_subframes = 20;
328 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
330 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
332 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
337 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
338 struct ieee80211_sta *sta,
339 struct ath9k_htc_target_rate *trate)
341 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
342 struct ieee80211_supported_band *sband;
346 /* Only 2GHz is supported */
347 sband = priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ];
349 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
350 if (sta->supp_rates[sband->band] & BIT(i)) {
351 trate->rates.legacy_rates.rs_rates[j]
352 = (sband->bitrates[i].bitrate * 2) / 10;
356 trate->rates.legacy_rates.rs_nrates = j;
358 if (sta->ht_cap.ht_supported) {
359 for (i = 0, j = 0; i < 77; i++) {
360 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
361 trate->rates.ht_rates.rs_rates[j++] = i;
362 if (j == ATH_HTC_RATE_MAX)
365 trate->rates.ht_rates.rs_nrates = j;
367 caps = WLAN_RC_HT_FLAG;
368 if (priv->ah->caps.tx_chainmask != 1 &&
369 ath9k_hw_getcapability(priv->ah, ATH9K_CAP_DS, 0, NULL)) {
370 if (sta->ht_cap.mcs.rx_mask[1])
371 caps |= WLAN_RC_DS_FLAG;
373 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
374 caps |= WLAN_RC_40_FLAG;
375 if (conf_is_ht40(&priv->hw->conf) &&
376 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
377 caps |= WLAN_RC_SGI_FLAG;
378 else if (conf_is_ht20(&priv->hw->conf) &&
379 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
380 caps |= WLAN_RC_SGI_FLAG;
383 trate->sta_index = ista->index;
385 trate->capflags = cpu_to_be32(caps);
388 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
389 struct ath9k_htc_target_rate *trate)
391 struct ath_common *common = ath9k_hw_common(priv->ah);
395 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
397 ath_print(common, ATH_DBG_FATAL,
398 "Unable to initialize Rate information on target\n");
404 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
405 struct ieee80211_sta *sta)
407 struct ath_common *common = ath9k_hw_common(priv->ah);
408 struct ath9k_htc_target_rate trate;
411 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
412 ath9k_htc_setup_rate(priv, sta, &trate);
413 ret = ath9k_htc_send_rate_cmd(priv, &trate);
415 ath_print(common, ATH_DBG_CONFIG,
416 "Updated target sta: %pM, rate caps: 0x%X\n",
417 sta->addr, be32_to_cpu(trate.capflags));
420 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
421 struct ieee80211_vif *vif,
422 struct ieee80211_bss_conf *bss_conf)
424 struct ath_common *common = ath9k_hw_common(priv->ah);
425 struct ath9k_htc_target_rate trate;
426 struct ieee80211_sta *sta;
429 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
432 sta = ieee80211_find_sta(vif, bss_conf->bssid);
437 ath9k_htc_setup_rate(priv, sta, &trate);
440 ret = ath9k_htc_send_rate_cmd(priv, &trate);
442 ath_print(common, ATH_DBG_CONFIG,
443 "Updated target sta: %pM, rate caps: 0x%X\n",
444 bss_conf->bssid, be32_to_cpu(trate.capflags));
447 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv *priv,
448 struct ieee80211_vif *vif,
449 u8 *sta_addr, u8 tid, bool oper)
451 struct ath_common *common = ath9k_hw_common(priv->ah);
452 struct ath9k_htc_target_aggr aggr;
453 struct ieee80211_sta *sta = NULL;
454 struct ath9k_htc_sta *ista;
458 if (tid >= ATH9K_HTC_MAX_TID)
461 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
465 /* Check if we are able to retrieve the station */
466 sta = ieee80211_find_sta(vif, sta_addr);
472 ista = (struct ath9k_htc_sta *) sta->drv_priv;
475 ista->tid_state[tid] = AGGR_START;
477 ista->tid_state[tid] = AGGR_STOP;
479 aggr.sta_index = ista->index;
484 aggr.aggr_enable = oper;
486 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
488 ath_print(common, ATH_DBG_CONFIG,
489 "Unable to %s TX aggregation for (%pM, %d)\n",
490 (oper) ? "start" : "stop", sta->addr, tid);
492 ath_print(common, ATH_DBG_CONFIG,
493 "%s aggregation for (%pM, %d)\n",
494 (oper) ? "Starting" : "Stopping", sta->addr, tid);
499 void ath9k_htc_aggr_work(struct work_struct *work)
502 struct ath9k_htc_priv *priv =
503 container_of(work, struct ath9k_htc_priv,
504 ath9k_aggr_work.work);
505 struct ath9k_htc_aggr_work *wk = &priv->aggr_work;
507 mutex_lock(&wk->mutex);
509 switch (wk->action) {
510 case IEEE80211_AMPDU_TX_START:
511 ret = ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
514 ieee80211_start_tx_ba_cb(wk->vif, wk->sta_addr,
517 case IEEE80211_AMPDU_TX_STOP:
518 ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
520 ieee80211_stop_tx_ba_cb(wk->vif, wk->sta_addr, wk->tid);
523 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
524 "Unknown AMPDU action\n");
527 mutex_unlock(&wk->mutex);
534 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
536 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
538 file->private_data = inode->i_private;
542 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
543 size_t count, loff_t *ppos)
545 struct ath9k_htc_priv *priv =
546 (struct ath9k_htc_priv *) file->private_data;
547 struct ath9k_htc_target_stats cmd_rsp;
549 unsigned int len = 0;
552 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
554 WMI_CMD(WMI_TGT_STATS_CMDID);
559 len += snprintf(buf + len, sizeof(buf) - len,
560 "%19s : %10u\n", "TX Short Retries",
561 be32_to_cpu(cmd_rsp.tx_shortretry));
562 len += snprintf(buf + len, sizeof(buf) - len,
563 "%19s : %10u\n", "TX Long Retries",
564 be32_to_cpu(cmd_rsp.tx_longretry));
565 len += snprintf(buf + len, sizeof(buf) - len,
566 "%19s : %10u\n", "TX Xretries",
567 be32_to_cpu(cmd_rsp.tx_xretries));
568 len += snprintf(buf + len, sizeof(buf) - len,
569 "%19s : %10u\n", "TX Unaggr. Xretries",
570 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
571 len += snprintf(buf + len, sizeof(buf) - len,
572 "%19s : %10u\n", "TX Xretries (HT)",
573 be32_to_cpu(cmd_rsp.ht_tx_xretries));
574 len += snprintf(buf + len, sizeof(buf) - len,
575 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
577 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
580 static const struct file_operations fops_tgt_stats = {
581 .read = read_file_tgt_stats,
582 .open = ath9k_debugfs_open,
586 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
587 size_t count, loff_t *ppos)
589 struct ath9k_htc_priv *priv =
590 (struct ath9k_htc_priv *) file->private_data;
592 unsigned int len = 0;
594 len += snprintf(buf + len, sizeof(buf) - len,
595 "%20s : %10u\n", "Buffers queued",
596 priv->debug.tx_stats.buf_queued);
597 len += snprintf(buf + len, sizeof(buf) - len,
598 "%20s : %10u\n", "Buffers completed",
599 priv->debug.tx_stats.buf_completed);
600 len += snprintf(buf + len, sizeof(buf) - len,
601 "%20s : %10u\n", "SKBs queued",
602 priv->debug.tx_stats.skb_queued);
603 len += snprintf(buf + len, sizeof(buf) - len,
604 "%20s : %10u\n", "SKBs completed",
605 priv->debug.tx_stats.skb_completed);
606 len += snprintf(buf + len, sizeof(buf) - len,
607 "%20s : %10u\n", "SKBs dropped",
608 priv->debug.tx_stats.skb_dropped);
610 len += snprintf(buf + len, sizeof(buf) - len,
611 "%20s : %10u\n", "BE queued",
612 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
613 len += snprintf(buf + len, sizeof(buf) - len,
614 "%20s : %10u\n", "BK queued",
615 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
616 len += snprintf(buf + len, sizeof(buf) - len,
617 "%20s : %10u\n", "VI queued",
618 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
619 len += snprintf(buf + len, sizeof(buf) - len,
620 "%20s : %10u\n", "VO queued",
621 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
623 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
626 static const struct file_operations fops_xmit = {
627 .read = read_file_xmit,
628 .open = ath9k_debugfs_open,
632 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
633 size_t count, loff_t *ppos)
635 struct ath9k_htc_priv *priv =
636 (struct ath9k_htc_priv *) file->private_data;
638 unsigned int len = 0;
640 len += snprintf(buf + len, sizeof(buf) - len,
641 "%20s : %10u\n", "SKBs allocated",
642 priv->debug.rx_stats.skb_allocated);
643 len += snprintf(buf + len, sizeof(buf) - len,
644 "%20s : %10u\n", "SKBs completed",
645 priv->debug.rx_stats.skb_completed);
646 len += snprintf(buf + len, sizeof(buf) - len,
647 "%20s : %10u\n", "SKBs Dropped",
648 priv->debug.rx_stats.skb_dropped);
650 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
653 static const struct file_operations fops_recv = {
654 .read = read_file_recv,
655 .open = ath9k_debugfs_open,
659 int ath9k_htc_init_debug(struct ath_hw *ah)
661 struct ath_common *common = ath9k_hw_common(ah);
662 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
664 if (!ath9k_debugfs_root)
667 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
669 if (!priv->debug.debugfs_phy)
672 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
673 priv->debug.debugfs_phy,
674 priv, &fops_tgt_stats);
675 if (!priv->debug.debugfs_tgt_stats)
679 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
680 priv->debug.debugfs_phy,
682 if (!priv->debug.debugfs_xmit)
685 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
686 priv->debug.debugfs_phy,
688 if (!priv->debug.debugfs_recv)
694 ath9k_htc_exit_debug(ah);
698 void ath9k_htc_exit_debug(struct ath_hw *ah)
700 struct ath_common *common = ath9k_hw_common(ah);
701 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
703 debugfs_remove(priv->debug.debugfs_recv);
704 debugfs_remove(priv->debug.debugfs_xmit);
705 debugfs_remove(priv->debug.debugfs_tgt_stats);
706 debugfs_remove(priv->debug.debugfs_phy);
709 int ath9k_htc_debug_create_root(void)
711 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
712 if (!ath9k_debugfs_root)
718 void ath9k_htc_debug_remove_root(void)
720 debugfs_remove(ath9k_debugfs_root);
721 ath9k_debugfs_root = NULL;
724 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
730 static void ath_start_ani(struct ath9k_htc_priv *priv)
732 struct ath_common *common = ath9k_hw_common(priv->ah);
733 unsigned long timestamp = jiffies_to_msecs(jiffies);
735 common->ani.longcal_timer = timestamp;
736 common->ani.shortcal_timer = timestamp;
737 common->ani.checkani_timer = timestamp;
739 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
740 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
743 void ath9k_ani_work(struct work_struct *work)
745 struct ath9k_htc_priv *priv =
746 container_of(work, struct ath9k_htc_priv,
747 ath9k_ani_work.work);
748 struct ath_hw *ah = priv->ah;
749 struct ath_common *common = ath9k_hw_common(ah);
750 bool longcal = false;
751 bool shortcal = false;
752 bool aniflag = false;
753 unsigned int timestamp = jiffies_to_msecs(jiffies);
754 u32 cal_interval, short_cal_interval;
756 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
758 /* Only calibrate if awake */
759 if (ah->power_mode != ATH9K_PM_AWAKE)
762 /* Long calibration runs independently of short calibration. */
763 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
765 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
766 common->ani.longcal_timer = timestamp;
769 /* Short calibration applies only while caldone is false */
770 if (!common->ani.caldone) {
771 if ((timestamp - common->ani.shortcal_timer) >=
772 short_cal_interval) {
774 ath_print(common, ATH_DBG_ANI,
775 "shortcal @%lu\n", jiffies);
776 common->ani.shortcal_timer = timestamp;
777 common->ani.resetcal_timer = timestamp;
780 if ((timestamp - common->ani.resetcal_timer) >=
781 ATH_RESTART_CALINTERVAL) {
782 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
783 if (common->ani.caldone)
784 common->ani.resetcal_timer = timestamp;
788 /* Verify whether we must check ANI */
789 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
791 common->ani.checkani_timer = timestamp;
794 /* Skip all processing if there's nothing to do. */
795 if (longcal || shortcal || aniflag) {
797 ath9k_htc_ps_wakeup(priv);
799 /* Call ANI routine if necessary */
801 ath9k_hw_ani_monitor(ah, ah->curchan);
803 /* Perform calibration if necessary */
804 if (longcal || shortcal) {
805 common->ani.caldone =
806 ath9k_hw_calibrate(ah, ah->curchan,
807 common->rx_chainmask,
811 common->ani.noise_floor =
812 ath9k_hw_getchan_noise(ah, ah->curchan);
814 ath_print(common, ATH_DBG_ANI,
815 " calibrate chan %u/%x nf: %d\n",
816 ah->curchan->channel,
817 ah->curchan->channelFlags,
818 common->ani.noise_floor);
821 ath9k_htc_ps_restore(priv);
826 * Set timer interval based on previous results.
827 * The interval must be the shortest necessary to satisfy ANI,
828 * short calibration and long calibration.
830 cal_interval = ATH_LONG_CALINTERVAL;
831 if (priv->ah->config.enable_ani)
832 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
833 if (!common->ani.caldone)
834 cal_interval = min(cal_interval, (u32)short_cal_interval);
836 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
837 msecs_to_jiffies(cal_interval));
844 static void ath9k_led_blink_work(struct work_struct *work)
846 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
847 ath9k_led_blink_work.work);
849 if (!(priv->op_flags & OP_LED_ASSOCIATED))
852 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
853 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
854 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
856 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
857 (priv->op_flags & OP_LED_ON) ? 1 : 0);
859 ieee80211_queue_delayed_work(priv->hw,
860 &priv->ath9k_led_blink_work,
861 (priv->op_flags & OP_LED_ON) ?
862 msecs_to_jiffies(priv->led_off_duration) :
863 msecs_to_jiffies(priv->led_on_duration));
865 priv->led_on_duration = priv->led_on_cnt ?
866 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
867 ATH_LED_ON_DURATION_IDLE;
868 priv->led_off_duration = priv->led_off_cnt ?
869 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
870 ATH_LED_OFF_DURATION_IDLE;
871 priv->led_on_cnt = priv->led_off_cnt = 0;
873 if (priv->op_flags & OP_LED_ON)
874 priv->op_flags &= ~OP_LED_ON;
876 priv->op_flags |= OP_LED_ON;
879 static void ath9k_led_brightness_work(struct work_struct *work)
881 struct ath_led *led = container_of(work, struct ath_led,
882 brightness_work.work);
883 struct ath9k_htc_priv *priv = led->priv;
885 switch (led->brightness) {
887 if (led->led_type == ATH_LED_ASSOC ||
888 led->led_type == ATH_LED_RADIO) {
889 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
890 (led->led_type == ATH_LED_RADIO));
891 priv->op_flags &= ~OP_LED_ASSOCIATED;
892 if (led->led_type == ATH_LED_RADIO)
893 priv->op_flags &= ~OP_LED_ON;
899 if (led->led_type == ATH_LED_ASSOC) {
900 priv->op_flags |= OP_LED_ASSOCIATED;
901 ieee80211_queue_delayed_work(priv->hw,
902 &priv->ath9k_led_blink_work, 0);
903 } else if (led->led_type == ATH_LED_RADIO) {
904 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
905 priv->op_flags |= OP_LED_ON;
915 static void ath9k_led_brightness(struct led_classdev *led_cdev,
916 enum led_brightness brightness)
918 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
919 struct ath9k_htc_priv *priv = led->priv;
921 led->brightness = brightness;
922 if (!(priv->op_flags & OP_LED_DEINIT))
923 ieee80211_queue_delayed_work(priv->hw,
924 &led->brightness_work, 0);
927 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
929 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
930 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
931 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
932 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
935 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
941 led->led_cdev.name = led->name;
942 led->led_cdev.default_trigger = trigger;
943 led->led_cdev.brightness_set = ath9k_led_brightness;
945 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
947 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
948 "Failed to register led:%s", led->name);
952 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
957 static void ath9k_unregister_led(struct ath_led *led)
959 if (led->registered) {
960 led_classdev_unregister(&led->led_cdev);
965 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
967 priv->op_flags |= OP_LED_DEINIT;
968 ath9k_unregister_led(&priv->assoc_led);
969 priv->op_flags &= ~OP_LED_ASSOCIATED;
970 ath9k_unregister_led(&priv->tx_led);
971 ath9k_unregister_led(&priv->rx_led);
972 ath9k_unregister_led(&priv->radio_led);
975 void ath9k_init_leds(struct ath9k_htc_priv *priv)
980 if (AR_SREV_9287(priv->ah))
981 priv->ah->led_pin = ATH_LED_PIN_9287;
982 else if (AR_SREV_9271(priv->ah))
983 priv->ah->led_pin = ATH_LED_PIN_9271;
985 priv->ah->led_pin = ATH_LED_PIN_DEF;
987 /* Configure gpio 1 for output */
988 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
989 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
990 /* LED off, active low */
991 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
993 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
995 trigger = ieee80211_get_radio_led_name(priv->hw);
996 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
997 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
998 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
999 priv->radio_led.led_type = ATH_LED_RADIO;
1003 trigger = ieee80211_get_assoc_led_name(priv->hw);
1004 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
1005 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
1006 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
1007 priv->assoc_led.led_type = ATH_LED_ASSOC;
1011 trigger = ieee80211_get_tx_led_name(priv->hw);
1012 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
1013 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
1014 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
1015 priv->tx_led.led_type = ATH_LED_TX;
1019 trigger = ieee80211_get_rx_led_name(priv->hw);
1020 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
1021 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
1022 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
1023 priv->rx_led.led_type = ATH_LED_RX;
1027 priv->op_flags &= ~OP_LED_DEINIT;
1032 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1033 ath9k_deinit_leds(priv);
1036 /*******************/
1038 /*******************/
1040 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1042 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1043 priv->ah->rfkill_polarity;
1046 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1048 struct ath9k_htc_priv *priv = hw->priv;
1049 bool blocked = !!ath_is_rfkill_set(priv);
1051 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1054 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1056 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1057 wiphy_rfkill_start_polling(priv->hw->wiphy);
1060 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1062 struct ath9k_htc_priv *priv = hw->priv;
1063 struct ath_hw *ah = priv->ah;
1064 struct ath_common *common = ath9k_hw_common(ah);
1069 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1072 ret = ath9k_hw_reset(ah, ah->curchan, false);
1074 ath_print(common, ATH_DBG_FATAL,
1075 "Unable to reset hardware; reset status %d "
1076 "(freq %u MHz)\n", ret, ah->curchan->channel);
1079 ath_update_txpow(priv);
1082 WMI_CMD(WMI_START_RECV_CMDID);
1083 ath9k_host_rx_init(priv);
1086 htc_start(priv->htc);
1087 spin_lock_bh(&priv->tx_lock);
1088 priv->tx_queues_stop = false;
1089 spin_unlock_bh(&priv->tx_lock);
1090 ieee80211_wake_queues(hw);
1092 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1095 ath9k_hw_cfg_output(ah, ah->led_pin,
1096 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1097 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1100 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1102 struct ath9k_htc_priv *priv = hw->priv;
1103 struct ath_hw *ah = priv->ah;
1104 struct ath_common *common = ath9k_hw_common(ah);
1108 ath9k_htc_ps_wakeup(priv);
1111 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1112 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1114 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1117 ieee80211_stop_queues(hw);
1118 htc_stop(priv->htc);
1119 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1120 skb_queue_purge(&priv->tx_queue);
1123 WMI_CMD(WMI_STOP_RECV_CMDID);
1126 * The MIB counters have to be disabled here,
1127 * since the target doesn't do it.
1129 ath9k_hw_disable_mib_counters(ah);
1132 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1135 ret = ath9k_hw_reset(ah, ah->curchan, false);
1137 ath_print(common, ATH_DBG_FATAL,
1138 "Unable to reset hardware; reset status %d "
1139 "(freq %u MHz)\n", ret, ah->curchan->channel);
1142 /* Disable the PHY */
1143 ath9k_hw_phy_disable(ah);
1145 ath9k_htc_ps_restore(priv);
1146 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1149 /**********************/
1150 /* mac80211 Callbacks */
1151 /**********************/
1153 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1155 struct ieee80211_hdr *hdr;
1156 struct ath9k_htc_priv *priv = hw->priv;
1157 int padpos, padsize, ret;
1159 hdr = (struct ieee80211_hdr *) skb->data;
1161 /* Add the padding after the header if this is not already done */
1162 padpos = ath9k_cmn_padpos(hdr->frame_control);
1163 padsize = padpos & 3;
1164 if (padsize && skb->len > padpos) {
1165 if (skb_headroom(skb) < padsize)
1167 skb_push(skb, padsize);
1168 memmove(skb->data, skb->data + padsize, padpos);
1171 ret = ath9k_htc_tx_start(priv, skb);
1173 if (ret == -ENOMEM) {
1174 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1175 "Stopping TX queues\n");
1176 ieee80211_stop_queues(hw);
1177 spin_lock_bh(&priv->tx_lock);
1178 priv->tx_queues_stop = true;
1179 spin_unlock_bh(&priv->tx_lock);
1181 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1190 dev_kfree_skb_any(skb);
1194 static int ath9k_htc_start(struct ieee80211_hw *hw)
1196 struct ath9k_htc_priv *priv = hw->priv;
1197 struct ath_hw *ah = priv->ah;
1198 struct ath_common *common = ath9k_hw_common(ah);
1199 struct ieee80211_channel *curchan = hw->conf.channel;
1200 struct ath9k_channel *init_channel;
1202 enum htc_phymode mode;
1206 mutex_lock(&priv->mutex);
1208 ath_print(common, ATH_DBG_CONFIG,
1209 "Starting driver with initial channel: %d MHz\n",
1210 curchan->center_freq);
1212 /* Ensure that HW is awake before flushing RX */
1213 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1214 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1216 /* setup initial channel */
1217 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1219 /* Reset SERDES registers */
1220 ath9k_hw_configpcipowersave(ah, 0, 0);
1222 ath9k_hw_htc_resetinit(ah);
1223 ret = ath9k_hw_reset(ah, init_channel, false);
1225 ath_print(common, ATH_DBG_FATAL,
1226 "Unable to reset hardware; reset status %d "
1227 "(freq %u MHz)\n", ret, curchan->center_freq);
1228 mutex_unlock(&priv->mutex);
1232 ath_update_txpow(priv);
1234 mode = ath9k_htc_get_curmode(priv, init_channel);
1235 htc_mode = cpu_to_be16(mode);
1236 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1237 WMI_CMD(WMI_ATH_INIT_CMDID);
1238 WMI_CMD(WMI_START_RECV_CMDID);
1240 ath9k_host_rx_init(priv);
1242 priv->op_flags &= ~OP_INVALID;
1243 htc_start(priv->htc);
1245 spin_lock_bh(&priv->tx_lock);
1246 priv->tx_queues_stop = false;
1247 spin_unlock_bh(&priv->tx_lock);
1249 ieee80211_wake_queues(hw);
1251 mutex_unlock(&priv->mutex);
1256 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1258 struct ath9k_htc_priv *priv = hw->priv;
1259 struct ath_hw *ah = priv->ah;
1260 struct ath_common *common = ath9k_hw_common(ah);
1264 mutex_lock(&priv->mutex);
1266 if (priv->op_flags & OP_INVALID) {
1267 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1268 mutex_unlock(&priv->mutex);
1272 /* Cancel all the running timers/work .. */
1273 cancel_work_sync(&priv->ps_work);
1274 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1275 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1276 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1277 ath9k_led_stop_brightness(priv);
1279 ath9k_htc_ps_wakeup(priv);
1280 htc_stop(priv->htc);
1281 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1282 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1283 WMI_CMD(WMI_STOP_RECV_CMDID);
1284 skb_queue_purge(&priv->tx_queue);
1286 /* Remove monitor interface here */
1287 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1288 if (ath9k_htc_remove_monitor_interface(priv))
1289 ath_print(common, ATH_DBG_FATAL,
1290 "Unable to remove monitor interface\n");
1292 ath_print(common, ATH_DBG_CONFIG,
1293 "Monitor interface removed\n");
1296 ath9k_hw_phy_disable(ah);
1297 ath9k_hw_disable(ah);
1298 ath9k_hw_configpcipowersave(ah, 1, 1);
1299 ath9k_htc_ps_restore(priv);
1300 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1302 priv->op_flags |= OP_INVALID;
1304 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1305 mutex_unlock(&priv->mutex);
1308 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1309 struct ieee80211_vif *vif)
1311 struct ath9k_htc_priv *priv = hw->priv;
1312 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1313 struct ath_common *common = ath9k_hw_common(priv->ah);
1314 struct ath9k_htc_target_vif hvif;
1318 mutex_lock(&priv->mutex);
1320 /* Only one interface for now */
1321 if (priv->nvifs > 0) {
1326 ath9k_htc_ps_wakeup(priv);
1327 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1328 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1330 switch (vif->type) {
1331 case NL80211_IFTYPE_STATION:
1332 hvif.opmode = cpu_to_be32(HTC_M_STA);
1334 case NL80211_IFTYPE_ADHOC:
1335 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1338 ath_print(common, ATH_DBG_FATAL,
1339 "Interface type %d not yet supported\n", vif->type);
1344 ath_print(common, ATH_DBG_CONFIG,
1345 "Attach a VIF of type: %d\n", vif->type);
1347 priv->ah->opmode = vif->type;
1349 /* Index starts from zero on the target */
1350 avp->index = hvif.index = priv->nvifs;
1351 hvif.rtsthreshold = cpu_to_be16(2304);
1352 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1359 * We need a node in target to tx mgmt frames
1360 * before association.
1362 ret = ath9k_htc_add_station(priv, vif, NULL);
1366 ret = ath9k_htc_update_cap_target(priv);
1368 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1369 " capability in target \n");
1373 ath9k_htc_ps_restore(priv);
1374 mutex_unlock(&priv->mutex);
1379 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1380 struct ieee80211_vif *vif)
1382 struct ath9k_htc_priv *priv = hw->priv;
1383 struct ath_common *common = ath9k_hw_common(priv->ah);
1384 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1385 struct ath9k_htc_target_vif hvif;
1389 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1391 mutex_lock(&priv->mutex);
1392 ath9k_htc_ps_wakeup(priv);
1394 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1395 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1396 hvif.index = avp->index;
1397 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1400 ath9k_htc_remove_station(priv, vif, NULL);
1403 ath9k_htc_ps_restore(priv);
1404 mutex_unlock(&priv->mutex);
1407 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1409 struct ath9k_htc_priv *priv = hw->priv;
1410 struct ath_common *common = ath9k_hw_common(priv->ah);
1411 struct ieee80211_conf *conf = &hw->conf;
1413 mutex_lock(&priv->mutex);
1415 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1416 bool enable_radio = false;
1417 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1419 mutex_lock(&priv->htc_pm_lock);
1420 if (!idle && priv->ps_idle)
1421 enable_radio = true;
1422 priv->ps_idle = idle;
1423 mutex_unlock(&priv->htc_pm_lock);
1426 ath_print(common, ATH_DBG_CONFIG,
1427 "not-idle: enabling radio\n");
1428 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1429 ath9k_htc_radio_enable(hw);
1433 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1434 struct ieee80211_channel *curchan = hw->conf.channel;
1435 int pos = curchan->hw_value;
1437 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1438 curchan->center_freq);
1440 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1442 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1443 ath_print(common, ATH_DBG_FATAL,
1444 "Unable to set channel\n");
1445 mutex_unlock(&priv->mutex);
1450 if (changed & IEEE80211_CONF_CHANGE_PS) {
1451 if (conf->flags & IEEE80211_CONF_PS) {
1452 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1453 priv->ps_enabled = true;
1455 priv->ps_enabled = false;
1456 cancel_work_sync(&priv->ps_work);
1457 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1461 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1462 if (conf->flags & IEEE80211_CONF_MONITOR) {
1463 if (ath9k_htc_add_monitor_interface(priv))
1464 ath_print(common, ATH_DBG_FATAL,
1465 "Failed to set monitor mode\n");
1467 ath_print(common, ATH_DBG_CONFIG,
1468 "HW opmode set to Monitor mode\n");
1472 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1473 mutex_lock(&priv->htc_pm_lock);
1474 if (!priv->ps_idle) {
1475 mutex_unlock(&priv->htc_pm_lock);
1478 mutex_unlock(&priv->htc_pm_lock);
1480 ath_print(common, ATH_DBG_CONFIG,
1481 "idle: disabling radio\n");
1482 ath9k_htc_radio_disable(hw);
1486 mutex_unlock(&priv->mutex);
1490 #define SUPPORTED_FILTERS \
1491 (FIF_PROMISC_IN_BSS | \
1496 FIF_BCN_PRBRESP_PROMISC | \
1499 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1500 unsigned int changed_flags,
1501 unsigned int *total_flags,
1504 struct ath9k_htc_priv *priv = hw->priv;
1507 mutex_lock(&priv->mutex);
1508 ath9k_htc_ps_wakeup(priv);
1510 changed_flags &= SUPPORTED_FILTERS;
1511 *total_flags &= SUPPORTED_FILTERS;
1513 priv->rxfilter = *total_flags;
1514 rfilt = ath9k_htc_calcrxfilter(priv);
1515 ath9k_hw_setrxfilter(priv->ah, rfilt);
1517 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1518 "Set HW RX filter: 0x%x\n", rfilt);
1520 ath9k_htc_ps_restore(priv);
1521 mutex_unlock(&priv->mutex);
1524 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1525 struct ieee80211_vif *vif,
1526 struct ieee80211_sta *sta)
1528 struct ath9k_htc_priv *priv = hw->priv;
1531 mutex_lock(&priv->mutex);
1532 ath9k_htc_ps_wakeup(priv);
1533 ret = ath9k_htc_add_station(priv, vif, sta);
1535 ath9k_htc_init_rate(priv, sta);
1536 ath9k_htc_ps_restore(priv);
1537 mutex_unlock(&priv->mutex);
1542 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1543 struct ieee80211_vif *vif,
1544 struct ieee80211_sta *sta)
1546 struct ath9k_htc_priv *priv = hw->priv;
1549 mutex_lock(&priv->mutex);
1550 ath9k_htc_ps_wakeup(priv);
1551 ret = ath9k_htc_remove_station(priv, vif, sta);
1552 ath9k_htc_ps_restore(priv);
1553 mutex_unlock(&priv->mutex);
1558 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1559 const struct ieee80211_tx_queue_params *params)
1561 struct ath9k_htc_priv *priv = hw->priv;
1562 struct ath_common *common = ath9k_hw_common(priv->ah);
1563 struct ath9k_tx_queue_info qi;
1566 if (queue >= WME_NUM_AC)
1569 mutex_lock(&priv->mutex);
1570 ath9k_htc_ps_wakeup(priv);
1572 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1574 qi.tqi_aifs = params->aifs;
1575 qi.tqi_cwmin = params->cw_min;
1576 qi.tqi_cwmax = params->cw_max;
1577 qi.tqi_burstTime = params->txop;
1579 qnum = get_hw_qnum(queue, priv->hwq_map);
1581 ath_print(common, ATH_DBG_CONFIG,
1582 "Configure tx [queue/hwq] [%d/%d], "
1583 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1584 queue, qnum, params->aifs, params->cw_min,
1585 params->cw_max, params->txop);
1587 ret = ath_htc_txq_update(priv, qnum, &qi);
1589 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1593 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1594 (qnum == priv->hwq_map[ATH9K_WME_AC_BE]))
1595 ath9k_htc_beaconq_config(priv);
1597 ath9k_htc_ps_restore(priv);
1598 mutex_unlock(&priv->mutex);
1603 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1604 enum set_key_cmd cmd,
1605 struct ieee80211_vif *vif,
1606 struct ieee80211_sta *sta,
1607 struct ieee80211_key_conf *key)
1609 struct ath9k_htc_priv *priv = hw->priv;
1610 struct ath_common *common = ath9k_hw_common(priv->ah);
1613 if (htc_modparam_nohwcrypt)
1616 mutex_lock(&priv->mutex);
1617 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1618 ath9k_htc_ps_wakeup(priv);
1622 ret = ath9k_cmn_key_config(common, vif, sta, key);
1624 key->hw_key_idx = ret;
1625 /* push IV and Michael MIC generation to stack */
1626 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1627 if (key->alg == ALG_TKIP)
1628 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1629 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1630 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1635 ath9k_cmn_key_delete(common, key);
1641 ath9k_htc_ps_restore(priv);
1642 mutex_unlock(&priv->mutex);
1647 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1648 struct ieee80211_vif *vif,
1649 struct ieee80211_bss_conf *bss_conf,
1652 struct ath9k_htc_priv *priv = hw->priv;
1653 struct ath_hw *ah = priv->ah;
1654 struct ath_common *common = ath9k_hw_common(ah);
1656 mutex_lock(&priv->mutex);
1657 ath9k_htc_ps_wakeup(priv);
1659 if (changed & BSS_CHANGED_ASSOC) {
1660 common->curaid = bss_conf->assoc ?
1662 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1665 if (bss_conf->assoc) {
1666 priv->op_flags |= OP_ASSOCIATED;
1667 ath_start_ani(priv);
1669 priv->op_flags &= ~OP_ASSOCIATED;
1670 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1674 if (changed & BSS_CHANGED_BSSID) {
1676 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1677 ath9k_hw_write_associd(ah);
1679 ath_print(common, ATH_DBG_CONFIG,
1680 "BSSID: %pM aid: 0x%x\n",
1681 common->curbssid, common->curaid);
1684 if ((changed & BSS_CHANGED_BEACON_INT) ||
1685 (changed & BSS_CHANGED_BEACON) ||
1686 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1687 bss_conf->enable_beacon)) {
1688 priv->op_flags |= OP_ENABLE_BEACON;
1689 ath9k_htc_beacon_config(priv, vif);
1692 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1693 !bss_conf->enable_beacon) {
1694 priv->op_flags &= ~OP_ENABLE_BEACON;
1695 ath9k_htc_beacon_config(priv, vif);
1698 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1699 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1700 bss_conf->use_short_preamble);
1701 if (bss_conf->use_short_preamble)
1702 priv->op_flags |= OP_PREAMBLE_SHORT;
1704 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1707 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1708 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1709 bss_conf->use_cts_prot);
1710 if (bss_conf->use_cts_prot &&
1711 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1712 priv->op_flags |= OP_PROTECT_ENABLE;
1714 priv->op_flags &= ~OP_PROTECT_ENABLE;
1717 if (changed & BSS_CHANGED_ERP_SLOT) {
1718 if (bss_conf->use_short_slot)
1723 ath9k_hw_init_global_settings(ah);
1726 if (changed & BSS_CHANGED_HT)
1727 ath9k_htc_update_rate(priv, vif, bss_conf);
1729 ath9k_htc_ps_restore(priv);
1730 mutex_unlock(&priv->mutex);
1733 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1735 struct ath9k_htc_priv *priv = hw->priv;
1738 mutex_lock(&priv->mutex);
1739 ath9k_htc_ps_wakeup(priv);
1740 tsf = ath9k_hw_gettsf64(priv->ah);
1741 ath9k_htc_ps_restore(priv);
1742 mutex_unlock(&priv->mutex);
1747 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1749 struct ath9k_htc_priv *priv = hw->priv;
1751 mutex_lock(&priv->mutex);
1752 ath9k_htc_ps_wakeup(priv);
1753 ath9k_hw_settsf64(priv->ah, tsf);
1754 ath9k_htc_ps_restore(priv);
1755 mutex_unlock(&priv->mutex);
1758 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1760 struct ath9k_htc_priv *priv = hw->priv;
1762 mutex_lock(&priv->mutex);
1763 ath9k_htc_ps_wakeup(priv);
1764 ath9k_hw_reset_tsf(priv->ah);
1765 ath9k_htc_ps_restore(priv);
1766 mutex_unlock(&priv->mutex);
1769 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1770 struct ieee80211_vif *vif,
1771 enum ieee80211_ampdu_mlme_action action,
1772 struct ieee80211_sta *sta,
1775 struct ath9k_htc_priv *priv = hw->priv;
1776 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1777 struct ath9k_htc_sta *ista;
1780 case IEEE80211_AMPDU_RX_START:
1782 case IEEE80211_AMPDU_RX_STOP:
1784 case IEEE80211_AMPDU_TX_START:
1785 case IEEE80211_AMPDU_TX_STOP:
1786 if (!(priv->op_flags & OP_TXAGGR))
1788 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1791 work->action = action;
1793 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1795 case IEEE80211_AMPDU_TX_OPERATIONAL:
1796 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1797 ista->tid_state[tid] = AGGR_OPERATIONAL;
1800 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1801 "Unknown AMPDU action\n");
1807 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1809 struct ath9k_htc_priv *priv = hw->priv;
1811 mutex_lock(&priv->mutex);
1812 spin_lock_bh(&priv->beacon_lock);
1813 priv->op_flags |= OP_SCANNING;
1814 spin_unlock_bh(&priv->beacon_lock);
1815 cancel_work_sync(&priv->ps_work);
1816 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1817 mutex_unlock(&priv->mutex);
1820 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1822 struct ath9k_htc_priv *priv = hw->priv;
1824 mutex_lock(&priv->mutex);
1825 ath9k_htc_ps_wakeup(priv);
1826 spin_lock_bh(&priv->beacon_lock);
1827 priv->op_flags &= ~OP_SCANNING;
1828 spin_unlock_bh(&priv->beacon_lock);
1829 priv->op_flags |= OP_FULL_RESET;
1830 if (priv->op_flags & OP_ASSOCIATED)
1831 ath9k_htc_beacon_config(priv, priv->vif);
1832 ath_start_ani(priv);
1833 ath9k_htc_ps_restore(priv);
1834 mutex_unlock(&priv->mutex);
1837 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1842 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1845 struct ath9k_htc_priv *priv = hw->priv;
1847 mutex_lock(&priv->mutex);
1848 ath9k_htc_ps_wakeup(priv);
1849 priv->ah->coverage_class = coverage_class;
1850 ath9k_hw_init_global_settings(priv->ah);
1851 ath9k_htc_ps_restore(priv);
1852 mutex_unlock(&priv->mutex);
1855 struct ieee80211_ops ath9k_htc_ops = {
1857 .start = ath9k_htc_start,
1858 .stop = ath9k_htc_stop,
1859 .add_interface = ath9k_htc_add_interface,
1860 .remove_interface = ath9k_htc_remove_interface,
1861 .config = ath9k_htc_config,
1862 .configure_filter = ath9k_htc_configure_filter,
1863 .sta_add = ath9k_htc_sta_add,
1864 .sta_remove = ath9k_htc_sta_remove,
1865 .conf_tx = ath9k_htc_conf_tx,
1866 .bss_info_changed = ath9k_htc_bss_info_changed,
1867 .set_key = ath9k_htc_set_key,
1868 .get_tsf = ath9k_htc_get_tsf,
1869 .set_tsf = ath9k_htc_set_tsf,
1870 .reset_tsf = ath9k_htc_reset_tsf,
1871 .ampdu_action = ath9k_htc_ampdu_action,
1872 .sw_scan_start = ath9k_htc_sw_scan_start,
1873 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1874 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1875 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1876 .set_coverage_class = ath9k_htc_set_coverage_class,