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 = 1;
330 tcap.tx_chainmask = 1;
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 (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
369 caps |= WLAN_RC_40_FLAG;
370 if (conf_is_ht40(&priv->hw->conf) &&
371 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
372 caps |= WLAN_RC_SGI_FLAG;
373 else if (conf_is_ht20(&priv->hw->conf) &&
374 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
375 caps |= WLAN_RC_SGI_FLAG;
378 trate->sta_index = ista->index;
380 trate->capflags = cpu_to_be32(caps);
383 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
384 struct ath9k_htc_target_rate *trate)
386 struct ath_common *common = ath9k_hw_common(priv->ah);
390 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
392 ath_print(common, ATH_DBG_FATAL,
393 "Unable to initialize Rate information on target\n");
399 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
400 struct ieee80211_sta *sta)
402 struct ath_common *common = ath9k_hw_common(priv->ah);
403 struct ath9k_htc_target_rate trate;
406 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
407 ath9k_htc_setup_rate(priv, sta, &trate);
408 ret = ath9k_htc_send_rate_cmd(priv, &trate);
410 ath_print(common, ATH_DBG_CONFIG,
411 "Updated target sta: %pM, rate caps: 0x%X\n",
412 sta->addr, be32_to_cpu(trate.capflags));
415 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
416 struct ieee80211_vif *vif,
417 struct ieee80211_bss_conf *bss_conf)
419 struct ath_common *common = ath9k_hw_common(priv->ah);
420 struct ath9k_htc_target_rate trate;
421 struct ieee80211_sta *sta;
424 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
427 sta = ieee80211_find_sta(vif, bss_conf->bssid);
432 ath9k_htc_setup_rate(priv, sta, &trate);
435 ret = ath9k_htc_send_rate_cmd(priv, &trate);
437 ath_print(common, ATH_DBG_CONFIG,
438 "Updated target sta: %pM, rate caps: 0x%X\n",
439 bss_conf->bssid, be32_to_cpu(trate.capflags));
442 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv *priv,
443 struct ieee80211_vif *vif,
444 u8 *sta_addr, u8 tid, bool oper)
446 struct ath_common *common = ath9k_hw_common(priv->ah);
447 struct ath9k_htc_target_aggr aggr;
448 struct ieee80211_sta *sta = NULL;
449 struct ath9k_htc_sta *ista;
453 if (tid >= ATH9K_HTC_MAX_TID)
456 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
460 /* Check if we are able to retrieve the station */
461 sta = ieee80211_find_sta(vif, sta_addr);
467 ista = (struct ath9k_htc_sta *) sta->drv_priv;
470 ista->tid_state[tid] = AGGR_START;
472 ista->tid_state[tid] = AGGR_STOP;
474 aggr.sta_index = ista->index;
479 aggr.aggr_enable = oper;
481 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
483 ath_print(common, ATH_DBG_CONFIG,
484 "Unable to %s TX aggregation for (%pM, %d)\n",
485 (oper) ? "start" : "stop", sta->addr, tid);
487 ath_print(common, ATH_DBG_CONFIG,
488 "%s aggregation for (%pM, %d)\n",
489 (oper) ? "Starting" : "Stopping", sta->addr, tid);
494 void ath9k_htc_aggr_work(struct work_struct *work)
497 struct ath9k_htc_priv *priv =
498 container_of(work, struct ath9k_htc_priv,
499 ath9k_aggr_work.work);
500 struct ath9k_htc_aggr_work *wk = &priv->aggr_work;
502 mutex_lock(&wk->mutex);
504 switch (wk->action) {
505 case IEEE80211_AMPDU_TX_START:
506 ret = ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
509 ieee80211_start_tx_ba_cb(wk->vif, wk->sta_addr,
512 case IEEE80211_AMPDU_TX_STOP:
513 ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
515 ieee80211_stop_tx_ba_cb(wk->vif, wk->sta_addr, wk->tid);
518 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
519 "Unknown AMPDU action\n");
522 mutex_unlock(&wk->mutex);
529 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
531 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
533 file->private_data = inode->i_private;
537 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
538 size_t count, loff_t *ppos)
540 struct ath9k_htc_priv *priv =
541 (struct ath9k_htc_priv *) file->private_data;
542 struct ath9k_htc_target_stats cmd_rsp;
544 unsigned int len = 0;
547 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
549 WMI_CMD(WMI_TGT_STATS_CMDID);
554 len += snprintf(buf + len, sizeof(buf) - len,
555 "%19s : %10u\n", "TX Short Retries",
556 be32_to_cpu(cmd_rsp.tx_shortretry));
557 len += snprintf(buf + len, sizeof(buf) - len,
558 "%19s : %10u\n", "TX Long Retries",
559 be32_to_cpu(cmd_rsp.tx_longretry));
560 len += snprintf(buf + len, sizeof(buf) - len,
561 "%19s : %10u\n", "TX Xretries",
562 be32_to_cpu(cmd_rsp.tx_xretries));
563 len += snprintf(buf + len, sizeof(buf) - len,
564 "%19s : %10u\n", "TX Unaggr. Xretries",
565 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
566 len += snprintf(buf + len, sizeof(buf) - len,
567 "%19s : %10u\n", "TX Xretries (HT)",
568 be32_to_cpu(cmd_rsp.ht_tx_xretries));
569 len += snprintf(buf + len, sizeof(buf) - len,
570 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
572 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
575 static const struct file_operations fops_tgt_stats = {
576 .read = read_file_tgt_stats,
577 .open = ath9k_debugfs_open,
581 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
582 size_t count, loff_t *ppos)
584 struct ath9k_htc_priv *priv =
585 (struct ath9k_htc_priv *) file->private_data;
587 unsigned int len = 0;
589 len += snprintf(buf + len, sizeof(buf) - len,
590 "%20s : %10u\n", "Buffers queued",
591 priv->debug.tx_stats.buf_queued);
592 len += snprintf(buf + len, sizeof(buf) - len,
593 "%20s : %10u\n", "Buffers completed",
594 priv->debug.tx_stats.buf_completed);
595 len += snprintf(buf + len, sizeof(buf) - len,
596 "%20s : %10u\n", "SKBs queued",
597 priv->debug.tx_stats.skb_queued);
598 len += snprintf(buf + len, sizeof(buf) - len,
599 "%20s : %10u\n", "SKBs completed",
600 priv->debug.tx_stats.skb_completed);
601 len += snprintf(buf + len, sizeof(buf) - len,
602 "%20s : %10u\n", "SKBs dropped",
603 priv->debug.tx_stats.skb_dropped);
605 len += snprintf(buf + len, sizeof(buf) - len,
606 "%20s : %10u\n", "BE queued",
607 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
608 len += snprintf(buf + len, sizeof(buf) - len,
609 "%20s : %10u\n", "BK queued",
610 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
611 len += snprintf(buf + len, sizeof(buf) - len,
612 "%20s : %10u\n", "VI queued",
613 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
614 len += snprintf(buf + len, sizeof(buf) - len,
615 "%20s : %10u\n", "VO queued",
616 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
618 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
621 static const struct file_operations fops_xmit = {
622 .read = read_file_xmit,
623 .open = ath9k_debugfs_open,
627 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
628 size_t count, loff_t *ppos)
630 struct ath9k_htc_priv *priv =
631 (struct ath9k_htc_priv *) file->private_data;
633 unsigned int len = 0;
635 len += snprintf(buf + len, sizeof(buf) - len,
636 "%20s : %10u\n", "SKBs allocated",
637 priv->debug.rx_stats.skb_allocated);
638 len += snprintf(buf + len, sizeof(buf) - len,
639 "%20s : %10u\n", "SKBs completed",
640 priv->debug.rx_stats.skb_completed);
641 len += snprintf(buf + len, sizeof(buf) - len,
642 "%20s : %10u\n", "SKBs Dropped",
643 priv->debug.rx_stats.skb_dropped);
645 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
648 static const struct file_operations fops_recv = {
649 .read = read_file_recv,
650 .open = ath9k_debugfs_open,
654 int ath9k_htc_init_debug(struct ath_hw *ah)
656 struct ath_common *common = ath9k_hw_common(ah);
657 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
659 if (!ath9k_debugfs_root)
662 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
664 if (!priv->debug.debugfs_phy)
667 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
668 priv->debug.debugfs_phy,
669 priv, &fops_tgt_stats);
670 if (!priv->debug.debugfs_tgt_stats)
674 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
675 priv->debug.debugfs_phy,
677 if (!priv->debug.debugfs_xmit)
680 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
681 priv->debug.debugfs_phy,
683 if (!priv->debug.debugfs_recv)
689 ath9k_htc_exit_debug(ah);
693 void ath9k_htc_exit_debug(struct ath_hw *ah)
695 struct ath_common *common = ath9k_hw_common(ah);
696 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
698 debugfs_remove(priv->debug.debugfs_recv);
699 debugfs_remove(priv->debug.debugfs_xmit);
700 debugfs_remove(priv->debug.debugfs_tgt_stats);
701 debugfs_remove(priv->debug.debugfs_phy);
704 int ath9k_htc_debug_create_root(void)
706 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
707 if (!ath9k_debugfs_root)
713 void ath9k_htc_debug_remove_root(void)
715 debugfs_remove(ath9k_debugfs_root);
716 ath9k_debugfs_root = NULL;
719 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
725 static void ath_start_ani(struct ath9k_htc_priv *priv)
727 struct ath_common *common = ath9k_hw_common(priv->ah);
728 unsigned long timestamp = jiffies_to_msecs(jiffies);
730 common->ani.longcal_timer = timestamp;
731 common->ani.shortcal_timer = timestamp;
732 common->ani.checkani_timer = timestamp;
734 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
735 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
738 void ath9k_ani_work(struct work_struct *work)
740 struct ath9k_htc_priv *priv =
741 container_of(work, struct ath9k_htc_priv,
742 ath9k_ani_work.work);
743 struct ath_hw *ah = priv->ah;
744 struct ath_common *common = ath9k_hw_common(ah);
745 bool longcal = false;
746 bool shortcal = false;
747 bool aniflag = false;
748 unsigned int timestamp = jiffies_to_msecs(jiffies);
749 u32 cal_interval, short_cal_interval;
751 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
753 /* Only calibrate if awake */
754 if (ah->power_mode != ATH9K_PM_AWAKE)
757 /* Long calibration runs independently of short calibration. */
758 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
760 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
761 common->ani.longcal_timer = timestamp;
764 /* Short calibration applies only while caldone is false */
765 if (!common->ani.caldone) {
766 if ((timestamp - common->ani.shortcal_timer) >=
767 short_cal_interval) {
769 ath_print(common, ATH_DBG_ANI,
770 "shortcal @%lu\n", jiffies);
771 common->ani.shortcal_timer = timestamp;
772 common->ani.resetcal_timer = timestamp;
775 if ((timestamp - common->ani.resetcal_timer) >=
776 ATH_RESTART_CALINTERVAL) {
777 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
778 if (common->ani.caldone)
779 common->ani.resetcal_timer = timestamp;
783 /* Verify whether we must check ANI */
784 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
786 common->ani.checkani_timer = timestamp;
789 /* Skip all processing if there's nothing to do. */
790 if (longcal || shortcal || aniflag) {
792 ath9k_htc_ps_wakeup(priv);
794 /* Call ANI routine if necessary */
796 ath9k_hw_ani_monitor(ah, ah->curchan);
798 /* Perform calibration if necessary */
799 if (longcal || shortcal) {
800 common->ani.caldone =
801 ath9k_hw_calibrate(ah, ah->curchan,
802 common->rx_chainmask,
806 common->ani.noise_floor =
807 ath9k_hw_getchan_noise(ah, ah->curchan);
809 ath_print(common, ATH_DBG_ANI,
810 " calibrate chan %u/%x nf: %d\n",
811 ah->curchan->channel,
812 ah->curchan->channelFlags,
813 common->ani.noise_floor);
816 ath9k_htc_ps_restore(priv);
821 * Set timer interval based on previous results.
822 * The interval must be the shortest necessary to satisfy ANI,
823 * short calibration and long calibration.
825 cal_interval = ATH_LONG_CALINTERVAL;
826 if (priv->ah->config.enable_ani)
827 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
828 if (!common->ani.caldone)
829 cal_interval = min(cal_interval, (u32)short_cal_interval);
831 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
832 msecs_to_jiffies(cal_interval));
839 static void ath9k_led_blink_work(struct work_struct *work)
841 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
842 ath9k_led_blink_work.work);
844 if (!(priv->op_flags & OP_LED_ASSOCIATED))
847 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
848 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
849 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
851 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
852 (priv->op_flags & OP_LED_ON) ? 1 : 0);
854 ieee80211_queue_delayed_work(priv->hw,
855 &priv->ath9k_led_blink_work,
856 (priv->op_flags & OP_LED_ON) ?
857 msecs_to_jiffies(priv->led_off_duration) :
858 msecs_to_jiffies(priv->led_on_duration));
860 priv->led_on_duration = priv->led_on_cnt ?
861 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
862 ATH_LED_ON_DURATION_IDLE;
863 priv->led_off_duration = priv->led_off_cnt ?
864 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
865 ATH_LED_OFF_DURATION_IDLE;
866 priv->led_on_cnt = priv->led_off_cnt = 0;
868 if (priv->op_flags & OP_LED_ON)
869 priv->op_flags &= ~OP_LED_ON;
871 priv->op_flags |= OP_LED_ON;
874 static void ath9k_led_brightness_work(struct work_struct *work)
876 struct ath_led *led = container_of(work, struct ath_led,
877 brightness_work.work);
878 struct ath9k_htc_priv *priv = led->priv;
880 switch (led->brightness) {
882 if (led->led_type == ATH_LED_ASSOC ||
883 led->led_type == ATH_LED_RADIO) {
884 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
885 (led->led_type == ATH_LED_RADIO));
886 priv->op_flags &= ~OP_LED_ASSOCIATED;
887 if (led->led_type == ATH_LED_RADIO)
888 priv->op_flags &= ~OP_LED_ON;
894 if (led->led_type == ATH_LED_ASSOC) {
895 priv->op_flags |= OP_LED_ASSOCIATED;
896 ieee80211_queue_delayed_work(priv->hw,
897 &priv->ath9k_led_blink_work, 0);
898 } else if (led->led_type == ATH_LED_RADIO) {
899 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
900 priv->op_flags |= OP_LED_ON;
910 static void ath9k_led_brightness(struct led_classdev *led_cdev,
911 enum led_brightness brightness)
913 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
914 struct ath9k_htc_priv *priv = led->priv;
916 led->brightness = brightness;
917 if (!(priv->op_flags & OP_LED_DEINIT))
918 ieee80211_queue_delayed_work(priv->hw,
919 &led->brightness_work, 0);
922 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
924 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
925 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
926 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
927 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
930 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
936 led->led_cdev.name = led->name;
937 led->led_cdev.default_trigger = trigger;
938 led->led_cdev.brightness_set = ath9k_led_brightness;
940 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
942 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
943 "Failed to register led:%s", led->name);
947 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
952 static void ath9k_unregister_led(struct ath_led *led)
954 if (led->registered) {
955 led_classdev_unregister(&led->led_cdev);
960 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
962 priv->op_flags |= OP_LED_DEINIT;
963 ath9k_unregister_led(&priv->assoc_led);
964 priv->op_flags &= ~OP_LED_ASSOCIATED;
965 ath9k_unregister_led(&priv->tx_led);
966 ath9k_unregister_led(&priv->rx_led);
967 ath9k_unregister_led(&priv->radio_led);
970 void ath9k_init_leds(struct ath9k_htc_priv *priv)
975 if (AR_SREV_9287(priv->ah))
976 priv->ah->led_pin = ATH_LED_PIN_9287;
977 else if (AR_SREV_9271(priv->ah))
978 priv->ah->led_pin = ATH_LED_PIN_9271;
980 priv->ah->led_pin = ATH_LED_PIN_DEF;
982 /* Configure gpio 1 for output */
983 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
984 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
985 /* LED off, active low */
986 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
988 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
990 trigger = ieee80211_get_radio_led_name(priv->hw);
991 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
992 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
993 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
994 priv->radio_led.led_type = ATH_LED_RADIO;
998 trigger = ieee80211_get_assoc_led_name(priv->hw);
999 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
1000 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
1001 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
1002 priv->assoc_led.led_type = ATH_LED_ASSOC;
1006 trigger = ieee80211_get_tx_led_name(priv->hw);
1007 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
1008 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
1009 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
1010 priv->tx_led.led_type = ATH_LED_TX;
1014 trigger = ieee80211_get_rx_led_name(priv->hw);
1015 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
1016 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
1017 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
1018 priv->rx_led.led_type = ATH_LED_RX;
1022 priv->op_flags &= ~OP_LED_DEINIT;
1027 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1028 ath9k_deinit_leds(priv);
1031 /*******************/
1033 /*******************/
1035 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1037 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1038 priv->ah->rfkill_polarity;
1041 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1043 struct ath9k_htc_priv *priv = hw->priv;
1044 bool blocked = !!ath_is_rfkill_set(priv);
1046 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1049 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1051 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1052 wiphy_rfkill_start_polling(priv->hw->wiphy);
1055 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1057 struct ath9k_htc_priv *priv = hw->priv;
1058 struct ath_hw *ah = priv->ah;
1059 struct ath_common *common = ath9k_hw_common(ah);
1064 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1067 ret = ath9k_hw_reset(ah, ah->curchan, false);
1069 ath_print(common, ATH_DBG_FATAL,
1070 "Unable to reset hardware; reset status %d "
1071 "(freq %u MHz)\n", ret, ah->curchan->channel);
1074 ath_update_txpow(priv);
1077 WMI_CMD(WMI_START_RECV_CMDID);
1078 ath9k_host_rx_init(priv);
1081 htc_start(priv->htc);
1082 spin_lock_bh(&priv->tx_lock);
1083 priv->tx_queues_stop = false;
1084 spin_unlock_bh(&priv->tx_lock);
1085 ieee80211_wake_queues(hw);
1087 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1090 ath9k_hw_cfg_output(ah, ah->led_pin,
1091 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1092 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1095 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1097 struct ath9k_htc_priv *priv = hw->priv;
1098 struct ath_hw *ah = priv->ah;
1099 struct ath_common *common = ath9k_hw_common(ah);
1103 ath9k_htc_ps_wakeup(priv);
1106 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1107 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1109 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1112 ieee80211_stop_queues(hw);
1113 htc_stop(priv->htc);
1114 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1115 skb_queue_purge(&priv->tx_queue);
1118 WMI_CMD(WMI_STOP_RECV_CMDID);
1121 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1124 ret = ath9k_hw_reset(ah, ah->curchan, false);
1126 ath_print(common, ATH_DBG_FATAL,
1127 "Unable to reset hardware; reset status %d "
1128 "(freq %u MHz)\n", ret, ah->curchan->channel);
1131 /* Disable the PHY */
1132 ath9k_hw_phy_disable(ah);
1134 ath9k_htc_ps_restore(priv);
1135 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1138 /**********************/
1139 /* mac80211 Callbacks */
1140 /**********************/
1142 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1144 struct ieee80211_hdr *hdr;
1145 struct ath9k_htc_priv *priv = hw->priv;
1146 int padpos, padsize, ret;
1148 hdr = (struct ieee80211_hdr *) skb->data;
1150 /* Add the padding after the header if this is not already done */
1151 padpos = ath9k_cmn_padpos(hdr->frame_control);
1152 padsize = padpos & 3;
1153 if (padsize && skb->len > padpos) {
1154 if (skb_headroom(skb) < padsize)
1156 skb_push(skb, padsize);
1157 memmove(skb->data, skb->data + padsize, padpos);
1160 ret = ath9k_htc_tx_start(priv, skb);
1162 if (ret == -ENOMEM) {
1163 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1164 "Stopping TX queues\n");
1165 ieee80211_stop_queues(hw);
1166 spin_lock_bh(&priv->tx_lock);
1167 priv->tx_queues_stop = true;
1168 spin_unlock_bh(&priv->tx_lock);
1170 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1179 dev_kfree_skb_any(skb);
1183 static int ath9k_htc_start(struct ieee80211_hw *hw)
1185 struct ath9k_htc_priv *priv = hw->priv;
1186 struct ath_hw *ah = priv->ah;
1187 struct ath_common *common = ath9k_hw_common(ah);
1188 struct ieee80211_channel *curchan = hw->conf.channel;
1189 struct ath9k_channel *init_channel;
1191 enum htc_phymode mode;
1195 mutex_lock(&priv->mutex);
1197 ath_print(common, ATH_DBG_CONFIG,
1198 "Starting driver with initial channel: %d MHz\n",
1199 curchan->center_freq);
1201 /* setup initial channel */
1202 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1204 /* Reset SERDES registers */
1205 ath9k_hw_configpcipowersave(ah, 0, 0);
1207 ath9k_hw_htc_resetinit(ah);
1208 ret = ath9k_hw_reset(ah, init_channel, false);
1210 ath_print(common, ATH_DBG_FATAL,
1211 "Unable to reset hardware; reset status %d "
1212 "(freq %u MHz)\n", ret, curchan->center_freq);
1213 mutex_unlock(&priv->mutex);
1217 ath_update_txpow(priv);
1219 mode = ath9k_htc_get_curmode(priv, init_channel);
1220 htc_mode = cpu_to_be16(mode);
1221 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1222 WMI_CMD(WMI_ATH_INIT_CMDID);
1223 WMI_CMD(WMI_START_RECV_CMDID);
1225 ath9k_host_rx_init(priv);
1227 priv->op_flags &= ~OP_INVALID;
1228 htc_start(priv->htc);
1230 spin_lock_bh(&priv->tx_lock);
1231 priv->tx_queues_stop = false;
1232 spin_unlock_bh(&priv->tx_lock);
1234 ieee80211_wake_queues(hw);
1236 mutex_unlock(&priv->mutex);
1241 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1243 struct ath9k_htc_priv *priv = hw->priv;
1244 struct ath_hw *ah = priv->ah;
1245 struct ath_common *common = ath9k_hw_common(ah);
1249 mutex_lock(&priv->mutex);
1251 if (priv->op_flags & OP_INVALID) {
1252 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1253 mutex_unlock(&priv->mutex);
1257 /* Cancel all the running timers/work .. */
1258 cancel_work_sync(&priv->ps_work);
1259 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1260 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1261 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1262 ath9k_led_stop_brightness(priv);
1264 ath9k_htc_ps_wakeup(priv);
1265 htc_stop(priv->htc);
1266 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1267 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1268 WMI_CMD(WMI_STOP_RECV_CMDID);
1269 ath9k_hw_phy_disable(ah);
1270 ath9k_hw_disable(ah);
1271 ath9k_hw_configpcipowersave(ah, 1, 1);
1272 ath9k_htc_ps_restore(priv);
1273 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1275 skb_queue_purge(&priv->tx_queue);
1277 /* Remove monitor interface here */
1278 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1279 if (ath9k_htc_remove_monitor_interface(priv))
1280 ath_print(common, ATH_DBG_FATAL,
1281 "Unable to remove monitor interface\n");
1283 ath_print(common, ATH_DBG_CONFIG,
1284 "Monitor interface removed\n");
1287 priv->op_flags |= OP_INVALID;
1289 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1290 mutex_unlock(&priv->mutex);
1293 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1294 struct ieee80211_vif *vif)
1296 struct ath9k_htc_priv *priv = hw->priv;
1297 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1298 struct ath_common *common = ath9k_hw_common(priv->ah);
1299 struct ath9k_htc_target_vif hvif;
1303 mutex_lock(&priv->mutex);
1305 /* Only one interface for now */
1306 if (priv->nvifs > 0) {
1311 ath9k_htc_ps_wakeup(priv);
1312 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1313 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1315 switch (vif->type) {
1316 case NL80211_IFTYPE_STATION:
1317 hvif.opmode = cpu_to_be32(HTC_M_STA);
1319 case NL80211_IFTYPE_ADHOC:
1320 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1323 ath_print(common, ATH_DBG_FATAL,
1324 "Interface type %d not yet supported\n", vif->type);
1329 ath_print(common, ATH_DBG_CONFIG,
1330 "Attach a VIF of type: %d\n", vif->type);
1332 priv->ah->opmode = vif->type;
1334 /* Index starts from zero on the target */
1335 avp->index = hvif.index = priv->nvifs;
1336 hvif.rtsthreshold = cpu_to_be16(2304);
1337 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1344 * We need a node in target to tx mgmt frames
1345 * before association.
1347 ret = ath9k_htc_add_station(priv, vif, NULL);
1351 ret = ath9k_htc_update_cap_target(priv);
1353 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1354 " capability in target \n");
1358 ath9k_htc_ps_restore(priv);
1359 mutex_unlock(&priv->mutex);
1364 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1365 struct ieee80211_vif *vif)
1367 struct ath9k_htc_priv *priv = hw->priv;
1368 struct ath_common *common = ath9k_hw_common(priv->ah);
1369 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1370 struct ath9k_htc_target_vif hvif;
1374 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1376 mutex_lock(&priv->mutex);
1377 ath9k_htc_ps_wakeup(priv);
1379 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1380 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1381 hvif.index = avp->index;
1382 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1385 ath9k_htc_remove_station(priv, vif, NULL);
1388 ath9k_htc_ps_restore(priv);
1389 mutex_unlock(&priv->mutex);
1392 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1394 struct ath9k_htc_priv *priv = hw->priv;
1395 struct ath_common *common = ath9k_hw_common(priv->ah);
1396 struct ieee80211_conf *conf = &hw->conf;
1398 mutex_lock(&priv->mutex);
1400 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1401 bool enable_radio = false;
1402 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1404 if (!idle && priv->ps_idle)
1405 enable_radio = true;
1407 priv->ps_idle = idle;
1410 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1411 ath9k_htc_radio_enable(hw);
1412 ath_print(common, ATH_DBG_CONFIG,
1413 "not-idle: enabling radio\n");
1417 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1418 struct ieee80211_channel *curchan = hw->conf.channel;
1419 int pos = curchan->hw_value;
1421 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1422 curchan->center_freq);
1424 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1426 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1427 ath_print(common, ATH_DBG_FATAL,
1428 "Unable to set channel\n");
1429 mutex_unlock(&priv->mutex);
1434 if (changed & IEEE80211_CONF_CHANGE_PS) {
1435 if (conf->flags & IEEE80211_CONF_PS) {
1436 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1437 priv->ps_enabled = true;
1439 priv->ps_enabled = false;
1440 cancel_work_sync(&priv->ps_work);
1441 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1445 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1446 if (conf->flags & IEEE80211_CONF_MONITOR) {
1447 if (ath9k_htc_add_monitor_interface(priv))
1448 ath_print(common, ATH_DBG_FATAL,
1449 "Failed to set monitor mode\n");
1451 ath_print(common, ATH_DBG_CONFIG,
1452 "HW opmode set to Monitor mode\n");
1456 if (priv->ps_idle) {
1457 ath_print(common, ATH_DBG_CONFIG,
1458 "idle: disabling radio\n");
1459 ath9k_htc_radio_disable(hw);
1462 mutex_unlock(&priv->mutex);
1467 #define SUPPORTED_FILTERS \
1468 (FIF_PROMISC_IN_BSS | \
1473 FIF_BCN_PRBRESP_PROMISC | \
1476 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1477 unsigned int changed_flags,
1478 unsigned int *total_flags,
1481 struct ath9k_htc_priv *priv = hw->priv;
1484 mutex_lock(&priv->mutex);
1485 ath9k_htc_ps_wakeup(priv);
1487 changed_flags &= SUPPORTED_FILTERS;
1488 *total_flags &= SUPPORTED_FILTERS;
1490 priv->rxfilter = *total_flags;
1491 rfilt = ath9k_htc_calcrxfilter(priv);
1492 ath9k_hw_setrxfilter(priv->ah, rfilt);
1494 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1495 "Set HW RX filter: 0x%x\n", rfilt);
1497 ath9k_htc_ps_restore(priv);
1498 mutex_unlock(&priv->mutex);
1501 static void ath9k_htc_sta_notify(struct ieee80211_hw *hw,
1502 struct ieee80211_vif *vif,
1503 enum sta_notify_cmd cmd,
1504 struct ieee80211_sta *sta)
1506 struct ath9k_htc_priv *priv = hw->priv;
1509 mutex_lock(&priv->mutex);
1510 ath9k_htc_ps_wakeup(priv);
1513 case STA_NOTIFY_ADD:
1514 ret = ath9k_htc_add_station(priv, vif, sta);
1516 ath9k_htc_init_rate(priv, sta);
1518 case STA_NOTIFY_REMOVE:
1519 ath9k_htc_remove_station(priv, vif, sta);
1525 ath9k_htc_ps_restore(priv);
1526 mutex_unlock(&priv->mutex);
1529 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1530 const struct ieee80211_tx_queue_params *params)
1532 struct ath9k_htc_priv *priv = hw->priv;
1533 struct ath_common *common = ath9k_hw_common(priv->ah);
1534 struct ath9k_tx_queue_info qi;
1537 if (queue >= WME_NUM_AC)
1540 mutex_lock(&priv->mutex);
1541 ath9k_htc_ps_wakeup(priv);
1543 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1545 qi.tqi_aifs = params->aifs;
1546 qi.tqi_cwmin = params->cw_min;
1547 qi.tqi_cwmax = params->cw_max;
1548 qi.tqi_burstTime = params->txop;
1550 qnum = get_hw_qnum(queue, priv->hwq_map);
1552 ath_print(common, ATH_DBG_CONFIG,
1553 "Configure tx [queue/hwq] [%d/%d], "
1554 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1555 queue, qnum, params->aifs, params->cw_min,
1556 params->cw_max, params->txop);
1558 ret = ath_htc_txq_update(priv, qnum, &qi);
1560 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1562 ath9k_htc_ps_restore(priv);
1563 mutex_unlock(&priv->mutex);
1568 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1569 enum set_key_cmd cmd,
1570 struct ieee80211_vif *vif,
1571 struct ieee80211_sta *sta,
1572 struct ieee80211_key_conf *key)
1574 struct ath9k_htc_priv *priv = hw->priv;
1575 struct ath_common *common = ath9k_hw_common(priv->ah);
1578 if (htc_modparam_nohwcrypt)
1581 mutex_lock(&priv->mutex);
1582 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1583 ath9k_htc_ps_wakeup(priv);
1587 ret = ath9k_cmn_key_config(common, vif, sta, key);
1589 key->hw_key_idx = ret;
1590 /* push IV and Michael MIC generation to stack */
1591 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1592 if (key->alg == ALG_TKIP)
1593 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1594 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1595 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1600 ath9k_cmn_key_delete(common, key);
1606 ath9k_htc_ps_restore(priv);
1607 mutex_unlock(&priv->mutex);
1612 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1613 struct ieee80211_vif *vif,
1614 struct ieee80211_bss_conf *bss_conf,
1617 struct ath9k_htc_priv *priv = hw->priv;
1618 struct ath_hw *ah = priv->ah;
1619 struct ath_common *common = ath9k_hw_common(ah);
1621 mutex_lock(&priv->mutex);
1622 ath9k_htc_ps_wakeup(priv);
1624 if (changed & BSS_CHANGED_ASSOC) {
1625 common->curaid = bss_conf->assoc ?
1627 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1630 if (bss_conf->assoc) {
1631 priv->op_flags |= OP_ASSOCIATED;
1632 ath_start_ani(priv);
1634 priv->op_flags &= ~OP_ASSOCIATED;
1635 cancel_work_sync(&priv->ps_work);
1636 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1640 if (changed & BSS_CHANGED_BSSID) {
1642 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1643 ath9k_hw_write_associd(ah);
1645 ath_print(common, ATH_DBG_CONFIG,
1646 "BSSID: %pM aid: 0x%x\n",
1647 common->curbssid, common->curaid);
1650 if ((changed & BSS_CHANGED_BEACON_INT) ||
1651 (changed & BSS_CHANGED_BEACON) ||
1652 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1653 bss_conf->enable_beacon)) {
1654 priv->op_flags |= OP_ENABLE_BEACON;
1655 ath9k_htc_beacon_config(priv, vif);
1658 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1659 !bss_conf->enable_beacon) {
1660 priv->op_flags &= ~OP_ENABLE_BEACON;
1661 ath9k_htc_beacon_config(priv, vif);
1664 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1665 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1666 bss_conf->use_short_preamble);
1667 if (bss_conf->use_short_preamble)
1668 priv->op_flags |= OP_PREAMBLE_SHORT;
1670 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1673 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1674 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1675 bss_conf->use_cts_prot);
1676 if (bss_conf->use_cts_prot &&
1677 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1678 priv->op_flags |= OP_PROTECT_ENABLE;
1680 priv->op_flags &= ~OP_PROTECT_ENABLE;
1683 if (changed & BSS_CHANGED_ERP_SLOT) {
1684 if (bss_conf->use_short_slot)
1689 ath9k_hw_init_global_settings(ah);
1692 if (changed & BSS_CHANGED_HT)
1693 ath9k_htc_update_rate(priv, vif, bss_conf);
1695 ath9k_htc_ps_restore(priv);
1696 mutex_unlock(&priv->mutex);
1699 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1701 struct ath9k_htc_priv *priv = hw->priv;
1704 mutex_lock(&priv->mutex);
1705 ath9k_htc_ps_wakeup(priv);
1706 tsf = ath9k_hw_gettsf64(priv->ah);
1707 ath9k_htc_ps_restore(priv);
1708 mutex_unlock(&priv->mutex);
1713 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1715 struct ath9k_htc_priv *priv = hw->priv;
1717 mutex_lock(&priv->mutex);
1718 ath9k_htc_ps_wakeup(priv);
1719 ath9k_hw_settsf64(priv->ah, tsf);
1720 ath9k_htc_ps_restore(priv);
1721 mutex_unlock(&priv->mutex);
1724 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1726 struct ath9k_htc_priv *priv = hw->priv;
1728 mutex_lock(&priv->mutex);
1729 ath9k_htc_ps_wakeup(priv);
1730 ath9k_hw_reset_tsf(priv->ah);
1731 ath9k_htc_ps_restore(priv);
1732 mutex_unlock(&priv->mutex);
1735 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1736 struct ieee80211_vif *vif,
1737 enum ieee80211_ampdu_mlme_action action,
1738 struct ieee80211_sta *sta,
1741 struct ath9k_htc_priv *priv = hw->priv;
1742 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1743 struct ath9k_htc_sta *ista;
1746 case IEEE80211_AMPDU_RX_START:
1748 case IEEE80211_AMPDU_RX_STOP:
1750 case IEEE80211_AMPDU_TX_START:
1751 case IEEE80211_AMPDU_TX_STOP:
1752 if (!(priv->op_flags & OP_TXAGGR))
1754 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1757 work->action = action;
1759 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1761 case IEEE80211_AMPDU_TX_OPERATIONAL:
1762 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1763 ista->tid_state[tid] = AGGR_OPERATIONAL;
1766 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1767 "Unknown AMPDU action\n");
1773 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1775 struct ath9k_htc_priv *priv = hw->priv;
1777 mutex_lock(&priv->mutex);
1778 spin_lock_bh(&priv->beacon_lock);
1779 priv->op_flags |= OP_SCANNING;
1780 spin_unlock_bh(&priv->beacon_lock);
1781 cancel_work_sync(&priv->ps_work);
1782 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1783 mutex_unlock(&priv->mutex);
1786 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1788 struct ath9k_htc_priv *priv = hw->priv;
1790 mutex_lock(&priv->mutex);
1791 ath9k_htc_ps_wakeup(priv);
1792 spin_lock_bh(&priv->beacon_lock);
1793 priv->op_flags &= ~OP_SCANNING;
1794 spin_unlock_bh(&priv->beacon_lock);
1795 priv->op_flags |= OP_FULL_RESET;
1796 if (priv->op_flags & OP_ASSOCIATED)
1797 ath9k_htc_beacon_config(priv, priv->vif);
1798 ath_start_ani(priv);
1799 ath9k_htc_ps_restore(priv);
1800 mutex_unlock(&priv->mutex);
1803 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1808 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1811 struct ath9k_htc_priv *priv = hw->priv;
1813 mutex_lock(&priv->mutex);
1814 ath9k_htc_ps_wakeup(priv);
1815 priv->ah->coverage_class = coverage_class;
1816 ath9k_hw_init_global_settings(priv->ah);
1817 ath9k_htc_ps_restore(priv);
1818 mutex_unlock(&priv->mutex);
1821 struct ieee80211_ops ath9k_htc_ops = {
1823 .start = ath9k_htc_start,
1824 .stop = ath9k_htc_stop,
1825 .add_interface = ath9k_htc_add_interface,
1826 .remove_interface = ath9k_htc_remove_interface,
1827 .config = ath9k_htc_config,
1828 .configure_filter = ath9k_htc_configure_filter,
1829 .sta_notify = ath9k_htc_sta_notify,
1830 .conf_tx = ath9k_htc_conf_tx,
1831 .bss_info_changed = ath9k_htc_bss_info_changed,
1832 .set_key = ath9k_htc_set_key,
1833 .get_tsf = ath9k_htc_get_tsf,
1834 .set_tsf = ath9k_htc_set_tsf,
1835 .reset_tsf = ath9k_htc_reset_tsf,
1836 .ampdu_action = ath9k_htc_ampdu_action,
1837 .sw_scan_start = ath9k_htc_sw_scan_start,
1838 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1839 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1840 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1841 .set_coverage_class = ath9k_htc_set_coverage_class,